gcode: Handle M117 and M118 commands that start with a special character

Commit 7ef7bf60 broke the special handling for M117 commands that
start with a number or special character.  Fix that support and extend
to M118 as well.

Also improve handling of commands not separated by a space (eg,
"M117HELLO").

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-01-18 11:21:53 -05:00
parent 02d5f9754f
commit f97fd7c6e3
1 changed files with 10 additions and 11 deletions

View File

@ -27,20 +27,19 @@ class GCodeCommand:
def get_command_parameters(self):
return self._params
def get_raw_command_parameters(self):
rawparams = self._commandline
command = self._command
if command.startswith("M117 ") or command.startswith("M118 "):
command = command[:4]
rawparams = self._commandline
urawparams = rawparams.upper()
if not urawparams.startswith(command):
start = urawparams.find(command)
rawparams = rawparams[urawparams.find(command):]
end = rawparams.rfind('*')
if end >= 0:
rawparams = rawparams[:end]
rawparams = rawparams[start:]
commandlen = len(command) + 1
if len(rawparams) > commandlen:
rawparams = rawparams[commandlen:]
else:
rawparams = ''
rawparams = rawparams[len(command):]
if rawparams.startswith(' '):
rawparams = rawparams[1:]
return rawparams
def ack(self, msg=None):
if not self._need_ack:
@ -277,9 +276,9 @@ class GCodeDispatch:
if cmdline:
logging.debug(cmdline)
return
if cmd.startswith("M117 "):
# Handle M117 gcode with numeric and special characters
handler = self.gcode_handlers.get("M117", None)
if cmd.startswith("M117 ") or cmd.startswith("M118 "):
# Handle M117/M118 gcode with numeric and special characters
handler = self.gcode_handlers.get(cmd[:4], None)
if handler is not None:
handler(gcmd)
return