30.11.2017, 14:43
I got it working, but I am unable to convert a string into a hex array to compute the code
These codes work
I use the following strings after computation
The following helpers do not convert correctly, but I am unable to determine why
These codes work
Code:
-- Power ON
-- HEX: 02 0A 53 4F 4E 59 00 01 30 02 00 01
SONYSDCP_CMD_ON = string.char(0x02, 0x0A, 0x53, 0x4F, 0x4E, 0x59, 0x00, 0x01, 0x30, 0x02, 0x00, 0x01)
-- Power Off
-- HEX: 02 0A 53 4F 4E 59 00 01 30 02 00 00
SONYSDCP_CMD_OFF =string.char(0x02, 0x0A, 0x53, 0x4F, 0x4E, 0x59, 0x00, 0x01, 0x30, 0x02, 0x00, 0x00)
I use the following strings after computation
Code:
-- Power ON
-- HEX: 02 0A 53 4F 4E 59 00 01 30 02 00 01
SONYSDCP_CMD_ON = "020A534F4E59000130020001"
-- Power Off
-- HEX: 02 0A 53 4F 4E 59 00 01 30 02 00 00
SONYSDCP_CMD_OFF = "020A534F4E59000130020000"
The following helpers do not convert correctly, but I am unable to determine why
Code:
-- convert hex char array to string
function string.fromhex(str)
return (str:gsub('..', function (cc)
return string.char(tonumber(cc, 16))
end))
end
-- convert string to hex char array
function string.tohex(str)
return (str:gsub('.', function (c)
return string.format('%02X', string.byte(c))
end))
end