aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-03-04 19:50:35 -0500
committerKevinOConnor <kevin@koconnor.net>2019-03-17 19:38:18 -0400
commit7eda55e2b042566020ade34d7b2cdb9296f37f1d (patch)
tree3fe33547e2d8d385effbb4ce33f9426459fd91e3 /scripts
parentb9b03dd0826f7212e78034bf522eca64de4a258e (diff)
downloadkutter-7eda55e2b042566020ade34d7b2cdb9296f37f1d.tar.gz
kutter-7eda55e2b042566020ade34d7b2cdb9296f37f1d.tar.xz
kutter-7eda55e2b042566020ade34d7b2cdb9296f37f1d.zip
buildcommands: Use dictionaries to describe commands, responses, and output
Avoid transmitting lists of message ids for commands and responses - gzip doesn't do a good job of compressing them. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/buildcommands.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/scripts/buildcommands.py b/scripts/buildcommands.py
index 2b892366..1c3448fe 100644
--- a/scripts/buildcommands.py
+++ b/scripts/buildcommands.py
@@ -131,7 +131,7 @@ class HandleCommandGeneration:
def __init__(self):
self.commands = {}
self.encoders = []
- self.msg_to_id = { m: i for i, m in msgproto.DefaultMessages.items() }
+ self.msg_to_id = dict(msgproto.DefaultMessages)
self.messages_by_name = { m.split()[0]: m for m in self.msg_to_id }
self.all_param_types = {}
self.ctr_dispatch = {
@@ -172,16 +172,20 @@ class HandleCommandGeneration:
# The mcu currently assumes all message ids encode to one byte
error("Too many message ids")
def update_data_dictionary(self, data):
- messages = { msgid: msg for msg, msgid in self.msg_to_id.items() }
- data['messages'] = messages
- commands = [self.msg_to_id[msg]
- for msgname, msg in self.messages_by_name.items()
- if msgname in self.commands]
- data['commands'] = sorted(commands)
- responses = [self.msg_to_id[msg]
- for msgname, msg in self.messages_by_name.items()
- if msgname not in self.commands]
- data['responses'] = sorted(responses)
+ command_ids = [self.msg_to_id[msg]
+ for msgname, msg in self.messages_by_name.items()
+ if msgname in self.commands]
+ response_ids = [self.msg_to_id[msg]
+ for msgname, msg in self.messages_by_name.items()
+ if msgname not in self.commands]
+ data['commands'] = { msg: msgid for msg, msgid in self.msg_to_id.items()
+ if msgid in command_ids }
+ data['responses'] = {msg: msgid for msg, msgid in self.msg_to_id.items()
+ if msgid in response_ids }
+ output = { msg: msgid for msg, msgid in self.msg_to_id.items()
+ if msgid not in command_ids and msgid not in response_ids }
+ if output:
+ data['output'] = output
def build_parser(self, parser, iscmd):
if parser.name == "#output":
comment = "Output: " + parser.msgformat
@@ -412,7 +416,7 @@ class HandleIdentify:
data = {}
for h in Handlers:
h.update_data_dictionary(data)
- datadict = json.dumps(data, separators=(',', ':'))
+ datadict = json.dumps(data, separators=(',', ':'), sort_keys=True)
# Write data dictionary
if options.write_dictionary: