This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Emergency Light, decoding of status
#2
You can convert event hex-encoded data to table with bytes like this:
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)
Reply


Messages In This Thread
RE: Emergency Light, decoding of status - by admin - 03.08.2018, 06:18

Forum Jump: