03.08.2018, 06:18
You can convert event hex-encoded data to table with bytes like this:
Then you can use bit operations to extract specific bits from bytes:
Code:
hex = event.datahex
bytes = {}
for i = 1, #hex, 2 do
bytes[ #bytes + 1 ] = tonumber(hex:sub(i, i + 1), 16)
end
Then you can use bit operations to extract specific bits from bytes:
Code:
cm = bit.band(bit.rshift(bytes[ 1 ], 4), 0x0F)
hs = bit.band(bytes[ 1 ], 0x0F)
fp = bit.band(bit.rshift(bytes[ 2 ], 6), 0x03)
dp = bit.band(bit.rshift(bytes[ 2 ], 4), 0x03)
pp = bit.band(bit.rshift(bytes[ 2 ], 2), 0x03)
cf = bit.band(bytes[ 2 ], 0x03)