editable serial input line buffer

Dependents:   MAX5715BOB_Tester MAX11131BOB_Tester MAX5171BOB_Tester MAX11410BOB_Tester ... more

Committer:
whismanoid
Date:
Tue Aug 13 16:20:23 2019 -0700
Revision:
6:88e92f832c9a
Parent:
5:1a14de1c4d7b
Child:
7:0bda7cfee767
optional diagnostic_led_EOF() handler

Who changed what in which revision?

UserRevisionLine numberNew 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.cpp
whismanoid 0:4d7de8b5c800 35 // *********************************************************************
whismanoid 0:4d7de8b5c800 36
whismanoid 0:4d7de8b5c800 37 #include "CmdLine.h"
whismanoid 0:4d7de8b5c800 38
whismanoid 0:4d7de8b5c800 39 CmdLine::CmdLine(Stream& AssociatedSerialPort, const char *Name)
whismanoid 0:4d7de8b5c800 40 : associatedSerialPort(AssociatedSerialPort)
whismanoid 0:4d7de8b5c800 41 , name(Name)
whismanoid 0:4d7de8b5c800 42 , onEOLcommandParser()
whismanoid 0:4d7de8b5c800 43 {
whismanoid 0:4d7de8b5c800 44 indexOfNextEmptyCell = 0;
whismanoid 0:4d7de8b5c800 45 memset(buf, 0, COMMAND_BUFFER_LENGTH);
whismanoid 0:4d7de8b5c800 46 }
whismanoid 0:4d7de8b5c800 47 /** CmdLine::clear empties the command-line buffer */
whismanoid 0:4d7de8b5c800 48 void CmdLine::clear(void)
whismanoid 0:4d7de8b5c800 49 {
whismanoid 0:4d7de8b5c800 50 indexOfNextEmptyCell = 0;
whismanoid 0:4d7de8b5c800 51 memset(buf, 0, COMMAND_BUFFER_LENGTH);
whismanoid 0:4d7de8b5c800 52 }
whismanoid 0:4d7de8b5c800 53 //void CmdLine::idleAppendIfReadable()
whismanoid 0:4d7de8b5c800 54 //{
whismanoid 0:4d7de8b5c800 55 // // append ch to buf, unless BS or EOL or other editing character
whismanoid 0:4d7de8b5c800 56 // // Polymorphism fail: associatedSerialPort.readable()
whismanoid 0:4d7de8b5c800 57 // if (associatedSerialPort.readable()) {
whismanoid 0:4d7de8b5c800 58 // append(associatedSerialPort.getc());
whismanoid 0:4d7de8b5c800 59 // //
whismanoid 0:4d7de8b5c800 60 // // TODO1: set EOL timeout, so that we don't get lingering buffer cruft
whismanoid 0:4d7de8b5c800 61 // //
whismanoid 0:4d7de8b5c800 62 // }
whismanoid 0:4d7de8b5c800 63 //}
whismanoid 0:4d7de8b5c800 64 /** CmdLine::append handles an input character by appending the buffer,
whismanoid 0:4d7de8b5c800 65 * or handling an immediate function like backspace/delete
whismanoid 0:4d7de8b5c800 66 * or other custom immediate motor control functions.
whismanoid 0:4d7de8b5c800 67 */
whismanoid 0:4d7de8b5c800 68 void CmdLine::append(char ch)
whismanoid 0:4d7de8b5c800 69 {
whismanoid 6:88e92f832c9a 70 // void diagnostic_led_EOF();
whismanoid 0:4d7de8b5c800 71 void main_menu_status(CmdLine & cmdLine);
whismanoid 0:4d7de8b5c800 72
whismanoid 0:4d7de8b5c800 73 // append ch to buf, unless BS or EOL or other editing character
whismanoid 0:4d7de8b5c800 74 switch (ch)
whismanoid 0:4d7de8b5c800 75 {
whismanoid 0:4d7de8b5c800 76 case '\b': // Unicode (U+0008) BS BACKSPACE as destructive backspace
whismanoid 0:4d7de8b5c800 77 case '\x7f': // Unicode (U+007F) DEL DELETE as destructive backspace
whismanoid 0:4d7de8b5c800 78 if (indexOfNextEmptyCell > 0)
whismanoid 0:4d7de8b5c800 79 {
whismanoid 0:4d7de8b5c800 80 buf[--indexOfNextEmptyCell] = '\0'; // pre-decrement index, overwrite with null
whismanoid 0:4d7de8b5c800 81 associatedSerialPort.printf("\b \b"); // tty: backspace, overwrite with space, backspace
whismanoid 0:4d7de8b5c800 82 }
whismanoid 0:4d7de8b5c800 83 break;
whismanoid 0:4d7de8b5c800 84 case '\r': // Unicode (U+000D) CR CARRIAGE RETURN(CR) as EOL end of line
whismanoid 0:4d7de8b5c800 85 case '\n': // Unicode (U+000A) LF LINE FEED(LF) as EOL end of line
whismanoid 0:4d7de8b5c800 86 //associatedSerialPort.printf("%c", ch); // echo line end
whismanoid 0:4d7de8b5c800 87 associatedSerialPort.printf("\r\n"); // echo line end
whismanoid 0:4d7de8b5c800 88 //~ associatedSerialPort.printf("\r\n~%s~\r\n", buf); // DIAGNOSTIC: print line buffer
whismanoid 0:4d7de8b5c800 89 // parse and handle the command by invoking onEOLcommandParser callback
whismanoid 0:4d7de8b5c800 90 if (onEOLcommandParser) {
whismanoid 0:4d7de8b5c800 91 onEOLcommandParser(*this);
whismanoid 0:4d7de8b5c800 92 }
whismanoid 0:4d7de8b5c800 93 clear();
whismanoid 0:4d7de8b5c800 94 break;
whismanoid 0:4d7de8b5c800 95 #define ECHO_EOF_IMMEDIATELY 1
whismanoid 0:4d7de8b5c800 96 #if ECHO_EOF_IMMEDIATELY
whismanoid 0:4d7de8b5c800 97 case '\x04': // Unicode (U+0004) EOT END OF TRANSMISSION = CTRL+D as EOF end of file
whismanoid 6:88e92f832c9a 98 if (diagnostic_led_EOF) { diagnostic_led_EOF(); }
whismanoid 0:4d7de8b5c800 99 //~ main_menu_status(*this);
whismanoid 0:4d7de8b5c800 100 associatedSerialPort.printf("** U+0004 EOT = EOF **"); // immediately echo EOF for test scripting
whismanoid 6:88e92f832c9a 101 if (diagnostic_led_EOF) { diagnostic_led_EOF(); }
whismanoid 0:4d7de8b5c800 102 associatedSerialPort.printf("\r\n\x04\r\n"); // immediately echo EOF for test scripting
whismanoid 0:4d7de8b5c800 103 //~ associatedSerialPort.printf("\x1a"); // immediately echo EOF for test scripting
whismanoid 0:4d7de8b5c800 104 //~ associatedSerialPort.printf("\x04"); // immediately echo EOF for test scripting
whismanoid 0:4d7de8b5c800 105 //~ associatedSerialPort.printf("\x1a"); // immediately echo EOF for test scripting
whismanoid 0:4d7de8b5c800 106 clear(); // EOF discard any pending commands, to avoid surprise
whismanoid 0:4d7de8b5c800 107 break;
whismanoid 0:4d7de8b5c800 108 case '\x1a': // Unicode (U+001A) SUB SUBSTITUTE = CTRL+Z as EOF end of file
whismanoid 6:88e92f832c9a 109 if (diagnostic_led_EOF) { diagnostic_led_EOF(); }
whismanoid 0:4d7de8b5c800 110 //~ main_menu_status(*this);
whismanoid 0:4d7de8b5c800 111 associatedSerialPort.printf("** U+001A SUB = EOF **"); // immediately echo EOF for test scripting
whismanoid 6:88e92f832c9a 112 if (diagnostic_led_EOF) { diagnostic_led_EOF(); }
whismanoid 0:4d7de8b5c800 113 associatedSerialPort.printf("\x1a"); // immediately echo EOF for test scripting
whismanoid 0:4d7de8b5c800 114 associatedSerialPort.printf("\x04"); // immediately echo EOF for test scripting
whismanoid 0:4d7de8b5c800 115 associatedSerialPort.printf("\x1a"); // immediately echo EOF for test scripting
whismanoid 0:4d7de8b5c800 116 associatedSerialPort.printf("\x04"); // immediately echo EOF for test scripting
whismanoid 0:4d7de8b5c800 117 clear(); // EOF discard any pending commands, to avoid surprise
whismanoid 0:4d7de8b5c800 118 break;
whismanoid 0:4d7de8b5c800 119 #endif
whismanoid 0:4d7de8b5c800 120 //
whismanoid 0:4d7de8b5c800 121 // Support commands that get handled immediately w/o waiting for EOL
whismanoid 0:4d7de8b5c800 122 // Avoid using characters that may appear in other commands,
whismanoid 0:4d7de8b5c800 123 // such as 0-9 A-Z a-z and some punctuation %*+-./=
whismanoid 0:4d7de8b5c800 124 // so these 25 characters are available: !"#$&'(),:;<>?@[\]^_`{|}~
whismanoid 0:4d7de8b5c800 125 //case '!': // immediate command !) example
whismanoid 0:4d7de8b5c800 126 // do_some_immediate_action();
whismanoid 0:4d7de8b5c800 127 // clear();
whismanoid 0:4d7de8b5c800 128 // break;
whismanoid 0:4d7de8b5c800 129 //case ' ':
whismanoid 0:4d7de8b5c800 130 // on_immediate_0x20(); // Unicode (U+0020) SPACE
whismanoid 0:4d7de8b5c800 131 // break;
whismanoid 0:4d7de8b5c800 132 case '!':
whismanoid 1:5b33e7447601 133 //~ on_immediate_0x21(); // Unicode (U+0021) ! EXCLAMATION MARK
whismanoid 1:5b33e7447601 134 //~ break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 135 if (on_immediate_0x21) {
whismanoid 1:5b33e7447601 136 on_immediate_0x21(); // Unicode (U+0021) ! EXCLAMATION MARK
whismanoid 1:5b33e7447601 137 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 138 }
whismanoid 0:4d7de8b5c800 139 case '{':
whismanoid 1:5b33e7447601 140 //~ on_immediate_0x7b(); // Unicode (U+007B) { LEFT CURLY BRACKET
whismanoid 1:5b33e7447601 141 //~ break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 142 if (on_immediate_0x7b) {
whismanoid 1:5b33e7447601 143 on_immediate_0x7b(); // Unicode (U+007B) { LEFT CURLY BRACKET
whismanoid 1:5b33e7447601 144 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 145 }
whismanoid 0:4d7de8b5c800 146 case '}':
whismanoid 1:5b33e7447601 147 //~ on_immediate_0x7d(); // Unicode (U+007D) } RIGHT CURLY BRACKET
whismanoid 1:5b33e7447601 148 //~ break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 149 if (on_immediate_0x7d) {
whismanoid 1:5b33e7447601 150 on_immediate_0x7d(); // Unicode (U+007D) } RIGHT CURLY BRACKET
whismanoid 1:5b33e7447601 151 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 152 }
whismanoid 0:4d7de8b5c800 153 //
whismanoid 0:4d7de8b5c800 154 // default:
whismanoid 0:4d7de8b5c800 155 case '"':
whismanoid 1:5b33e7447601 156 if (on_immediate_0x22) {
whismanoid 1:5b33e7447601 157 on_immediate_0x22(); // Unicode (U+0022) " QUOTATION MARK
whismanoid 1:5b33e7447601 158 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 159 }
whismanoid 0:4d7de8b5c800 160 case '#':
whismanoid 1:5b33e7447601 161 if (on_immediate_0x23) {
whismanoid 1:5b33e7447601 162 on_immediate_0x23(); // Unicode (U+0023) # NUMBER SIGN = pound sign, hash, crosshatch
whismanoid 1:5b33e7447601 163 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 164 }
whismanoid 0:4d7de8b5c800 165 case '$':
whismanoid 1:5b33e7447601 166 if (on_immediate_0x24) {
whismanoid 1:5b33e7447601 167 on_immediate_0x24(); // Unicode (U+0024) $ DOLLAR SIGN
whismanoid 1:5b33e7447601 168 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 169 }
whismanoid 0:4d7de8b5c800 170 //~ on_immediate_0x24(); // Unicode (U+0024) $ DOLLAR SIGN
whismanoid 0:4d7de8b5c800 171 //~ break; // handled as immediate command, do not append to buffer
whismanoid 0:4d7de8b5c800 172 //case '%':
whismanoid 0:4d7de8b5c800 173 // on_immediate_0x25(); // Unicode (U+0025) % PERCENT SIGN
whismanoid 0:4d7de8b5c800 174 // break;
whismanoid 0:4d7de8b5c800 175 case '&':
whismanoid 1:5b33e7447601 176 if (on_immediate_0x26) {
whismanoid 1:5b33e7447601 177 on_immediate_0x26(); // Unicode (U+0026) & AMPERSAND
whismanoid 1:5b33e7447601 178 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 179 }
whismanoid 0:4d7de8b5c800 180 case '\'':
whismanoid 1:5b33e7447601 181 if (on_immediate_0x27) {
whismanoid 1:5b33e7447601 182 on_immediate_0x27(); // Unicode (U+0027) ' APOSTROPHE
whismanoid 1:5b33e7447601 183 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 184 }
whismanoid 0:4d7de8b5c800 185 case '(':
whismanoid 1:5b33e7447601 186 if (on_immediate_0x28) {
whismanoid 1:5b33e7447601 187 on_immediate_0x28(); // Unicode (U+0028) ( LEFT PARENTHESIS
whismanoid 1:5b33e7447601 188 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 189 }
whismanoid 0:4d7de8b5c800 190 case ')':
whismanoid 1:5b33e7447601 191 if (on_immediate_0x29) {
whismanoid 1:5b33e7447601 192 on_immediate_0x29(); // Unicode (U+0029) ) RIGHT PARENTHESIS
whismanoid 1:5b33e7447601 193 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 194 }
whismanoid 0:4d7de8b5c800 195 //case '*':
whismanoid 0:4d7de8b5c800 196 // on_immediate_0x2a(); // Unicode (U+002A) * ASTERISK
whismanoid 0:4d7de8b5c800 197 // break;
whismanoid 0:4d7de8b5c800 198 //case '+':
whismanoid 0:4d7de8b5c800 199 // on_immediate_0x2b(); // Unicode (U+002B) + PLUS SIGN
whismanoid 0:4d7de8b5c800 200 // break;
whismanoid 0:4d7de8b5c800 201 case ',':
whismanoid 1:5b33e7447601 202 if (on_immediate_0x2c) {
whismanoid 1:5b33e7447601 203 on_immediate_0x2c(); // Unicode (U+002C) , COMMA
whismanoid 1:5b33e7447601 204 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 205 }
whismanoid 0:4d7de8b5c800 206 //case '-':
whismanoid 0:4d7de8b5c800 207 // on_immediate_0x2d(); // Unicode (U+002D) - HYPHEN-MINUS
whismanoid 0:4d7de8b5c800 208 // break;
whismanoid 0:4d7de8b5c800 209 //case '.':
whismanoid 0:4d7de8b5c800 210 // on_immediate_0x2e(); // Unicode (U+002E) . FULL STOP
whismanoid 0:4d7de8b5c800 211 // break;
whismanoid 0:4d7de8b5c800 212 //case '/':
whismanoid 0:4d7de8b5c800 213 // on_immediate_0x2f(); // Unicode (U+002F) / SOLIDUS =SLASH
whismanoid 0:4d7de8b5c800 214 // break;
whismanoid 0:4d7de8b5c800 215 case ':':
whismanoid 1:5b33e7447601 216 if (on_immediate_0x3a) {
whismanoid 1:5b33e7447601 217 on_immediate_0x3a(); // Unicode (U+003A) : COLON
whismanoid 1:5b33e7447601 218 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 219 }
whismanoid 0:4d7de8b5c800 220 case ';':
whismanoid 1:5b33e7447601 221 if (on_immediate_0x3b) {
whismanoid 1:5b33e7447601 222 on_immediate_0x3b(); // Unicode (U+003B) ; SEMICOLON
whismanoid 1:5b33e7447601 223 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 224 }
whismanoid 0:4d7de8b5c800 225 case '<':
whismanoid 1:5b33e7447601 226 if (on_immediate_0x3c) {
whismanoid 1:5b33e7447601 227 on_immediate_0x3c(); // Unicode (U+003C) < LESS-THAN SIGN
whismanoid 1:5b33e7447601 228 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 229 }
whismanoid 0:4d7de8b5c800 230 //case '=':
whismanoid 0:4d7de8b5c800 231 // on_immediate_0x3d(); // Unicode (U+003D) = EQUALS SIGN
whismanoid 0:4d7de8b5c800 232 // break;
whismanoid 0:4d7de8b5c800 233 case '>':
whismanoid 1:5b33e7447601 234 if (on_immediate_0x3e) {
whismanoid 1:5b33e7447601 235 on_immediate_0x3e(); // Unicode (U+003E) > GREATER-THAN SIGN
whismanoid 1:5b33e7447601 236 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 237 }
whismanoid 0:4d7de8b5c800 238 case '?':
whismanoid 1:5b33e7447601 239 if (on_immediate_0x3f) {
whismanoid 1:5b33e7447601 240 on_immediate_0x3f(); // Unicode (U+003F) ? QUESTION MARK
whismanoid 1:5b33e7447601 241 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 242 }
whismanoid 0:4d7de8b5c800 243 case '@':
whismanoid 1:5b33e7447601 244 if (on_immediate_0x40) {
whismanoid 1:5b33e7447601 245 on_immediate_0x40(); // Unicode (U+0040) @ COMMERCIAL AT = at sign
whismanoid 1:5b33e7447601 246 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 247 }
whismanoid 0:4d7de8b5c800 248 case '[':
whismanoid 1:5b33e7447601 249 if (on_immediate_0x5b) {
whismanoid 1:5b33e7447601 250 on_immediate_0x5b(); // Unicode (U+005B) [ LEFT SQUARE BRACKET
whismanoid 1:5b33e7447601 251 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 252 }
whismanoid 0:4d7de8b5c800 253 case '\\':
whismanoid 1:5b33e7447601 254 if (on_immediate_0x5c) {
whismanoid 1:5b33e7447601 255 on_immediate_0x5c(); // Unicode (U+005C) \ REVERSE SOLIDUS
whismanoid 1:5b33e7447601 256 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 257 }
whismanoid 0:4d7de8b5c800 258 case ']':
whismanoid 1:5b33e7447601 259 if (on_immediate_0x5d) {
whismanoid 1:5b33e7447601 260 on_immediate_0x5d(); // Unicode (U+005D) ] RIGHT SQUARE BRACKET
whismanoid 1:5b33e7447601 261 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 262 }
whismanoid 0:4d7de8b5c800 263 case '^':
whismanoid 1:5b33e7447601 264 if (on_immediate_0x5e) {
whismanoid 1:5b33e7447601 265 on_immediate_0x5e(); // Unicode (U+005E) ^ CIRCUMFLEX ACCENT
whismanoid 1:5b33e7447601 266 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 267 }
whismanoid 0:4d7de8b5c800 268 case '_':
whismanoid 1:5b33e7447601 269 if (on_immediate_0x5f) {
whismanoid 1:5b33e7447601 270 on_immediate_0x5f(); // Unicode (U+005F) _ LOW LINE =SPACING UNDERSCORE
whismanoid 1:5b33e7447601 271 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 272 }
whismanoid 0:4d7de8b5c800 273 case '`':
whismanoid 1:5b33e7447601 274 if (on_immediate_0x60) {
whismanoid 1:5b33e7447601 275 on_immediate_0x60(); // Unicode (U+0060) ` GRAVE ACCENT (also called backtick)
whismanoid 1:5b33e7447601 276 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 277 }
whismanoid 0:4d7de8b5c800 278 case '|':
whismanoid 1:5b33e7447601 279 if (on_immediate_0x7c) {
whismanoid 1:5b33e7447601 280 on_immediate_0x7c(); // Unicode (U+007C) | VERTICAL LINE
whismanoid 1:5b33e7447601 281 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 282 }
whismanoid 0:4d7de8b5c800 283 case '~':
whismanoid 1:5b33e7447601 284 if (on_immediate_0x7e) {
whismanoid 1:5b33e7447601 285 on_immediate_0x7e(); // Unicode (U+007E) ~ TILDE
whismanoid 1:5b33e7447601 286 break; // handled as immediate command, do not append to buffer
whismanoid 1:5b33e7447601 287 }
whismanoid 0:4d7de8b5c800 288 //
whismanoid 0:4d7de8b5c800 289 default:
whismanoid 0:4d7de8b5c800 290 MBED_ASSERT(indexOfNextEmptyCell <= COMMAND_BUFFER_LENGTH - 2);
whismanoid 0:4d7de8b5c800 291 buf[indexOfNextEmptyCell++] = ch; // append character, post-increment index
whismanoid 0:4d7de8b5c800 292 buf[indexOfNextEmptyCell] = '\0'; // null-terminate the buffer
whismanoid 0:4d7de8b5c800 293 MBED_ASSERT(indexOfNextEmptyCell <= COMMAND_BUFFER_LENGTH - 1);
whismanoid 0:4d7de8b5c800 294 associatedSerialPort.printf("%c", ch); // echo
whismanoid 0:4d7de8b5c800 295 if (indexOfNextEmptyCell == COMMAND_BUFFER_LENGTH - 1)
whismanoid 0:4d7de8b5c800 296 {
whismanoid 0:4d7de8b5c800 297 // buffer is full, parse what we've got
whismanoid 0:4d7de8b5c800 298 if (onEOLcommandParser) {
whismanoid 0:4d7de8b5c800 299 onEOLcommandParser(*this);
whismanoid 0:4d7de8b5c800 300 }
whismanoid 0:4d7de8b5c800 301 clear();
whismanoid 0:4d7de8b5c800 302 }
whismanoid 0:4d7de8b5c800 303 break;
whismanoid 0:4d7de8b5c800 304 }
whismanoid 0:4d7de8b5c800 305 }
whismanoid 1:5b33e7447601 306
whismanoid 0:4d7de8b5c800 307 /** CmdLine::parse_and_remove_key matches "key"
whismanoid 0:4d7de8b5c800 308 *
whismanoid 0:4d7de8b5c800 309 * @return true if keyword was found in buffer
whismanoid 0:4d7de8b5c800 310 * @param[in] key string value to match
whismanoid 0:4d7de8b5c800 311 * @param[out] valueBuf buffer is populated with the substring between key= and the first space delimiter (or end of string)
whismanoid 0:4d7de8b5c800 312 * @param[in] valueBufLen limits the size of valueBuf
whismanoid 0:4d7de8b5c800 313 *
whismanoid 0:4d7de8b5c800 314 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 0:4d7de8b5c800 315 *
whismanoid 0:4d7de8b5c800 316 */
whismanoid 0:4d7de8b5c800 317 bool CmdLine::parse_and_remove_key(const char *key, char *valueBuf, size_t valueBufLen)
whismanoid 0:4d7de8b5c800 318 {
whismanoid 0:4d7de8b5c800 319 // serial().printf("\r\n parse_and_remove_key(\"%s\")...", key);
whismanoid 0:4d7de8b5c800 320 // match key inside buf[]?
whismanoid 0:4d7de8b5c800 321 for (unsigned int idxSearch = 0; idxSearch < indexOfNextEmptyCell; idxSearch++)
whismanoid 0:4d7de8b5c800 322 {
whismanoid 0:4d7de8b5c800 323 if (buf[idxSearch] == '\0') {
whismanoid 0:4d7de8b5c800 324 // serial().printf("\r\n parse_and_remove_key(\"%s\") no match", key);
whismanoid 0:4d7de8b5c800 325 return false; /* no match */
whismanoid 0:4d7de8b5c800 326 }
whismanoid 0:4d7de8b5c800 327 if (buf[idxSearch] != key[0]) { continue; }
whismanoid 0:4d7de8b5c800 328 // possible match; compare buf[idxSearch..] to key[0..]
whismanoid 0:4d7de8b5c800 329 unsigned int idxKey = idxSearch; // test whether buf[idxKey..] == key[0..]
whismanoid 0:4d7de8b5c800 330 unsigned int idxEqualSign = idxSearch; // test whether key=value pair
whismanoid 0:4d7de8b5c800 331 unsigned int idxSpace = idxSearch; // end of key=value word
whismanoid 0:4d7de8b5c800 332 for (unsigned int offset = 0; offset < strlen(key); offset++)
whismanoid 0:4d7de8b5c800 333 {
whismanoid 0:4d7de8b5c800 334 if (buf[idxKey + offset] != key[offset]) { idxKey = 0; break; }
whismanoid 0:4d7de8b5c800 335 idxSpace = idxKey + offset + 1;
whismanoid 0:4d7de8b5c800 336 idxEqualSign = idxKey + offset + 1;
whismanoid 0:4d7de8b5c800 337 if (buf[idxEqualSign] != '=') { idxEqualSign = 0; }
whismanoid 0:4d7de8b5c800 338 }
whismanoid 0:4d7de8b5c800 339 if (idxKey == 0) continue; // no match at idxSearch but keep searching
whismanoid 0:4d7de8b5c800 340 // ASSERT buf[idxKey..] == key[0..]
whismanoid 0:4d7de8b5c800 341 while ((buf[idxSpace] != ' ') && idxSpace < indexOfNextEmptyCell) { idxSpace++; }
whismanoid 0:4d7de8b5c800 342 // serial().printf("\r\n parse_and_remove_key(\"%s\") match at index %d length %d, '=' index %d, ' ' index %d",
whismanoid 0:4d7de8b5c800 343 // key, idxKey, strlen(key), idxEqualSign, idxSpace);
whismanoid 0:4d7de8b5c800 344 if (idxEqualSign != 0) {
whismanoid 0:4d7de8b5c800 345 // found key=value: copy buf[idxEqualSign+1..' '-1] into valueBuf[0..valueBufLen-1]
whismanoid 0:4d7de8b5c800 346 for (unsigned int offset = 0; offset < valueBufLen - 1; offset++)
whismanoid 0:4d7de8b5c800 347 {
whismanoid 0:4d7de8b5c800 348 if (buf[idxEqualSign + 1 + offset] == ' ') break;
whismanoid 0:4d7de8b5c800 349 valueBuf[offset] = buf[idxEqualSign + 1 + offset];
whismanoid 0:4d7de8b5c800 350 valueBuf[offset + 1] = '\0';
whismanoid 0:4d7de8b5c800 351 }
whismanoid 0:4d7de8b5c800 352 } else {
whismanoid 0:4d7de8b5c800 353 // found key but no =value: valueBuf[] = ""
whismanoid 0:4d7de8b5c800 354 valueBuf[0] = '\0';
whismanoid 0:4d7de8b5c800 355 }
whismanoid 0:4d7de8b5c800 356 // on successful match, the key=value should be deleted from cmdbuf
whismanoid 0:4d7de8b5c800 357 //serial().printf("\r\n parse_and_remove_key(\"%s\") buf=\"%s\" valueBuf=\"%s\" before deleting key",
whismanoid 0:4d7de8b5c800 358 // key, buf, valueBuf);
whismanoid 0:4d7de8b5c800 359 for (unsigned int offset = 0; offset < indexOfNextEmptyCell; offset++)
whismanoid 0:4d7de8b5c800 360 {
whismanoid 0:4d7de8b5c800 361 unsigned int idxCopyDst = idxKey + offset;
whismanoid 0:4d7de8b5c800 362 unsigned int idxCopySrc = idxSpace + 1 + offset;
whismanoid 0:4d7de8b5c800 363 if (idxCopyDst > indexOfNextEmptyCell) break;
whismanoid 0:4d7de8b5c800 364 if (idxCopySrc > indexOfNextEmptyCell) break;
whismanoid 0:4d7de8b5c800 365 buf[idxCopyDst] = buf[idxCopySrc];
whismanoid 0:4d7de8b5c800 366 }
whismanoid 0:4d7de8b5c800 367 // serial().printf("\r\n parse_and_remove_key(\"%s\") buf=\"%s\" valueBuf=\"%s\" after deleting key",
whismanoid 0:4d7de8b5c800 368 // key, buf, valueBuf);
whismanoid 0:4d7de8b5c800 369 // serial().printf("\r\n parse_and_remove_key(\"%s\") returning true: valueBuf=\"%s\"", key, valueBuf);
whismanoid 0:4d7de8b5c800 370 return true;
whismanoid 0:4d7de8b5c800 371 }
whismanoid 0:4d7de8b5c800 372 // serial().printf("\r\n parse_and_remove_key(\"%s\") no match", key);
whismanoid 0:4d7de8b5c800 373 return false; // no match
whismanoid 0:4d7de8b5c800 374 }
whismanoid 0:4d7de8b5c800 375
whismanoid 0:4d7de8b5c800 376 /** CmdLine::parse_frequency_Hz matches "key"=digits
whismanoid 0:4d7de8b5c800 377 *
whismanoid 0:4d7de8b5c800 378 * @return true if keyword was found in buffer
whismanoid 0:4d7de8b5c800 379 * @param[in] key string value to match
whismanoid 0:4d7de8b5c800 380 * @param[out] frequency_Hz updated from value string if match "key"=value,
whismanoid 0:4d7de8b5c800 381 * optional suffix kHz or MHz scales the value by 1000 or 10000000
whismanoid 0:4d7de8b5c800 382 *
whismanoid 0:4d7de8b5c800 383 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 0:4d7de8b5c800 384 *
whismanoid 0:4d7de8b5c800 385 */
whismanoid 0:4d7de8b5c800 386 bool CmdLine::parse_frequency_Hz(const char *key, uint32_t& frequency_Hz)
whismanoid 0:4d7de8b5c800 387 {
whismanoid 0:4d7de8b5c800 388 char valueBuf[16];
whismanoid 0:4d7de8b5c800 389 // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen);
whismanoid 0:4d7de8b5c800 390 if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf)))
whismanoid 0:4d7de8b5c800 391 {
whismanoid 0:4d7de8b5c800 392 // ASSERT: buf[matched_index] contains '=' followed by value
whismanoid 0:4d7de8b5c800 393 // parse cmdLine arg (SCLK=\d+(kHZ|MHZ)?)? --> g_SPI_SCLK_Hz
whismanoid 0:4d7de8b5c800 394 frequency_Hz = strtoul(valueBuf, NULL, 10);
whismanoid 0:4d7de8b5c800 395 if (strstr(valueBuf, "M")) {
whismanoid 0:4d7de8b5c800 396 frequency_Hz = frequency_Hz * 1000000;
whismanoid 0:4d7de8b5c800 397 }
whismanoid 0:4d7de8b5c800 398 if (strstr(valueBuf, "k")) {
whismanoid 0:4d7de8b5c800 399 frequency_Hz = frequency_Hz * 1000;
whismanoid 0:4d7de8b5c800 400 }
whismanoid 0:4d7de8b5c800 401 return true;
whismanoid 0:4d7de8b5c800 402 }
whismanoid 0:4d7de8b5c800 403 return false; // no match
whismanoid 0:4d7de8b5c800 404 }
whismanoid 0:4d7de8b5c800 405
whismanoid 4:700b71cd3bd2 406 /** CmdLine::parse_interval_usec matches "key"=digits
whismanoid 4:700b71cd3bd2 407 *
whismanoid 4:700b71cd3bd2 408 * @return true if keyword was found in buffer
whismanoid 4:700b71cd3bd2 409 * @param[in] key string value to match
whismanoid 4:700b71cd3bd2 410 * @param[out] interval_usec updated from value string if match "key"=value,
whismanoid 4:700b71cd3bd2 411 * optional suffix Hz kHz or MHz 1/x inverts and scales the value
whismanoid 4:700b71cd3bd2 412 * optional suffix s or ms or msec or us or usec scales the value
whismanoid 4:700b71cd3bd2 413 *
whismanoid 4:700b71cd3bd2 414 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 4:700b71cd3bd2 415 *
whismanoid 4:700b71cd3bd2 416 */
whismanoid 4:700b71cd3bd2 417 bool CmdLine::parse_interval_usec(const char *key, us_timestamp_t& interval_usec)
whismanoid 4:700b71cd3bd2 418 {
whismanoid 4:700b71cd3bd2 419 char valueBuf[32];
whismanoid 4:700b71cd3bd2 420 // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen);
whismanoid 4:700b71cd3bd2 421 if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf)))
whismanoid 4:700b71cd3bd2 422 {
whismanoid 4:700b71cd3bd2 423 // ASSERT: buf[matched_index] contains '=' followed by value
whismanoid 4:700b71cd3bd2 424 interval_usec = strtoul(valueBuf, NULL, 10);
whismanoid 4:700b71cd3bd2 425 if (strstr(valueBuf, "ms")) {
whismanoid 4:700b71cd3bd2 426 interval_usec = interval_usec * 1000;
whismanoid 5:1a14de1c4d7b 427 } else if (strstr(valueBuf, "us")) {
whismanoid 5:1a14de1c4d7b 428 // avoid matching "s" which is a subset of "us"
whismanoid 5:1a14de1c4d7b 429 // interval_usec = interval_usec * 1;
whismanoid 4:700b71cd3bd2 430 } else if (strstr(valueBuf, "s")) {
whismanoid 4:700b71cd3bd2 431 interval_usec = interval_usec * 1000000;
whismanoid 4:700b71cd3bd2 432 } else if (strstr(valueBuf, "MHz")) {
whismanoid 4:700b71cd3bd2 433 interval_usec = 1. / interval_usec;
whismanoid 4:700b71cd3bd2 434 } else if (strstr(valueBuf, "kHz")) {
whismanoid 4:700b71cd3bd2 435 interval_usec = 1000. / interval_usec;
whismanoid 4:700b71cd3bd2 436 } else if (strstr(valueBuf, "Hz")) {
whismanoid 4:700b71cd3bd2 437 interval_usec = 1000000. / interval_usec;
whismanoid 4:700b71cd3bd2 438 }
whismanoid 4:700b71cd3bd2 439 return true;
whismanoid 4:700b71cd3bd2 440 }
whismanoid 4:700b71cd3bd2 441 return false; // no match
whismanoid 4:700b71cd3bd2 442 }
whismanoid 4:700b71cd3bd2 443
whismanoid 0:4d7de8b5c800 444 /** CmdLine::parse_flag matches "key"=0 or 1
whismanoid 0:4d7de8b5c800 445 *
whismanoid 0:4d7de8b5c800 446 * @return true if keyword was found in buffer
whismanoid 0:4d7de8b5c800 447 * @param[in] key string value to match
whismanoid 0:4d7de8b5c800 448 * @param[out] nFlagVar variable to be updated by setting or clearing bits specified by nFlagBitMask.
whismanoid 0:4d7de8b5c800 449 * If match "key"=0 then the nFlagBitMask bits in nFlagVar are cleared.
whismanoid 0:4d7de8b5c800 450 * If match "key"=1 then the nFlagBitMask bits in nFlagVar are set.
whismanoid 0:4d7de8b5c800 451 * @param[in] nFlagBitMask bit mask contains binary 1 in the bit to be controlled by the key=value setting
whismanoid 0:4d7de8b5c800 452 *
whismanoid 0:4d7de8b5c800 453 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 0:4d7de8b5c800 454 *
whismanoid 0:4d7de8b5c800 455 */
whismanoid 0:4d7de8b5c800 456 bool CmdLine::parse_flag(const char *key, uint8_t& nFlagVar, const uint8_t nFlagBitMask)
whismanoid 0:4d7de8b5c800 457 {
whismanoid 0:4d7de8b5c800 458 char valueBuf[16];
whismanoid 0:4d7de8b5c800 459 // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen);
whismanoid 0:4d7de8b5c800 460 if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf)))
whismanoid 0:4d7de8b5c800 461 {
whismanoid 0:4d7de8b5c800 462 // ASSERT: buf[matched_index] contains '=' followed by value
whismanoid 0:4d7de8b5c800 463 // parse cmdLine arg (CPHA=\d)? --> g_SPI_dataMode | SPI_MODE1
whismanoid 0:4d7de8b5c800 464 int x = strtoul(valueBuf, NULL, 10);
whismanoid 0:4d7de8b5c800 465 if (x)
whismanoid 0:4d7de8b5c800 466 {
whismanoid 0:4d7de8b5c800 467 nFlagVar |= nFlagBitMask;
whismanoid 0:4d7de8b5c800 468 }
whismanoid 0:4d7de8b5c800 469 else
whismanoid 0:4d7de8b5c800 470 {
whismanoid 0:4d7de8b5c800 471 nFlagVar &= ~nFlagBitMask;
whismanoid 0:4d7de8b5c800 472 }
whismanoid 0:4d7de8b5c800 473 return true;
whismanoid 0:4d7de8b5c800 474 }
whismanoid 0:4d7de8b5c800 475 return false; // no match
whismanoid 0:4d7de8b5c800 476 }
whismanoid 0:4d7de8b5c800 477
whismanoid 0:4d7de8b5c800 478 /** CmdLine::parse_byte_hex matches "key"=value
whismanoid 0:4d7de8b5c800 479 *
whismanoid 0:4d7de8b5c800 480 * @return true if keyword was found in buffer
whismanoid 0:4d7de8b5c800 481 * @param[in] key string value to match
whismanoid 0:4d7de8b5c800 482 * @param[out] nByteVar updated from value string if match "key"=value
whismanoid 0:4d7de8b5c800 483 *
whismanoid 0:4d7de8b5c800 484 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 0:4d7de8b5c800 485 *
whismanoid 2:0f702da53f2a 486 * Prefix '$' or '0x' or '0X' selects radix base-16 hexadecimal.
whismanoid 2:0f702da53f2a 487 * Default number conversion radix is base-16 hexadecimal.
whismanoid 0:4d7de8b5c800 488 */
whismanoid 0:4d7de8b5c800 489 bool CmdLine::parse_byte_hex(const char *key, uint8_t& nByteVar)
whismanoid 0:4d7de8b5c800 490 {
whismanoid 0:4d7de8b5c800 491 char valueBuf[16];
whismanoid 0:4d7de8b5c800 492 // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen);
whismanoid 0:4d7de8b5c800 493 if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf)))
whismanoid 0:4d7de8b5c800 494 {
whismanoid 0:4d7de8b5c800 495 // ASSERT: buf[matched_index] contains '=' followed by value
whismanoid 0:4d7de8b5c800 496 // parse cmdLine arg (CMD=\d)? --> g_I2C_command_regAddress
whismanoid 0:4d7de8b5c800 497 // TODO1: parse_byte_hex take hex prefix 0x 0X or suffix $ h H
whismanoid 0:4d7de8b5c800 498 if (valueBuf[0] == '$')
whismanoid 0:4d7de8b5c800 499 {
whismanoid 0:4d7de8b5c800 500 nByteVar = strtoul(valueBuf + 1, NULL, 16);
whismanoid 0:4d7de8b5c800 501 return true;
whismanoid 0:4d7de8b5c800 502 }
whismanoid 0:4d7de8b5c800 503 if (valueBuf[0] == '0' && (valueBuf[1] == 'X' || valueBuf[1] == 'x'))
whismanoid 0:4d7de8b5c800 504 {
whismanoid 0:4d7de8b5c800 505 nByteVar = strtoul(valueBuf + 2, NULL, 16);
whismanoid 0:4d7de8b5c800 506 return true;
whismanoid 0:4d7de8b5c800 507 }
whismanoid 2:0f702da53f2a 508 nByteVar = strtoul(valueBuf, NULL, 16); // default radix hex
whismanoid 0:4d7de8b5c800 509 return true;
whismanoid 0:4d7de8b5c800 510 }
whismanoid 0:4d7de8b5c800 511 return false; // no match
whismanoid 0:4d7de8b5c800 512 }
whismanoid 0:4d7de8b5c800 513
whismanoid 0:4d7de8b5c800 514 /** CmdLine::parse_byte_dec matches "key"=value
whismanoid 0:4d7de8b5c800 515 *
whismanoid 0:4d7de8b5c800 516 * @return true if keyword was found in buffer
whismanoid 0:4d7de8b5c800 517 * @param[in] key string value to match
whismanoid 0:4d7de8b5c800 518 * @param[out] nByteVar updated from value string if match "key"=value
whismanoid 0:4d7de8b5c800 519 *
whismanoid 0:4d7de8b5c800 520 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 0:4d7de8b5c800 521 *
whismanoid 2:0f702da53f2a 522 * Prefix '$' or '0x' or '0X' selects radix base-16 hexadecimal.
whismanoid 2:0f702da53f2a 523 * Default number conversion radix is base-10 decimal.
whismanoid 0:4d7de8b5c800 524 */
whismanoid 0:4d7de8b5c800 525 bool CmdLine::parse_byte_dec(const char *key, uint8_t& nByteVar)
whismanoid 0:4d7de8b5c800 526 {
whismanoid 0:4d7de8b5c800 527 char valueBuf[16];
whismanoid 0:4d7de8b5c800 528 // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen);
whismanoid 0:4d7de8b5c800 529 if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf)))
whismanoid 0:4d7de8b5c800 530 {
whismanoid 0:4d7de8b5c800 531 // ASSERT: buf[matched_index] contains '=' followed by value
whismanoid 0:4d7de8b5c800 532 // parse cmdLine arg (CMD=\d)? --> g_I2C_command_regAddress
whismanoid 0:4d7de8b5c800 533 // TODO1: parse_byte_dec take hex prefix 0x 0X or suffix $ h H
whismanoid 0:4d7de8b5c800 534 if (valueBuf[0] == '$')
whismanoid 0:4d7de8b5c800 535 {
whismanoid 0:4d7de8b5c800 536 nByteVar = strtoul(valueBuf + 1, NULL, 16);
whismanoid 0:4d7de8b5c800 537 return true;
whismanoid 0:4d7de8b5c800 538 }
whismanoid 0:4d7de8b5c800 539 if (valueBuf[0] == '0' && (valueBuf[1] == 'X' || valueBuf[1] == 'x'))
whismanoid 0:4d7de8b5c800 540 {
whismanoid 0:4d7de8b5c800 541 nByteVar = strtoul(valueBuf + 2, NULL, 16);
whismanoid 0:4d7de8b5c800 542 return true;
whismanoid 0:4d7de8b5c800 543 }
whismanoid 2:0f702da53f2a 544 nByteVar = strtoul(valueBuf, NULL, 10); // default radix decimal
whismanoid 0:4d7de8b5c800 545 return true;
whismanoid 0:4d7de8b5c800 546 }
whismanoid 0:4d7de8b5c800 547 return false; // no match
whismanoid 0:4d7de8b5c800 548 }
whismanoid 0:4d7de8b5c800 549
whismanoid 0:4d7de8b5c800 550 /** CmdLine::parse_uint16_hex matches "key"=value
whismanoid 0:4d7de8b5c800 551 *
whismanoid 0:4d7de8b5c800 552 * @return true if keyword was found in buffer
whismanoid 0:4d7de8b5c800 553 * @param[in] key string value to match
whismanoid 0:4d7de8b5c800 554 * @param[out] uint16Var updated from value string if match "key"=value
whismanoid 0:4d7de8b5c800 555 *
whismanoid 0:4d7de8b5c800 556 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 0:4d7de8b5c800 557 *
whismanoid 2:0f702da53f2a 558 * Prefix '$' or '0x' or '0X' selects radix base-16 hexadecimal.
whismanoid 2:0f702da53f2a 559 * Default number conversion radix is base-16 hexadecimal.
whismanoid 0:4d7de8b5c800 560 */
whismanoid 0:4d7de8b5c800 561 bool CmdLine::parse_uint16_hex(const char *key, uint16_t& uint16Var)
whismanoid 0:4d7de8b5c800 562 {
whismanoid 0:4d7de8b5c800 563 char valueBuf[16];
whismanoid 0:4d7de8b5c800 564 // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen);
whismanoid 0:4d7de8b5c800 565 if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf)))
whismanoid 0:4d7de8b5c800 566 {
whismanoid 0:4d7de8b5c800 567 // ASSERT: buf[matched_index] contains '=' followed by value
whismanoid 0:4d7de8b5c800 568 // parse cmdLine arg (CMD=\d)? --> g_I2C_command_regAddress
whismanoid 0:4d7de8b5c800 569 // TODO1: parse_byte_hex take hex prefix 0x 0X or suffix $ h H
whismanoid 0:4d7de8b5c800 570 if (valueBuf[0] == '$')
whismanoid 0:4d7de8b5c800 571 {
whismanoid 0:4d7de8b5c800 572 uint16Var = strtoul(valueBuf + 1, NULL, 16);
whismanoid 0:4d7de8b5c800 573 return true;
whismanoid 0:4d7de8b5c800 574 }
whismanoid 0:4d7de8b5c800 575 if (valueBuf[0] == '0' && (valueBuf[1] == 'X' || valueBuf[1] == 'x'))
whismanoid 0:4d7de8b5c800 576 {
whismanoid 0:4d7de8b5c800 577 uint16Var = strtoul(valueBuf + 2, NULL, 16);
whismanoid 0:4d7de8b5c800 578 return true;
whismanoid 0:4d7de8b5c800 579 }
whismanoid 2:0f702da53f2a 580 uint16Var = strtoul(valueBuf, NULL, 16); // default radix hex
whismanoid 2:0f702da53f2a 581 return true;
whismanoid 2:0f702da53f2a 582 }
whismanoid 2:0f702da53f2a 583 return false; // no match
whismanoid 2:0f702da53f2a 584 }
whismanoid 2:0f702da53f2a 585
whismanoid 2:0f702da53f2a 586 /** CmdLine::parse_uint16_dec matches "key"=value
whismanoid 2:0f702da53f2a 587 *
whismanoid 2:0f702da53f2a 588 * @return true if keyword was found in buffer
whismanoid 2:0f702da53f2a 589 * @param[in] key string value to match
whismanoid 2:0f702da53f2a 590 * @param[out] uint16Var updated from value string if match "key"=value
whismanoid 2:0f702da53f2a 591 *
whismanoid 2:0f702da53f2a 592 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 2:0f702da53f2a 593 *
whismanoid 2:0f702da53f2a 594 * Prefix '$' or '0x' or '0X' selects radix base-16 hexadecimal.
whismanoid 2:0f702da53f2a 595 * Default number conversion radix is base-10 decimal.
whismanoid 2:0f702da53f2a 596 */
whismanoid 2:0f702da53f2a 597 bool CmdLine::parse_uint16_dec(const char *key, uint16_t& uint16Var)
whismanoid 2:0f702da53f2a 598 {
whismanoid 2:0f702da53f2a 599 char valueBuf[16];
whismanoid 2:0f702da53f2a 600 // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen);
whismanoid 2:0f702da53f2a 601 if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf)))
whismanoid 2:0f702da53f2a 602 {
whismanoid 2:0f702da53f2a 603 // ASSERT: buf[matched_index] contains '=' followed by value
whismanoid 2:0f702da53f2a 604 // parse cmdLine arg (CMD=\d)? --> g_I2C_command_regAddress
whismanoid 2:0f702da53f2a 605 // TODO1: parse_byte_hex take hex prefix 0x 0X or suffix $ h H
whismanoid 2:0f702da53f2a 606 if (valueBuf[0] == '$')
whismanoid 2:0f702da53f2a 607 {
whismanoid 2:0f702da53f2a 608 uint16Var = strtoul(valueBuf + 1, NULL, 16);
whismanoid 2:0f702da53f2a 609 return true;
whismanoid 2:0f702da53f2a 610 }
whismanoid 2:0f702da53f2a 611 if (valueBuf[0] == '0' && (valueBuf[1] == 'X' || valueBuf[1] == 'x'))
whismanoid 2:0f702da53f2a 612 {
whismanoid 2:0f702da53f2a 613 uint16Var = strtoul(valueBuf + 2, NULL, 16);
whismanoid 2:0f702da53f2a 614 return true;
whismanoid 2:0f702da53f2a 615 }
whismanoid 2:0f702da53f2a 616 uint16Var = strtoul(valueBuf, NULL, 10); // default radix decimal
whismanoid 0:4d7de8b5c800 617 return true;
whismanoid 0:4d7de8b5c800 618 }
whismanoid 0:4d7de8b5c800 619 return false; // no match
whismanoid 0:4d7de8b5c800 620 }
whismanoid 0:4d7de8b5c800 621
whismanoid 0:4d7de8b5c800 622 /** CmdLine::parse_int16_hex matches "key"=value
whismanoid 0:4d7de8b5c800 623 *
whismanoid 0:4d7de8b5c800 624 * @return true if keyword was found in buffer
whismanoid 0:4d7de8b5c800 625 * @param[in] key string value to match
whismanoid 0:4d7de8b5c800 626 * @param[out] int16Var updated from value string if match "key"=value
whismanoid 0:4d7de8b5c800 627 *
whismanoid 0:4d7de8b5c800 628 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 0:4d7de8b5c800 629 *
whismanoid 2:0f702da53f2a 630 * Prefix '$' or '0x' or '0X' selects radix base-16 hexadecimal.
whismanoid 2:0f702da53f2a 631 * Default number conversion radix is base-16 hexadecimal.
whismanoid 0:4d7de8b5c800 632 */
whismanoid 0:4d7de8b5c800 633 bool CmdLine::parse_int16_hex(const char *key, int16_t& int16Var)
whismanoid 0:4d7de8b5c800 634 {
whismanoid 0:4d7de8b5c800 635 char valueBuf[16];
whismanoid 0:4d7de8b5c800 636 // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen);
whismanoid 0:4d7de8b5c800 637 if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf)))
whismanoid 0:4d7de8b5c800 638 {
whismanoid 0:4d7de8b5c800 639 // ASSERT: buf[matched_index] contains '=' followed by value
whismanoid 0:4d7de8b5c800 640 // parse cmdLine arg (CMD=\d)? --> g_I2C_command_regAddress
whismanoid 0:4d7de8b5c800 641 // TODO1: parse_byte_hex take hex prefix 0x 0X or suffix $ h H
whismanoid 0:4d7de8b5c800 642 if (valueBuf[0] == '$')
whismanoid 0:4d7de8b5c800 643 {
whismanoid 0:4d7de8b5c800 644 int16Var = strtoul(valueBuf + 1, NULL, 16);
whismanoid 0:4d7de8b5c800 645 return true;
whismanoid 0:4d7de8b5c800 646 }
whismanoid 0:4d7de8b5c800 647 if (valueBuf[0] == '0' && (valueBuf[1] == 'X' || valueBuf[1] == 'x'))
whismanoid 0:4d7de8b5c800 648 {
whismanoid 0:4d7de8b5c800 649 int16Var = strtoul(valueBuf + 2, NULL, 16);
whismanoid 0:4d7de8b5c800 650 return true;
whismanoid 0:4d7de8b5c800 651 }
whismanoid 2:0f702da53f2a 652 int16Var = strtoul(valueBuf, NULL, 16); // default radix hex
whismanoid 2:0f702da53f2a 653 return true;
whismanoid 2:0f702da53f2a 654 }
whismanoid 2:0f702da53f2a 655 return false; // no match
whismanoid 2:0f702da53f2a 656 }
whismanoid 2:0f702da53f2a 657
whismanoid 2:0f702da53f2a 658 /** CmdLine::parse_int16_dec matches "key"=value
whismanoid 2:0f702da53f2a 659 *
whismanoid 2:0f702da53f2a 660 * @return true if keyword was found in buffer
whismanoid 2:0f702da53f2a 661 * @param[in] key string value to match
whismanoid 2:0f702da53f2a 662 * @param[out] int16Var updated from value string if match "key"=value
whismanoid 2:0f702da53f2a 663 *
whismanoid 2:0f702da53f2a 664 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 2:0f702da53f2a 665 *
whismanoid 2:0f702da53f2a 666 * Prefix '$' or '0x' or '0X' selects radix base-16 hexadecimal.
whismanoid 2:0f702da53f2a 667 * Default number conversion radix is base-10 decimal.
whismanoid 2:0f702da53f2a 668 */
whismanoid 2:0f702da53f2a 669 bool CmdLine::parse_int16_dec(const char *key, int16_t& int16Var)
whismanoid 2:0f702da53f2a 670 {
whismanoid 2:0f702da53f2a 671 char valueBuf[16];
whismanoid 2:0f702da53f2a 672 // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen);
whismanoid 2:0f702da53f2a 673 if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf)))
whismanoid 2:0f702da53f2a 674 {
whismanoid 2:0f702da53f2a 675 // ASSERT: buf[matched_index] contains '=' followed by value
whismanoid 2:0f702da53f2a 676 // parse cmdLine arg (CMD=\d)? --> g_I2C_command_regAddress
whismanoid 2:0f702da53f2a 677 // TODO1: parse_byte_hex take hex prefix 0x 0X or suffix $ h H
whismanoid 2:0f702da53f2a 678 if (valueBuf[0] == '$')
whismanoid 2:0f702da53f2a 679 {
whismanoid 2:0f702da53f2a 680 int16Var = strtoul(valueBuf + 1, NULL, 16);
whismanoid 2:0f702da53f2a 681 return true;
whismanoid 2:0f702da53f2a 682 }
whismanoid 2:0f702da53f2a 683 if (valueBuf[0] == '0' && (valueBuf[1] == 'X' || valueBuf[1] == 'x'))
whismanoid 2:0f702da53f2a 684 {
whismanoid 2:0f702da53f2a 685 int16Var = strtoul(valueBuf + 2, NULL, 16);
whismanoid 2:0f702da53f2a 686 return true;
whismanoid 2:0f702da53f2a 687 }
whismanoid 2:0f702da53f2a 688 int16Var = strtoul(valueBuf, NULL, 10); // default radix decimal
whismanoid 0:4d7de8b5c800 689 return true;
whismanoid 0:4d7de8b5c800 690 }
whismanoid 0:4d7de8b5c800 691 return false; // no match
whismanoid 0:4d7de8b5c800 692 }
whismanoid 0:4d7de8b5c800 693
whismanoid 0:4d7de8b5c800 694 /** CmdLine::parse_float matches "key"=value
whismanoid 0:4d7de8b5c800 695 *
whismanoid 0:4d7de8b5c800 696 * @return true if keyword was found in buffer
whismanoid 0:4d7de8b5c800 697 * @param[in] key string value to match
whismanoid 0:4d7de8b5c800 698 * @param[out] floatVar updated from value string if match "key"=value
whismanoid 0:4d7de8b5c800 699 *
whismanoid 0:4d7de8b5c800 700 * @post on successful match, the key=value substring is deleted from cmdbuf
whismanoid 0:4d7de8b5c800 701 *
whismanoid 0:4d7de8b5c800 702 */
whismanoid 0:4d7de8b5c800 703 bool CmdLine::parse_float(const char *key, float& floatVar)
whismanoid 0:4d7de8b5c800 704 {
whismanoid 0:4d7de8b5c800 705 char valueBuf[16];
whismanoid 0:4d7de8b5c800 706 char *end;
whismanoid 0:4d7de8b5c800 707 // bool parse_and_remove_key(const char *key, char *valueBuf, int valueBufLen);
whismanoid 0:4d7de8b5c800 708 if (parse_and_remove_key(key, valueBuf, sizeof(valueBuf)))
whismanoid 0:4d7de8b5c800 709 {
whismanoid 0:4d7de8b5c800 710 floatVar = strtof(valueBuf, &end);
whismanoid 0:4d7de8b5c800 711 return true;
whismanoid 0:4d7de8b5c800 712 }
whismanoid 0:4d7de8b5c800 713 return false; // no match
whismanoid 0:4d7de8b5c800 714 }
whismanoid 0:4d7de8b5c800 715
whismanoid 0:4d7de8b5c800 716 /** CmdLine::parse_byteCount_byteList_hex matches hexadecimal digits separated by spaces.
whismanoid 0:4d7de8b5c800 717 * The 0x / 0X prefix is optional. The numbers must be hexadecimal.
whismanoid 0:4d7de8b5c800 718 *
whismanoid 0:4d7de8b5c800 719 * @return true if more than one hex byte found in buffer
whismanoid 0:4d7de8b5c800 720 * @param[out] byteCount is populated with the number of hex bytes found
whismanoid 0:4d7de8b5c800 721 * @param[out] mosiDataBuf buffer mosiDataBuf[0..byteCount-1] is populated with the hex bytes found
whismanoid 0:4d7de8b5c800 722 * @param[in] mosiDataBufSize limits the number of bytes that will be used
whismanoid 0:4d7de8b5c800 723 *
whismanoid 0:4d7de8b5c800 724 */
whismanoid 0:4d7de8b5c800 725 bool CmdLine::parse_byteCount_byteList_hex(size_t& byteCount, char *mosiDataBuf, size_t mosiDataBufSize)
whismanoid 0:4d7de8b5c800 726 {
whismanoid 0:4d7de8b5c800 727 //serial().printf("\r\n parse_byteCount_byteList_hex (buf=\"%s\")...", buf);
whismanoid 0:4d7de8b5c800 728 // parse cmdLine hex byte list --> int byteCount; int mosiData[MAX_SPI_BYTE_COUNT];
whismanoid 0:4d7de8b5c800 729 byteCount = 0;
whismanoid 0:4d7de8b5c800 730 bool got_value = false;
whismanoid 0:4d7de8b5c800 731 uint8_t nybbleValue;
whismanoid 0:4d7de8b5c800 732 uint8_t temp_value = 0;
whismanoid 0:4d7de8b5c800 733 for (unsigned int idxSearch = 0; idxSearch < indexOfNextEmptyCell; idxSearch++)
whismanoid 0:4d7de8b5c800 734 {
whismanoid 0:4d7de8b5c800 735 if (buf[idxSearch] == '\0') {
whismanoid 0:4d7de8b5c800 736 break; // end of buffer
whismanoid 0:4d7de8b5c800 737 }
whismanoid 0:4d7de8b5c800 738 switch (buf[idxSearch])
whismanoid 0:4d7de8b5c800 739 {
whismanoid 0:4d7de8b5c800 740 case '0': case '1': case '2': case '3':
whismanoid 0:4d7de8b5c800 741 case '4': case '5': case '6': case '7':
whismanoid 0:4d7de8b5c800 742 case '8': case '9':
whismanoid 0:4d7de8b5c800 743 nybbleValue = buf[idxSearch] - '0';
whismanoid 0:4d7de8b5c800 744 temp_value = temp_value * 0x10;
whismanoid 0:4d7de8b5c800 745 temp_value = temp_value + nybbleValue;
whismanoid 0:4d7de8b5c800 746 got_value = true;
whismanoid 0:4d7de8b5c800 747 break;
whismanoid 0:4d7de8b5c800 748 case 'a': case 'b': case 'c':
whismanoid 0:4d7de8b5c800 749 case 'd': case 'e': case 'f':
whismanoid 0:4d7de8b5c800 750 nybbleValue = buf[idxSearch] - 'a' + 0x0a;
whismanoid 0:4d7de8b5c800 751 temp_value = temp_value * 0x10;
whismanoid 0:4d7de8b5c800 752 temp_value = temp_value + nybbleValue;
whismanoid 0:4d7de8b5c800 753 got_value = true;
whismanoid 0:4d7de8b5c800 754 break;
whismanoid 0:4d7de8b5c800 755 case 'A': case 'B': case 'C':
whismanoid 0:4d7de8b5c800 756 case 'D': case 'E': case 'F':
whismanoid 0:4d7de8b5c800 757 nybbleValue = buf[idxSearch] - 'A' + 0x0a;
whismanoid 0:4d7de8b5c800 758 temp_value = temp_value * 0x10;
whismanoid 0:4d7de8b5c800 759 temp_value = temp_value + nybbleValue;
whismanoid 0:4d7de8b5c800 760 got_value = true;
whismanoid 0:4d7de8b5c800 761 break;
whismanoid 0:4d7de8b5c800 762 case 'x': case 'X':
whismanoid 0:4d7de8b5c800 763 temp_value = 0;
whismanoid 0:4d7de8b5c800 764 break;
whismanoid 0:4d7de8b5c800 765 case ' ': case ',':
whismanoid 0:4d7de8b5c800 766 if ((got_value) && (byteCount < mosiDataBufSize))
whismanoid 0:4d7de8b5c800 767 {
whismanoid 0:4d7de8b5c800 768 //serial().printf("\r\n parse_byteCount_byteList_hex mosiDataBuf[%d] = 0x%2.2x", byteCount, temp_value);
whismanoid 0:4d7de8b5c800 769 mosiDataBuf[byteCount++] = temp_value;
whismanoid 0:4d7de8b5c800 770 temp_value = 0;
whismanoid 0:4d7de8b5c800 771 got_value = false;
whismanoid 0:4d7de8b5c800 772 }
whismanoid 0:4d7de8b5c800 773 break;
whismanoid 0:4d7de8b5c800 774 }
whismanoid 0:4d7de8b5c800 775 } // for idxSearch
whismanoid 0:4d7de8b5c800 776 if ((got_value) && (byteCount < mosiDataBufSize))
whismanoid 0:4d7de8b5c800 777 {
whismanoid 0:4d7de8b5c800 778 //serial().printf("\r\n parse_byteCount_byteList_hex mosiDataBuf[%d] = 0x%2.2x", byteCount, temp_value);
whismanoid 0:4d7de8b5c800 779 mosiDataBuf[byteCount++] = temp_value;
whismanoid 0:4d7de8b5c800 780 temp_value = 0;
whismanoid 0:4d7de8b5c800 781 got_value = false;
whismanoid 0:4d7de8b5c800 782 }
whismanoid 0:4d7de8b5c800 783 //serial().printf("\r\n parse_byteCount_byteList_hex (buf=\"%s\") returning: byteCount=%d", buf, byteCount);
whismanoid 0:4d7de8b5c800 784 return (byteCount > 0);
whismanoid 0:4d7de8b5c800 785 }
whismanoid 0:4d7de8b5c800 786
whismanoid 0:4d7de8b5c800 787 /** CmdLine::parse_byteCount_byteList_dec matches a list of numbers, separated by spaces.
whismanoid 0:4d7de8b5c800 788 * The 0x / 0X prefix may be used to select hexadecimal instead of decimal.
whismanoid 0:4d7de8b5c800 789 *
whismanoid 0:4d7de8b5c800 790 * @return true if more than one number found in buffer
whismanoid 0:4d7de8b5c800 791 * @param[out] byteCount is populated with the number of numbers found
whismanoid 0:4d7de8b5c800 792 * @param[out] mosiDataBuf buffer mosiDataBuf[0..byteCount-1] is populated with the numbers found
whismanoid 0:4d7de8b5c800 793 * @param[in] mosiDataBufSize limits the number of bytes that will be used
whismanoid 0:4d7de8b5c800 794 *
whismanoid 0:4d7de8b5c800 795 */
whismanoid 0:4d7de8b5c800 796 bool CmdLine::parse_byteCount_byteList_dec(size_t& byteCount, char *mosiDataBuf, size_t mosiDataBufSize)
whismanoid 0:4d7de8b5c800 797 {
whismanoid 0:4d7de8b5c800 798 //serial().printf("\r\n parse_byteCount_byteList_dec (buf=\"%s\")...", buf);
whismanoid 0:4d7de8b5c800 799 // parse cmdLine hex byte list --> int byteCount; int mosiData[MAX_SPI_BYTE_COUNT];
whismanoid 0:4d7de8b5c800 800 byteCount = 0;
whismanoid 0:4d7de8b5c800 801 bool got_value = false;
whismanoid 0:4d7de8b5c800 802 uint8_t nybbleValue;
whismanoid 0:4d7de8b5c800 803 uint8_t temp_value = 0;
whismanoid 0:4d7de8b5c800 804 uint8_t radix = 10;
whismanoid 0:4d7de8b5c800 805 for (unsigned int idxSearch = 0; idxSearch < indexOfNextEmptyCell; idxSearch++)
whismanoid 0:4d7de8b5c800 806 {
whismanoid 0:4d7de8b5c800 807 if (buf[idxSearch] == '\0') {
whismanoid 0:4d7de8b5c800 808 break; // end of buffer
whismanoid 0:4d7de8b5c800 809 }
whismanoid 0:4d7de8b5c800 810 switch (buf[idxSearch])
whismanoid 0:4d7de8b5c800 811 {
whismanoid 0:4d7de8b5c800 812 case '0': case '1': case '2': case '3':
whismanoid 0:4d7de8b5c800 813 case '4': case '5': case '6': case '7':
whismanoid 0:4d7de8b5c800 814 case '8': case '9':
whismanoid 0:4d7de8b5c800 815 nybbleValue = buf[idxSearch] - '0';
whismanoid 0:4d7de8b5c800 816 temp_value = temp_value * radix;
whismanoid 0:4d7de8b5c800 817 temp_value = temp_value + nybbleValue;
whismanoid 0:4d7de8b5c800 818 got_value = true;
whismanoid 0:4d7de8b5c800 819 break;
whismanoid 0:4d7de8b5c800 820 case 'a': case 'b': case 'c':
whismanoid 0:4d7de8b5c800 821 case 'd': case 'e': case 'f':
whismanoid 0:4d7de8b5c800 822 nybbleValue = buf[idxSearch] - 'a' + 0x0a;
whismanoid 0:4d7de8b5c800 823 radix = 0x10;
whismanoid 0:4d7de8b5c800 824 temp_value = temp_value * radix;
whismanoid 0:4d7de8b5c800 825 temp_value = temp_value + nybbleValue;
whismanoid 0:4d7de8b5c800 826 got_value = true;
whismanoid 0:4d7de8b5c800 827 break;
whismanoid 0:4d7de8b5c800 828 case 'A': case 'B': case 'C':
whismanoid 0:4d7de8b5c800 829 case 'D': case 'E': case 'F':
whismanoid 0:4d7de8b5c800 830 nybbleValue = buf[idxSearch] - 'A' + 0x0a;
whismanoid 0:4d7de8b5c800 831 radix = 0x10;
whismanoid 0:4d7de8b5c800 832 temp_value = temp_value * radix;
whismanoid 0:4d7de8b5c800 833 temp_value = temp_value + nybbleValue;
whismanoid 0:4d7de8b5c800 834 got_value = true;
whismanoid 0:4d7de8b5c800 835 break;
whismanoid 0:4d7de8b5c800 836 case 'x': case 'X':
whismanoid 0:4d7de8b5c800 837 temp_value = 0;
whismanoid 0:4d7de8b5c800 838 radix = 0x10;
whismanoid 0:4d7de8b5c800 839 break;
whismanoid 0:4d7de8b5c800 840 case ' ': case ',':
whismanoid 0:4d7de8b5c800 841 if ((got_value) && (byteCount < mosiDataBufSize))
whismanoid 0:4d7de8b5c800 842 {
whismanoid 0:4d7de8b5c800 843 //serial().printf("\r\n parse_byteCount_byteList_dec mosiDataBuf[%d] = 0x%2.2x", byteCount, temp_value);
whismanoid 0:4d7de8b5c800 844 mosiDataBuf[byteCount++] = temp_value;
whismanoid 0:4d7de8b5c800 845 temp_value = 0;
whismanoid 0:4d7de8b5c800 846 radix = 10;
whismanoid 0:4d7de8b5c800 847 got_value = false;
whismanoid 0:4d7de8b5c800 848 }
whismanoid 0:4d7de8b5c800 849 break;
whismanoid 0:4d7de8b5c800 850 }
whismanoid 0:4d7de8b5c800 851 } // for idxSearch
whismanoid 0:4d7de8b5c800 852 if ((got_value) && (byteCount < mosiDataBufSize))
whismanoid 0:4d7de8b5c800 853 {
whismanoid 0:4d7de8b5c800 854 //serial().printf("\r\n parse_byteCount_byteList_dec mosiDataBuf[%d] = 0x%2.2x", byteCount, temp_value);
whismanoid 0:4d7de8b5c800 855 mosiDataBuf[byteCount++] = temp_value;
whismanoid 0:4d7de8b5c800 856 temp_value = 0;
whismanoid 0:4d7de8b5c800 857 got_value = false;
whismanoid 0:4d7de8b5c800 858 }
whismanoid 0:4d7de8b5c800 859 //serial().printf("\r\n parse_byteCount_byteList_dec (buf=\"%s\") returning: byteCount=%d", buf, byteCount);
whismanoid 0:4d7de8b5c800 860 return (byteCount > 0);
whismanoid 0:4d7de8b5c800 861 }
whismanoid 0:4d7de8b5c800 862
whismanoid 0:4d7de8b5c800 863
whismanoid 0:4d7de8b5c800 864 // End of file