flasher.py: formatting commands
authorRobin Krens <robin@robinkrens.nl>
Fri, 9 Feb 2024 23:08:51 +0000 (00:08 +0100)
committerRobin Krens <robin@robinkrens.nl>
Fri, 9 Feb 2024 23:08:51 +0000 (00:08 +0100)
flasher.py [new file with mode: 0644]

diff --git a/flasher.py b/flasher.py
new file mode 100644 (file)
index 0000000..446a66d
--- /dev/null
@@ -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 = '<BBBB'
+    fmt_footer = 'BB'
+    return (fmt_header + str(len(data)) + 's' + fmt_footer)
+
+def format_data(data):
+    SOD = 0x81
+    ETX = 0x03
+
+cmd = format_command(INQ_CMD, "")
+print(cmd, struct.calcsize(cmd))
+
+
+
+
+