Fix test and work with bootloader

Fix tests

Fix commit
This commit is contained in:
Valentin Dabstep 2025-06-03 10:48:29 +03:00
parent e9fb2656b8
commit 05621e7150
11 changed files with 128 additions and 54 deletions

View file

@ -20,7 +20,7 @@ ACK_CAN_ID = 0x05
def debug_print(msg):
print(f"[DEBUG] {msg}")
def calculate_crc16_modbus(data: bytes) -> int:
def calculate_crc16(data: bytes) -> int:
crc = 0xFFFF
for byte in data:
crc ^= byte
@ -49,7 +49,7 @@ def send_firmware(hex_file):
# Расчет CRC
debug_print("Расчёт CRC...")
# calculator = Calculator(Crc16.IBM)
fw_crc = calculate_crc16_modbus(binary_data)
fw_crc = calculate_crc16(binary_data)
debug_print(f"CRC: 0x{fw_crc:04X}")
# Отправка START
@ -113,7 +113,7 @@ def send_firmware(hex_file):
)
bus.send(finish_msg)
ack = wait_for_ack(bus, timeout=3)
ack = wait_for_ack(bus, timeout=1.0)
if ack and ack.data[0] == 0xAA:
debug_print("Прошивка подтверждена!")
else:
@ -127,7 +127,7 @@ def send_firmware(hex_file):
def wait_for_ack(bus, timeout=1.0):
start_time = time.time()
while time.time() - start_time < timeout:
msg = bus.recv(timeout=0) # Неблокирующий режим
msg = bus.recv(timeout=0.1) # Неблокирующий режим
if msg and msg.arbitration_id == ACK_CAN_ID:
return msg
return None