Объединить протокол терминала TMS2812 для Python и Android
This commit is contained in:
@@ -8,6 +8,7 @@ from dataclasses import dataclass
|
||||
import struct
|
||||
|
||||
from protocan.tms2812 import crc16_modbus, build_upload_request, decode_upload_reply
|
||||
from protocan.tms_terminal import build_fixed_request, validate_response
|
||||
|
||||
CMD_LOAD = 51
|
||||
CMD_UPLOAD = 52
|
||||
@@ -17,8 +18,7 @@ CMD_EXTEND = 60
|
||||
|
||||
|
||||
def packet(controller: int, command: int, payload: bytes) -> bytes:
|
||||
raw = bytes((controller, command)) + payload
|
||||
return raw + struct.pack("<H", crc16_modbus(raw))
|
||||
return build_fixed_request(controller, command, payload)
|
||||
|
||||
|
||||
def init_load(controller: int, ram: int, size: int) -> bytes:
|
||||
@@ -52,8 +52,11 @@ def normalize_reply(raw: bytes, controller: int, command: int, size: int) -> byt
|
||||
decode_upload_reply(full, controller, size - 8)
|
||||
except ValueError:
|
||||
return None
|
||||
elif crc16_modbus(full[:-4]) != int.from_bytes(full[-4:-2], "little"):
|
||||
return None
|
||||
else:
|
||||
try:
|
||||
validate_response(raw, controller, command, size, True)
|
||||
except ValueError:
|
||||
return None
|
||||
return full
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user