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
#3
(03.08.2018, 06:18)admin Wrote: 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)

Hello admin and anyone that may help,

Could you please give me a full example of the script. I would like to have this script in general for anykind of bitset decoding. In my case I need to decode a 1byte message to 8 bits (boolean) and then visualize them so to be able to write a KNX Object or Virtual for each bit. (Please have a look at the attached photo)
But I also have a big project where emergency dali lights are insalled and I would like to be able to decode the status of the converter (1byte and 3bytes) bit by bit.

Regards,

Attached Files Thumbnail(s)
   
Reply


Messages In This Thread
RE: Emergency Light, decoding of status - by manos@dynamitec - 21.09.2018, 09:54

Forum Jump: