editable serial input line buffer
Dependents: MAX5715BOB_Tester MAX11131BOB_Tester MAX5171BOB_Tester MAX11410BOB_Tester ... more
CmdLine.h@15:34b039027e5f, 2021-04-27 (annotated)
- Committer:
- whismanoid
- Date:
- Tue Apr 27 03:47:33 2021 -0700
- Revision:
- 15:34b039027e5f
- Parent:
- 13:abedfe18f924
- Child:
- 16:592df067fe14
cmdLine.quiet support datalogger and button events
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
whismanoid | 0:4d7de8b5c800 | 1 | // /******************************************************************************* |
whismanoid | 0:4d7de8b5c800 | 2 | // * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved. |
whismanoid | 0:4d7de8b5c800 | 3 | // * |
whismanoid | 0:4d7de8b5c800 | 4 | // * Permission is hereby granted, free of charge, to any person obtaining a |
whismanoid | 0:4d7de8b5c800 | 5 | // * copy of this software and associated documentation files (the "Software"), |
whismanoid | 0:4d7de8b5c800 | 6 | // * to deal in the Software without restriction, including without limitation |
whismanoid | 0:4d7de8b5c800 | 7 | // * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
whismanoid | 0:4d7de8b5c800 | 8 | // * and/or sell copies of the Software, and to permit persons to whom the |
whismanoid | 0:4d7de8b5c800 | 9 | // * Software is furnished to do so, subject to the following conditions: |
whismanoid | 0:4d7de8b5c800 | 10 | // * |
whismanoid | 0:4d7de8b5c800 | 11 | // * The above copyright notice and this permission notice shall be included |
whismanoid | 0:4d7de8b5c800 | 12 | // * in all copies or substantial portions of the Software. |
whismanoid | 0:4d7de8b5c800 | 13 | // * |
whismanoid | 0:4d7de8b5c800 | 14 | // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
whismanoid | 0:4d7de8b5c800 | 15 | // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
whismanoid | 0:4d7de8b5c800 | 16 | // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
whismanoid | 0:4d7de8b5c800 | 17 | // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
whismanoid | 0:4d7de8b5c800 | 18 | // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
whismanoid | 0:4d7de8b5c800 | 19 | // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
whismanoid | 0:4d7de8b5c800 | 20 | // * OTHER DEALINGS IN THE SOFTWARE. |
whismanoid | 0:4d7de8b5c800 | 21 | // * |
whismanoid | 0:4d7de8b5c800 | 22 | // * Except as contained in this notice, the name of Maxim Integrated |
whismanoid | 0:4d7de8b5c800 | 23 | // * Products, Inc. shall not be used except as stated in the Maxim Integrated |
whismanoid | 0:4d7de8b5c800 | 24 | // * Products, Inc. Branding Policy. |
whismanoid | 0:4d7de8b5c800 | 25 | // * |
whismanoid | 0:4d7de8b5c800 | 26 | // * The mere transfer of this software does not imply any licenses |
whismanoid | 0:4d7de8b5c800 | 27 | // * of trade secrets, proprietary technology, copyrights, patents, |
whismanoid | 0:4d7de8b5c800 | 28 | // * trademarks, maskwork rights, or any other form of intellectual |
whismanoid | 0:4d7de8b5c800 | 29 | // * property whatsoever. Maxim Integrated Products, Inc. retains all |
whismanoid | 0:4d7de8b5c800 | 30 | // * ownership rights. |
whismanoid | 0:4d7de8b5c800 | 31 | // ******************************************************************************* |
whismanoid | 0:4d7de8b5c800 | 32 | // */ |
whismanoid | 0:4d7de8b5c800 | 33 | // ********************************************************************* |
whismanoid | 0:4d7de8b5c800 | 34 | // @file CmdLine.h |
whismanoid | 0:4d7de8b5c800 | 35 | // ********************************************************************* |
whismanoid | 0:4d7de8b5c800 | 36 | |
whismanoid | 0:4d7de8b5c800 | 37 | // Prevent multiple declaration |
whismanoid | 0:4d7de8b5c800 | 38 | #ifndef __CmdLine_H__ |
whismanoid | 0:4d7de8b5c800 | 39 | #define __CmdLine_H__ |
whismanoid | 0:4d7de8b5c800 | 40 | |
whismanoid | 6:88e92f832c9a | 41 | // standard include for target platform |
whismanoid | 0:4d7de8b5c800 | 42 | #include "mbed.h" |
whismanoid | 0:4d7de8b5c800 | 43 | |
whismanoid | 0:4d7de8b5c800 | 44 | /** |
whismanoid | 0:4d7de8b5c800 | 45 | @brief CmdLine class manages an editable serial input line buffer |
whismanoid | 0:4d7de8b5c800 | 46 | */ |
whismanoid | 0:4d7de8b5c800 | 47 | class CmdLine |
whismanoid | 0:4d7de8b5c800 | 48 | { |
whismanoid | 1:5b33e7447601 | 49 | /// @page Immediate Immediate command character |
whismanoid | 1:5b33e7447601 | 50 | /// Class CmdLine supports immeidate command character handler functions. |
whismanoid | 1:5b33e7447601 | 51 | /// Immediate command characters get handled immediately, |
whismanoid | 1:5b33e7447601 | 52 | /// without waiting for End Of Line CR or LF, |
whismanoid | 1:5b33e7447601 | 53 | /// and without appearing in the command buffer. |
whismanoid | 1:5b33e7447601 | 54 | /// Avoid using characters that may appear in other commands, |
whismanoid | 1:5b33e7447601 | 55 | /// such as 0-9 A-Z a-z and some punctuation %*+-./= |
whismanoid | 1:5b33e7447601 | 56 | /// so these 25 characters are available: !"#$&'(),:;<>?@[\]^_`{|}~ |
whismanoid | 2:0f702da53f2a | 57 | /// @see on_immediate_0x21 handler for Unicode (U+0021) ! EXCLAMATION MARK |
whismanoid | 2:0f702da53f2a | 58 | /// @see on_immediate_0x22 handler for Unicode (U+0022) " QUOTATION MARK |
whismanoid | 2:0f702da53f2a | 59 | /// @see on_immediate_0x23 handler for Unicode (U+0023) # NUMBER SIGN = pound sign, hash, crosshatch |
whismanoid | 2:0f702da53f2a | 60 | /// @see on_immediate_0x24 handler for Unicode (U+0024) $ DOLLAR SIGN |
whismanoid | 2:0f702da53f2a | 61 | /// @see on_immediate_0x26 handler for Unicode (U+0026) & AMPERSAND |
whismanoid | 2:0f702da53f2a | 62 | /// @see on_immediate_0x27 handler for Unicode (U+0027) ' APOSTROPHE |
whismanoid | 2:0f702da53f2a | 63 | /// @see on_immediate_0x28 handler for Unicode (U+0028) ( LEFT PARENTHESIS |
whismanoid | 2:0f702da53f2a | 64 | /// @see on_immediate_0x29 handler for Unicode (U+0029) ) RIGHT PARENTHESIS |
whismanoid | 2:0f702da53f2a | 65 | /// @see on_immediate_0x2c handler for Unicode (U+002C) , COMMA |
whismanoid | 2:0f702da53f2a | 66 | /// @see on_immediate_0x3a handler for Unicode (U+003A) : COLON |
whismanoid | 2:0f702da53f2a | 67 | /// @see on_immediate_0x3b handler for Unicode (U+003B) ; SEMICOLON |
whismanoid | 2:0f702da53f2a | 68 | /// @see on_immediate_0x3c handler for Unicode (U+003C) < LESS-THAN SIGN |
whismanoid | 2:0f702da53f2a | 69 | /// @see on_immediate_0x3e handler for Unicode (U+003E) > GREATER-THAN SIGN |
whismanoid | 2:0f702da53f2a | 70 | /// @see on_immediate_0x3f handler for Unicode (U+003F) ? QUESTION MARK |
whismanoid | 2:0f702da53f2a | 71 | /// @see on_immediate_0x40 handler for Unicode (U+0040) @ COMMERCIAL AT = at sign |
whismanoid | 2:0f702da53f2a | 72 | /// @see on_immediate_0x5b handler for Unicode (U+005B) [ LEFT SQUARE BRACKET |
whismanoid | 2:0f702da53f2a | 73 | /// @see on_immediate_0x5c handler for Unicode (U+005C) \ REVERSE SOLIDUS |
whismanoid | 2:0f702da53f2a | 74 | /// @see on_immediate_0x5d handler for Unicode (U+005D) ] RIGHT SQUARE BRACKET |
whismanoid | 2:0f702da53f2a | 75 | /// @see on_immediate_0x5e handler for Unicode (U+005E) ^ CIRCUMFLEX ACCENT |
whismanoid | 2:0f702da53f2a | 76 | /// @see on_immediate_0x5f handler for Unicode (U+005F) _ LOW LINE =SPACING UNDERSCORE |
whismanoid | 2:0f702da53f2a | 77 | /// @see on_immediate_0x60 handler for Unicode (U+0060) ` GRAVE ACCENT (also called backtick) |
whismanoid | 2:0f702da53f2a | 78 | /// @see on_immediate_0x7b handler for Unicode (U+007B) { LEFT CURLY BRACKET |
whismanoid | 2:0f702da53f2a | 79 | /// @see on_immediate_0x7c handler for Unicode (U+007C) | VERTICAL LINE |
whismanoid | 2:0f702da53f2a | 80 | /// @see on_immediate_0x7d handler for Unicode (U+007D) } RIGHT CURLY BRACKET |
whismanoid | 2:0f702da53f2a | 81 | /// @see on_immediate_0x7e handler for Unicode (U+007E) ~ TILDE |
whismanoid | 1:5b33e7447601 | 82 | |
whismanoid | 0:4d7de8b5c800 | 83 | protected: |
whismanoid | 0:4d7de8b5c800 | 84 | static const unsigned int COMMAND_BUFFER_LENGTH = 96; // buffer includes null termination |
whismanoid | 0:4d7de8b5c800 | 85 | unsigned int indexOfNextEmptyCell; |
whismanoid | 0:4d7de8b5c800 | 86 | char buf[COMMAND_BUFFER_LENGTH]; |
whismanoid | 0:4d7de8b5c800 | 87 | Stream& associatedSerialPort; |
whismanoid | 0:4d7de8b5c800 | 88 | const char *name; |
whismanoid | 1:5b33e7447601 | 89 | |
whismanoid | 0:4d7de8b5c800 | 90 | public: |
whismanoid | 0:4d7de8b5c800 | 91 | CmdLine(Stream& AssociatedSerialPort, const char *Name); |
whismanoid | 1:5b33e7447601 | 92 | |
whismanoid | 0:4d7de8b5c800 | 93 | void clear(); |
whismanoid | 1:5b33e7447601 | 94 | |
whismanoid | 0:4d7de8b5c800 | 95 | //void idleAppendIfReadable(); // append ch to buf, unless BS or EOL or other editing character |
whismanoid | 1:5b33e7447601 | 96 | |
whismanoid | 15:34b039027e5f | 97 | bool quiet; // suppress append(ch) from writing to associatedSerialPort |
whismanoid | 0:4d7de8b5c800 | 98 | void append(char ch); // append ch to buf, unless BS or EOL or other editing character |
whismanoid | 1:5b33e7447601 | 99 | |
whismanoid | 10:3e2ff983be1c | 100 | // onEOLcommandParser |
whismanoid | 1:5b33e7447601 | 101 | Callback<void(CmdLine&)> onEOLcommandParser; //!< optional immediate handler for End Of Line CR or LF, parse the command buffer |
whismanoid | 1:5b33e7447601 | 102 | |
whismanoid | 10:3e2ff983be1c | 103 | // diagnostic_led_EOF |
whismanoid | 6:88e92f832c9a | 104 | Callback<void(void)> diagnostic_led_EOF; //!< optional @ref diagnostic_led_EOF |
whismanoid | 6:88e92f832c9a | 105 | |
whismanoid | 10:3e2ff983be1c | 106 | // Immediate handlers on_immediate_0x21 .. on_immediate_0x7e |
whismanoid | 1:5b33e7447601 | 107 | Callback<void(void)> on_immediate_0x21; //!< optional @ref Immediate handler for Unicode (U+0021) ! EXCLAMATION MARK |
whismanoid | 1:5b33e7447601 | 108 | Callback<void(void)> on_immediate_0x22; //!< optional @ref Immediate handler for Unicode (U+0022) " QUOTATION MARK |
whismanoid | 1:5b33e7447601 | 109 | Callback<void(void)> on_immediate_0x23; //!< optional @ref Immediate handler for Unicode (U+0023) # NUMBER SIGN = pound sign, hash, crosshatch |
whismanoid | 1:5b33e7447601 | 110 | Callback<void(void)> on_immediate_0x24; //!< optional @ref Immediate handler for Unicode (U+0024) $ DOLLAR SIGN |
whismanoid | 1:5b33e7447601 | 111 | Callback<void(void)> on_immediate_0x26; //!< optional @ref Immediate handler for Unicode (U+0026) & AMPERSAND |
whismanoid | 1:5b33e7447601 | 112 | Callback<void(void)> on_immediate_0x27; //!< optional @ref Immediate handler for Unicode (U+0027) ' APOSTROPHE |
whismanoid | 1:5b33e7447601 | 113 | Callback<void(void)> on_immediate_0x28; //!< optional @ref Immediate handler for Unicode (U+0028) ( LEFT PARENTHESIS |
whismanoid | 1:5b33e7447601 | 114 | Callback<void(void)> on_immediate_0x29; //!< optional @ref Immediate handler for Unicode (U+0029) ) RIGHT PARENTHESIS |
whismanoid | 1:5b33e7447601 | 115 | Callback<void(void)> on_immediate_0x2c; //!< optional @ref Immediate handler for Unicode (U+002C) , COMMA |
whismanoid | 1:5b33e7447601 | 116 | Callback<void(void)> on_immediate_0x3a; //!< optional @ref Immediate handler for Unicode (U+003A) : COLON |
whismanoid | 1:5b33e7447601 | 117 | Callback<void(void)> on_immediate_0x3b; //!< optional @ref Immediate handler for Unicode (U+003B) ; SEMICOLON |
whismanoid | 1:5b33e7447601 | 118 | Callback<void(void)> on_immediate_0x3c; //!< optional @ref Immediate handler for Unicode (U+003C) < LESS-THAN SIGN |
whismanoid | 1:5b33e7447601 | 119 | Callback<void(void)> on_immediate_0x3e; //!< optional @ref Immediate handler for Unicode (U+003E) > GREATER-THAN SIGN |
whismanoid | 1:5b33e7447601 | 120 | Callback<void(void)> on_immediate_0x3f; //!< optional @ref Immediate handler for Unicode (U+003F) ? QUESTION MARK |
whismanoid | 1:5b33e7447601 | 121 | Callback<void(void)> on_immediate_0x40; //!< optional @ref Immediate handler for Unicode (U+0040) @ COMMERCIAL AT = at sign |
whismanoid | 1:5b33e7447601 | 122 | Callback<void(void)> on_immediate_0x5b; //!< optional @ref Immediate handler for Unicode (U+005B) [ LEFT SQUARE BRACKET |
whismanoid | 1:5b33e7447601 | 123 | Callback<void(void)> on_immediate_0x5c; //!< optional @ref Immediate handler for Unicode (U+005C) \ REVERSE SOLIDUS |
whismanoid | 1:5b33e7447601 | 124 | Callback<void(void)> on_immediate_0x5d; //!< optional @ref Immediate handler for Unicode (U+005D) ] RIGHT SQUARE BRACKET |
whismanoid | 1:5b33e7447601 | 125 | Callback<void(void)> on_immediate_0x5e; //!< optional @ref Immediate handler for Unicode (U+005E) ^ CIRCUMFLEX ACCENT |
whismanoid | 1:5b33e7447601 | 126 | Callback<void(void)> on_immediate_0x5f; //!< optional @ref Immediate handler for Unicode (U+005F) _ LOW LINE =SPACING UNDERSCORE |
whismanoid | 1:5b33e7447601 | 127 | Callback<void(void)> on_immediate_0x60; //!< optional @ref Immediate handler for Unicode (U+0060) ` GRAVE ACCENT (also called backtick) |
whismanoid | 1:5b33e7447601 | 128 | Callback<void(void)> on_immediate_0x7b; //!< optional @ref Immediate handler for Unicode (U+007B) { LEFT CURLY BRACKET |
whismanoid | 1:5b33e7447601 | 129 | Callback<void(void)> on_immediate_0x7c; //!< optional @ref Immediate handler for Unicode (U+007C) | VERTICAL LINE |
whismanoid | 1:5b33e7447601 | 130 | Callback<void(void)> on_immediate_0x7d; //!< optional @ref Immediate handler for Unicode (U+007D) } RIGHT CURLY BRACKET |
whismanoid | 1:5b33e7447601 | 131 | Callback<void(void)> on_immediate_0x7e; //!< optional @ref Immediate handler for Unicode (U+007E) ~ TILDE |
whismanoid | 1:5b33e7447601 | 132 | |
whismanoid | 0:4d7de8b5c800 | 133 | /** serial returns reference to the associated serial port */ |
whismanoid | 0:4d7de8b5c800 | 134 | Stream& serial(void) const { |
whismanoid | 0:4d7de8b5c800 | 135 | return associatedSerialPort; |
whismanoid | 0:4d7de8b5c800 | 136 | }; |
whismanoid | 1:5b33e7447601 | 137 | |
whismanoid | 0:4d7de8b5c800 | 138 | /** CmdLine[index] returns the character at specified index; [0] is the first character */ |
whismanoid | 0:4d7de8b5c800 | 139 | char operator[] (unsigned int index) const { |
whismanoid | 0:4d7de8b5c800 | 140 | if (index >= indexOfNextEmptyCell) return '\0'; |
whismanoid | 0:4d7de8b5c800 | 141 | return buf[index]; |
whismanoid | 0:4d7de8b5c800 | 142 | }; |
whismanoid | 1:5b33e7447601 | 143 | |
whismanoid | 0:4d7de8b5c800 | 144 | /** str returns the c-string buffer */ |
whismanoid | 0:4d7de8b5c800 | 145 | const char *str() const { |
whismanoid | 0:4d7de8b5c800 | 146 | return buf; |
whismanoid | 0:4d7de8b5c800 | 147 | }; |
whismanoid | 1:5b33e7447601 | 148 | |
whismanoid | 0:4d7de8b5c800 | 149 | /** nameStr returns the names of the associated serial port */ |
whismanoid | 0:4d7de8b5c800 | 150 | const char *nameStr() const { |
whismanoid | 0:4d7de8b5c800 | 151 | return name; |
whismanoid | 0:4d7de8b5c800 | 152 | }; |
whismanoid | 0:4d7de8b5c800 | 153 | |
whismanoid | 0:4d7de8b5c800 | 154 | // bool parse_and_remove_key(const char *key, int& matched_index); |
whismanoid | 0:4d7de8b5c800 | 155 | bool parse_and_remove_key(const char *key, char *valueBuf, size_t valueBufLen); |
whismanoid | 9:12e37800ecdd | 156 | char chSeparator; |
whismanoid | 10:3e2ff983be1c | 157 | bool match_is_case_sensitive; |
whismanoid | 0:4d7de8b5c800 | 158 | |
whismanoid | 0:4d7de8b5c800 | 159 | bool parse_frequency_Hz(const char *key, uint32_t& frequency_Hz); |
whismanoid | 4:700b71cd3bd2 | 160 | bool parse_interval_usec(const char *key, us_timestamp_t& interval_usec); |
whismanoid | 0:4d7de8b5c800 | 161 | bool parse_flag(const char *key, uint8_t& nFlagVar, const uint8_t nFlagBitMask); |
whismanoid | 0:4d7de8b5c800 | 162 | bool parse_byte_hex(const char *key, uint8_t& nByteVar); |
whismanoid | 0:4d7de8b5c800 | 163 | bool parse_byte_dec(const char *key, uint8_t& nByteVar); |
whismanoid | 6:88e92f832c9a | 164 | bool parse_uint8_dec(const char *key, uint8_t& nByteVar) { return parse_byte_dec(key, nByteVar); }; |
whismanoid | 0:4d7de8b5c800 | 165 | bool parse_uint16_hex(const char *key, uint16_t& uint16Var); |
whismanoid | 2:0f702da53f2a | 166 | bool parse_uint16_dec(const char *key, uint16_t& uint16Var); |
whismanoid | 13:abedfe18f924 | 167 | bool parse_int_dec(const char *key, int& intVar); |
whismanoid | 0:4d7de8b5c800 | 168 | bool parse_int16_hex(const char *key, int16_t& int16Var); |
whismanoid | 2:0f702da53f2a | 169 | bool parse_int16_dec(const char *key, int16_t& int16Var); |
whismanoid | 9:12e37800ecdd | 170 | bool parse_uint32_hex(const char *key, uint32_t& uint32Var); |
whismanoid | 9:12e37800ecdd | 171 | bool parse_uint32_dec(const char *key, uint32_t& uint32Var); |
whismanoid | 9:12e37800ecdd | 172 | bool parse_int32_hex(const char *key, int32_t& int32Var); |
whismanoid | 9:12e37800ecdd | 173 | bool parse_int32_dec(const char *key, int32_t& int32Var); |
whismanoid | 7:0bda7cfee767 | 174 | bool parse_double(const char *key, double& doubleVar); |
whismanoid | 0:4d7de8b5c800 | 175 | bool parse_float(const char *key, float& floatVar); |
whismanoid | 0:4d7de8b5c800 | 176 | bool parse_byteCount_byteList_hex(size_t& byteCount, char *mosiDataBuf, size_t mosiDataBufSize); |
whismanoid | 0:4d7de8b5c800 | 177 | bool parse_byteCount_byteList_dec(size_t& byteCount, char *mosiDataBuf, size_t mosiDataBufSize); |
whismanoid | 0:4d7de8b5c800 | 178 | }; |
whismanoid | 0:4d7de8b5c800 | 179 | |
whismanoid | 0:4d7de8b5c800 | 180 | #endif // __CmdLine_H__ |
whismanoid | 0:4d7de8b5c800 | 181 | |
whismanoid | 0:4d7de8b5c800 | 182 | // End of file |