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.

Translating code between Lua and JS
#1
Hi,

I am currently translate some code which I've created in NodeJS for controlling Somfy blinds into Lua to use it by LM. Could you help me with translate some functions?

Code:
parseInt(hexValue[i], 16)

toString(16) // e.g. decimalChecksum.toString(16)

And also how can I convert hex string to hex?


Code:
'7FF2FAB843FA000000FFFE065D' => string.char(0x7F,0xF2,0xFA,0xB8,0x43,0xFA,0x00,0x00,0x00,0xFF,0xFE,0x06,0x5D)
Done is better than perfect
Reply
#2
Code:
number = tonumber(input, 16)
hex = string.format('%X', number)

Convert hex string to raw binary, make sure second argument is true otherwise zero bytes will be ignored:
Code:
str = lmcore.hextostr('7FF2FAB843FA000000FFFE065D', true)
Reply
#3
I've translated whole code and now it produces correct string frame, but I've found some ~bug/~lack in log() function which could be produced by such code:

Code:
S01_up = string.char(0x7F,0xF2,0xFA,0xFF,0x00,0x00,0x8E,0x5E,0xFA,0xFE,0xFE,0x07,0x4C)
S01_up_new = lmcore.hextostr('7FF2FAFF00008E5EFAFEFE074C', true)

log(S01_up, S01_up_new, 'end')


And this is from log():

Code:
* arg: 1
 * string: ���


So it looks that log() doesn't notice the end of first variable.
Done is better than perfect
Reply
#4
use loghex if you want to get readable binary strings
Reply
#5
NiceWink Thanks
Done is better than perfect
Reply


Forum Jump: