diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2023-01-13 12:42:14 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2023-02-22 11:34:36 -0500 |
commit | d8811717391cb9ac11eaebf342387edd7404fdd0 (patch) | |
tree | 2fd2c0f9030f5c7cd88f5156934952cd413b158f /klippy/msgproto.py | |
parent | 69dcda1696a04e303f70632a09869f3cc57bb94f (diff) | |
download | kutter-d8811717391cb9ac11eaebf342387edd7404fdd0.tar.gz kutter-d8811717391cb9ac11eaebf342387edd7404fdd0.tar.xz kutter-d8811717391cb9ac11eaebf342387edd7404fdd0.zip |
mcu: Move lookup_command_tag() to CommandWrapper class
Use mcu.lookup_command().get_command_tag() instead of
mcu.lookup_command_tag(). This improves error reporting on a protocol
mismatch. It also enables support for a msgtag that is negative.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/msgproto.py')
-rw-r--r-- | klippy/msgproto.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/klippy/msgproto.py b/klippy/msgproto.py index 177dbf7b..f8a12530 100644 --- a/klippy/msgproto.py +++ b/klippy/msgproto.py @@ -234,6 +234,7 @@ class MessageParser: self.messages = [] self.messages_by_id = {} self.messages_by_name = {} + self.msgtag_by_format = {} self.config = {} self.version = self.build_versions = "" self.raw_identify_data = "" @@ -316,6 +317,11 @@ class MessageParser: self._error("Command format mismatch: %s vs %s", msgformat, mp.msgformat) return mp + def lookup_msgtag(self, msgformat): + msgtag = self.msgtag_by_format.get(msgformat) + if msgtag is None: + self._error("Unknown command: %s", msgformat) + return msgtag def create_command(self, msg): parts = msg.strip().split() if not parts: @@ -376,6 +382,7 @@ class MessageParser: self.messages.append((msgtag, msgtype, msgformat)) if msgtag < -32 or msgtag > 95: self._error("Multi-byte msgtag not supported") + self.msgtag_by_format[msgformat] = msgtag msgid = msgtag & 0x7f if msgtype == 'output': self.messages_by_id[msgid] = OutputFormat(msgid, msgformat) |