diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index 0b97bb147..65d8bc8e8 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -146,6 +146,7 @@ class VirtualPrinter(object): self._debug_sleep = None self._sleepAfterNext = dict() self._sleepAfter = dict() + self._rerequest_last = False self._dont_answer = False @@ -364,6 +365,9 @@ class VirtualPrinter(object): elif isinstance(prepared, basestring): self._send(prepared) continue + elif self._rerequest_last: + self._triggerResend(actual=linenumber) + continue else: self.lastN = linenumber data = data.split(None, 1)[1].strip() @@ -753,6 +757,8 @@ class VirtualPrinter(object): prepare_ok | Will cause to be enqueued for use, | will be used instead of actual "ok" + rerequest_last + | Will cause the last line number + 1 to be rerequest add infinitum # Reply Timing / Sleeping @@ -814,6 +820,9 @@ class VirtualPrinter(object): elif data == "go_awol": self._send("// Going AWOL") self._debug_awol = True + elif data == "rerequest_last": + self._send("// Entering rerequest loop") + self._rerequest_last = True elif data == "cancel_sd": if self._sdPrinting and self._sdPrinter: self._pauseSdPrint() diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 9799d75d6..659b3ae5d 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -145,6 +145,7 @@ default_settings = { "firmwareDetection": True, "blockWhileDwelling": False, "useParityWorkaround": "detect", + "maxConsecutiveResends": 10, "capabilities": { "autoreport_temp": True, diff --git a/src/octoprint/static/js/app/dataupdater.js b/src/octoprint/static/js/app/dataupdater.js index b3f14af90..cf485ef3a 100644 --- a/src/octoprint/static/js/app/dataupdater.js +++ b/src/octoprint/static/js/app/dataupdater.js @@ -266,6 +266,7 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) { break; } case "resend": + case "resend_loop": case "timeout": { title = gettext("Communication error"); text = _.sprintf(gettext("There was a communication error while talking to your printer. Please consult the terminal output and octoprint.log for details. Error: %(error)s"), payload); diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 4b60ca2af..e53358ef4 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -469,6 +469,10 @@ class MachineCom(object): self._lastResendNumber = None self._currentResendCount = 0 + self._currentConsecutiveResendNumber = None + self._currentConsecutiveResendCount = 0 + self._maxConsecutiveResends = settings().getInt(["serial", "maxConsecutiveResends"]) + self._errorValue = "" self._firmware_detection = settings().getBoolean(["serial", "firmwareDetection"]) @@ -2910,13 +2914,25 @@ class MachineCom(object): self._currentResendCount += 1 return True + if self._currentConsecutiveResendNumber == lineToResend: + self._currentConsecutiveResendCount += 1 + if self._currentConsecutiveResendCount >= self._maxConsecutiveResends: + # printer keeps requesting the same line again and again, something is severely broken here + error_text = "Printer keeps requesting line {} again and again, communication stuck".format(lineToResend) + self._log(error_text) + self._logger.warn(error_text) + self._trigger_error(error_text, "resend_loop") + else: + self._currentConsecutiveResendNumber = lineToResend + self._currentConsecutiveResendCount = 0 + self._resendActive = True self._resendDelta = resendDelta self._lastResendNumber = lineToResend self._currentResendCount = 0 if self._resendDelta > len(self._lastLines) or len(self._lastLines) == 0 or self._resendDelta < 0: - error_text = "Printer requested line %d but no sufficient history is available, can't resend" % lineToResend + error_text = "Printer requested line {} but no sufficient history is available, can't resend".format(lineToResend) self._log(error_text) self._logger.warn(error_text + ". Printer requested line {}, current line is {}, line history has {} entries.".format(lineToResend, self._currentLine, len(self._lastLines))) if self.isPrinting():