Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/4493 - Defer M20 commands until initial capability report is done #4577

Merged
merged 8 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ date of first contribution):
* [Zack Lewis](https://github.com/lima3w)
* [Billy Richardson](https://github.com/richardsondev)
* [Christian Bianchini](https://github.com/max246)
* [Kestin Goforth](https://github.com/kforth)

OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
[Daid Braam](https://github.com/daid). Parts of its communication layer and
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration/config_yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,10 @@ Use the following settings to configure the serial connection to the printer:
# during connect.
waitForStartOnConnect: false

# Specifies whether OctoPrint should wait to load the SD card file list until the first firmware capability
# report is processed.
waitToLoadSdFileList: false

# Specifies whether OctoPrint should send linenumber + checksum with every printer command. Needed for
# successful communication with Repetier firmware
alwaysSendChecksum: false
Expand Down
3 changes: 3 additions & 0 deletions src/octoprint/schema/config/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ class SerialConfig(BaseModel):
waitForStartOnConnect: bool = False
"""Whether OctoPrint should wait for the `start` response from the printer before trying to send commands during connect."""

waitToLoadSdFileList: bool = False
"""Specifies whether OctoPrint should wait to load the SD card file list until the first firmware capability report is processed."""

alwaysSendChecksum: bool = False
"""Specifies whether OctoPrint should send linenumber + checksum with every printer command. Needed for successful communication with Repetier firmware."""

Expand Down
6 changes: 6 additions & 0 deletions src/octoprint/server/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def getSettings():
"abortHeatupOnCancel": s.getBoolean(["serial", "abortHeatupOnCancel"]),
"supportResendsWithoutOk": s.get(["serial", "supportResendsWithoutOk"]),
"waitForStart": s.getBoolean(["serial", "waitForStartOnConnect"]),
"waitToLoadSdFileList": s.getBoolean(["serial", "waitToLoadSdFileList"]),
"alwaysSendChecksum": s.getBoolean(["serial", "alwaysSendChecksum"]),
"neverSendChecksum": s.getBoolean(["serial", "neverSendChecksum"]),
"sendChecksumWithUnknownCommands": s.getBoolean(
Expand Down Expand Up @@ -840,6 +841,11 @@ def _saveSettings(data):
s.setBoolean(
["serial", "waitForStartOnConnect"], data["serial"]["waitForStart"]
)
if "waitToLoadSdFileList" in data["serial"]:
s.setBoolean(
["serial", "waitToLoadSdFileList"],
data["serial"]["waitToLoadSdFileList"],
)
if "alwaysSendChecksum" in data["serial"]:
s.setBoolean(
["serial", "alwaysSendChecksum"], data["serial"]["alwaysSendChecksum"]
Expand Down
2 changes: 2 additions & 0 deletions src/octoprint/static/js/app/viewmodels/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ $(function () {
self.serial_serialErrorBehaviour = ko.observable("cancel");
self.serial_triggerOkForM29 = ko.observable(undefined);
self.serial_waitForStart = ko.observable(undefined);
self.serial_waitToLoadSdFileList = ko.observable(undefined);
self.serial_sendChecksum = ko.observable("print");
self.serial_sendChecksumWithUnknownCommands = ko.observable(undefined);
self.serial_unknownCommandsNeedAck = ko.observable(undefined);
Expand Down Expand Up @@ -402,6 +403,7 @@ $(function () {

self.observableCopies = {
feature_waitForStart: "serial_waitForStart",
feature_waitToLoadSdFileList: "serial_waitToLoadSdFileList",
feature_sendChecksum: "serial_sendChecksum",
feature_sdRelativePath: "serial_sdRelativePath",
feature_sdAlwaysAvailable: "serial_sdAlwaysAvailable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@
<span class="help-block">{{ _('Try checking this if you run into connection timeouts due to your printer taking too long to respond to OctoPrint\'s handshake attempts on connect.') }}</span>
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_waitToLoadSdFileList" id="settings-serialWaitToLoadSdFileList"> {{ _('Wait to load the SD card file list until the firmware capability report is processed.') }}
<span class="help-block">{{ _('Try checking this if the SD card file list loads improperly after connecting to the printer.') }}</span>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label" for="settings-serialBlockedCommands">{{ _('Blocked commands') }}</label>
Expand Down
49 changes: 44 additions & 5 deletions src/octoprint/util/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,11 @@ def __init__(
self._ignore_select = False
self._manualStreaming = False

# Capability report tracking
self._first_cap_report_pending = False
self._first_cap_report_started = False
self._refresh_sd_files_after_cap_report = False

self.last_temperature = TemperatureRecord()
self.pause_temperature = TemperatureRecord()
self.cancel_temperature = TemperatureRecord()
Expand Down Expand Up @@ -2003,6 +2008,16 @@ def refreshSdFiles(self, tags=None):
if not self.isOperational() or self.isBusy():
return

if (
settings().get(["serial", "waitToLoadSdFileList"])
and self._first_cap_report_pending
):
self._refresh_sd_files_after_cap_report = True
self._logger.info(
kForth marked this conversation as resolved.
Show resolved Hide resolved
"Deferring sd file refresh until capability report is processed"
)
return

if tags is None:
tags = set()

Expand Down Expand Up @@ -2581,6 +2596,27 @@ def convert_line(line):
):
continue

# track the start and end of the first firmware capability reporting (from M115) so the sd card
# file list can be loaded afterwards for some printers
if (
settings().get(["serial", "waitToLoadSdFileList"])
and self._first_cap_report_pending
):
# capability report in progress
if lower_line.startswith("cap:"):
self._first_cap_report_started = True

# capability report done
elif self._first_cap_report_started:
self._first_cap_report_pending = False
self._first_cap_report_started = False

# refresh sd files now if it was deferred while waiting for report
if self._refresh_sd_files_after_cap_report:
self._refresh_sd_files_after_cap_report = False
self._logger.info("Performing deferred sd file refresh")
kForth marked this conversation as resolved.
Show resolved Hide resolved
self.refreshSdFiles()

##~~ position report processing
if "X:" in line and "Y:" in line and "Z:" in line:
parsed = parse_position_line(line)
Expand Down Expand Up @@ -2730,6 +2766,10 @@ def convert_line(line):
self._logger.info(
"Firmware states that it supports emergency GCODEs to be sent without waiting for an acknowledgement first"
)
elif capability == self.CAPABILITY_EXTENDED_M20 and enabled:
self._logger.info(
kForth marked this conversation as resolved.
Show resolved Hide resolved
"Firmware states that it supports long filenames"
)

# notify plugins
for name, hook in self._firmware_info_hooks[
Expand Down Expand Up @@ -3627,13 +3667,12 @@ def _onConnected(self):
"trigger:comm.on_connected",
},
)
if settings().get(["serial", "waitToLoadSdFileList"]):
self._first_cap_report_pending = True
self._first_cap_report_started = False

if self._sdAvailable:
self.refreshSdFiles(
tags={
"trigger:comm.on_connected",
}
)
self.refreshSdFiles(tags={"trigger:comm.on_connected"})
else:
self.initSdCard(tags={"trigger:comm.on_connected"})

Expand Down