From 0ac518040b42396ba509e02aa3e8c4866fac63d8 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 2 Jul 2017 14:11:10 -0400 Subject: [PATCH] msgproto: Export static_strings from mcu to host as a dictionary Export the static strings as a dictionary instead of as a list. Signed-off-by: Kevin O'Connor --- klippy/msgproto.py | 7 ++++--- scripts/buildcommands.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/klippy/msgproto.py b/klippy/msgproto.py index df7b6717..9f8082cb 100644 --- a/klippy/msgproto.py +++ b/klippy/msgproto.py @@ -185,7 +185,7 @@ class MessageParser: self.unknown = UnknownFormat() self.messages_by_id = {} self.messages_by_name = {} - self.static_strings = [] + self.static_strings = {} self.config = {} self.version = "" self.raw_identify_data = "" @@ -240,7 +240,7 @@ class MessageParser: params['#name'] = mid.name static_string_id = params.get('static_string_id') if static_string_id is not None: - params['#msg'] = self.static_strings[static_string_id] + params['#msg'] = self.static_strings.get(static_string_id, "?") return params def encode(self, seq, cmd): msglen = MESSAGE_MIN + len(cmd) @@ -311,7 +311,8 @@ class MessageParser: commands = data.get('commands') responses = data.get('responses') self._init_messages(messages, commands+responses) - self.static_strings = data.get('static_strings', []) + static_strings = data.get('static_strings', {}) + self.static_strings = { int(k): v for k, v in static_strings.items() } self.config.update(data.get('config', {})) self.version = data.get('version', '') def get_constant(self, name): diff --git a/scripts/buildcommands.py b/scripts/buildcommands.py index 0c147191..93c0eb37 100644 --- a/scripts/buildcommands.py +++ b/scripts/buildcommands.py @@ -187,7 +187,8 @@ def build_identify(cmd_by_id, msg_to_id, responses, static_strings data['messages'] = messages data['commands'] = sorted(cmd_by_id.keys()) data['responses'] = sorted(responses) - data['static_strings'] = static_strings + data['static_strings'] = { i: static_strings[i] + for i in range(len(static_strings)) } data['config'] = constants data['version'] = version