make feather can ack example work with stm32f405
This commit is contained in:
parent
45500df488
commit
34466ae7a1
2 changed files with 20 additions and 13 deletions
|
|
@ -50,5 +50,5 @@ while True:
|
|||
if gap != 1:
|
||||
print(f"gap: {gap}")
|
||||
|
||||
print("Sending ACK")
|
||||
print(f"Sending ACK: {count}")
|
||||
can.send(canio.Message(id=0x409, data=struct.pack("<I", count)))
|
||||
|
|
|
|||
|
|
@ -38,14 +38,14 @@ while True:
|
|||
print(f"Sending message: count={count} now_ms={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:
|
||||
received_ack_confirmed = False
|
||||
can.send(message)
|
||||
|
||||
message_in = listener.receive()
|
||||
if message_in is None:
|
||||
print("No ACK received within timeout")
|
||||
continue
|
||||
|
||||
# Read in all messages.
|
||||
for message_in in listener:
|
||||
data = message_in.data
|
||||
if len(data) != 4:
|
||||
print(f"Unusual message length {len(data)}")
|
||||
|
|
@ -53,9 +53,16 @@ while True:
|
|||
|
||||
ack_count = struct.unpack("<I", data)[0]
|
||||
if ack_count == count:
|
||||
print("Received ACK")
|
||||
print(f"Received ACK: {ack_count}")
|
||||
received_ack_confirmed = True
|
||||
break
|
||||
else:
|
||||
print(f"Received incorrect ACK: {ack_count} should be {count}")
|
||||
|
||||
if received_ack_confirmed:
|
||||
break
|
||||
|
||||
print(f"No ACK received within receive timeout, sending {count} again")
|
||||
|
||||
time.sleep(.5)
|
||||
count += 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue