Logic Machine Forum
Emergency Light, decoding of status - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Emergency Light, decoding of status (/showthread.php?tid=1511)



Emergency Light, decoding of status - eirik - 02.08.2018

Hello

I've been testing some emergency lights with a KNX/DALI-gateway.
There are two status-objects from each converter: 
- DPT244.600 DALI converter status
- DPT245.600 DALI converter test result
   

In the manual the 2byte and the 6byte object are divided into several results, like converter status, hardware status and so on.
Here are the full explanation on the content of these two objects:
.pdf   DALIBOX Interface Emergency.pdf (Size: 643.53 KB / Downloads: 71)


Anyone made a solution for this in LM5/SL/Wiser??
Or maybe another post on this forum I've overlooked?

I would like to have one GA for each status/result in these objects, but can't get it to work. 
I've managed to get some HEX-value, but somehow the part in the string with 00 get "lost in translation  Confused "
Have been testing with some of the solutions in this forum, but not sure if I understand it right. 

I'm working with a Zennio DALIBOX KNX-gateway at the moment. 

Would appreciate all input on this matter Smile


RE: Emergency Light, decoding of status - admin - 03.08.2018

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)



RE: Emergency Light, decoding of status - manos@dynamitec - 21.09.2018

(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,


RE: Emergency Light, decoding of status - admin - 21.09.2018

Use this event script to get specific bits from an integer value. Make sure to create bit objects manually before running it.
Code:
function getbit(value, nr)
  value = bit.rshift(value, nr)
  return bit.band(value, 1) == 1
end

value = event.getvalue()

grp.checkupdate('1/1/1', getbit(value, 0))
grp.checkupdate('1/1/2', getbit(value, 1))
grp.checkupdate('1/1/3', getbit(value, 2))
grp.checkupdate('1/1/4', getbit(value, 3))
grp.checkupdate('1/1/5', getbit(value, 4))
grp.checkupdate('1/1/6', getbit(value, 5))



RE: Emergency Light, decoding of status - manos@dynamitec - 21.09.2018

(21.09.2018, 10:04)admin Wrote: Use this event script to get specific bits from an integer value. Make sure to create bit objects manually before running it.
Code:
function getbit(value, nr)
 value = bit.rshift(value, nr)
 return bit.band(value, 1) == 1
end

value = event.getvalue()

grp.checkupdate('1/1/1', getbit(value, 0))
grp.checkupdate('1/1/2', getbit(value, 1))
grp.checkupdate('1/1/3', getbit(value, 2))
grp.checkupdate('1/1/4', getbit(value, 3))
grp.checkupdate('1/1/5', getbit(value, 4))
grp.checkupdate('1/1/6', getbit(value, 5))

Thank you for your quick reply. What about decoding 2 or 3 byte objects?  Huh


RE: Emergency Light, decoding of status - admin - 21.09.2018

You can access any value up to 4 bytes the same way. Second argument for getbit function is bit number (starting from 0, up to 31).

You can also access bytes separately by using the code from the first example:
Code:
hex = event.datahex
bytes = {}

for i = 1, #hex, 2 do
  bytes[ #bytes + 1 ] = tonumber(hex:sub(i, i + 1), 16)
end

function getbit(value, nr)
  value = bit.rshift(value, nr)
  return bit.band(value, 1)
end

-- first byte
grp.checkupdate('32/1/1', getbit(bytes[ 1 ], 0))
grp.checkupdate('32/1/2', getbit(bytes[ 1 ], 1))
grp.checkupdate('32/1/3', getbit(bytes[ 1 ], 2))
grp.checkupdate('32/1/4', getbit(bytes[ 1 ], 3))
grp.checkupdate('32/1/5', getbit(bytes[ 1 ], 4))
grp.checkupdate('32/1/6', getbit(bytes[ 1 ], 5))
grp.checkupdate('32/1/7', getbit(bytes[ 1 ], 6))
grp.checkupdate('32/1/8', getbit(bytes[ 1 ], 7))

-- second byte
grp.checkupdate('32/2/1', getbit(bytes[ 2 ], 0))
grp.checkupdate('32/2/2', getbit(bytes[ 2 ], 1))
grp.checkupdate('32/2/3', getbit(bytes[ 2 ], 2))
grp.checkupdate('32/2/4', getbit(bytes[ 2 ], 3))
grp.checkupdate('32/2/5', getbit(bytes[ 2 ], 4))
grp.checkupdate('32/2/6', getbit(bytes[ 2 ], 5))
grp.checkupdate('32/2/7', getbit(bytes[ 2 ], 6))
grp.checkupdate('32/2/8', getbit(bytes[ 2 ], 7))



RE: Emergency Light, decoding of status - manos@dynamitec - 21.09.2018

(21.09.2018, 10:54)admin Wrote: You can access any value up to 4 bytes the same way. Second argument for getbit function is bit number (starting from 0, up to 31).

You can also access bytes separately by using the code from the first example:
Code:
hex = event.datahex
bytes = {}

for i = 1, #hex, 2 do
 bytes[ #bytes + 1 ] = tonumber(hex:sub(i, i + 1), 16)
end

function getbit(value, nr)
 value = bit.rshift(value, nr)
 return bit.band(value, 1)
end

-- first byte
grp.checkupdate('32/1/1', getbit(bytes[ 1 ], 0))
grp.checkupdate('32/1/2', getbit(bytes[ 1 ], 1))
grp.checkupdate('32/1/3', getbit(bytes[ 1 ], 2))
grp.checkupdate('32/1/4', getbit(bytes[ 1 ], 3))
grp.checkupdate('32/1/5', getbit(bytes[ 1 ], 4))
grp.checkupdate('32/1/6', getbit(bytes[ 1 ], 5))
grp.checkupdate('32/1/7', getbit(bytes[ 1 ], 6))
grp.checkupdate('32/1/8', getbit(bytes[ 1 ], 7))

-- second byte
grp.checkupdate('32/2/1', getbit(bytes[ 2 ], 0))
grp.checkupdate('32/2/2', getbit(bytes[ 2 ], 1))
grp.checkupdate('32/2/3', getbit(bytes[ 2 ], 2))
grp.checkupdate('32/2/4', getbit(bytes[ 2 ], 3))
grp.checkupdate('32/2/5', getbit(bytes[ 2 ], 4))
grp.checkupdate('32/2/6', getbit(bytes[ 2 ], 5))
grp.checkupdate('32/2/7', getbit(bytes[ 2 ], 6))
grp.checkupdate('32/2/8', getbit(bytes[ 2 ], 7))

Thank you again for the great support.  Excellent!!!  Smile Smile


RE: Emergency Light, decoding of status - chriscroko - 13.12.2019

What would I piece together from this thread to read out the "DPT245.600 DALI converter test result"? The 6byte signal. 

Could you explain in "layman's terms"?


RE: Emergency Light, decoding of status - admin - 13.12.2019

Use this script:
Code:
hex = event.datahex
bytes = {}

for i = 1, 6 do
  pos = 1 + (i - 1) * 2
  ch = hex:sub(pos, pos + 1)
  bytes[ i ] = tonumber(ch, 16) or 0
end

ltrf = bit.band(bit.rshift(bytes[ 1 ], 4), 0x0F)
ltrd = bit.band(bytes[ 1 ], 0x0F)

ltrp = bit.band(bit.rshift(bytes[ 2 ], 4), 0x0F)

sf = bit.band(bit.rshift(bytes[ 3 ], 6), 0x03)
sd = bit.band(bit.rshift(bytes[ 3 ], 4), 0x03)
sp = bit.band(bit.rshift(bytes[ 3 ], 2), 0x03)

ldtr = bit.bor(bit.lshift(bytes[ 4 ], 8), bytes[ 5 ])

lpdtr = bytes[ 6 ]

log(ltrf, ltrd, ltrp, sf, sd, sp, lpdtr)



RE: Emergency Light, decoding of status - chriscroko - 10.01.2020

(13.12.2019, 11:59)admin Wrote: Use this script:
Code:
hex = event.datahex
bytes = {}

for i = 1, 6 do
  pos = 1 + (i - 1) * 2
  ch = hex:sub(pos, pos + 1)
  bytes[ i ] = tonumber(ch, 16) or 0
end

ltrf = bit.band(bit.rshift(bytes[ 1 ], 4), 0x0F)
ltrd = bit.band(bytes[ 1 ], 0x0F)

ltrp = bit.band(bit.rshift(bytes[ 2 ], 4), 0x0F)

sf = bit.band(bit.rshift(bytes[ 3 ], 6), 0x03)
sd = bit.band(bit.rshift(bytes[ 3 ], 4), 0x03)
sp = bit.band(bit.rshift(bytes[ 3 ], 2), 0x03)

ldtr = bit.bor(bit.lshift(bytes[ 4 ], 8), bytes[ 5 ])

lpdtr = bytes[ 6 ]

log(ltrf, ltrd, ltrp, sf, sd, sp, lpdtr)


The script works and logs the right datasets. What I need now is a way to write out the different parts to different group addresses for BMS purposes. Could you give a hint on how to do this also? 

And also thanks for the base script. Smile


RE: Emergency Light, decoding of status - Daniel - 10.01.2020

Just add this for every value on the end

grp.checkupdate('32/1/1', ltrf )


RE: Emergency Light, decoding of status - chriscroko - 10.01.2020

(10.01.2020, 09:34)Daniel. Wrote: Just add this for every value on the end

grp.checkupdate('32/1/1', ltrf )

Awesome! Thanks for the tip. Smile