Upload files to "utils"

This commit is contained in:
2026-07-06 06:11:12 +00:00
parent d561d4c8b4
commit f75a14acc5
2 changed files with 22 additions and 0 deletions
BIN
View File
Binary file not shown.
+22
View File
@@ -0,0 +1,22 @@
import struct
HEAD_STANDARD = 0x05
HEAD_FOTA = 0x15
CMD_GET_BUILD = 0x1E08
CMD_READ_FLASH = 0x0403
CMD_GET_BD_ADDR = 0x0C05
def build_race_packet(cmd: int, payload: bytes = b'', head: int = HEAD_STANDARD) -> bytes:
pkt_type = 0x00
length = 2 + len(payload)
header = struct.pack('<BBH', head, pkt_type, length)
cmd_bytes = struct.pack('<H', cmd)
return header + cmd_bytes + payload
def parse_race_response(data: bytes) -> dict:
if len(data) < 6:
return {"error": "Packet too short"}
head, pkt_type, length = struct.unpack_from('<BBH', data, 0)
cmd = struct.unpack_from('<H', data, 4)[0]
payload = data[6:6+length-2]
return {"head": hex(head), "type": pkt_type, "length": length, "cmd": hex(cmd), "payload": payload}