diff options
Diffstat (limited to 'scripts/buildcommands.py')
-rw-r--r-- | scripts/buildcommands.py | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/scripts/buildcommands.py b/scripts/buildcommands.py index eaa6d585..9e811485 100644 --- a/scripts/buildcommands.py +++ b/scripts/buildcommands.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # Script to handle build time requests embedded in C code. # -# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net> +# Copyright (C) 2016-2021 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. import sys, os, subprocess, optparse, logging, shlex, socket, time, traceback @@ -172,8 +172,8 @@ class HandleInitialPins: if not self.initial_pins: return [] mp = msgproto.MessageParser() - mp._fill_enumerations(HandlerEnumerations.enumerations) - pinmap = mp.enumerations.get('pin', {}) + mp.fill_enumerations(HandlerEnumerations.enumerations) + pinmap = mp.get_enumerations().get('pin', {}) out = [] for p in self.initial_pins: flag = "IP_OUT_HIGH" @@ -304,13 +304,15 @@ class HandleCommandGeneration: 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 + def build_parser(self, msgid, msgformat, msgtype): + if msgtype == "output": + param_types = msgproto.lookup_output_params(msgformat) + comment = "Output: " + msgformat else: - comment = parser.msgformat + param_types = [t for name, t in msgproto.lookup_params(msgformat)] + comment = msgformat params = '0' - types = tuple([t.__class__.__name__ for t in parser.param_types]) + types = tuple([t.__class__.__name__ for t in param_types]) if types: paramid = self.all_param_types.get(types) if paramid is None: @@ -322,15 +324,15 @@ class HandleCommandGeneration: .msg_id=%d, .num_params=%d, .param_types = %s, -""" % (comment, parser.msgid, len(types), params) - if iscmd: +""" % (comment, msgid, len(types), params) + if msgtype == 'response': num_args = (len(types) + types.count('PT_progmem_buffer') + types.count('PT_buffer')) out += " .num_args=%d," % (num_args,) else: max_size = min(msgproto.MESSAGE_MAX, (msgproto.MESSAGE_MIN + 1 - + sum([t.max_length for t in parser.param_types]))) + + sum([t.max_length for t in param_types]))) out += " .max_size=%d," % (max_size,) return out def generate_responses_code(self): @@ -342,17 +344,15 @@ class HandleCommandGeneration: msgid = self.msg_to_id[msg] if msgid in did_output: continue - s = msg did_output[msgid] = True code = (' if (__builtin_strcmp(str, "%s") == 0)\n' - ' return &command_encoder_%s;\n' % (s, msgid)) + ' return &command_encoder_%s;\n' % (msg, msgid)) if msgname is None: - parser = msgproto.OutputFormat(msgid, msg) + parsercode = self.build_parser(msgid, msg, 'output') output_code.append(code) else: - parser = msgproto.MessageFormat(msgid, msg) + parsercode = self.build_parser(msgid, msg, 'command') encoder_code.append(code) - parsercode = self.build_parser(parser, 0) encoder_defs.append( "const struct command_encoder command_encoder_%s PROGMEM = {" " %s\n};\n" % ( @@ -392,8 +392,7 @@ ctr_lookup_output(const char *str) funcname, flags, msgname = cmd_by_id[msgid] msg = self.messages_by_name[msgname] externs[funcname] = 1 - parser = msgproto.MessageFormat(msgid, msg) - parsercode = self.build_parser(parser, 1) + parsercode = self.build_parser(msgid, msg, 'response') index.append(" {%s\n .flags=%s,\n .func=%s\n}," % ( parsercode, flags, funcname)) index = "".join(index).strip() |