From 31fbebdbb9f92476da9ad591b7457de2f48e49ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 5 Jun 2018 17:39:04 +0200 Subject: [PATCH] Basic action commands are working --- .../comm/protocol/reprap/__init__.py | 38 ++++++++++++++++++- .../comm/protocol/reprap/flavors/generic.py | 9 ++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index 81b4e439f..d780ef3fb 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -193,14 +193,19 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt self._last_lines = LineHistory(maxlen = 50) self._last_communication_error = None + # TODO GCODE Hooks self._gcode_hooks = dict(queuing=dict(), queued=dict(), sending=dict(), sent=dict()) + # TODO atcommand hooks self._atcommand_hooks = dict(queuing=dict(), sending=dict()) + # TODO action hooks + self._action_hooks = dict() + # temperature polling self._temperature_poller = None @@ -742,6 +747,37 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt self._set_busy_protocol_interval(interval=busy_interval) + def _on_comm_action_command(self, line, lower_line, action): + if action == "cancel": + self.process_protocol_log("Cancelling on request of the printer...") + self.cancel_processing() + elif action == "pause": + self.process_protocol_log("Pausing on request of the printer...") + self.pause_processing() + elif action == "paused": + self.process_protocol_log("Printer signalled that it paused, switching state...") + # TODO disable local handling + self.pause_processing() + elif action == "resume": + self.process_protocol_log("Resuming on request of the printer...") + self.resume_processing() + elif action == "resumed": + self.process_protocol_log("Printer signalled that it resumed, switching state...") + # TODO disable local handling + self.resume_processing() + elif action == "disconnect": + self.process_protocol_log("Disconnecting on request of the printer...") + # TODO inform printer about forced disconnect + self.disconnect() + else: + for hook in self._action_hooks: + try: + self._action_hooks[hook](self, line, action) + except: + self._logger.exception("Error while calling hook {} with action command {}".format(self._action_hooks[hook], + action)) + continue + def _on_message_temperature(self, max_tool_num, temperatures, heatup_detected): if heatup_detected: self._logger.debug("Externally triggered heatup detected") @@ -940,7 +976,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt try: if isinstance(entry, tuple): - if not len(entry) == 3: + if not len(entry) == 2: # something with that entry is broken, ignore it and fetch # the next one continue diff --git a/src/octoprint/comm/protocol/reprap/flavors/generic.py b/src/octoprint/comm/protocol/reprap/flavors/generic.py index cd22fa249..039ab4581 100644 --- a/src/octoprint/comm/protocol/reprap/flavors/generic.py +++ b/src/octoprint/comm/protocol/reprap/flavors/generic.py @@ -135,8 +135,8 @@ class GenericFlavor(object): return lower_line.startswith("resend") or lower_line.startswith("rs") @classmethod - def comm_debug(cls, line, lower_line, state, flags): - return line.startswith("//") + def comm_action_command(cls, line, lower_line, state, flags): + return line.startswith("//") and line[2:].strip().startswith("action:") @classmethod def comm_error(cls, line, lower_line, state, flags): @@ -232,6 +232,11 @@ class GenericFlavor(object): def parse_comm_timeout(cls, line, lower_line, state, flags): return dict(line=line, lower_line=lower_line) + @classmethod + def parse_comm_action_command(cls, line, lower_line, state, flags): + action = line[2:].strip()[len("action:"):].strip() + return dict(line=line, lower_line=lower_line, action=action) + @classmethod def parse_error_communication(cls, line, lower_line, state, flags): if "line number" in lower_line or "expected line" in lower_line: