From d4b86669626a75cc5b92e2cc26f23bb46a8dc73e Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Sat, 10 Feb 2024 00:47:20 +0100 Subject: [PATCH] flasher.py: initial packing --- flasher.py | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/flasher.py b/flasher.py index 446a66d..7a1463c 100644 --- a/flasher.py +++ b/flasher.py @@ -9,21 +9,41 @@ BAU_CMD = 0x34 SIG_CMD = 0x3A ARE_CMD = 0x3B +TESTID = [ + "0xF0", "0xF1", "0xF2", "0xF3", + "0xE4", "0xE5", "0xE6", "0xE7", + "0xD8", "0xD9", "0xDA", "0xDB", + "0xCC", "0xCD", "0xCE", "0xCF" +] + def format_command(cmd, data): + COM_LEN = len(data) SOD = 0x01 COM = cmd - COM_DATA = bytes(data.encode('utf-8')) - LNH = len(data) + 1 & 0xFF00 - LNL = len(data) + 1 & 0x00FF + LNH = COM_LEN + 1 & 0xFF00 + LNL = COM_LEN + 1 & 0x00FF calcsum = LNH + LNL - for i in range(len(data)): - calcsum += ord(data[i]) + + if isinstance(data, str): + byte_data = bytes(data.encode('utf-8')) + else: + byte_data = bytes([int(x, 16) for x in data]) + + for i in range(COM_LEN): + if isinstance(data[i], str): + calcsum += int(data[i], 16) + else: + calcsum += ord(data[i]) SUM = ~(calcsum) & 0xFF # two's complement - print("sum calculation:", SUM) ETX = 0x03 fmt_header = '