From 6f836951b5300130758f226538c7bca690168cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 24 Aug 2015 13:40:00 +0200 Subject: [PATCH] Handle Repetier resend repetitions Repetier might resend the same resend request to make sure it arrives. This commit makes OctoPrint not react to such a repeated request and instead ignore up to a configurable amount of repeated requests for the same (current) line. --- src/octoprint/settings.py | 4 +++- src/octoprint/util/comm.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 115932d9..969467e7 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -86,7 +86,9 @@ default_settings = { "additionalBaudrates": [], "longRunningCommands": ["G4", "G28", "G29", "G30", "G32", "M400", "M226"], "checksumRequiringCommands": ["M110"], - "helloCommand": "M110 N0" + "helloCommand": "M110 N0", + "ignoreIdenticalResends": False, + "identicalResendsCountdown": 7 }, "server": { "host": "0.0.0.0", diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 788299f8..de819989 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -249,6 +249,8 @@ class MachineCom(object): self._lastResendNumber = None self._currentResendCount = 0 self._resendSwallowNextOk = False + self._resendSwallowRepetitions = settings().getBoolean(["serial", "ignoreIdenticalResends"]) + self._resendSwallowRepetitionsCounter = 0 self._checksum_requiring_commands = settings().get(["serial", "checksumRequiringCommands"]) self._clear_to_send = CountedEvent(max=10, name="comm.clear_to_send") @@ -1484,9 +1486,18 @@ class MachineCom(object): self._currentResendCount += 1 return + # If we ignore resend repetitions (Repetier firmware...), check if we + # need to do this now. If the same line number has been requested we + # already saw and resent, we'll ignore it up to times. + if self._resendSwallowRepetitions and lineToResend == self._lastResendNumber and self._resendSwallowRepetitionsCounter > 0: + self._logger.debug("Ignoring resend request for line %d, that is probably a repetition sent by the firmware to ensure it arrives, not a real request" % lineToResend) + self._resendSwallowRepetitionsCounter -= 1 + return + self._resendDelta = resendDelta self._lastResendNumber = lineToResend self._currentResendCount = 0 + self._resendSwallowRepetitionsCounter = settings().getInt(["serial", "identicalResendsCountdown"]) if self._resendDelta > len(self._lastLines) or len(self._lastLines) == 0 or self._resendDelta < 0: self._errorValue = "Printer requested line %d but no sufficient history is available, can't resend" % lineToResend