Allow detection of firmware w/ broken resend

If firmware doesn't send an ok immediately after a resend request, we
will now be able to detect this (if enabled to do so) by starting a
timer that will simulate an ok after .5s if none has been received.

This should help with issues like prusa3d/Prusa-Firmware#331 where an ok
is only missing sometimes and not always, making the existing workaround
of always simulating an ok after a resend cause additional problems.
This commit is contained in:
Gina Häußge committed 2018-03-06 12:48:24 +01:00
1 parent 11eb731b3d
commit ee36e2abd3
4 files changed
+62 -18

No files matched your search

+5 -2
View File
@@ -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"])
+21 -3
View File
@@ -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
@@ -250,17 +250,28 @@
</label>
</div>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_triggerOkForM29" id="settings-serialTriggerOkForM29"> {{ _('Simulate <code>ok</code> for <code>M29</code>') }}
<span class="help-block">{{ _('Most Marlin forks that were derived from Marlin versions < v1.1.0 do not send an acknowledging <code>ok</code> for a <code>M29</code>. Check this if you run into communication stalls following streaming of a file to your printer\'s SD.') }}</span>
</label>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_triggerOkForM29" id="settings-serialTriggerOkForM29"> {{ _('Simulate <code>ok</code> for <code>M29</code>') }}
<span class="help-block">{{ _('Most Marlin forks that were derived from Marlin versions < v1.1.0 do not send an acknowledging <code>ok</code> for a <code>M29</code>. Check this if you run into communication stalls following streaming of a file to your printer\'s SD.') }}</span>
</label>
</div>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_supportResendsWithoutOk" id="settings-serialSupportResendsWithoutOk"> {{ _('Simulate <code>ok</code> for resend requests') }}
<span class="help-block">{{ _('Some Marlin forks do not send an acknowledging <code>ok</code> with their resend requests. Check this if you run into communication stalls following resend requests due to that.') }}</span>
</label>
<div class="control-group">
<label class="control-label"> {{ _('Simulate <code>ok</code> for resend requests') }}</label>
<div class="controls">
<label class="radio">
<input type="radio" name="resendWithoutOkGroup" value="detect" data-bind="checked: serial_supportResendsWithoutOk" id="settings-serialSupportResendsWithoutOkDetect"> {{ _('If detected as necessary') }}
</label>
<label class="radio">
<input type="radio" name="resendWithoutOkGroup" value="always" data-bind="checked: serial_supportResendsWithoutOk" id="settings-serialSupportResendsWithoutOkAlways"> {{ _('Always') }}
</label>
<label class="radio">
<input type="radio" name="resendWithoutOkGroup" value="never" data-bind="checked: serial_supportResendsWithoutOk" id="settings-serialSupportResendsWithoutOkNever"> {{ _('Never') }}
</label>
<span class="help-block">{{ _('Some Marlin forks lack an acknowledging <code>ok</code> with their resend requests. Set this to "always" or "if detected as necessary" if you run into communication stalls on resend requests.') }}</span>
</div>
</div>
</div>
</div>
+15 -3
View File
@@ -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)