update python test script to support utf8

This commit is contained in:
joBr99
2022-04-05 23:13:47 +02:00
parent fe2efe6bd5
commit ea9412ffc2

View File

@@ -5,7 +5,7 @@ import codecs
print("Calculate NSPanel hex command from JSON payload\n") print("Calculate NSPanel hex command from JSON payload\n")
#value = input("Enter JSON:\n") #value = input("Enter JSON:\n")
value = "entityUpdHeading,Heading1234" value = "weatherUpdate~1~9.4 C~Wed~2~14.1 C~Thu~3~12.4 C~Fri~4~7.6 C~Sat~5~8.5 C~6~90 %"
def crc16(data:bytes, poly:hex=0xA001) -> str: def crc16(data:bytes, poly:hex=0xA001) -> str:
''' '''
@@ -21,13 +21,13 @@ def crc16(data:bytes, poly:hex=0xA001) -> str:
return crc return crc
payload = bytes(value, 'ascii') payload = bytes(value, 'utf-8')
header = binascii.unhexlify('55BB') header = binascii.unhexlify('55BB')
print("length:", len(value)) print("length:", len(payload))
length = len(value).to_bytes(2, 'little') length = len(payload).to_bytes(2, 'little')
bytes_payload = header + length + payload bytes_payload = header + length + payload