From d8811717391cb9ac11eaebf342387edd7404fdd0 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 13 Jan 2023 12:42:14 -0500 Subject: 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 --- klippy/msgproto.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'klippy/msgproto.py') 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) -- cgit v1.2.3-70-g09d2