#define isSpace(c)(c == ' ' || c == '\t')
int CLIParserParseString(const char* str, void* vargtable[], size_t vargtableLen, bool allowEmptyExec) {
+ return CLIParserParseStringEx(str, vargtable, vargtableLen, allowEmptyExec, false);
+}
+
+int CLIParserParseStringEx(const char* str, void* vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData) {
int argc = 0;
char *argv[200] = {NULL};
for (int i = 0; i < len; i++) {
switch(state){
case PS_FIRST: // first char
- if (str[i] == '-'){ // first char before space is '-' - next element - option
+ if (!clueData || str[i] == '-'){ // first char before space is '-' - next element - option OR not "clueData" for not-option fields
state = PS_OPTION;
if (spaceptr) {
// convertors
int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) {
- switch(param_gethex_to_eol(argstr->sval[0], 0, data, maxdatalen, datalen)) {
+ *datalen = 0;
+
+ int ibuf = 0;
+ uint8_t buf[256] = {0};
+ int res = CLIParamStrToBuf(argstr, buf, maxdatalen * 2, &ibuf); // *2 because here HEX
+ if (res || !ibuf)
+ return res;
+
+ switch(param_gethex_to_eol((char *)buf, 0, data, maxdatalen, datalen)) {
case 1:
printf("Parameter error: Invalid HEX value.\n");
return 1;
return 0;
}
+int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) {
+ *datalen = 0;
+ if (!argstr->count)
+ return 0;
+
+ uint8_t buf[256] = {0};
+ int ibuf = 0;
+
+ for (int i = 0; i < argstr->count; i++) {
+ int len = strlen(argstr->sval[i]);
+ memcpy(&buf[ibuf], argstr->sval[i], len);
+ ibuf += len;
+ }
+ buf[ibuf] = 0;
+
+ if (!ibuf)
+ return 0;
+
+ if (ibuf > maxdatalen)
+ return 2;
+
+ memcpy(data, buf, ibuf);
+ *datalen = ibuf;
+
+ return 0;
+}