🐛 Fixed ok tracking

Repositioning of clear_to_send clearing removes synchronization issues.

Big thanks to @KevinOConnor for pointing this out!
This commit is contained in:
Gina Häußge committed 2019-11-05 12:38:02 +01:00
1 parent 2aec0b3a75
commit 2263ebde72
5 files changed
+37 -18

No files matched your search

+2
View File
@@ -176,6 +176,7 @@ def getSettings():
"blockWhileDwelling": s.getBoolean(["serial", "blockWhileDwelling"]),
"useParityWorkaround": s.get(["serial", "useParityWorkaround"]),
"sendM112OnError": s.getBoolean(["serial", "sendM112OnError"]),
"ackMax": s.getInt(["serial", "ackMax"]),
"maxTimeoutsIdle": s.getInt(["serial", "maxCommunicationTimeouts", "idle"]),
"maxTimeoutsPrinting": s.getInt(["serial", "maxCommunicationTimeouts", "printing"]),
"maxTimeoutsLong": s.getInt(["serial", "maxCommunicationTimeouts", "long"]),
@@ -471,6 +472,7 @@ def _saveSettings(data):
if value in ("always", "detect", "never"):
s.set(["serial", "useParityWorkaround"], value)
if "sendM112OnError" in data["serial"]: s.setBoolean(["serial", "sendM112OnError"], data["serial"]["sendM112OnError"])
if "ackMax" in data["serial"]: s.setInt(["serial", "ackMax"], data["serial"]["ackMax"])
if "logPositionOnPause" in data["serial"]: s.setBoolean(["serial", "logPositionOnPause"], data["serial"]["logPositionOnPause"])
if "logPositionOnCancel" in data["serial"]: s.setBoolean(["serial", "logPositionOnCancel"], data["serial"]["logPositionOnCancel"])
if "abortHeatupOnCancel" in data["serial"]: s.setBoolean(["serial", "abortHeatupOnCancel"], data["serial"]["abortHeatupOnCancel"])
+1
View File
@@ -147,6 +147,7 @@ default_settings = {
"useParityWorkaround": "detect",
"maxConsecutiveResends": 10,
"sendM112OnError": True,
"ackMax": 1,
"capabilities": {
"autoreport_temp": True,
@@ -200,6 +200,7 @@ $(function() {
self.serial_capBusyProtocol = ko.observable(undefined);
self.serial_capEmergencyParser = ko.observable(undefined);
self.serial_sendM112OnError = ko.observable(undefined);
self.serial_ackMax = ko.observable(undefined);
self.folder_uploads = ko.observable(undefined);
self.folder_timelapse = ko.observable(undefined);
@@ -398,6 +398,13 @@
<span class="help-inline">{{ _('Use this to specify which commands <strong>always</strong> need to be sent with a checksum. Comma separated list.') }}</span>
</div>
</div>
<div class="control-group" title="{{ _('ok buffer size')|edq }}">
<label class="control-label" for="settings-serialAckMax">{{ _('<code>ok</code> buffer size') }}</label>
<div class="controls">
<input type="number" min="0" class="input-mini text-right" id="settings-serialAckMax" data-bind="value: serial_ackMax">
<span class="help-block">{{ _('Only modify if told to do so') }}</span>
</div>
</div>
</div>
</div>
</fieldset>
+26 -18
View File
@@ -512,7 +512,8 @@ class MachineCom(object):
self._pausing_commands = settings().get(["serial", "pausingCommands"])
self._emergency_commands = settings().get(["serial", "emergencyCommands"])
self._clear_to_send = CountedEvent(name="comm.clear_to_send", minimum=None)
self._ack_max = settings().getInt(["serial", "ackMax"])
self._clear_to_send = CountedEvent(name="comm.clear_to_send", minimum=None, maximum=self._ack_max)
self._send_queue = SendQueue()
self._temperature_timer = None
self._sd_status_timer = None
@@ -3143,6 +3144,19 @@ class MachineCom(object):
self._logger.debug("Type already in send queue: " + e.type)
return False
def _use_up_clear(self, gcode):
# we only need to use up a clear if the command we just sent was either a gcode command or if we also
# require ack's for unknown commands
eats_clear = self._unknownCommandsNeedAck
if gcode is not None:
eats_clear = True
if eats_clear:
# if we need to use up a clear, do that now
self._clear_to_send.clear()
return eats_clear
def _send_loop(self):
"""
The send loop is responsible of sending commands in ``self._send_queue`` over the line, if it is cleared for
@@ -3189,6 +3203,7 @@ class MachineCom(object):
if linenumber is not None:
# line number predetermined - this only happens for resends, so we'll use the number and
# send directly without any processing (since that already took place on the first sending!)
self._use_up_clear(gcode)
self._do_send_with_checksum(command, linenumber)
else:
@@ -3239,7 +3254,13 @@ class MachineCom(object):
continue
# now comes the part where we increase line numbers and send stuff - no turning back now
used_up_clear = self._use_up_clear(gcode)
self._do_send(command, gcode=gcode)
if not used_up_clear:
# If we didn't use up a clear we need to tickle the read queue - there might
# not be a reply to this command, so our _monitor loop will stay waiting until
# timeout. We definitely do not want that, so we tickle the queue manually here
self._continue_sending()
# trigger "sent" phase and use up one "ok"
if on_sent is not None and callable(on_sent):
@@ -3247,21 +3268,6 @@ class MachineCom(object):
on_sent()
self._process_command_phase("sent", command, command_type, gcode=gcode, subcode=subcode, tags=tags)
# we only need to use up a clear if the command we just sent was either a gcode command or if we also
# require ack's for unknown commands
use_up_clear = self._unknownCommandsNeedAck
if gcode is not None:
use_up_clear = True
if use_up_clear:
# if we need to use up a clear, do that now
self._clear_to_send.clear()
else:
# Otherwise we need to tickle the read queue - there might not be a reply
# to this command, so our _monitor loop will stay waiting until timeout. We
# definitely do not want that, so we tickle the queue manually here
self._continue_sending()
finally:
# no matter _how_ we exit this block, we signal that we
# are done processing the last fetched queue entry
@@ -3788,10 +3794,12 @@ class MachineCom(object):
return
self._logger.info(message)
self._do_send(cmd, gcode=gcode)
# use up an ok since we will get one back for this command and don't want to get out of sync
self._clear_to_send.clear()
used_up_clear = self._use_up_clear(gcode)
self._do_send(cmd, gcode=gcode)
if not used_up_clear:
self._continue_sending()
return None,