From e1b42da41e769ad83f50f2f221bf4ae8d31bb7f6 Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Sat, 10 Feb 2024 00:08:51 +0100 Subject: [PATCH 1/1] flasher.py: formatting commands --- flasher.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 flasher.py diff --git a/flasher.py b/flasher.py new file mode 100644 index 0000000..446a66d --- /dev/null +++ b/flasher.py @@ -0,0 +1,38 @@ +import struct + +INQ_CMD = 0x00 +ERA_CMD = 0x12 +WRI_CMD = 0x13 +REA_CMD = 0x15 +IDA_CMD = 0x30 +BAU_CMD = 0x34 +SIG_CMD = 0x3A +ARE_CMD = 0x3B + +def format_command(cmd, data): + SOD = 0x01 + COM = cmd + COM_DATA = bytes(data.encode('utf-8')) + LNH = len(data) + 1 & 0xFF00 + LNL = len(data) + 1 & 0x00FF + calcsum = LNH + LNL + for i in range(len(data)): + calcsum += ord(data[i]) + SUM = ~(calcsum) & 0xFF # two's complement + print("sum calculation:", SUM) + ETX = 0x03 + fmt_header = '