diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 0ea189907..ff578813a 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -148,7 +148,7 @@ def getSettings(): "triggerOkForM29": s.getBoolean(["serial", "triggerOkForM29"]), "logPositionOnPause": s.getBoolean(["serial", "logPositionOnPause"]), "logPositionOnCancel": s.getBoolean(["serial", "logPositionOnCancel"]), - "supportResendsWithoutOk": s.getBoolean(["serial", "supportResendsWithoutOk"]), + "supportResendsWithoutOk": s.get(["serial", "supportResendsWithoutOk"]), "waitForStart": s.getBoolean(["serial", "waitForStartOnConnect"]), "alwaysSendChecksum": s.getBoolean(["serial", "alwaysSendChecksum"]), "neverSendChecksum": s.getBoolean(["serial", "neverSendChecksum"]), @@ -374,7 +374,10 @@ def _saveSettings(data): if "ignoreErrorsFromFirmware" in data["serial"]: s.setBoolean(["serial", "ignoreErrorsFromFirmware"], data["serial"]["ignoreErrorsFromFirmware"]) if "disconnectOnErrors" in data["serial"]: s.setBoolean(["serial", "disconnectOnErrors"], data["serial"]["disconnectOnErrors"]) if "triggerOkForM29" in data["serial"]: s.setBoolean(["serial", "triggerOkForM29"], data["serial"]["triggerOkForM29"]) - if "supportResendsWithoutOk" in data["serial"]: s.setBoolean(["serial", "supportResendsWithoutOk"], data["serial"]["supportResendsWithoutOk"]) + if "supportResendsWithoutOk" in data["serial"]: + value = data["serial"]["supportResendsWithoutOk"] + if value in ("always", "detect", "never"): + s.set(["serial", "supportResendsWithoutOk"], value) if "waitForStart" in data["serial"]: s.setBoolean(["serial", "waitForStartOnConnect"], data["serial"]["waitForStart"]) if "alwaysSendChecksum" in data["serial"]: s.setBoolean(["serial", "alwaysSendChecksum"], data["serial"]["alwaysSendChecksum"]) if "neverSendChecksum" in data["serial"]: s.setBoolean(["serial", "neverSendChecksum"], data["serial"]["neverSendChecksum"]) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 9b6606737..6ed1d1bb7 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -98,7 +98,8 @@ default_settings = { "temperature": 5, "temperatureTargetSet": 2, "temperatureAutoreport": 2, - "sdStatus": 1 + "sdStatus": 1, + "resendOk": .5 }, "maxCommunicationTimeouts": { "idle": 2, @@ -114,7 +115,7 @@ default_settings = { "disconnectOnErrors": True, "ignoreErrorsFromFirmware": False, "logResends": True, - "supportResendsWithoutOk": False, + "supportResendsWithoutOk": "detect", "logPositionOnPause": True, "logPositionOnCancel": True, "waitForStartOnConnect": False, @@ -910,7 +911,8 @@ class Settings(object): self._migrate_printer_parameters, self._migrate_gcode_scripts, self._migrate_core_system_commands, - self._migrate_serial_features + self._migrate_serial_features, + self._migrate_resend_without_ok ) for migrate in migrators: @@ -1217,6 +1219,22 @@ class Settings(object): return changed + def _migrate_resend_without_ok(self, config): + """ + Migrates supportResendsWithoutOk flag from boolean to ("always", "detect", "never") value range. + + True gets migrated to "always", False to "detect" (which is the new default). + """ + if "serial" in config and "supportResendsWithoutOk" in config["serial"] \ + and config["serial"]["supportResendsWithoutOk"] not in ("always", "detect", "never"): + value = config["serial"]["supportResendsWithoutOk"] + if value: + config["serial"]["supportResendsWithoutOk"] = "always" + else: + config["serial"]["supportResendsWithoutOk"] = "detect" + return True + return False + def backup(self, suffix, path=None): import shutil diff --git a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 index 5b40eaab8..355c8a023 100644 --- a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 +++ b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 @@ -250,17 +250,28 @@ -
- +
+
+ +
-
- +
+ +
+ + + + {{ _('Some Marlin forks lack an acknowledging ok with their resend requests. Set this to "always" or "if detected as necessary" if you run into communication stalls on resend requests.') }} +
diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 6cde33f9d..d697de8e8 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -440,7 +440,8 @@ class MachineCom(object): self._temperature_autoreporting = False self._busy_protocol_detected = False - self._supportResendsWithoutOk = settings().getBoolean(["serial", "supportResendsWithoutOk"]) + self._trigger_ok_after_resend = settings().get(["serial", "supportResendsWithoutOk"]) + self._resend_ok_timer = None self._resendActive = False @@ -1838,6 +1839,10 @@ class MachineCom(object): self._log("Connection closed, closing down monitor") def _handle_ok(self): + if self._resend_ok_timer: + self._resend_ok_timer.cancel() + self._resend_ok_timer = None + self._ok_timeout = get_new_timeout("communicationBusy" if self._busy_protocol_detected else "communication", self._timeout_intervals) self._clear_to_send.set() @@ -2436,11 +2441,18 @@ class MachineCom(object): self._log_resends_rate_count += 1 self._send_queue.resend_active = True + return True finally: - if self._supportResendsWithoutOk: - # simulate an ok if our flags indicate that the printer needs that for resend requests to work + if self._trigger_ok_after_resend == "always": self._handle_ok() + elif self._trigger_ok_after_resend == "detect": + def process(): + self._resend_ok_timer = None + self._handle_ok() + self._logger.info("Firmware didn't send an 'ok' with their resend request. That's a known bug with some firmware variants out there. Simulating an ok to continue...") + self._resend_ok_timer = threading.Timer(self._timeout_intervals.get("resendOk", 1.0), process) + self._resend_ok_timer.start() def _resendSameCommand(self): return self._resendNextCommand(again=True)