A Command Interpreter with support for used defined commands, subsystems, macros, help and parameter parsing.

Committer:
wvd_vegt
Date:
Thu Feb 10 18:54:17 2011 +0000
Revision:
2:7d00f6d78090
Parent:
1:6627eed48db5
Child:
3:abbf43fab7d5
Alpha

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wvd_vegt 0:4d95ee0b4c37 1 /* mbed Command Interpreter Library
wvd_vegt 1:6627eed48db5 2 * Copyright (c) 2011 wvd_vegt
wvd_vegt 1:6627eed48db5 3 *
wvd_vegt 1:6627eed48db5 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
wvd_vegt 1:6627eed48db5 5 * of this software and associated documentation files (the "Software"), to deal
wvd_vegt 1:6627eed48db5 6 * in the Software without restriction, including without limitation the rights
wvd_vegt 1:6627eed48db5 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wvd_vegt 1:6627eed48db5 8 * copies of the Software, and to permit persons to whom the Software is
wvd_vegt 1:6627eed48db5 9 * furnished to do so, subject to the following conditions:
wvd_vegt 1:6627eed48db5 10 *
wvd_vegt 1:6627eed48db5 11 * The above copyright notice and this permission notice shall be included in
wvd_vegt 1:6627eed48db5 12 * all copies or substantial portions of the Software.
wvd_vegt 1:6627eed48db5 13 *
wvd_vegt 1:6627eed48db5 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wvd_vegt 1:6627eed48db5 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wvd_vegt 1:6627eed48db5 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wvd_vegt 1:6627eed48db5 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wvd_vegt 1:6627eed48db5 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wvd_vegt 1:6627eed48db5 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wvd_vegt 1:6627eed48db5 20 * THE SOFTWARE.
wvd_vegt 1:6627eed48db5 21 */
wvd_vegt 0:4d95ee0b4c37 22
wvd_vegt 0:4d95ee0b4c37 23 #ifndef MBED_CMDB_H
wvd_vegt 0:4d95ee0b4c37 24 #define MBED_CMDB_H
wvd_vegt 0:4d95ee0b4c37 25
wvd_vegt 0:4d95ee0b4c37 26 #include "mbed.h"
wvd_vegt 0:4d95ee0b4c37 27
wvd_vegt 0:4d95ee0b4c37 28 #include <vector>
wvd_vegt 0:4d95ee0b4c37 29
wvd_vegt 0:4d95ee0b4c37 30 //Max size of an Ansi escape code.
wvd_vegt 0:4d95ee0b4c37 31 #define MAX_ESC_LEN 5
wvd_vegt 0:4d95ee0b4c37 32
wvd_vegt 0:4d95ee0b4c37 33 //Max (strlen) of a Param.
wvd_vegt 0:4d95ee0b4c37 34 #define MAX_PARM_LEN 32
wvd_vegt 0:4d95ee0b4c37 35
wvd_vegt 0:4d95ee0b4c37 36 //Max eight parms.
wvd_vegt 0:4d95ee0b4c37 37 #define MAX_ARGS 8
wvd_vegt 0:4d95ee0b4c37 38
wvd_vegt 0:4d95ee0b4c37 39 //Max 132 characters commandline.
wvd_vegt 0:4d95ee0b4c37 40 #define MAX_CMD_LEN 132
wvd_vegt 0:4d95ee0b4c37 41
wvd_vegt 0:4d95ee0b4c37 42 //'Show' hidden subsystems and commands.
wvd_vegt 0:4d95ee0b4c37 43 #define SHOWHIDDEN
wvd_vegt 0:4d95ee0b4c37 44
wvd_vegt 0:4d95ee0b4c37 45 #define MIN_BYTE -128
wvd_vegt 0:4d95ee0b4c37 46 #define MAX_BYTE +127
wvd_vegt 0:4d95ee0b4c37 47
wvd_vegt 0:4d95ee0b4c37 48 #define MIN_SHORT -32768
wvd_vegt 0:4d95ee0b4c37 49 #define MAX_SHORT +32767
wvd_vegt 0:4d95ee0b4c37 50
wvd_vegt 0:4d95ee0b4c37 51 #define MIN_INT -32768
wvd_vegt 0:4d95ee0b4c37 52 #define MAX_INT +32767
wvd_vegt 0:4d95ee0b4c37 53
wvd_vegt 0:4d95ee0b4c37 54 //TODO Make sure we use id and array index properly!!
wvd_vegt 0:4d95ee0b4c37 55
wvd_vegt 0:4d95ee0b4c37 56 struct cmdb_cmd {
wvd_vegt 0:4d95ee0b4c37 57 char *cmdstr;
wvd_vegt 0:4d95ee0b4c37 58 int subs;
wvd_vegt 0:4d95ee0b4c37 59 int id; //Changed to int as signed char won't compile
wvd_vegt 0:4d95ee0b4c37 60 char *parms;
wvd_vegt 0:4d95ee0b4c37 61 char *cmddescr;
wvd_vegt 0:4d95ee0b4c37 62 char *parmdescr;
wvd_vegt 0:4d95ee0b4c37 63 };
wvd_vegt 0:4d95ee0b4c37 64
wvd_vegt 0:4d95ee0b4c37 65 //----Escape Codes and Strings
wvd_vegt 0:4d95ee0b4c37 66
wvd_vegt 0:4d95ee0b4c37 67 const char cr = '\r';
wvd_vegt 0:4d95ee0b4c37 68 const char lf = '\n';
wvd_vegt 0:4d95ee0b4c37 69 const char bell = '\7';
wvd_vegt 0:4d95ee0b4c37 70 const char esc = '\033';
wvd_vegt 0:4d95ee0b4c37 71 const char sp = ' ';
wvd_vegt 0:4d95ee0b4c37 72 const char crlf[] = "\r\n\0";
wvd_vegt 0:4d95ee0b4c37 73
wvd_vegt 0:4d95ee0b4c37 74 const char bs[] = "\b \b\0";
wvd_vegt 0:4d95ee0b4c37 75
wvd_vegt 0:4d95ee0b4c37 76 const char boldon[] = "\033[1m\0";
wvd_vegt 0:4d95ee0b4c37 77 const char boldoff[] = "\033[0m\0";
wvd_vegt 0:4d95ee0b4c37 78 const char cls[] = "\033[2J\0";
wvd_vegt 0:4d95ee0b4c37 79 const char home[] = "\033[H\0";
wvd_vegt 0:4d95ee0b4c37 80
wvd_vegt 0:4d95ee0b4c37 81 const char prompt[] = "CMD>";
wvd_vegt 0:4d95ee0b4c37 82
wvd_vegt 0:4d95ee0b4c37 83 //Before including this file, define CID_LAST as the last value from the enum with commands.
wvd_vegt 0:4d95ee0b4c37 84
wvd_vegt 0:4d95ee0b4c37 85 //#define CMD_TBL_LEN CID_LAST
wvd_vegt 0:4d95ee0b4c37 86
wvd_vegt 0:4d95ee0b4c37 87 #define SUBSYSTEM -1
wvd_vegt 0:4d95ee0b4c37 88 #define GLOBALCMD -2
wvd_vegt 0:4d95ee0b4c37 89 #define HIDDENSUB -3
wvd_vegt 0:4d95ee0b4c37 90
wvd_vegt 0:4d95ee0b4c37 91 #define CID_BOOT 9991
wvd_vegt 0:4d95ee0b4c37 92 #define CID_MACRO 9992
wvd_vegt 0:4d95ee0b4c37 93 #define CID_RUN 9993
wvd_vegt 0:4d95ee0b4c37 94 #define CID_MACROS 9994
wvd_vegt 0:4d95ee0b4c37 95
wvd_vegt 0:4d95ee0b4c37 96 #define CID_ECHO 9995
wvd_vegt 0:4d95ee0b4c37 97 #define CID_BOLD 9996
wvd_vegt 0:4d95ee0b4c37 98 #define CID_CLS 9997
wvd_vegt 0:4d95ee0b4c37 99 #define CID_IDLE 9998
wvd_vegt 0:4d95ee0b4c37 100 #define CID_HELP 9999
wvd_vegt 0:4d95ee0b4c37 101
wvd_vegt 0:4d95ee0b4c37 102 //You need to add the following commands to your command table.
wvd_vegt 0:4d95ee0b4c37 103
wvd_vegt 0:4d95ee0b4c37 104 //Optional
wvd_vegt 0:4d95ee0b4c37 105 cmdb_cmd BOOT = { "Boot", GLOBALCMD ,CID_BOOT ,"" ,"Boot" ,""};
wvd_vegt 0:4d95ee0b4c37 106
wvd_vegt 0:4d95ee0b4c37 107 //Optional
wvd_vegt 0:4d95ee0b4c37 108 cmdb_cmd MACRO = { "Macro", GLOBALCMD ,CID_MACRO ,"%s" ,"Define macro (sp->_, cr->|)" ,"command(s)"};
wvd_vegt 0:4d95ee0b4c37 109 cmdb_cmd RUN = { "Run", GLOBALCMD ,CID_RUN ,"" ,"Run a macro" ,""};
wvd_vegt 0:4d95ee0b4c37 110 cmdb_cmd MACROS = { "Macros", GLOBALCMD ,CID_MACROS ,"" ,"List macro(s)" ,""};
wvd_vegt 0:4d95ee0b4c37 111
wvd_vegt 0:4d95ee0b4c37 112 //Optional
wvd_vegt 0:4d95ee0b4c37 113 cmdb_cmd ECHO = { "Echo", GLOBALCMD ,CID_ECHO ,"%bu" ,"Echo On|Off (1|0)" ,"state"};
wvd_vegt 0:4d95ee0b4c37 114 cmdb_cmd BOLD = { "Bold", GLOBALCMD ,CID_BOLD ,"%bu" ,"Bold On|Off (1|0)" ,"state"};
wvd_vegt 0:4d95ee0b4c37 115 cmdb_cmd CLS = { "Cls", GLOBALCMD ,CID_CLS ,"" ,"Clears the terminal screen" ,""};
wvd_vegt 0:4d95ee0b4c37 116
wvd_vegt 0:4d95ee0b4c37 117 //Mandatory!
wvd_vegt 0:4d95ee0b4c37 118 cmdb_cmd IDLE = { "Idle", GLOBALCMD ,CID_IDLE ,"" ,"Deselect Subsystems" ,""};
wvd_vegt 0:4d95ee0b4c37 119
wvd_vegt 0:4d95ee0b4c37 120 //Mandatory!
wvd_vegt 0:4d95ee0b4c37 121 cmdb_cmd HELP = { "Help", GLOBALCMD ,CID_HELP ,"%s" ,"Help" ,""};
wvd_vegt 0:4d95ee0b4c37 122
wvd_vegt 0:4d95ee0b4c37 123 #define ESC_TBL_LEN 4
wvd_vegt 0:4d95ee0b4c37 124
wvd_vegt 0:4d95ee0b4c37 125 struct esc_st {
wvd_vegt 0:4d95ee0b4c37 126 char *escstr;
wvd_vegt 0:4d95ee0b4c37 127 int id;
wvd_vegt 0:4d95ee0b4c37 128 };
wvd_vegt 0:4d95ee0b4c37 129
wvd_vegt 0:4d95ee0b4c37 130 enum {
wvd_vegt 0:4d95ee0b4c37 131 EID_CURSOR_UP,
wvd_vegt 0:4d95ee0b4c37 132 EID_CURSOR_DOWN,
wvd_vegt 0:4d95ee0b4c37 133 EID_CURSOR_RIGHT,
wvd_vegt 0:4d95ee0b4c37 134 EID_CURSOR_LEFT,
wvd_vegt 0:4d95ee0b4c37 135 EID_LAST
wvd_vegt 0:4d95ee0b4c37 136 };
wvd_vegt 0:4d95ee0b4c37 137
wvd_vegt 0:4d95ee0b4c37 138 const struct esc_st esc_tbl [ESC_TBL_LEN] = {
wvd_vegt 0:4d95ee0b4c37 139 { "\033[A", EID_CURSOR_UP },
wvd_vegt 0:4d95ee0b4c37 140 { "\033[B", EID_CURSOR_DOWN },
wvd_vegt 0:4d95ee0b4c37 141 { "\033[C", EID_CURSOR_RIGHT },
wvd_vegt 0:4d95ee0b4c37 142 { "\033[D", EID_CURSOR_LEFT },
wvd_vegt 0:4d95ee0b4c37 143 };
wvd_vegt 0:4d95ee0b4c37 144
wvd_vegt 0:4d95ee0b4c37 145 //Define a const struct cmbd_cmd cmdb_tbl [CMD_TBL_LEN] {}; that is passed into the constructor.
wvd_vegt 0:4d95ee0b4c37 146
wvd_vegt 2:7d00f6d78090 147 /** Command Interpreter class.<br/>
wvd_vegt 2:7d00f6d78090 148 * <br/>
wvd_vegt 2:7d00f6d78090 149 * Steps to take:<br/>
wvd_vegt 2:7d00f6d78090 150 * <br/>
wvd_vegt 2:7d00f6d78090 151 * 1) Create a std::vector<cmdb_cmd> and fill it with at least<br/>
wvd_vegt 2:7d00f6d78090 152 * the mandatory commands IDLE and HELP.<br/>
wvd_vegt 2:7d00f6d78090 153 * 2) Create an Cmdb class instance and pass it both the vector and<br/>
wvd_vegt 2:7d00f6d78090 154 * a Serial port object like Serial serial(USBTX, USBRX);<br/>
wvd_vegt 2:7d00f6d78090 155 * 3) Feed the interpreter with characters received from your serial port.<br/>
wvd_vegt 2:7d00f6d78090 156 * Note Cmdb self does not retrieve input it must be handed to it<br/>
wvd_vegt 2:7d00f6d78090 157 * 4) Handle commands added by the application by the Id and parameters passed.<br/>
wvd_vegt 0:4d95ee0b4c37 158 *
wvd_vegt 0:4d95ee0b4c37 159 */
wvd_vegt 0:4d95ee0b4c37 160 class Cmdb {
wvd_vegt 0:4d95ee0b4c37 161 public:
wvd_vegt 0:4d95ee0b4c37 162 /** Create a Command Interpreter.
wvd_vegt 0:4d95ee0b4c37 163 *
wvd_vegt 0:4d95ee0b4c37 164 * @param serial a Serial port used for communication.
wvd_vegt 0:4d95ee0b4c37 165 * @param cmds a vector with the command table.
wvd_vegt 0:4d95ee0b4c37 166 */
wvd_vegt 0:4d95ee0b4c37 167 Cmdb(const Serial serial, const std::vector<cmdb_cmd>& cmds);
wvd_vegt 0:4d95ee0b4c37 168
wvd_vegt 0:4d95ee0b4c37 169 /** Checks if the macro buffer has any characters left.
wvd_vegt 0:4d95ee0b4c37 170 *
wvd_vegt 0:4d95ee0b4c37 171 * @returns true if any characters left.
wvd_vegt 0:4d95ee0b4c37 172 */
wvd_vegt 0:4d95ee0b4c37 173 bool cmdb_macro_hasnext();
wvd_vegt 1:6627eed48db5 174
wvd_vegt 1:6627eed48db5 175 /** Gets the next character from the macro buffer and
wvd_vegt 1:6627eed48db5 176 * advances the macro buffer pointer.
wvd_vegt 1:6627eed48db5 177 *
wvd_vegt 1:6627eed48db5 178 * Do not call if no more characters are left!
wvd_vegt 1:6627eed48db5 179 *
wvd_vegt 1:6627eed48db5 180 * @returns the next character.
wvd_vegt 1:6627eed48db5 181 */
wvd_vegt 0:4d95ee0b4c37 182 char cmdb_macro_next();
wvd_vegt 1:6627eed48db5 183
wvd_vegt 1:6627eed48db5 184 /** Gets the next character from the macro buffer
wvd_vegt 1:6627eed48db5 185 * but does not advance the macro buffer pointer.
wvd_vegt 1:6627eed48db5 186 *
wvd_vegt 1:6627eed48db5 187 * Do not call if no more characters are left!
wvd_vegt 1:6627eed48db5 188 *
wvd_vegt 1:6627eed48db5 189 * @returns the next character.
wvd_vegt 1:6627eed48db5 190 */
wvd_vegt 0:4d95ee0b4c37 191 char cmdb_macro_peek();
wvd_vegt 1:6627eed48db5 192
wvd_vegt 1:6627eed48db5 193 /** Resets the macro buffer and macro buffer pointer.
wvd_vegt 1:6627eed48db5 194 *
wvd_vegt 1:6627eed48db5 195 */
wvd_vegt 0:4d95ee0b4c37 196 void cmdb_macro_reset();
wvd_vegt 0:4d95ee0b4c37 197
wvd_vegt 1:6627eed48db5 198 /** Checks if the serial port has any characters
wvd_vegt 1:6627eed48db5 199 * left to read by calling serial.readable().
wvd_vegt 1:6627eed48db5 200 *
wvd_vegt 1:6627eed48db5 201 * @returns true if any characters available.
wvd_vegt 1:6627eed48db5 202 */
wvd_vegt 0:4d95ee0b4c37 203 bool cmdb_hasnext();
wvd_vegt 1:6627eed48db5 204
wvd_vegt 1:6627eed48db5 205 /** Gets the next character from the serial port by
wvd_vegt 1:6627eed48db5 206 * calling serial.getc().
wvd_vegt 1:6627eed48db5 207 *
wvd_vegt 1:6627eed48db5 208 * Do not call if no characters are left!
wvd_vegt 1:6627eed48db5 209 *
wvd_vegt 1:6627eed48db5 210 * @returns the next character.
wvd_vegt 1:6627eed48db5 211 */
wvd_vegt 0:4d95ee0b4c37 212 char cmdb_next();
wvd_vegt 0:4d95ee0b4c37 213
wvd_vegt 0:4d95ee0b4c37 214 private:
wvd_vegt 2:7d00f6d78090 215 /** Searches the escape code list for a match.
wvd_vegt 0:4d95ee0b4c37 216 *
wvd_vegt 0:4d95ee0b4c37 217 * @param char* escstr the escape code to lookup.
wvd_vegt 0:4d95ee0b4c37 218 *
wvd_vegt 0:4d95ee0b4c37 219 * @returns the index of the escape code or -1.
wvd_vegt 0:4d95ee0b4c37 220 */
wvd_vegt 0:4d95ee0b4c37 221 int cmdb_escid_search(char *escstr);
wvd_vegt 2:7d00f6d78090 222
wvd_vegt 2:7d00f6d78090 223 /** Checks if the command table for a match.
wvd_vegt 2:7d00f6d78090 224 *
wvd_vegt 2:7d00f6d78090 225 * @param char* cmdstr the command to lookup.
wvd_vegt 2:7d00f6d78090 226 *
wvd_vegt 2:7d00f6d78090 227 * @returns the id of the command or -1.
wvd_vegt 2:7d00f6d78090 228 */
wvd_vegt 0:4d95ee0b4c37 229 int cmdb_cmdid_search(char *cmdstr);
wvd_vegt 2:7d00f6d78090 230
wvd_vegt 2:7d00f6d78090 231 /** Converts an command id to an index of the command table.
wvd_vegt 2:7d00f6d78090 232 *
wvd_vegt 2:7d00f6d78090 233 * @param cmdid the command id to lookup.
wvd_vegt 2:7d00f6d78090 234 *
wvd_vegt 2:7d00f6d78090 235 * @returns the index of the command or -1.
wvd_vegt 2:7d00f6d78090 236 */
wvd_vegt 0:4d95ee0b4c37 237 int cmdb_cmdid_index(int cmdid);
wvd_vegt 0:4d95ee0b4c37 238
wvd_vegt 2:7d00f6d78090 239 /** Initializes the parser.
wvd_vegt 2:7d00f6d78090 240 *
wvd_vegt 2:7d00f6d78090 241 * @parm full if true the macro buffer is also cleared else only the command interpreter is reset.
wvd_vegt 2:7d00f6d78090 242 */
wvd_vegt 0:4d95ee0b4c37 243 void cmdb_init(const char full);
wvd_vegt 2:7d00f6d78090 244
wvd_vegt 2:7d00f6d78090 245 /** Writes a prompt to the serial port.
wvd_vegt 2:7d00f6d78090 246 *
wvd_vegt 2:7d00f6d78090 247 */
wvd_vegt 0:4d95ee0b4c37 248 void cmdb_prompt(void);
wvd_vegt 2:7d00f6d78090 249
wvd_vegt 2:7d00f6d78090 250 /** Add a character to the command being processed.
wvd_vegt 2:7d00f6d78090 251 * If a cr is added, the command is parsed and executed if possible
wvd_vegt 2:7d00f6d78090 252 * If supported special keys are encountered (like backspace, delete and cursor up) they are processed.
wvd_vegt 2:7d00f6d78090 253 *
wvd_vegt 2:7d00f6d78090 254 * @parmam c the character to add.
wvd_vegt 2:7d00f6d78090 255 *
wvd_vegt 2:7d00f6d78090 256 * @returns true if a command was recognized and executed.
wvd_vegt 2:7d00f6d78090 257 */
wvd_vegt 0:4d95ee0b4c37 258 bool cmdb_scan(const char c);
wvd_vegt 2:7d00f6d78090 259
wvd_vegt 2:7d00f6d78090 260 /** Called by cmdb_cmd_proc it parses the command against the command table.
wvd_vegt 2:7d00f6d78090 261 *
wvd_vegt 2:7d00f6d78090 262 * @param cmd the command and paramaters to parse.
wvd_vegt 2:7d00f6d78090 263 *
wvd_vegt 2:7d00f6d78090 264 * @returns the id of the parsed command.
wvd_vegt 2:7d00f6d78090 265 */
wvd_vegt 0:4d95ee0b4c37 266 int cmdb_parse(char *cmd);
wvd_vegt 0:4d95ee0b4c37 267
wvd_vegt 0:4d95ee0b4c37 268 //TODO Must call Callback function.
wvd_vegt 2:7d00f6d78090 269
wvd_vegt 2:7d00f6d78090 270 /** Called by cmdb_scan it processes the arguments and Executes the command.
wvd_vegt 2:7d00f6d78090 271 *
wvd_vegt 2:7d00f6d78090 272 * @param cmd the command to execute.
wvd_vegt 2:7d00f6d78090 273 */
wvd_vegt 0:4d95ee0b4c37 274 void cmdb_cmd_proc(char *cmd);
wvd_vegt 0:4d95ee0b4c37 275
wvd_vegt 2:7d00f6d78090 276 /** Generates Help from the command table and prints it.
wvd_vegt 2:7d00f6d78090 277 *
wvd_vegt 2:7d00f6d78090 278 * @param pre leading text
wvd_vegt 2:7d00f6d78090 279 * @param ndx the index of the command in the command table.
wvd_vegt 2:7d00f6d78090 280 * @param post trailing text.
wvd_vegt 2:7d00f6d78090 281 */
wvd_vegt 0:4d95ee0b4c37 282 void cmdb_cmdhelp(char *pre, int ndx, char *post);
wvd_vegt 0:4d95ee0b4c37 283
wvd_vegt 0:4d95ee0b4c37 284 //Output.
wvd_vegt 0:4d95ee0b4c37 285 int cmdb_printf(const char *format, ...);
wvd_vegt 0:4d95ee0b4c37 286 int cmdb_print(const char *msg);
wvd_vegt 0:4d95ee0b4c37 287 char cmdb_printch(const char ch);
wvd_vegt 0:4d95ee0b4c37 288
wvd_vegt 0:4d95ee0b4c37 289 //Utilities.
wvd_vegt 0:4d95ee0b4c37 290 void zeromemory(char *p,unsigned int siz);
wvd_vegt 0:4d95ee0b4c37 291 int stricmp (char *s1, char *s2);
wvd_vegt 0:4d95ee0b4c37 292
wvd_vegt 0:4d95ee0b4c37 293
wvd_vegt 0:4d95ee0b4c37 294 //Storage, see http://www.cplusplus.com/reference/stl/vector/
wvd_vegt 0:4d95ee0b4c37 295 std::vector<cmdb_cmd> _cmds;
wvd_vegt 0:4d95ee0b4c37 296 Serial _serial;
wvd_vegt 0:4d95ee0b4c37 297 bool echo;
wvd_vegt 0:4d95ee0b4c37 298 bool bold;
wvd_vegt 0:4d95ee0b4c37 299
wvd_vegt 0:4d95ee0b4c37 300 int CID_LAST;
wvd_vegt 0:4d95ee0b4c37 301 int CMD_TBL_LEN;
wvd_vegt 0:4d95ee0b4c37 302
wvd_vegt 0:4d95ee0b4c37 303 //Macro's.
wvd_vegt 0:4d95ee0b4c37 304 int macro_ptr;
wvd_vegt 0:4d95ee0b4c37 305 char macro_buf[1 + MAX_CMD_LEN];
wvd_vegt 0:4d95ee0b4c37 306
wvd_vegt 0:4d95ee0b4c37 307 enum parmtype {
wvd_vegt 0:4d95ee0b4c37 308 PARM_UNUSED, //0
wvd_vegt 0:4d95ee0b4c37 309
wvd_vegt 0:4d95ee0b4c37 310 PARM_FLOAT, //1 (f)
wvd_vegt 0:4d95ee0b4c37 311
wvd_vegt 0:4d95ee0b4c37 312 PARM_LONG, //2 (l/ul)
wvd_vegt 0:4d95ee0b4c37 313 PARM_INT, //3 (i/ui)
wvd_vegt 0:4d95ee0b4c37 314 PARM_SHORT, //4 (w/uw)
wvd_vegt 0:4d95ee0b4c37 315
wvd_vegt 0:4d95ee0b4c37 316 PARM_CHAR, //5 (c/uc)
wvd_vegt 0:4d95ee0b4c37 317 PARM_STRING //6 (s)
wvd_vegt 0:4d95ee0b4c37 318 };
wvd_vegt 0:4d95ee0b4c37 319
wvd_vegt 0:4d95ee0b4c37 320 union value {
wvd_vegt 0:4d95ee0b4c37 321 float f;
wvd_vegt 0:4d95ee0b4c37 322
wvd_vegt 0:4d95ee0b4c37 323 unsigned long ul;
wvd_vegt 0:4d95ee0b4c37 324 long l;
wvd_vegt 0:4d95ee0b4c37 325
wvd_vegt 0:4d95ee0b4c37 326 int i;
wvd_vegt 0:4d95ee0b4c37 327 unsigned int ui;
wvd_vegt 0:4d95ee0b4c37 328
wvd_vegt 0:4d95ee0b4c37 329 short w;
wvd_vegt 0:4d95ee0b4c37 330 unsigned short uw;
wvd_vegt 0:4d95ee0b4c37 331
wvd_vegt 0:4d95ee0b4c37 332 char c;
wvd_vegt 0:4d95ee0b4c37 333 unsigned char uc;
wvd_vegt 0:4d95ee0b4c37 334
wvd_vegt 0:4d95ee0b4c37 335 char s[MAX_PARM_LEN];
wvd_vegt 0:4d95ee0b4c37 336 };
wvd_vegt 0:4d95ee0b4c37 337
wvd_vegt 0:4d95ee0b4c37 338 struct parm {
wvd_vegt 0:4d95ee0b4c37 339 enum parmtype type;
wvd_vegt 0:4d95ee0b4c37 340 union value val;
wvd_vegt 0:4d95ee0b4c37 341 };
wvd_vegt 0:4d95ee0b4c37 342
wvd_vegt 0:4d95ee0b4c37 343 //------------------------------------------------------------------------------
wvd_vegt 0:4d95ee0b4c37 344 //----These helper functions retieve parameters in the correct format.
wvd_vegt 0:4d95ee0b4c37 345 //------------------------------------------------------------------------------
wvd_vegt 0:4d95ee0b4c37 346
wvd_vegt 0:4d95ee0b4c37 347 //TODO Add tests for correct type of parameter.
wvd_vegt 0:4d95ee0b4c37 348
wvd_vegt 0:4d95ee0b4c37 349 bool BOOLPARM(int ndx) {
wvd_vegt 0:4d95ee0b4c37 350 return parms[ndx].val.uc!=0;
wvd_vegt 0:4d95ee0b4c37 351 }
wvd_vegt 0:4d95ee0b4c37 352
wvd_vegt 0:4d95ee0b4c37 353 unsigned char BYTEPARM(int ndx) {
wvd_vegt 0:4d95ee0b4c37 354 return parms[ndx].val.uc;
wvd_vegt 0:4d95ee0b4c37 355 }
wvd_vegt 0:4d95ee0b4c37 356
wvd_vegt 0:4d95ee0b4c37 357 char CHARPARM(int ndx) {
wvd_vegt 0:4d95ee0b4c37 358 return parms[ndx].val.c;
wvd_vegt 0:4d95ee0b4c37 359 }
wvd_vegt 0:4d95ee0b4c37 360
wvd_vegt 0:4d95ee0b4c37 361 unsigned int WORDPARM(int ndx) {
wvd_vegt 0:4d95ee0b4c37 362 return parms[ndx].val.ui;
wvd_vegt 0:4d95ee0b4c37 363 }
wvd_vegt 0:4d95ee0b4c37 364
wvd_vegt 0:4d95ee0b4c37 365 unsigned int UINTPARM(int ndx) {
wvd_vegt 0:4d95ee0b4c37 366 return parms[ndx].val.ui;
wvd_vegt 0:4d95ee0b4c37 367 }
wvd_vegt 0:4d95ee0b4c37 368
wvd_vegt 0:4d95ee0b4c37 369 int INTPARM(int ndx) {
wvd_vegt 0:4d95ee0b4c37 370 return parms[ndx].val.i;
wvd_vegt 0:4d95ee0b4c37 371 }
wvd_vegt 0:4d95ee0b4c37 372
wvd_vegt 0:4d95ee0b4c37 373 unsigned long DWORDPARM(int ndx) {
wvd_vegt 0:4d95ee0b4c37 374 return parms[ndx].val.ul;
wvd_vegt 0:4d95ee0b4c37 375 }
wvd_vegt 0:4d95ee0b4c37 376
wvd_vegt 0:4d95ee0b4c37 377 long LONGPARM(int ndx) {
wvd_vegt 0:4d95ee0b4c37 378 return parms[ndx].val.l;
wvd_vegt 0:4d95ee0b4c37 379 }
wvd_vegt 0:4d95ee0b4c37 380
wvd_vegt 0:4d95ee0b4c37 381 float FLOATPARM(int ndx) {
wvd_vegt 0:4d95ee0b4c37 382 return parms[ndx].val.f;
wvd_vegt 0:4d95ee0b4c37 383 }
wvd_vegt 0:4d95ee0b4c37 384
wvd_vegt 0:4d95ee0b4c37 385 char* STRINGPARM(int ndx) {
wvd_vegt 0:4d95ee0b4c37 386 return parms[ndx].val.s;
wvd_vegt 0:4d95ee0b4c37 387 }
wvd_vegt 0:4d95ee0b4c37 388
wvd_vegt 0:4d95ee0b4c37 389 //------------------------------------------------------------------------------
wvd_vegt 0:4d95ee0b4c37 390 //----Buffers
wvd_vegt 0:4d95ee0b4c37 391 //------------------------------------------------------------------------------
wvd_vegt 0:4d95ee0b4c37 392
wvd_vegt 0:4d95ee0b4c37 393 char cmdbuf [1 + MAX_CMD_LEN]; // command buffer
wvd_vegt 0:4d95ee0b4c37 394 char cmdndx; // command index
wvd_vegt 0:4d95ee0b4c37 395
wvd_vegt 0:4d95ee0b4c37 396 char lstbuf [1 + MAX_CMD_LEN]; // last command buffer
wvd_vegt 0:4d95ee0b4c37 397
wvd_vegt 0:4d95ee0b4c37 398 char escbuf [1 + MAX_ESC_LEN]; // command buffer
wvd_vegt 0:4d95ee0b4c37 399 unsigned char escndx; // command index
wvd_vegt 0:4d95ee0b4c37 400
wvd_vegt 0:4d95ee0b4c37 401 struct parm parms[MAX_ARGS];
wvd_vegt 0:4d95ee0b4c37 402 int noparms;
wvd_vegt 0:4d95ee0b4c37 403
wvd_vegt 0:4d95ee0b4c37 404 int subsystem;
wvd_vegt 0:4d95ee0b4c37 405
wvd_vegt 0:4d95ee0b4c37 406 int argcnt; //No of arguments found in command
wvd_vegt 0:4d95ee0b4c37 407 int argfnd; //No of arguments to find in parameter definition.
wvd_vegt 0:4d95ee0b4c37 408 int error; //strtoXX() Error detection
wvd_vegt 0:4d95ee0b4c37 409
wvd_vegt 0:4d95ee0b4c37 410 };
wvd_vegt 0:4d95ee0b4c37 411
wvd_vegt 0:4d95ee0b4c37 412 #endif