editable serial input line buffer
Dependents: MAX5715BOB_Tester MAX11131BOB_Tester MAX5171BOB_Tester MAX11410BOB_Tester ... more
Diff: CmdLine.h
- Revision:
- 1:5b33e7447601
- Parent:
- 0:4d7de8b5c800
- Child:
- 2:0f702da53f2a
--- a/CmdLine.h Thu May 23 22:08:35 2019 +0000 +++ b/CmdLine.h Thu May 30 00:14:34 2019 +0000 @@ -40,43 +40,105 @@ #include "mbed.h" -/// @todo on_immediate_0x21() on_immediate_0x7b() on_immediate_0x7d() -/// should be declared in a more extensible way -void on_immediate_0x21(); // Unicode (U+0021) ! EXCLAMATION MARK -void on_immediate_0x7b(); // Unicode (U+007B) { LEFT CURLY BRACKET -void on_immediate_0x7d(); // Unicode (U+007D) } RIGHT CURLY BRACKET - - /** @brief CmdLine class manages an editable serial input line buffer */ class CmdLine { +/// @page Immediate Immediate command character +/// Class CmdLine supports immeidate command character handler functions. +/// Immediate command characters get handled immediately, +/// without waiting for End Of Line CR or LF, +/// and without appearing in the command buffer. +/// Avoid using characters that may appear in other commands, +/// such as 0-9 A-Z a-z and some punctuation %*+-./= +/// so these 25 characters are available: !"#$&'(),:;<>?@[\]^_`{|}~ +/// @see on_immediate_0x21 +/// @see on_immediate_0x22 +/// @see on_immediate_0x23 +/// @see on_immediate_0x24 +/// @see on_immediate_0x26 +/// @see on_immediate_0x27 +/// @see on_immediate_0x28 +/// @see on_immediate_0x29 +/// @see on_immediate_0x2c +/// @see on_immediate_0x3a +/// @see on_immediate_0x3b +/// @see on_immediate_0x3c +/// @see on_immediate_0x3e +/// @see on_immediate_0x3f +/// @see on_immediate_0x40 +/// @see on_immediate_0x5b +/// @see on_immediate_0x5c +/// @see on_immediate_0x5d +/// @see on_immediate_0x5e +/// @see on_immediate_0x5f +/// @see on_immediate_0x60 +/// @see on_immediate_0x7b +/// @see on_immediate_0x7c +/// @see on_immediate_0x7d +/// @see on_immediate_0x7e + protected: static const unsigned int COMMAND_BUFFER_LENGTH = 96; // buffer includes null termination unsigned int indexOfNextEmptyCell; char buf[COMMAND_BUFFER_LENGTH]; Stream& associatedSerialPort; const char *name; + public: CmdLine(Stream& AssociatedSerialPort, const char *Name); + void clear(); + //void idleAppendIfReadable(); // append ch to buf, unless BS or EOL or other editing character + void append(char ch); // append ch to buf, unless BS or EOL or other editing character - Callback<void(CmdLine&)> onEOLcommandParser; // on CR or LF, parse the command buffer + + Callback<void(CmdLine&)> onEOLcommandParser; //!< optional immediate handler for End Of Line CR or LF, parse the command buffer + + Callback<void(void)> on_immediate_0x21; //!< optional @ref Immediate handler for Unicode (U+0021) ! EXCLAMATION MARK + Callback<void(void)> on_immediate_0x22; //!< optional @ref Immediate handler for Unicode (U+0022) " QUOTATION MARK + Callback<void(void)> on_immediate_0x23; //!< optional @ref Immediate handler for Unicode (U+0023) # NUMBER SIGN = pound sign, hash, crosshatch + Callback<void(void)> on_immediate_0x24; //!< optional @ref Immediate handler for Unicode (U+0024) $ DOLLAR SIGN + Callback<void(void)> on_immediate_0x26; //!< optional @ref Immediate handler for Unicode (U+0026) & AMPERSAND + Callback<void(void)> on_immediate_0x27; //!< optional @ref Immediate handler for Unicode (U+0027) ' APOSTROPHE + Callback<void(void)> on_immediate_0x28; //!< optional @ref Immediate handler for Unicode (U+0028) ( LEFT PARENTHESIS + Callback<void(void)> on_immediate_0x29; //!< optional @ref Immediate handler for Unicode (U+0029) ) RIGHT PARENTHESIS + Callback<void(void)> on_immediate_0x2c; //!< optional @ref Immediate handler for Unicode (U+002C) , COMMA + Callback<void(void)> on_immediate_0x3a; //!< optional @ref Immediate handler for Unicode (U+003A) : COLON + Callback<void(void)> on_immediate_0x3b; //!< optional @ref Immediate handler for Unicode (U+003B) ; SEMICOLON + Callback<void(void)> on_immediate_0x3c; //!< optional @ref Immediate handler for Unicode (U+003C) < LESS-THAN SIGN + Callback<void(void)> on_immediate_0x3e; //!< optional @ref Immediate handler for Unicode (U+003E) > GREATER-THAN SIGN + Callback<void(void)> on_immediate_0x3f; //!< optional @ref Immediate handler for Unicode (U+003F) ? QUESTION MARK + Callback<void(void)> on_immediate_0x40; //!< optional @ref Immediate handler for Unicode (U+0040) @ COMMERCIAL AT = at sign + Callback<void(void)> on_immediate_0x5b; //!< optional @ref Immediate handler for Unicode (U+005B) [ LEFT SQUARE BRACKET + Callback<void(void)> on_immediate_0x5c; //!< optional @ref Immediate handler for Unicode (U+005C) \ REVERSE SOLIDUS + Callback<void(void)> on_immediate_0x5d; //!< optional @ref Immediate handler for Unicode (U+005D) ] RIGHT SQUARE BRACKET + Callback<void(void)> on_immediate_0x5e; //!< optional @ref Immediate handler for Unicode (U+005E) ^ CIRCUMFLEX ACCENT + Callback<void(void)> on_immediate_0x5f; //!< optional @ref Immediate handler for Unicode (U+005F) _ LOW LINE =SPACING UNDERSCORE + Callback<void(void)> on_immediate_0x60; //!< optional @ref Immediate handler for Unicode (U+0060) ` GRAVE ACCENT (also called backtick) + Callback<void(void)> on_immediate_0x7b; //!< optional @ref Immediate handler for Unicode (U+007B) { LEFT CURLY BRACKET + Callback<void(void)> on_immediate_0x7c; //!< optional @ref Immediate handler for Unicode (U+007C) | VERTICAL LINE + Callback<void(void)> on_immediate_0x7d; //!< optional @ref Immediate handler for Unicode (U+007D) } RIGHT CURLY BRACKET + Callback<void(void)> on_immediate_0x7e; //!< optional @ref Immediate handler for Unicode (U+007E) ~ TILDE + /** serial returns reference to the associated serial port */ Stream& serial(void) const { return associatedSerialPort; }; + /** CmdLine[index] returns the character at specified index; [0] is the first character */ char operator[] (unsigned int index) const { if (index >= indexOfNextEmptyCell) return '\0'; return buf[index]; }; + /** str returns the c-string buffer */ const char *str() const { return buf; }; + /** nameStr returns the names of the associated serial port */ const char *nameStr() const { return name; @@ -99,4 +161,3 @@ #endif // __CmdLine_H__ // End of file -