From 354e06496947b2efa45c31916475f34d4d8c9962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 13 Apr 2015 12:23:52 +0200 Subject: [PATCH] Only resend next line after first resend is through Tracking the "ok" attached to a resend is necessary in order to make sure that it does not trigger the resend of the next line after the requested one right after, causing resend loops in some cases, e.g. "> 100", "> 101" , "< rs 100", "ok", "> 100", "< expected 100, got 101, rs 100" -- here the last error from the firmware could not be processed as "false negative" correctly (101 was already sent to the printer when it detected the error for 100, so this error just needs to be ignored) since the resend flag was already cleared due to line 100 and 101 having been enqueued, 100 in the resend handler, 101 due to the following ok. This patch fixes the latter, thus solving the problem. --- src/octoprint/util/comm.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index d92a559c..c6f7a4b4 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -162,6 +162,7 @@ class MachineCom(object): self._lastCommError = None self._lastResendNumber = None self._currentResendCount = 0 + self._resendSwallowNextOk = False self._clear_to_send = CountedEvent(max=10, name="comm.clear_to_send") self._send_queue = TypedQueue() @@ -1048,7 +1049,9 @@ class MachineCom(object): elif self._state == self.STATE_OPERATIONAL or self._state == self.STATE_PAUSED: if "ok" in line: # if we still have commands to process, process them - if self._resendDelta is not None: + if self._resendSwallowNextOk: + self._resendSwallowNextOk = False + elif self._resendDelta is not None: self._resendNextCommand() elif self._sendFromQueue(): pass @@ -1067,8 +1070,12 @@ class MachineCom(object): self._logger.debug("Ran into a communication timeout, but a blocking command is currently active") if "ok" in line: - if self._resendDelta is not None: + if self._resendSwallowNextOk: + self._resendSwallowNextOk = False + + elif self._resendDelta is not None: self._resendNextCommand() + else: if self._sendFromQueue(sendChecksum=True): pass @@ -1308,6 +1315,8 @@ class MachineCom(object): lineToResend = int(line.split()[1]) if lineToResend is not None: + self._resendSwallowNextOk = True + lastCommError = self._lastCommError self._lastCommError = None @@ -1339,7 +1348,6 @@ class MachineCom(object): self._resendNextCommand() def _resendNextCommand(self): - lastCommError = self._lastCommError self._lastCommError = None # Make sure we are only handling one sending job at a time