21.09.2018, 09:54
(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,