editable serial input line buffer
Dependents: MAX5715BOB_Tester MAX11131BOB_Tester MAX5171BOB_Tester MAX11410BOB_Tester ... more
Diff: CmdLine.cpp
- Revision:
- 13:abedfe18f924
- Parent:
- 12:447a747099e6
- Child:
- 14:9abcdf4eb4e4
--- a/CmdLine.cpp Thu Dec 19 01:28:54 2019 +0000 +++ b/CmdLine.cpp Mon Apr 06 05:12:27 2020 -0700 @@ -640,6 +640,42 @@ return false; // no match } +/** CmdLine::parse_int_dec matches "key"=value + * + * @return true if keyword was found in buffer + * @param[in] key string value to match + * @param[out] intVar updated from value string if match "key"=value + * + * @post on successful match, the key=value substring is deleted from cmdbuf + * + * Prefix '$' or '0x' or '0X' selects radix base-16 hexadecimal. + * Default number conversion radix is base-10 decimal. + */ +bool CmdLine::parse_int_dec(const char *key, int& intVar) +{ + char valueBuf[16]; + // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen); + if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf))) + { + // ASSERT: buf[matched_index] contains '=' followed by value + // parse cmdLine arg (CMD=\d)? --> g_I2C_command_regAddress + // TODO1: parse_byte_hex take hex prefix 0x 0X or suffix $ h H + if (valueBuf[0] == '$') + { + intVar = strtoul(valueBuf + 1, NULL, 16); + return true; + } + if (valueBuf[0] == '0' && (valueBuf[1] == 'X' || valueBuf[1] == 'x')) + { + intVar = strtoul(valueBuf + 2, NULL, 16); + return true; + } + intVar = strtoul(valueBuf, NULL, 10); // default radix decimal + return true; + } + return false; // no match +} + /** CmdLine::parse_int16_hex matches "key"=value * * @return true if keyword was found in buffer