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>
This commit is contained in:
Kevin O'Connor 2023-01-13 12:42:14 -05:00
parent 69dcda1696
commit d881171739
3 changed files with 24 additions and 14 deletions

View file

@ -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)