Skip to content

Commit

Permalink
Autogenerated - Upstream v0.12.0-393-g35dd0140
Browse files Browse the repository at this point in the history
  • Loading branch information
Klippy-Tools-Bot committed Dec 1, 2024
1 parent 86f4e86 commit 242e963
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion klippy/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.12.0-386-ga079e986
v0.12.0-393-g35dd0140
6 changes: 6 additions & 0 deletions klippy/docs/Config_Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ All dates in this document are approximate.

## Changes

20241201: In some cases Klipper may have ignored leading characters or
spaces in a traditional G-Code command. For example, "99M123" may have
been interpreted as "M123" and "M 321" may have been interpreted as
"M321". Klipper will now report these cases with an "Unknown command"
warning.

20241112: Option `CHIPS=<chip_name>` in `TEST_RESONANCES` and
`SHAPER_CALIBRATE` requires specifying the full name(s) of the accel
chip(s). For example, `adxl345 rpi` instead of short name - `rpi`.
Expand Down
82 changes: 41 additions & 41 deletions klippy/gcode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Parse gcode commands
#
# Copyright (C) 2016-2021 Kevin O'Connor <[email protected]>
# Copyright (C) 2016-2024 Kevin O'Connor <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import os, re, logging, collections, shlex
Expand Down Expand Up @@ -28,19 +28,18 @@ def get_command_parameters(self):
return self._params
def get_raw_command_parameters(self):
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):
rawparams = rawparams[urawparams.find(command):]
end = rawparams.rfind('*')
if end >= 0:
rawparams = rawparams[:end]
rawparams = rawparams[len(command):]
if rawparams.startswith(' '):
rawparams = rawparams[1:]
return rawparams
origline = self._commandline
param_start = len(command)
param_end = len(origline)
if origline[:param_start].upper() != command:
# Skip any gcode line-number and ignore any trailing checksum
param_start += origline.upper().find(command)
end = origline.rfind('*')
if end >= 0 and origline[end+1:].isdigit():
param_end = end
if origline[param_start:param_start+1].isspace():
param_start += 1
return origline[param_start:param_end]
def ack(self, msg=None):
if not self._need_ack:
return False
Expand Down Expand Up @@ -133,6 +132,10 @@ def register_command(self, cmd, func, when_not_ready=False, desc=None):
raise self.printer.config_error(
"gcode command %s already registered" % (cmd,))
if not self.is_traditional_gcode(cmd):
if (cmd.upper() != cmd or not cmd.replace('_', 'A').isalnum()
or cmd[0].isdigit() or cmd[1:2].isdigit()):
raise self.printer.config_error(
"Can't register '%s' as it is an invalid name" % (cmd,))
origfunc = func
func = lambda params: origfunc(self._get_extended_params(params))
self.ready_gcode_handlers[cmd] = func
Expand Down Expand Up @@ -184,7 +187,7 @@ def _handle_ready(self):
self._build_status_commands()
self._respond_state("Ready")
# Parse input into commands
args_r = re.compile('([A-Z_]+|[A-Z*/])')
args_r = re.compile('([A-Z_]+|[A-Z*])')
def _process_commands(self, commands, need_ack=True):
for line in commands:
# Ignore comments and leading/trailing spaces
Expand All @@ -194,16 +197,14 @@ def _process_commands(self, commands, need_ack=True):
line = line[:cpos]
# Break line into parts and determine command
parts = self.args_r.split(line.upper())
numparts = len(parts)
cmd = ""
if numparts >= 3 and parts[1] != 'N':
cmd = parts[1] + parts[2].strip()
elif numparts >= 5 and parts[1] == 'N':
if ''.join(parts[:2]) == 'N':
# Skip line number at start of command
cmd = parts[3] + parts[4].strip()
cmd = ''.join(parts[3:5]).strip()
else:
cmd = ''.join(parts[:3]).strip()
# Build gcode "params" dictionary
params = { parts[i]: parts[i+1].strip()
for i in range(1, numparts, 2) }
for i in range(1, len(parts), 2) }
gcmd = GCodeCommand(self, cmd, origline, params, need_ack)
# Invoke handler for command
handler = self.gcode_handlers.get(cmd, self.cmd_default)
Expand Down Expand Up @@ -251,26 +252,22 @@ def _respond_error(self, msg):
def _respond_state(self, state):
self.respond_info("Klipper state: %s" % (state,), log=False)
# Parameter parsing helpers
extended_r = re.compile(
r'^\s*(?:N[0-9]+\s*)?'
r'(?P<cmd>[a-zA-Z_][a-zA-Z0-9_]+)(?:\s+|$)'
r'(?P<args>[^#*;]*?)'
r'\s*(?:[#*;].*)?$')
def _get_extended_params(self, gcmd):
m = self.extended_r.match(gcmd.get_commandline())
if m is None:
raise self.error("Malformed command '%s'"
% (gcmd.get_commandline(),))
eargs = m.group('args')
rawparams = gcmd.get_raw_command_parameters()
# Extract args while allowing shell style quoting
s = shlex.shlex(rawparams, posix=True)
s.whitespace_split = True
s.commenters = '#;'
try:
eparams = [earg.split('=', 1) for earg in shlex.split(eargs)]
eparams = [earg.split('=', 1) for earg in s]
eparams = { k.upper(): v for k, v in eparams }
gcmd._params.clear()
gcmd._params.update(eparams)
return gcmd
except ValueError as e:
raise self.error("Malformed command '%s'"
% (gcmd.get_commandline(),))
# Update gcmd with new parameters
gcmd._params.clear()
gcmd._params.update(eparams)
return gcmd
# G-Code special command handlers
def cmd_default(self, gcmd):
cmd = gcmd.get_command()
Expand All @@ -289,12 +286,15 @@ def cmd_default(self, gcmd):
if cmdline:
logging.debug(cmdline)
return
if cmd.startswith("M117 ") or cmd.startswith("M118 "):
if ' ' in cmd:
# 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
realcmd = cmd.split()[0]
if realcmd in ["M117", "M118", "M23"]:
handler = self.gcode_handlers.get(realcmd, None)
if handler is not None:
gcmd._command = realcmd
handler(gcmd)
return
elif cmd in ['M140', 'M104'] and not gcmd.get_float('S', 0.):
# Don't warn about requests to turn off heaters when not present
return
Expand Down

0 comments on commit 242e963

Please sign in to comment.