File tree Expand file tree Collapse file tree 2 files changed +20
-13
lines changed Expand file tree Collapse file tree 2 files changed +20
-13
lines changed Original file line number Diff line number Diff line change 5050 if gap != 1 :
5151 print (f"gap: { gap } " )
5252
53- print ("Sending ACK" )
53+ print (f "Sending ACK: { count } " )
5454 can .send (canio .Message (id = 0x409 , data = struct .pack ("<I" , count )))
Original file line number Diff line number Diff line change 3838 print (f"Sending message: count={ count } now_ms={ now_ms } " )
3939
4040 message = canio .Message (id = 0x408 , data = struct .pack ("<II" , count , now_ms ))
41+
42+ # Keep trying to send the same message until confirmed.
4143 while True :
44+ received_ack_confirmed = False
4245 can .send (message )
4346
44- message_in = listener .receive ()
45- if message_in is None :
46- print ("No ACK received within timeout" )
47- continue
47+ # Read in all messages.
48+ for message_in in listener :
49+ data = message_in .data
50+ if len (data ) != 4 :
51+ print (f"Unusual message length { len (data )} " )
52+ continue
53+
54+ ack_count = struct .unpack ("<I" , data )[0 ]
55+ if ack_count == count :
56+ print (f"Received ACK: { ack_count } " )
57+ received_ack_confirmed = True
58+ break
4859
49- data = message_in .data
50- if len (data ) != 4 :
51- print (f"Unusual message length { len (data )} " )
52- continue
60+ print (f"Received incorrect ACK: { ack_count } should be { count } " )
5361
54- ack_count = struct .unpack ("<I" , data )[0 ]
55- if ack_count == count :
56- print ("Received ACK" )
62+ if received_ack_confirmed :
5763 break
58- print (f"Received incorrect ACK: { ack_count } should be { count } " )
64+
65+ print (f"No ACK received within receive timeout, sending { count } again" )
5966
6067 time .sleep (.5 )
6168 count += 1
You can’t perform that action at this time.
0 commit comments