drivers: modem: modem_cmd_handler: Allow dynamic number of commands args

This is necessary to allow parsing of commands with dynamic number of
arguments.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
This commit is contained in:
Xavier Chapron 2020-07-17 09:59:43 +02:00 committed by Anas Nashif
commit 3d61989bc7
2 changed files with 19 additions and 6 deletions

View file

@ -134,7 +134,7 @@ static int parse_params(struct modem_cmd_handler_data *data, size_t match_len,
}
}
if (count >= cmd->arg_count) {
if (count >= cmd->arg_count_max) {
break;
}
@ -158,7 +158,7 @@ static int parse_params(struct modem_cmd_handler_data *data, size_t match_len,
}
/* missing arguments */
if (*argc < cmd->arg_count) {
if (*argc < cmd->arg_count_min) {
return -EAGAIN;
}
@ -181,7 +181,7 @@ static int process_cmd(const struct modem_cmd *cmd, size_t match_len,
memset(argv, 0, sizeof(argv[0]) * ARRAY_SIZE(argv));
/* do we need to parse arguments? */
if (cmd->arg_count > 0U) {
if (cmd->arg_count_max > 0U) {
/* returns < 0 on error and > 0 for parsed len */
parsed_len = parse_params(data, match_len, cmd,
argv, ARRAY_SIZE(argv), &argc);

View file

@ -29,7 +29,18 @@ static int name_(struct modem_cmd_handler_data *data, uint16_t len, \
.cmd = cmd_, \
.cmd_len = (uint16_t)sizeof(cmd_)-1, \
.func = func_cb_, \
.arg_count = acount_, \
.arg_count_min = acount_, \
.arg_count_max = acount_, \
.delim = adelim_, \
.direct = false, \
}
#define MODEM_CMD_ARGS_MAX(cmd_, func_cb_, acount_, acountmax_, adelim_) { \
.cmd = cmd_, \
.cmd_len = (uint16_t)sizeof(cmd_)-1, \
.func = func_cb_, \
.arg_count_min = acount_, \
.arg_count_max = acountmax_, \
.delim = adelim_, \
.direct = false, \
}
@ -40,7 +51,8 @@ static int name_(struct modem_cmd_handler_data *data, uint16_t len, \
.cmd = cmd_, \
.cmd_len = (uint16_t)sizeof(cmd_)-1, \
.func = func_cb_, \
.arg_count = 0, \
.arg_count_min = 0, \
.arg_count_max = 0, \
.delim = "", \
.direct = true, \
}
@ -58,7 +70,8 @@ struct modem_cmd {
const char *cmd;
const char *delim;
uint16_t cmd_len;
uint16_t arg_count;
uint16_t arg_count_min;
uint16_t arg_count_max;
bool direct;
};