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.

LUA : An easy way to separate an int64 into two int32 ?
#1
Hi everybody,

I'm looking for a solution to separate one data int64 into two data int32, in the aim to send energy from a smartlink (int64) via bacnet (int32).

In the device wich receive the two point int32 via Bacnet, i will aggregate this two points to reach the original value.

Thanks, 
Best regards
Hubert FEBRAUD
Home automation integrator
Connectibat, Nantes, France
Reply
#2
Which device are you using? Latest LM firmware supports int64 in BACnet.
Reply
#3
(05.08.2020, 08:11)admin Wrote: Which device are you using? Latest LM firmware supports int64 in BACnet.
It's a Wiser for KNX in 2.4.0
Hubert FEBRAUD
Home automation integrator
Connectibat, Nantes, France
Reply
#4
There is a fix for this, you can send the whole int64.
https://dl.openrb.com/lmup/2020.07.14-bacnet-64bit.lmup
You may need latest fw for wiser 2.5.1
------------------------------
Ctrl+F5
Reply
#5
Thanks everybody, it works fine.
Solution : firmware 2.5.1 with patch is OK

I hope this can help someone else.

BR
Hubert FEBRAUD
Home automation integrator
Connectibat, Nantes, France
Reply
#6
Hi,

And if you ever need to do a split with a 8 byte value into 2x 4 bytes you can do it like this:
Code:
value = 0xffffffff
high32 = bit.rshift(bit.band(value,0xffff0000),16)
low32 = bit.band(value,0x0000ffff)
BR,

Erwin
Reply
#7
@Erwin, you example splits 32 bits into two 16 bit values. Lua bit operations work only with 32 bit numbers. FFI can be used to convert between different types:
Code:
function u64_to_u32(value)
  local ffi = require('ffi')
  local u64 = ffi.new('uint64_t[1]', value)
  local u32 = ffi.new('uint32_t[2]')
  ffi.copy(u32, u64, 8)
  return u32[0], u32[1]
end

value = math.pow(2, 53) - 1 -- some large value

u32_l, u32_h = u64_to_u32(value)
log(u32_l, u32_h)
Reply
#8
Aahhh, yep your right 4x8 = still 32 (:

Sorry missed that on my free day (:
Reply
#9
Admin has a free week Wink
------------------------------
Ctrl+F5
Reply
#10
He deserves it!

And he is always sharper then me so that’s not an excuse (:

BR,

Erwin
Reply


Forum Jump: