From: Robin Krens Date: Fri, 9 Feb 2024 23:08:51 +0000 (+0100) Subject: flasher.py: formatting commands X-Git-Tag: v0.0.1~58 X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=e1b42da41e769ad83f50f2f221bf4ae8d31bb7f6;p=renesas-ra-flasher flasher.py: formatting commands --- e1b42da41e769ad83f50f2f221bf4ae8d31bb7f6 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 = '