editable serial input line buffer
Dependents: MAX5715BOB_Tester MAX11131BOB_Tester MAX5171BOB_Tester MAX11410BOB_Tester ... more
Diff: CmdLine.cpp
- Revision:
- 4:700b71cd3bd2
- Parent:
- 3:cf3de26aa444
- Child:
- 5:1a14de1c4d7b
--- a/CmdLine.cpp Thu Jun 20 22:25:39 2019 +0000 +++ b/CmdLine.cpp Tue Jul 16 10:24:18 2019 +0000 @@ -403,6 +403,41 @@ return false; // no match } +/** CmdLine::parse_interval_usec matches "key"=digits + * + * @return true if keyword was found in buffer + * @param[in] key string value to match + * @param[out] interval_usec updated from value string if match "key"=value, + * optional suffix Hz kHz or MHz 1/x inverts and scales the value + * optional suffix s or ms or msec or us or usec scales the value + * + * @post on successful match, the key=value substring is deleted from cmdbuf + * + */ +bool CmdLine::parse_interval_usec(const char *key, us_timestamp_t& interval_usec) +{ + char valueBuf[32]; + // 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 + interval_usec = strtoul(valueBuf, NULL, 10); + if (strstr(valueBuf, "ms")) { + interval_usec = interval_usec * 1000; + } else if (strstr(valueBuf, "s")) { + interval_usec = interval_usec * 1000000; + } else if (strstr(valueBuf, "MHz")) { + interval_usec = 1. / interval_usec; + } else if (strstr(valueBuf, "kHz")) { + interval_usec = 1000. / interval_usec; + } else if (strstr(valueBuf, "Hz")) { + interval_usec = 1000000. / interval_usec; + } + return true; + } + return false; // no match +} + /** CmdLine::parse_flag matches "key"=0 or 1 * * @return true if keyword was found in buffer