command: Encode MESSAGE_MIN in command_parser->max_size

Add the message minimum into the stored constant so it does not need
to be added at run-time.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-06-15 14:01:42 -04:00
parent 1c3cbe9456
commit 1ae78d08e9
2 changed files with 6 additions and 4 deletions

View File

@ -30,7 +30,8 @@ def error(msg):
def build_parser(parser, iscmd, all_param_types): def build_parser(parser, iscmd, all_param_types):
if parser.name == "#empty": if parser.name == "#empty":
return "\n // Empty message\n .max_size=0," return "\n // Empty message\n .max_size=%d," % (
msgproto.MESSAGE_MIN,)
if parser.name == "#output": if parser.name == "#output":
comment = "Output: " + parser.msgformat comment = "Output: " + parser.msgformat
else: else:
@ -54,8 +55,9 @@ def build_parser(parser, iscmd, all_param_types):
+ types.count('PT_buffer')) + types.count('PT_buffer'))
out += " .num_args=%d," % (num_args,) out += " .num_args=%d," % (num_args,)
else: else:
max_size = min(msgproto.MESSAGE_MAX - msgproto.MESSAGE_MIN max_size = min(msgproto.MESSAGE_MAX,
, 1 + sum([t.max_length for t in parser.param_types])) (msgproto.MESSAGE_MIN + 1
+ sum([t.max_length for t in parser.param_types])))
out += " .max_size=%d," % (max_size,) out += " .max_size=%d," % (max_size,)
return out return out

View File

@ -192,7 +192,7 @@ _sendf(const struct command_encoder *ce, ...)
return; return;
writeb(&in_sendf, 1); writeb(&in_sendf, 1);
uint8_t buf_len = READP(ce->max_size) + MESSAGE_MIN; uint8_t buf_len = READP(ce->max_size);
char *buf = console_get_output(buf_len); char *buf = console_get_output(buf_len);
if (!buf) if (!buf)
goto done; goto done;