Skip to content

Commit e9bf2d4

Browse files
committed
mcu: Enhance RetryAsyncCommand to handle low-level retransmits
The RetryAsyncCommand code needs to ensure that any response messages are not from a previous (unrelated) query. To do that it compares the '#sent_time' from potential responses to ensure they are not from a previous session. However, if there are any low-level serial retransmits then the low-level code sets the '#sent_time' to zero (to indicate that the query send time is not strictly known). That could result in a valid response not being accepted by RetryAsyncCommand. If a low-level connection is experiencing a small amount of periodic retransmits it could result in multiple high-level retry attempts failing to the point that there is a user-facing error. This could result in "Timeout on wait for 'tmcuart_response' response" errors. Fix by accepting responses even if there is a low-level retransmit once the code can confirm that there can be no previous query still in progress. Signed-off-by: Kevin O'Connor <[email protected]>
1 parent 8ef0f7d commit e9bf2d4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

klippy/mcu.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ def __init__(self, serial, name, oid=None):
2525
self.reactor = serial.get_reactor()
2626
self.completion = self.reactor.completion()
2727
self.min_query_time = self.reactor.monotonic()
28+
self.need_response = True
2829
self.serial.register_response(self.handle_callback, name, oid)
2930
def handle_callback(self, params):
30-
if params['#sent_time'] >= self.min_query_time:
31-
self.min_query_time = self.reactor.NEVER
31+
if self.need_response and params['#sent_time'] >= self.min_query_time:
32+
self.need_response = False
3233
self.reactor.async_complete(self.completion, params)
3334
def get_response(self, cmds, cmd_queue, minclock=0, reqclock=0):
3435
cmd, = cmds
3536
self.serial.raw_send_wait_ack(cmd, minclock, reqclock, cmd_queue)
37+
self.min_query_time = 0.
3638
first_query_time = query_time = self.reactor.monotonic()
3739
while 1:
3840
params = self.completion.wait(query_time + self.RETRY_TIME)

0 commit comments

Comments
 (0)