From 024cf812380b1621d3e7729439a667b978f3b5f3 Mon Sep 17 00:00:00 2001 From: Dattas Moonchaser Date: Sat, 8 Nov 2014 11:36:31 -0700 Subject: [PATCH] Allow gcode commands to get farther into the processing, but ensure they don't get pushed to the printer --- .../comm/protocol/reprap/__init__.py | 2 +- src/octoprint/comm/protocol/reprap/util.py | 52 ++++++++++--------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index e8e7f937b..ba01bd3fd 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -882,7 +882,7 @@ class RepRapProtocol(Protocol): def _prepare_for_sending(self, command, with_line_number=None): command, with_line_number = self._process_command(command, "sent", with_line_number=with_line_number) - if command is None: + if command is None or command.unknown: return None, None if self._force_checksum: diff --git a/src/octoprint/comm/protocol/reprap/util.py b/src/octoprint/comm/protocol/reprap/util.py index ea7fd5ae7..fcae5cb35 100644 --- a/src/octoprint/comm/protocol/reprap/util.py +++ b/src/octoprint/comm/protocol/reprap/util.py @@ -26,33 +26,35 @@ class GcodeCommand(object): @staticmethod def from_line(line): line = line.strip() + command = "" + args = {"original": line} match = GcodeCommand.COMMAND_REGEX.match(line) if match is None: - return None - - commandType = match.group(1) - commandNumber = int(match.group(2)) - command = "%s%d" % (commandType, commandNumber) - args = {"original": line} - - if commandType == "T": - args["tool"] = commandNumber + args["unknown"] = True else: - matchedArgs = GcodeCommand.ARGUMENT_REGEX.findall(line) - if len(matchedArgs) == 0: - paramMatch = GcodeCommand.PARAM_REGEX.match(line) - if paramMatch is not None: - args["param"] = paramMatch.group(1) + commandType = match.group(1) + commandNumber = int(match.group(2)) + command = "%s%d" % (commandType, commandNumber) + + + if commandType == "T": + args["tool"] = commandNumber else: - for arg in matchedArgs: - key = arg[0].lower() - if key in GcodeCommand.KNOWN_INT_ATTRIBUTES: - value = int(arg[1:]) - elif key in GcodeCommand.KNOWN_FLOAT_ATTRIBUTES: - value = float(arg[1:]) - else: - value = str(arg[1:]) - args[key] = value + matchedArgs = GcodeCommand.ARGUMENT_REGEX.findall(line) + if len(matchedArgs) == 0: + paramMatch = GcodeCommand.PARAM_REGEX.match(line) + if paramMatch is not None: + args["param"] = paramMatch.group(1) + else: + for arg in matchedArgs: + key = arg[0].lower() + if key in GcodeCommand.KNOWN_INT_ATTRIBUTES: + value = int(arg[1:]) + elif key in GcodeCommand.KNOWN_FLOAT_ATTRIBUTES: + value = float(arg[1:]) + else: + value = str(arg[1:]) + args[key] = value return GcodeCommand(command, **args) @@ -76,8 +78,10 @@ class GcodeCommand(object): self.progress = None self.callback = None + self.unknown = False + for key, value in kwargs.iteritems(): - if key in GcodeCommand.KNOWN_ATTRIBUTES + ("tool", "original", "param", "progress", "callback"): + if key in GcodeCommand.KNOWN_ATTRIBUTES + ("tool", "original", "param", "progress", "callback", "unknown"): self.__setattr__(key, value) def isGetTemperatureCommand(self):