make feather can ack example work with stm32f405

This commit is contained in:
Karl Parks 2024-03-16 17:36:33 -04:00
parent 45500df488
commit 34466ae7a1
2 changed files with 20 additions and 13 deletions

View file

@ -50,5 +50,5 @@ while True:
if gap != 1: if gap != 1:
print(f"gap: {gap}") print(f"gap: {gap}")
print("Sending ACK") print(f"Sending ACK: {count}")
can.send(canio.Message(id=0x409, data=struct.pack("<I", count))) can.send(canio.Message(id=0x409, data=struct.pack("<I", count)))

View file

@ -38,24 +38,31 @@ while True:
print(f"Sending message: count={count} now_ms={now_ms}") print(f"Sending message: count={count} now_ms={now_ms}")
message = canio.Message(id=0x408, data=struct.pack("<II", count, now_ms)) message = canio.Message(id=0x408, data=struct.pack("<II", count, now_ms))
# Keep trying to send the same message until confirmed.
while True: while True:
received_ack_confirmed = False
can.send(message) can.send(message)
message_in = listener.receive() # Read in all messages.
if message_in is None: for message_in in listener:
print("No ACK received within timeout") data = message_in.data
continue if len(data) != 4:
print(f"Unusual message length {len(data)}")
continue
data = message_in.data ack_count = struct.unpack("<I", data)[0]
if len(data) != 4: if ack_count == count:
print(f"Unusual message length {len(data)}") print(f"Received ACK: {ack_count}")
continue received_ack_confirmed = True
break
else:
print(f"Received incorrect ACK: {ack_count} should be {count}")
ack_count = struct.unpack("<I", data)[0] if received_ack_confirmed:
if ack_count == count:
print("Received ACK")
break break
print(f"Received incorrect ACK: {ack_count} should be {count}")
print(f"No ACK received within receive timeout, sending {count} again")
time.sleep(.5) time.sleep(.5)
count += 1 count += 1