A Command Interpreter with support for used defined commands, subsystems, macros, help and parameter parsing.
cmdb.h@23:73a4f087c1b9, 2012-02-15 (annotated)
- Committer:
- wvd_vegt
- Date:
- Wed Feb 15 09:42:30 2012 +0000
- Revision:
- 23:73a4f087c1b9
- Parent:
- 22:5192a468d7fa
Some bugfixes and more ini file related print* methods (including commented ini file entries).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wvd_vegt | 20:62318ba945de | 1 | /* mbed Command Interpreter Library |
wvd_vegt | 20:62318ba945de | 2 | * Copyright (c) 2011 wvd_vegt |
wvd_vegt | 20:62318ba945de | 3 | * |
wvd_vegt | 20:62318ba945de | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wvd_vegt | 20:62318ba945de | 5 | * of this software and associated documentation files (the "Software"), to deal |
wvd_vegt | 20:62318ba945de | 6 | * in the Software without restriction, including without limitation the rights |
wvd_vegt | 20:62318ba945de | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wvd_vegt | 20:62318ba945de | 8 | * copies of the Software, and to permit persons to whom the Software is |
wvd_vegt | 20:62318ba945de | 9 | * furnished to do so, subject to the following conditions: |
wvd_vegt | 20:62318ba945de | 10 | * |
wvd_vegt | 20:62318ba945de | 11 | * The above copyright notice and this permission notice shall be included in |
wvd_vegt | 20:62318ba945de | 12 | * all copies or substantial portions of the Software. |
wvd_vegt | 20:62318ba945de | 13 | * |
wvd_vegt | 20:62318ba945de | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wvd_vegt | 20:62318ba945de | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wvd_vegt | 20:62318ba945de | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wvd_vegt | 20:62318ba945de | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wvd_vegt | 20:62318ba945de | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wvd_vegt | 20:62318ba945de | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wvd_vegt | 20:62318ba945de | 20 | * THE SOFTWARE. |
wvd_vegt | 20:62318ba945de | 21 | */ |
wvd_vegt | 20:62318ba945de | 22 | |
wvd_vegt | 20:62318ba945de | 23 | #ifndef MBED_CMDB_H |
wvd_vegt | 20:62318ba945de | 24 | #define MBED_CMDB_H |
wvd_vegt | 20:62318ba945de | 25 | |
wvd_vegt | 20:62318ba945de | 26 | #include "mbed.h" |
wvd_vegt | 20:62318ba945de | 27 | |
wvd_vegt | 20:62318ba945de | 28 | #include <vector> |
wvd_vegt | 20:62318ba945de | 29 | #include <limits> |
wvd_vegt | 20:62318ba945de | 30 | |
wvd_vegt | 20:62318ba945de | 31 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 32 | |
wvd_vegt | 20:62318ba945de | 33 | /** Max size of an Ansi escape code. |
wvd_vegt | 20:62318ba945de | 34 | */ |
wvd_vegt | 20:62318ba945de | 35 | #define MAX_ESC_LEN 5 |
wvd_vegt | 20:62318ba945de | 36 | |
wvd_vegt | 20:62318ba945de | 37 | /** Max (strlen) of a Param. |
wvd_vegt | 20:62318ba945de | 38 | */ |
wvd_vegt | 20:62318ba945de | 39 | #define MAX_PARM_LEN 32 |
wvd_vegt | 20:62318ba945de | 40 | |
wvd_vegt | 20:62318ba945de | 41 | /** Max eight parms. |
wvd_vegt | 20:62318ba945de | 42 | */ |
wvd_vegt | 20:62318ba945de | 43 | #define MAX_ARGS 8 |
wvd_vegt | 20:62318ba945de | 44 | |
wvd_vegt | 20:62318ba945de | 45 | /** Max 132 characters commandline. |
wvd_vegt | 20:62318ba945de | 46 | */ |
wvd_vegt | 20:62318ba945de | 47 | #define MAX_CMD_LEN 132 |
wvd_vegt | 20:62318ba945de | 48 | |
wvd_vegt | 20:62318ba945de | 49 | /** 'Show' hidden subsystems and commands. |
wvd_vegt | 20:62318ba945de | 50 | */ |
wvd_vegt | 20:62318ba945de | 51 | #define SHOWHIDDEN |
wvd_vegt | 20:62318ba945de | 52 | |
wvd_vegt | 20:62318ba945de | 53 | /** Enable macro commands. |
wvd_vegt | 20:62318ba945de | 54 | */ |
wvd_vegt | 20:62318ba945de | 55 | #define ENABLEMACROS |
wvd_vegt | 20:62318ba945de | 56 | |
wvd_vegt | 20:62318ba945de | 57 | /** Enable statemachine. |
wvd_vegt | 20:62318ba945de | 58 | * |
wvd_vegt | 20:62318ba945de | 59 | * Used to implement a series of commands running at power-up. |
wvd_vegt | 20:62318ba945de | 60 | * |
wvd_vegt | 20:62318ba945de | 61 | * @note Not Implemented! |
wvd_vegt | 20:62318ba945de | 62 | */ |
wvd_vegt | 20:62318ba945de | 63 | #undef STATEMACHINE |
wvd_vegt | 20:62318ba945de | 64 | |
wvd_vegt | 20:62318ba945de | 65 | /** Enable subsystem prompts. |
wvd_vegt | 20:62318ba945de | 66 | * |
wvd_vegt | 20:62318ba945de | 67 | * When defined, prompts will reflect the SubSystem. |
wvd_vegt | 20:62318ba945de | 68 | */ |
wvd_vegt | 20:62318ba945de | 69 | #define SUBSYSTEMPROMPTS |
wvd_vegt | 20:62318ba945de | 70 | |
wvd_vegt | 20:62318ba945de | 71 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 72 | |
wvd_vegt | 20:62318ba945de | 73 | /** 8 bit limits. |
wvd_vegt | 20:62318ba945de | 74 | * |
wvd_vegt | 20:62318ba945de | 75 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 20:62318ba945de | 76 | */ |
wvd_vegt | 23:73a4f087c1b9 | 77 | #define MIN_BYTE std::numeric_limits<unsigned char>::min() |
wvd_vegt | 20:62318ba945de | 78 | |
wvd_vegt | 20:62318ba945de | 79 | /** 8 bit limits. |
wvd_vegt | 20:62318ba945de | 80 | * |
wvd_vegt | 20:62318ba945de | 81 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 20:62318ba945de | 82 | */ |
wvd_vegt | 23:73a4f087c1b9 | 83 | #define MAX_BYTE std::numeric_limits<unsigned char>::max() |
wvd_vegt | 23:73a4f087c1b9 | 84 | |
wvd_vegt | 23:73a4f087c1b9 | 85 | /** 8 bit limits. |
wvd_vegt | 23:73a4f087c1b9 | 86 | * |
wvd_vegt | 23:73a4f087c1b9 | 87 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 23:73a4f087c1b9 | 88 | */ |
wvd_vegt | 23:73a4f087c1b9 | 89 | #define MIN_CHAR std::numeric_limits<signed char>::min() |
wvd_vegt | 23:73a4f087c1b9 | 90 | |
wvd_vegt | 23:73a4f087c1b9 | 91 | /** 8 bit limits. |
wvd_vegt | 23:73a4f087c1b9 | 92 | * |
wvd_vegt | 23:73a4f087c1b9 | 93 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 23:73a4f087c1b9 | 94 | */ |
wvd_vegt | 23:73a4f087c1b9 | 95 | #define MAX_CHAR std::numeric_limits<signed char>::max() |
wvd_vegt | 20:62318ba945de | 96 | |
wvd_vegt | 20:62318ba945de | 97 | /** 16 bit limits. |
wvd_vegt | 20:62318ba945de | 98 | * |
wvd_vegt | 20:62318ba945de | 99 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 20:62318ba945de | 100 | */ |
wvd_vegt | 20:62318ba945de | 101 | #define MIN_SHORT std::numeric_limits<short int>::min() |
wvd_vegt | 20:62318ba945de | 102 | |
wvd_vegt | 20:62318ba945de | 103 | /** 16 bit limits. |
wvd_vegt | 20:62318ba945de | 104 | * |
wvd_vegt | 20:62318ba945de | 105 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 20:62318ba945de | 106 | */ |
wvd_vegt | 20:62318ba945de | 107 | #define MAX_SHORT std::numeric_limits<short int>::max() |
wvd_vegt | 20:62318ba945de | 108 | |
wvd_vegt | 23:73a4f087c1b9 | 109 | /** 16 bit limits. |
wvd_vegt | 23:73a4f087c1b9 | 110 | * |
wvd_vegt | 23:73a4f087c1b9 | 111 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 23:73a4f087c1b9 | 112 | */ |
wvd_vegt | 23:73a4f087c1b9 | 113 | #define MIN_USHORT std::numeric_limits<unsigned short int>::min() |
wvd_vegt | 23:73a4f087c1b9 | 114 | |
wvd_vegt | 23:73a4f087c1b9 | 115 | /** 16 bit limits. |
wvd_vegt | 23:73a4f087c1b9 | 116 | * |
wvd_vegt | 23:73a4f087c1b9 | 117 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 23:73a4f087c1b9 | 118 | */ |
wvd_vegt | 23:73a4f087c1b9 | 119 | #define MAX_USHORT std::numeric_limits<unsigned short int>::max() |
wvd_vegt | 23:73a4f087c1b9 | 120 | |
wvd_vegt | 20:62318ba945de | 121 | /** 32 bit limits. |
wvd_vegt | 20:62318ba945de | 122 | * |
wvd_vegt | 20:62318ba945de | 123 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 20:62318ba945de | 124 | */ |
wvd_vegt | 20:62318ba945de | 125 | #define MIN_INT std::numeric_limits<int>::min() |
wvd_vegt | 20:62318ba945de | 126 | #define MAX_INT std::numeric_limits<int>::max() |
wvd_vegt | 20:62318ba945de | 127 | |
wvd_vegt | 20:62318ba945de | 128 | /** 32 bit limits. |
wvd_vegt | 20:62318ba945de | 129 | * |
wvd_vegt | 20:62318ba945de | 130 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 20:62318ba945de | 131 | */ |
wvd_vegt | 23:73a4f087c1b9 | 132 | #define MIN_UINT std::numeric_limits<unsigned int>::min() |
wvd_vegt | 23:73a4f087c1b9 | 133 | #define MAX_UINT std::numeric_limits<unsigned int>::max() |
wvd_vegt | 23:73a4f087c1b9 | 134 | |
wvd_vegt | 23:73a4f087c1b9 | 135 | /** 32 bit limits. |
wvd_vegt | 23:73a4f087c1b9 | 136 | * |
wvd_vegt | 23:73a4f087c1b9 | 137 | * @see http://www.daniweb.com/forums/thread18963.html |
wvd_vegt | 23:73a4f087c1b9 | 138 | */ |
wvd_vegt | 20:62318ba945de | 139 | #define MIN_LONG std::numeric_limits<long>::min() |
wvd_vegt | 20:62318ba945de | 140 | #define MAX_LONG std::numeric_limits<long>::max() |
wvd_vegt | 20:62318ba945de | 141 | |
wvd_vegt | 20:62318ba945de | 142 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 143 | |
wvd_vegt | 20:62318ba945de | 144 | /** Description of a command. |
wvd_vegt | 20:62318ba945de | 145 | */ |
wvd_vegt | 20:62318ba945de | 146 | struct cmd { |
wvd_vegt | 20:62318ba945de | 147 | public: |
wvd_vegt | 20:62318ba945de | 148 | const char *cmdstr; |
wvd_vegt | 20:62318ba945de | 149 | int subs; |
wvd_vegt | 20:62318ba945de | 150 | int cid; |
wvd_vegt | 20:62318ba945de | 151 | const char *parms; |
wvd_vegt | 20:62318ba945de | 152 | const char *cmddescr; |
wvd_vegt | 20:62318ba945de | 153 | const char *parmdescr; |
wvd_vegt | 20:62318ba945de | 154 | }; |
wvd_vegt | 20:62318ba945de | 155 | |
wvd_vegt | 20:62318ba945de | 156 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 157 | |
wvd_vegt | 20:62318ba945de | 158 | /** Cr. |
wvd_vegt | 20:62318ba945de | 159 | */ |
wvd_vegt | 20:62318ba945de | 160 | static const char cr = '\r'; |
wvd_vegt | 20:62318ba945de | 161 | |
wvd_vegt | 20:62318ba945de | 162 | /** Lf. |
wvd_vegt | 20:62318ba945de | 163 | */ |
wvd_vegt | 20:62318ba945de | 164 | static const char lf = '\n'; |
wvd_vegt | 20:62318ba945de | 165 | |
wvd_vegt | 20:62318ba945de | 166 | /** Bell. |
wvd_vegt | 20:62318ba945de | 167 | */ |
wvd_vegt | 20:62318ba945de | 168 | static const char bell = '\7'; |
wvd_vegt | 20:62318ba945de | 169 | |
wvd_vegt | 20:62318ba945de | 170 | /** Escape. |
wvd_vegt | 20:62318ba945de | 171 | */ |
wvd_vegt | 20:62318ba945de | 172 | static const char esc = '\033'; |
wvd_vegt | 20:62318ba945de | 173 | |
wvd_vegt | 20:62318ba945de | 174 | /** Space. |
wvd_vegt | 20:62318ba945de | 175 | */ |
wvd_vegt | 20:62318ba945de | 176 | static const char sp = ' '; |
wvd_vegt | 20:62318ba945de | 177 | |
wvd_vegt | 20:62318ba945de | 178 | /** CrLf. |
wvd_vegt | 20:62318ba945de | 179 | */ |
wvd_vegt | 20:62318ba945de | 180 | static const char crlf[] = "\r\n"; |
wvd_vegt | 20:62318ba945de | 181 | |
wvd_vegt | 20:62318ba945de | 182 | /** Backspace that 'tries' to wipe the last character. |
wvd_vegt | 20:62318ba945de | 183 | */ |
wvd_vegt | 20:62318ba945de | 184 | static const char bs[] = "\b \b"; |
wvd_vegt | 20:62318ba945de | 185 | |
wvd_vegt | 20:62318ba945de | 186 | /** VT100 Bold Command. |
wvd_vegt | 20:62318ba945de | 187 | */ |
wvd_vegt | 20:62318ba945de | 188 | static const char boldon[] = "\033[1m"; |
wvd_vegt | 20:62318ba945de | 189 | |
wvd_vegt | 20:62318ba945de | 190 | /** VT100 Normal Command. |
wvd_vegt | 20:62318ba945de | 191 | */ |
wvd_vegt | 20:62318ba945de | 192 | static const char boldoff[] = "\033[0m"; |
wvd_vegt | 20:62318ba945de | 193 | |
wvd_vegt | 20:62318ba945de | 194 | /** VT100 Cls Command. |
wvd_vegt | 20:62318ba945de | 195 | */ |
wvd_vegt | 20:62318ba945de | 196 | static const char cls[] = "\033[2J"; |
wvd_vegt | 20:62318ba945de | 197 | |
wvd_vegt | 20:62318ba945de | 198 | /** VT100 Home Command. |
wvd_vegt | 20:62318ba945de | 199 | */ |
wvd_vegt | 20:62318ba945de | 200 | static const char home[] = "\033[H"; |
wvd_vegt | 20:62318ba945de | 201 | |
wvd_vegt | 20:62318ba945de | 202 | /** The default command prompt. |
wvd_vegt | 20:62318ba945de | 203 | */ |
wvd_vegt | 20:62318ba945de | 204 | static const char PROMPT[] = "CMD>"; |
wvd_vegt | 20:62318ba945de | 205 | |
wvd_vegt | 20:62318ba945de | 206 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 207 | |
wvd_vegt | 20:62318ba945de | 208 | /** Subsystem Id for a Subsystem. |
wvd_vegt | 20:62318ba945de | 209 | */ |
wvd_vegt | 20:62318ba945de | 210 | #define SUBSYSTEM -1 |
wvd_vegt | 20:62318ba945de | 211 | |
wvd_vegt | 20:62318ba945de | 212 | /** Subsystem Id for a Global Command (always available). |
wvd_vegt | 20:62318ba945de | 213 | */ |
wvd_vegt | 20:62318ba945de | 214 | #define GLOBALCMD -2 |
wvd_vegt | 20:62318ba945de | 215 | |
wvd_vegt | 20:62318ba945de | 216 | /** Subsystem Id for a Hidden Subsystem (ommitted from help). |
wvd_vegt | 20:62318ba945de | 217 | */ |
wvd_vegt | 20:62318ba945de | 218 | #define HIDDENSUB -3 |
wvd_vegt | 20:62318ba945de | 219 | |
wvd_vegt | 20:62318ba945de | 220 | /** Predefined Dump Command. |
wvd_vegt | 20:62318ba945de | 221 | */ |
wvd_vegt | 20:62318ba945de | 222 | #define CID_COMMANDS 9989 |
wvd_vegt | 20:62318ba945de | 223 | |
wvd_vegt | 20:62318ba945de | 224 | /** Predefined Boot Command. |
wvd_vegt | 20:62318ba945de | 225 | */ |
wvd_vegt | 20:62318ba945de | 226 | #define CID_BOOT 9990 |
wvd_vegt | 20:62318ba945de | 227 | |
wvd_vegt | 20:62318ba945de | 228 | /** Predefined Macro Command. |
wvd_vegt | 20:62318ba945de | 229 | * |
wvd_vegt | 20:62318ba945de | 230 | * This command will take a string with spaces replace by _ and cr replace by | for later replay with run. |
wvd_vegt | 20:62318ba945de | 231 | */ |
wvd_vegt | 20:62318ba945de | 232 | #define CID_MACRO 9991 |
wvd_vegt | 20:62318ba945de | 233 | |
wvd_vegt | 20:62318ba945de | 234 | /** Predefined Macro Command. |
wvd_vegt | 20:62318ba945de | 235 | * |
wvd_vegt | 20:62318ba945de | 236 | * This command replay a macro. |
wvd_vegt | 20:62318ba945de | 237 | */ |
wvd_vegt | 20:62318ba945de | 238 | #define CID_RUN 9992 |
wvd_vegt | 20:62318ba945de | 239 | |
wvd_vegt | 20:62318ba945de | 240 | /** Predefined Macro Command. |
wvd_vegt | 20:62318ba945de | 241 | * |
wvd_vegt | 20:62318ba945de | 242 | * This command print the current macro. |
wvd_vegt | 20:62318ba945de | 243 | */ |
wvd_vegt | 20:62318ba945de | 244 | #define CID_MACROS 9993 |
wvd_vegt | 20:62318ba945de | 245 | |
wvd_vegt | 20:62318ba945de | 246 | /** Predefined Echo Command. |
wvd_vegt | 20:62318ba945de | 247 | * |
wvd_vegt | 20:62318ba945de | 248 | * This command turn echo on or off. |
wvd_vegt | 20:62318ba945de | 249 | */ |
wvd_vegt | 20:62318ba945de | 250 | #define CID_ECHO 9994 |
wvd_vegt | 20:62318ba945de | 251 | |
wvd_vegt | 20:62318ba945de | 252 | /** Predefined VT100 Bold Command. |
wvd_vegt | 20:62318ba945de | 253 | * |
wvd_vegt | 20:62318ba945de | 254 | * This command turn VT100 bold usage on or off. |
wvd_vegt | 20:62318ba945de | 255 | */ |
wvd_vegt | 20:62318ba945de | 256 | #define CID_BOLD 9995 |
wvd_vegt | 20:62318ba945de | 257 | |
wvd_vegt | 20:62318ba945de | 258 | /** Predefined VT100 Cls Command. |
wvd_vegt | 20:62318ba945de | 259 | * |
wvd_vegt | 20:62318ba945de | 260 | * This command will clear the screen. |
wvd_vegt | 20:62318ba945de | 261 | */ |
wvd_vegt | 20:62318ba945de | 262 | #define CID_CLS 9996 |
wvd_vegt | 20:62318ba945de | 263 | |
wvd_vegt | 20:62318ba945de | 264 | /** Predefined Idle Command. |
wvd_vegt | 20:62318ba945de | 265 | * |
wvd_vegt | 20:62318ba945de | 266 | * This command will return to the global command level, leaving the active subsystem. |
wvd_vegt | 20:62318ba945de | 267 | */ |
wvd_vegt | 20:62318ba945de | 268 | #define CID_IDLE 9997 |
wvd_vegt | 20:62318ba945de | 269 | |
wvd_vegt | 20:62318ba945de | 270 | /** Predefined Help Command. |
wvd_vegt | 20:62318ba945de | 271 | * |
wvd_vegt | 20:62318ba945de | 272 | * This command will either print all active command (without parameters) or a more detailed |
wvd_vegt | 20:62318ba945de | 273 | * help for a command passed as parameter. |
wvd_vegt | 20:62318ba945de | 274 | */ |
wvd_vegt | 20:62318ba945de | 275 | #define CID_HELP 9998 |
wvd_vegt | 20:62318ba945de | 276 | |
wvd_vegt | 20:62318ba945de | 277 | /** Predefided Semi Command. |
wvd_vegt | 20:62318ba945de | 278 | * |
wvd_vegt | 20:62318ba945de | 279 | * CID_LAST only functions as a special Commend Id to signal unknown commands. |
wvd_vegt | 20:62318ba945de | 280 | */ |
wvd_vegt | 20:62318ba945de | 281 | #define CID_LAST 9999 |
wvd_vegt | 20:62318ba945de | 282 | |
wvd_vegt | 20:62318ba945de | 283 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 284 | |
wvd_vegt | 20:62318ba945de | 285 | /** The Boot Command. |
wvd_vegt | 20:62318ba945de | 286 | * |
wvd_vegt | 20:62318ba945de | 287 | * @note: this command can be used to list all commands in Windows ini file format for host processing. |
wvd_vegt | 20:62318ba945de | 288 | * |
wvd_vegt | 20:62318ba945de | 289 | * Optional. |
wvd_vegt | 20:62318ba945de | 290 | */ |
wvd_vegt | 20:62318ba945de | 291 | static const cmd COMMANDS = {"Commands",GLOBALCMD,CID_COMMANDS,"","Dump Commands"}; |
wvd_vegt | 20:62318ba945de | 292 | |
wvd_vegt | 20:62318ba945de | 293 | /** The Boot Command. |
wvd_vegt | 20:62318ba945de | 294 | * |
wvd_vegt | 20:62318ba945de | 295 | * Optional. |
wvd_vegt | 20:62318ba945de | 296 | */ |
wvd_vegt | 20:62318ba945de | 297 | static const cmd BOOT = {"Boot",GLOBALCMD,CID_BOOT,"","Boot mBed"}; |
wvd_vegt | 20:62318ba945de | 298 | |
wvd_vegt | 20:62318ba945de | 299 | /** The Macro Command. |
wvd_vegt | 20:62318ba945de | 300 | * |
wvd_vegt | 20:62318ba945de | 301 | * Optional. |
wvd_vegt | 20:62318ba945de | 302 | */ |
wvd_vegt | 20:62318ba945de | 303 | static const cmd MACRO = {"Macro",GLOBALCMD,CID_MACRO,"%s","Define macro (sp->_, cr->|)","command(s)"}; |
wvd_vegt | 20:62318ba945de | 304 | |
wvd_vegt | 20:62318ba945de | 305 | /** The Run Command. |
wvd_vegt | 20:62318ba945de | 306 | * |
wvd_vegt | 20:62318ba945de | 307 | * Optional. |
wvd_vegt | 20:62318ba945de | 308 | */ |
wvd_vegt | 20:62318ba945de | 309 | static const cmd RUN = {"Run",GLOBALCMD,CID_RUN,"","Run a macro"}; |
wvd_vegt | 20:62318ba945de | 310 | |
wvd_vegt | 20:62318ba945de | 311 | /** The Macros Command. |
wvd_vegt | 20:62318ba945de | 312 | * |
wvd_vegt | 20:62318ba945de | 313 | * Optional. |
wvd_vegt | 20:62318ba945de | 314 | */ |
wvd_vegt | 20:62318ba945de | 315 | static const cmd MACROS = {"Macros",GLOBALCMD,CID_MACROS,"","List macro(s)"}; |
wvd_vegt | 20:62318ba945de | 316 | |
wvd_vegt | 20:62318ba945de | 317 | /** The Echo Command. |
wvd_vegt | 20:62318ba945de | 318 | * |
wvd_vegt | 20:62318ba945de | 319 | * Optional. |
wvd_vegt | 20:62318ba945de | 320 | */ |
wvd_vegt | 20:62318ba945de | 321 | static const cmd ECHO = {"Echo",GLOBALCMD,CID_ECHO,"%bu","Echo On|Off (1|0)","state"}; |
wvd_vegt | 20:62318ba945de | 322 | |
wvd_vegt | 20:62318ba945de | 323 | /** The Bold Command. |
wvd_vegt | 20:62318ba945de | 324 | * |
wvd_vegt | 20:62318ba945de | 325 | * Optional. |
wvd_vegt | 20:62318ba945de | 326 | */ |
wvd_vegt | 20:62318ba945de | 327 | static const cmd BOLD = {"Bold",GLOBALCMD,CID_BOLD,"%bu","Bold On|Off (1|0)","state"}; |
wvd_vegt | 20:62318ba945de | 328 | |
wvd_vegt | 20:62318ba945de | 329 | /** The Cls Command. |
wvd_vegt | 20:62318ba945de | 330 | * |
wvd_vegt | 20:62318ba945de | 331 | * Optional. |
wvd_vegt | 20:62318ba945de | 332 | */ |
wvd_vegt | 20:62318ba945de | 333 | static const cmd CLS = {"Cls",GLOBALCMD,CID_CLS,"","Clears the terminal screen"}; |
wvd_vegt | 20:62318ba945de | 334 | |
wvd_vegt | 20:62318ba945de | 335 | /** The Idle Command. |
wvd_vegt | 20:62318ba945de | 336 | * |
wvd_vegt | 20:62318ba945de | 337 | * Mandatory if you use subsystems. |
wvd_vegt | 20:62318ba945de | 338 | */ |
wvd_vegt | 20:62318ba945de | 339 | static const cmd IDLE = {"Idle",GLOBALCMD,CID_IDLE,"","Deselect Subsystems"}; |
wvd_vegt | 20:62318ba945de | 340 | |
wvd_vegt | 20:62318ba945de | 341 | /** The Help Command. |
wvd_vegt | 20:62318ba945de | 342 | * |
wvd_vegt | 20:62318ba945de | 343 | * Mandatory. |
wvd_vegt | 20:62318ba945de | 344 | */ |
wvd_vegt | 20:62318ba945de | 345 | static const cmd HELP = {"Help",GLOBALCMD,CID_HELP,"%s","Help"}; |
wvd_vegt | 20:62318ba945de | 346 | |
wvd_vegt | 20:62318ba945de | 347 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 348 | |
wvd_vegt | 20:62318ba945de | 349 | /** We'll only define the 4 cursor codes at the moment. |
wvd_vegt | 20:62318ba945de | 350 | */ |
wvd_vegt | 20:62318ba945de | 351 | #define ESC_TBL_LEN 4 |
wvd_vegt | 20:62318ba945de | 352 | |
wvd_vegt | 20:62318ba945de | 353 | /** Escape code definition struct. |
wvd_vegt | 20:62318ba945de | 354 | */ |
wvd_vegt | 20:62318ba945de | 355 | struct esc { |
wvd_vegt | 20:62318ba945de | 356 | char *escstr; |
wvd_vegt | 20:62318ba945de | 357 | int id; |
wvd_vegt | 20:62318ba945de | 358 | }; |
wvd_vegt | 20:62318ba945de | 359 | |
wvd_vegt | 20:62318ba945de | 360 | /** The Escape Code Id's. |
wvd_vegt | 20:62318ba945de | 361 | */ |
wvd_vegt | 20:62318ba945de | 362 | enum { |
wvd_vegt | 20:62318ba945de | 363 | EID_CURSOR_UP, |
wvd_vegt | 20:62318ba945de | 364 | EID_CURSOR_DOWN, |
wvd_vegt | 20:62318ba945de | 365 | EID_CURSOR_RIGHT, |
wvd_vegt | 20:62318ba945de | 366 | EID_CURSOR_LEFT, |
wvd_vegt | 20:62318ba945de | 367 | EID_LAST |
wvd_vegt | 20:62318ba945de | 368 | }; |
wvd_vegt | 20:62318ba945de | 369 | |
wvd_vegt | 20:62318ba945de | 370 | /** The Escape Codes Table. |
wvd_vegt | 20:62318ba945de | 371 | */ |
wvd_vegt | 20:62318ba945de | 372 | static const struct esc esc_tbl [ESC_TBL_LEN] = { |
wvd_vegt | 20:62318ba945de | 373 | { "\033[A", EID_CURSOR_UP }, |
wvd_vegt | 20:62318ba945de | 374 | { "\033[B", EID_CURSOR_DOWN }, |
wvd_vegt | 20:62318ba945de | 375 | { "\033[C", EID_CURSOR_RIGHT }, |
wvd_vegt | 20:62318ba945de | 376 | { "\033[D", EID_CURSOR_LEFT }, |
wvd_vegt | 20:62318ba945de | 377 | }; |
wvd_vegt | 20:62318ba945de | 378 | |
wvd_vegt | 20:62318ba945de | 379 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 380 | |
wvd_vegt | 20:62318ba945de | 381 | /** The Command Interpreter Version. |
wvd_vegt | 20:62318ba945de | 382 | */ |
wvd_vegt | 20:62318ba945de | 383 | #define CMDB_VERSION 0.81 |
wvd_vegt | 20:62318ba945de | 384 | |
wvd_vegt | 20:62318ba945de | 385 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 386 | |
wvd_vegt | 20:62318ba945de | 387 | /** Command Interpreter class. |
wvd_vegt | 20:62318ba945de | 388 | * |
wvd_vegt | 20:62318ba945de | 389 | * Steps to take: |
wvd_vegt | 20:62318ba945de | 390 | * |
wvd_vegt | 20:62318ba945de | 391 | * 1) Create a std::vector<cmd> and fill it with at least |
wvd_vegt | 20:62318ba945de | 392 | * the mandatory commands IDLE and HELP. |
wvd_vegt | 20:62318ba945de | 393 | * |
wvd_vegt | 20:62318ba945de | 394 | * 2) Create an Cmdb class instance and pass it the vector, |
wvd_vegt | 20:62318ba945de | 395 | * a Serial port object like Serial serial(USBTX, USBRX); |
wvd_vegt | 20:62318ba945de | 396 | * and finally a command dispatcher function. |
wvd_vegt | 20:62318ba945de | 397 | * |
wvd_vegt | 20:62318ba945de | 398 | * 3) Feed the interpreter with characters received from your serial port. |
wvd_vegt | 20:62318ba945de | 399 | * Note: Cmdb self does not retrieve input it must be handed to it. |
wvd_vegt | 20:62318ba945de | 400 | * It implements basic members for checking/reading the serial port. |
wvd_vegt | 20:62318ba945de | 401 | * |
wvd_vegt | 20:62318ba945de | 402 | * 4) Handle commands added by the application by the Cid and parameters passed. |
wvd_vegt | 20:62318ba945de | 403 | * |
wvd_vegt | 20:62318ba945de | 404 | * Note: Predefined commands and all subsystems transitions are handled by the internal dispatcher. |
wvd_vegt | 20:62318ba945de | 405 | * So the passed dispatcher only has to handle user/application defined commands'. |
wvd_vegt | 20:62318ba945de | 406 | * |
wvd_vegt | 20:62318ba945de | 407 | * @see main.cpp for a demo. |
wvd_vegt | 20:62318ba945de | 408 | */ |
wvd_vegt | 20:62318ba945de | 409 | class Cmdb { |
wvd_vegt | 20:62318ba945de | 410 | public: |
wvd_vegt | 20:62318ba945de | 411 | /** Create a Command Interpreter. |
wvd_vegt | 20:62318ba945de | 412 | * |
wvd_vegt | 20:62318ba945de | 413 | * @see http://www.newty.de/fpt/fpt.html#chapter2 for function pointers. |
wvd_vegt | 20:62318ba945de | 414 | * @see http://stackoverflow.com/questions/9410/how-do-you-pass-a-function-as-a-parameter-in-c |
wvd_vegt | 20:62318ba945de | 415 | * @see http://www.daniweb.com/forums/thread293338.html |
wvd_vegt | 20:62318ba945de | 416 | * |
wvd_vegt | 20:62318ba945de | 417 | * @param serial a Serial port used for communication. |
wvd_vegt | 20:62318ba945de | 418 | * @param cmds a vector with the command table. |
wvd_vegt | 20:62318ba945de | 419 | */ |
wvd_vegt | 20:62318ba945de | 420 | Cmdb(const Serial& _serial, std::vector<cmd>& _cmds, void (*_callback)(Cmdb&,int) ); |
wvd_vegt | 20:62318ba945de | 421 | |
wvd_vegt | 20:62318ba945de | 422 | /** The version of the Command Interpreter. |
wvd_vegt | 20:62318ba945de | 423 | * |
wvd_vegt | 20:62318ba945de | 424 | * returns the version. |
wvd_vegt | 20:62318ba945de | 425 | */ |
wvd_vegt | 20:62318ba945de | 426 | static float version() { |
wvd_vegt | 20:62318ba945de | 427 | return CMDB_VERSION; |
wvd_vegt | 20:62318ba945de | 428 | } |
wvd_vegt | 20:62318ba945de | 429 | |
wvd_vegt | 20:62318ba945de | 430 | /** NULL is used as No Comment Value. |
wvd_vegt | 20:62318ba945de | 431 | */ |
wvd_vegt | 20:62318ba945de | 432 | static const char* NoComment; |
wvd_vegt | 20:62318ba945de | 433 | |
wvd_vegt | 20:62318ba945de | 434 | /** Column 72 is used as Default Comment Starting Position. |
wvd_vegt | 20:62318ba945de | 435 | */ |
wvd_vegt | 20:62318ba945de | 436 | static int DefComPos; |
wvd_vegt | 20:62318ba945de | 437 | |
wvd_vegt | 20:62318ba945de | 438 | /** Checks if the macro buffer has any characters left. |
wvd_vegt | 20:62318ba945de | 439 | * |
wvd_vegt | 20:62318ba945de | 440 | * @returns true if any characters left. |
wvd_vegt | 20:62318ba945de | 441 | */ |
wvd_vegt | 20:62318ba945de | 442 | bool macro_hasnext(); |
wvd_vegt | 20:62318ba945de | 443 | |
wvd_vegt | 20:62318ba945de | 444 | /** Gets the next character from the macro buffer and |
wvd_vegt | 20:62318ba945de | 445 | * advances the macro buffer pointer. |
wvd_vegt | 20:62318ba945de | 446 | * |
wvd_vegt | 20:62318ba945de | 447 | * @note Do not call if no more characters are left! |
wvd_vegt | 20:62318ba945de | 448 | * |
wvd_vegt | 20:62318ba945de | 449 | * @returns the next character. |
wvd_vegt | 20:62318ba945de | 450 | */ |
wvd_vegt | 20:62318ba945de | 451 | char macro_next(); |
wvd_vegt | 20:62318ba945de | 452 | |
wvd_vegt | 20:62318ba945de | 453 | /** Gets the next character from the macro buffer |
wvd_vegt | 20:62318ba945de | 454 | * but does not advance the macro buffer pointer. |
wvd_vegt | 20:62318ba945de | 455 | * |
wvd_vegt | 20:62318ba945de | 456 | * @note Do not call if no more characters are left! |
wvd_vegt | 20:62318ba945de | 457 | * |
wvd_vegt | 20:62318ba945de | 458 | * @returns the next character. |
wvd_vegt | 20:62318ba945de | 459 | */ |
wvd_vegt | 20:62318ba945de | 460 | char macro_peek(); |
wvd_vegt | 20:62318ba945de | 461 | |
wvd_vegt | 20:62318ba945de | 462 | /** Resets the macro buffer and macro buffer pointer. |
wvd_vegt | 20:62318ba945de | 463 | * |
wvd_vegt | 20:62318ba945de | 464 | */ |
wvd_vegt | 20:62318ba945de | 465 | void macro_reset(); |
wvd_vegt | 20:62318ba945de | 466 | |
wvd_vegt | 20:62318ba945de | 467 | /** Checks if the serial port has any characters |
wvd_vegt | 20:62318ba945de | 468 | * left to read by calling serial.readable(). |
wvd_vegt | 20:62318ba945de | 469 | * |
wvd_vegt | 20:62318ba945de | 470 | * @returns true if any characters available. |
wvd_vegt | 20:62318ba945de | 471 | */ |
wvd_vegt | 20:62318ba945de | 472 | bool hasnext(); |
wvd_vegt | 20:62318ba945de | 473 | |
wvd_vegt | 20:62318ba945de | 474 | /** Gets the next character from the serial port by |
wvd_vegt | 20:62318ba945de | 475 | * calling serial.getc(). |
wvd_vegt | 20:62318ba945de | 476 | * |
wvd_vegt | 20:62318ba945de | 477 | * Do not call if no characters are left! |
wvd_vegt | 20:62318ba945de | 478 | * |
wvd_vegt | 20:62318ba945de | 479 | * @returns the next character. |
wvd_vegt | 20:62318ba945de | 480 | */ |
wvd_vegt | 20:62318ba945de | 481 | char next(); |
wvd_vegt | 20:62318ba945de | 482 | |
wvd_vegt | 20:62318ba945de | 483 | /** Add a character to the command being processed. |
wvd_vegt | 20:62318ba945de | 484 | * If a cr is added, the command is parsed and executed if possible |
wvd_vegt | 20:62318ba945de | 485 | * If supported special keys are encountered (like backspace, delete and cursor up) they are processed. |
wvd_vegt | 20:62318ba945de | 486 | * |
wvd_vegt | 20:62318ba945de | 487 | * @param c the character to add. |
wvd_vegt | 20:62318ba945de | 488 | * |
wvd_vegt | 20:62318ba945de | 489 | * @returns true if a command was recognized and executed. |
wvd_vegt | 20:62318ba945de | 490 | */ |
wvd_vegt | 20:62318ba945de | 491 | bool scan(const char c); |
wvd_vegt | 20:62318ba945de | 492 | |
wvd_vegt | 20:62318ba945de | 493 | /** printf substitute using the serial parameter passed to the constructor. |
wvd_vegt | 20:62318ba945de | 494 | * |
wvd_vegt | 20:62318ba945de | 495 | * @see http://www.cplusplus.com/reference/clibrary/cstdio/printf/ |
wvd_vegt | 20:62318ba945de | 496 | * |
wvd_vegt | 20:62318ba945de | 497 | * @parm format the printf format string. |
wvd_vegt | 20:62318ba945de | 498 | * @parm ... optional paramaters to be merged into the format string. |
wvd_vegt | 20:62318ba945de | 499 | * |
wvd_vegt | 20:62318ba945de | 500 | * @returns the printf return value. |
wvd_vegt | 20:62318ba945de | 501 | */ |
wvd_vegt | 20:62318ba945de | 502 | int printf(const char *format, ...); |
wvd_vegt | 20:62318ba945de | 503 | |
wvd_vegt | 20:62318ba945de | 504 | /** print is simply printf without parameters using the serial parameter passed to the constructor. |
wvd_vegt | 20:62318ba945de | 505 | * |
wvd_vegt | 20:62318ba945de | 506 | * @parm msg the string to print. |
wvd_vegt | 20:62318ba945de | 507 | * |
wvd_vegt | 20:62318ba945de | 508 | * @returns the printf return value. |
wvd_vegt | 20:62318ba945de | 509 | */ |
wvd_vegt | 20:62318ba945de | 510 | int print(const char *msg); |
wvd_vegt | 20:62318ba945de | 511 | |
wvd_vegt | 23:73a4f087c1b9 | 512 | /** println is simply printf without parameters using the serial parameter passed to the constructor. |
wvd_vegt | 23:73a4f087c1b9 | 513 | * |
wvd_vegt | 23:73a4f087c1b9 | 514 | * @parm msg the string to print followed by a crlf. |
wvd_vegt | 23:73a4f087c1b9 | 515 | * |
wvd_vegt | 23:73a4f087c1b9 | 516 | * @returns the printf return value. |
wvd_vegt | 23:73a4f087c1b9 | 517 | */ |
wvd_vegt | 23:73a4f087c1b9 | 518 | int println(const char *msg); |
wvd_vegt | 23:73a4f087c1b9 | 519 | |
wvd_vegt | 20:62318ba945de | 520 | /** printch is simply putc subsitute using the serial parameter passed to the constructor. |
wvd_vegt | 20:62318ba945de | 521 | * |
wvd_vegt | 20:62318ba945de | 522 | * @parm msg the string to print. |
wvd_vegt | 20:62318ba945de | 523 | * |
wvd_vegt | 20:62318ba945de | 524 | * @returns the printf return value. |
wvd_vegt | 20:62318ba945de | 525 | */ |
wvd_vegt | 20:62318ba945de | 526 | char printch(const char ch); |
wvd_vegt | 20:62318ba945de | 527 | |
wvd_vegt | 20:62318ba945de | 528 | /** printsection prints an inifile Section Header |
wvd_vegt | 20:62318ba945de | 529 | * like: |
wvd_vegt | 20:62318ba945de | 530 | * |
wvd_vegt | 20:62318ba945de | 531 | * [Section]\r\n |
wvd_vegt | 20:62318ba945de | 532 | * |
wvd_vegt | 20:62318ba945de | 533 | * Usage: cmdb.printsection("GP"); |
wvd_vegt | 20:62318ba945de | 534 | * |
wvd_vegt | 20:62318ba945de | 535 | * @parm section the section to print. |
wvd_vegt | 20:62318ba945de | 536 | * |
wvd_vegt | 20:62318ba945de | 537 | * @returns the printf return value. |
wvd_vegt | 20:62318ba945de | 538 | */ |
wvd_vegt | 20:62318ba945de | 539 | int printsection(const char *section); |
wvd_vegt | 20:62318ba945de | 540 | |
wvd_vegt | 22:5192a468d7fa | 541 | /** printmsg prints an inifile Msg Key=Value pair. |
wvd_vegt | 22:5192a468d7fa | 542 | * like: |
wvd_vegt | 22:5192a468d7fa | 543 | * |
wvd_vegt | 22:5192a468d7fa | 544 | * Msg={msg}\r\n |
wvd_vegt | 22:5192a468d7fa | 545 | * |
wvd_vegt | 22:5192a468d7fa | 546 | * Usage: cmdb.printmsg("Validation successfull"); |
wvd_vegt | 22:5192a468d7fa | 547 | * |
wvd_vegt | 22:5192a468d7fa | 548 | * @parm msg the msg to print. |
wvd_vegt | 22:5192a468d7fa | 549 | * |
wvd_vegt | 22:5192a468d7fa | 550 | * @returns the printf return value. |
wvd_vegt | 22:5192a468d7fa | 551 | */ |
wvd_vegt | 23:73a4f087c1b9 | 552 | int printmsg(const char *msg); |
wvd_vegt | 22:5192a468d7fa | 553 | |
wvd_vegt | 22:5192a468d7fa | 554 | /** printerror prints an inifile Error Section Header and Error Msg Key=Value pair. |
wvd_vegt | 21:d22068e2bbd1 | 555 | * like: |
wvd_vegt | 21:d22068e2bbd1 | 556 | * |
wvd_vegt | 21:d22068e2bbd1 | 557 | * [Error]\r\nmsg={errormsg}\r\n |
wvd_vegt | 21:d22068e2bbd1 | 558 | * |
wvd_vegt | 21:d22068e2bbd1 | 559 | * Usage: cmdb.printerror("Data Size Incorrect"); |
wvd_vegt | 21:d22068e2bbd1 | 560 | * |
wvd_vegt | 23:73a4f087c1b9 | 561 | * @parm errormsg the error msg to print. |
wvd_vegt | 21:d22068e2bbd1 | 562 | * |
wvd_vegt | 23:73a4f087c1b9 | 563 | * @returns the printf return value. |
wvd_vegt | 21:d22068e2bbd1 | 564 | */ |
wvd_vegt | 21:d22068e2bbd1 | 565 | int printerror(const char *errormsg); |
wvd_vegt | 22:5192a468d7fa | 566 | |
wvd_vegt | 23:73a4f087c1b9 | 567 | /** printerror prints an inifile Error Section Header and Error Msg Key=Value pair. |
wvd_vegt | 23:73a4f087c1b9 | 568 | * like: |
wvd_vegt | 23:73a4f087c1b9 | 569 | * |
wvd_vegt | 23:73a4f087c1b9 | 570 | * [Error]\r\nmsg={errormsg}\r\n |
wvd_vegt | 23:73a4f087c1b9 | 571 | * |
wvd_vegt | 23:73a4f087c1b9 | 572 | * Usage: cmdb.printerrorf("Data Size Incorrect %d", 15); |
wvd_vegt | 23:73a4f087c1b9 | 573 | * |
wvd_vegt | 23:73a4f087c1b9 | 574 | * @parm format the error msg to print. |
wvd_vegt | 23:73a4f087c1b9 | 575 | * @parm parameter to print. |
wvd_vegt | 23:73a4f087c1b9 | 576 | * |
wvd_vegt | 23:73a4f087c1b9 | 577 | * @returns the printf return value. |
wvd_vegt | 23:73a4f087c1b9 | 578 | */ |
wvd_vegt | 23:73a4f087c1b9 | 579 | int printerrorf(const char *format, ...); |
wvd_vegt | 23:73a4f087c1b9 | 580 | |
wvd_vegt | 20:62318ba945de | 581 | /** printvalue prints an inifile Key/Value Pair |
wvd_vegt | 20:62318ba945de | 582 | * like: |
wvd_vegt | 20:62318ba945de | 583 | * |
wvd_vegt | 20:62318ba945de | 584 | * Key=Value ;comment\r\n |
wvd_vegt | 20:62318ba945de | 585 | * |
wvd_vegt | 20:62318ba945de | 586 | * Note: the Comment is (if present) located at position 72. |
wvd_vegt | 20:62318ba945de | 587 | * |
wvd_vegt | 20:62318ba945de | 588 | * Usage: cmdb.printvaluef("Value", Cmdb::DefComPos, "Hex", "0x%8.8X", LPC_RTC->GPREG0); |
wvd_vegt | 20:62318ba945de | 589 | * |
wvd_vegt | 20:62318ba945de | 590 | * @parm key the key to print. |
wvd_vegt | 20:62318ba945de | 591 | * @parm comment the comment to print. |
wvd_vegt | 20:62318ba945de | 592 | * @parm width the location of the comment to print. |
wvd_vegt | 20:62318ba945de | 593 | * @parm format the value to print. |
wvd_vegt | 20:62318ba945de | 594 | * @parm parameter to print. |
wvd_vegt | 20:62318ba945de | 595 | * |
wvd_vegt | 20:62318ba945de | 596 | * @returns the printf return value. |
wvd_vegt | 20:62318ba945de | 597 | */ |
wvd_vegt | 20:62318ba945de | 598 | int printvaluef(const char *key, const int width, const char *comment, const char *format, ...); |
wvd_vegt | 20:62318ba945de | 599 | |
wvd_vegt | 20:62318ba945de | 600 | /** printvalue prints an inifile Key/Value Pair |
wvd_vegt | 20:62318ba945de | 601 | * like: |
wvd_vegt | 20:62318ba945de | 602 | * |
wvd_vegt | 20:62318ba945de | 603 | * Key=Value\r\n |
wvd_vegt | 20:62318ba945de | 604 | * |
wvd_vegt | 20:62318ba945de | 605 | * Usage: cmdb.printvaluef("Value", "0x%8.8X", LPC_RTC->GPREG0); |
wvd_vegt | 20:62318ba945de | 606 | * |
wvd_vegt | 20:62318ba945de | 607 | * @parm key the key to print. |
wvd_vegt | 20:62318ba945de | 608 | * @parm format the value to print. |
wvd_vegt | 20:62318ba945de | 609 | * @parm parameter to print. |
wvd_vegt | 20:62318ba945de | 610 | * |
wvd_vegt | 20:62318ba945de | 611 | * @returns the printf return value. |
wvd_vegt | 20:62318ba945de | 612 | */ |
wvd_vegt | 20:62318ba945de | 613 | int printvaluef(const char *key, const char *format, ...); |
wvd_vegt | 20:62318ba945de | 614 | |
wvd_vegt | 20:62318ba945de | 615 | /** printvalue prints an inifile Key/Value Pair |
wvd_vegt | 20:62318ba945de | 616 | * like: |
wvd_vegt | 20:62318ba945de | 617 | * |
wvd_vegt | 20:62318ba945de | 618 | * Key=Value ;comment\r\n |
wvd_vegt | 20:62318ba945de | 619 | * |
wvd_vegt | 20:62318ba945de | 620 | * Note the Comment is (if present) located at position 72. |
wvd_vegt | 20:62318ba945de | 621 | * |
wvd_vegt | 20:62318ba945de | 622 | * @parm key the key to print. |
wvd_vegt | 20:62318ba945de | 623 | * @parm value the value to print. |
wvd_vegt | 20:62318ba945de | 624 | * @parm comment the comment to print. |
wvd_vegt | 20:62318ba945de | 625 | * @parm width the location of the comment to print. |
wvd_vegt | 20:62318ba945de | 626 | * |
wvd_vegt | 20:62318ba945de | 627 | * @returns the printf return value. |
wvd_vegt | 20:62318ba945de | 628 | */ |
wvd_vegt | 20:62318ba945de | 629 | int printvalue(const char *key, const char *value, const char *comment = NoComment, const int width = DefComPos); |
wvd_vegt | 20:62318ba945de | 630 | |
wvd_vegt | 23:73a4f087c1b9 | 631 | int printcomment(const char *comment, const int width = DefComPos); |
wvd_vegt | 23:73a4f087c1b9 | 632 | |
wvd_vegt | 20:62318ba945de | 633 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 634 | |
wvd_vegt | 20:62318ba945de | 635 | /** Initializes the parser (called by the constructor). |
wvd_vegt | 20:62318ba945de | 636 | * |
wvd_vegt | 20:62318ba945de | 637 | * @parm full if true the macro buffer is also cleared else only the command interpreter is reset. |
wvd_vegt | 20:62318ba945de | 638 | */ |
wvd_vegt | 20:62318ba945de | 639 | void init(const char full); |
wvd_vegt | 20:62318ba945de | 640 | |
wvd_vegt | 20:62318ba945de | 641 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 642 | //----These helper functions retieve parameters in the correct format. |
wvd_vegt | 20:62318ba945de | 643 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 644 | |
wvd_vegt | 20:62318ba945de | 645 | /** Typecasts parameter ndx to a bool. |
wvd_vegt | 20:62318ba945de | 646 | * |
wvd_vegt | 20:62318ba945de | 647 | * mask: %bu |
wvd_vegt | 20:62318ba945de | 648 | * |
wvd_vegt | 20:62318ba945de | 649 | * @parm the parameter index |
wvd_vegt | 20:62318ba945de | 650 | * |
wvd_vegt | 20:62318ba945de | 651 | * @return a bool |
wvd_vegt | 20:62318ba945de | 652 | */ |
wvd_vegt | 20:62318ba945de | 653 | bool BOOLPARM(int ndx) { |
wvd_vegt | 20:62318ba945de | 654 | return parms[ndx].val.uc!=0; |
wvd_vegt | 20:62318ba945de | 655 | } |
wvd_vegt | 20:62318ba945de | 656 | |
wvd_vegt | 20:62318ba945de | 657 | /** Typecasts parameter ndx to a byte/unsigned char. |
wvd_vegt | 20:62318ba945de | 658 | * |
wvd_vegt | 20:62318ba945de | 659 | * mask: %bu |
wvd_vegt | 20:62318ba945de | 660 | * |
wvd_vegt | 20:62318ba945de | 661 | * @parm the parameter index |
wvd_vegt | 20:62318ba945de | 662 | * |
wvd_vegt | 20:62318ba945de | 663 | * @return a byte/unsigned char |
wvd_vegt | 20:62318ba945de | 664 | */ |
wvd_vegt | 20:62318ba945de | 665 | unsigned char BYTEPARM(int ndx) { |
wvd_vegt | 20:62318ba945de | 666 | return parms[ndx].val.uc; |
wvd_vegt | 20:62318ba945de | 667 | } |
wvd_vegt | 20:62318ba945de | 668 | |
wvd_vegt | 20:62318ba945de | 669 | /** Typecasts parameter ndx to a char. |
wvd_vegt | 20:62318ba945de | 670 | * |
wvd_vegt | 20:62318ba945de | 671 | * mask: %c |
wvd_vegt | 20:62318ba945de | 672 | * |
wvd_vegt | 20:62318ba945de | 673 | * @parm the parameter index |
wvd_vegt | 20:62318ba945de | 674 | * |
wvd_vegt | 20:62318ba945de | 675 | * @return a char |
wvd_vegt | 20:62318ba945de | 676 | */ |
wvd_vegt | 20:62318ba945de | 677 | char CHARPARM(int ndx) { |
wvd_vegt | 20:62318ba945de | 678 | return parms[ndx].val.c; |
wvd_vegt | 20:62318ba945de | 679 | } |
wvd_vegt | 20:62318ba945de | 680 | |
wvd_vegt | 20:62318ba945de | 681 | /** Typecasts parameter ndx to word/unsigned int. |
wvd_vegt | 20:62318ba945de | 682 | * |
wvd_vegt | 20:62318ba945de | 683 | * mask: %hu |
wvd_vegt | 20:62318ba945de | 684 | * |
wvd_vegt | 20:62318ba945de | 685 | * @parm the parameter index |
wvd_vegt | 20:62318ba945de | 686 | * |
wvd_vegt | 20:62318ba945de | 687 | * @return a word/unsigned int |
wvd_vegt | 20:62318ba945de | 688 | */ |
wvd_vegt | 20:62318ba945de | 689 | unsigned int WORDPARM(int ndx) { |
wvd_vegt | 20:62318ba945de | 690 | return parms[ndx].val.ui; |
wvd_vegt | 20:62318ba945de | 691 | } |
wvd_vegt | 20:62318ba945de | 692 | |
wvd_vegt | 20:62318ba945de | 693 | /** Typecasts parameter ndx to a unsigned int. |
wvd_vegt | 20:62318ba945de | 694 | * |
wvd_vegt | 20:62318ba945de | 695 | * mask: %u |
wvd_vegt | 20:62318ba945de | 696 | * |
wvd_vegt | 20:62318ba945de | 697 | * @parm the parameter index |
wvd_vegt | 20:62318ba945de | 698 | * |
wvd_vegt | 20:62318ba945de | 699 | * @return a unsigned int |
wvd_vegt | 20:62318ba945de | 700 | */ |
wvd_vegt | 20:62318ba945de | 701 | unsigned int UINTPARM(int ndx) { |
wvd_vegt | 20:62318ba945de | 702 | return parms[ndx].val.ui; |
wvd_vegt | 20:62318ba945de | 703 | } |
wvd_vegt | 20:62318ba945de | 704 | |
wvd_vegt | 20:62318ba945de | 705 | /** Typecasts parameter ndx to a int. |
wvd_vegt | 20:62318ba945de | 706 | * |
wvd_vegt | 20:62318ba945de | 707 | * mask: %i |
wvd_vegt | 20:62318ba945de | 708 | * |
wvd_vegt | 20:62318ba945de | 709 | * @parm the parameter index |
wvd_vegt | 20:62318ba945de | 710 | * |
wvd_vegt | 20:62318ba945de | 711 | * @return a int |
wvd_vegt | 20:62318ba945de | 712 | */ |
wvd_vegt | 20:62318ba945de | 713 | int INTPARM(int ndx) { |
wvd_vegt | 20:62318ba945de | 714 | return parms[ndx].val.i; |
wvd_vegt | 20:62318ba945de | 715 | } |
wvd_vegt | 20:62318ba945de | 716 | |
wvd_vegt | 20:62318ba945de | 717 | /** Typecasts parameter ndx to a bool. |
wvd_vegt | 20:62318ba945de | 718 | * |
wvd_vegt | 20:62318ba945de | 719 | * mask: %lu |
wvd_vegt | 20:62318ba945de | 720 | * |
wvd_vegt | 20:62318ba945de | 721 | * @parm the parameter index |
wvd_vegt | 20:62318ba945de | 722 | * |
wvd_vegt | 20:62318ba945de | 723 | * @return a bool |
wvd_vegt | 20:62318ba945de | 724 | */ |
wvd_vegt | 20:62318ba945de | 725 | unsigned long DWORDPARM(int ndx) { |
wvd_vegt | 20:62318ba945de | 726 | return parms[ndx].val.ul; |
wvd_vegt | 20:62318ba945de | 727 | } |
wvd_vegt | 20:62318ba945de | 728 | |
wvd_vegt | 20:62318ba945de | 729 | /** Typecasts parameter ndx to a long. |
wvd_vegt | 20:62318ba945de | 730 | * |
wvd_vegt | 20:62318ba945de | 731 | * mask: %li |
wvd_vegt | 20:62318ba945de | 732 | * |
wvd_vegt | 20:62318ba945de | 733 | * @parm the parameter index |
wvd_vegt | 20:62318ba945de | 734 | * |
wvd_vegt | 20:62318ba945de | 735 | * @return a long |
wvd_vegt | 20:62318ba945de | 736 | */ |
wvd_vegt | 20:62318ba945de | 737 | long LONGPARM(int ndx) { |
wvd_vegt | 20:62318ba945de | 738 | return parms[ndx].val.l; |
wvd_vegt | 20:62318ba945de | 739 | } |
wvd_vegt | 20:62318ba945de | 740 | |
wvd_vegt | 20:62318ba945de | 741 | /** Typecasts parameter ndx to a float. |
wvd_vegt | 20:62318ba945de | 742 | * |
wvd_vegt | 20:62318ba945de | 743 | * mask: %f |
wvd_vegt | 20:62318ba945de | 744 | * |
wvd_vegt | 20:62318ba945de | 745 | * @parm the parameter index |
wvd_vegt | 20:62318ba945de | 746 | * |
wvd_vegt | 20:62318ba945de | 747 | * @return a float |
wvd_vegt | 20:62318ba945de | 748 | */ |
wvd_vegt | 20:62318ba945de | 749 | float FLOATPARM(int ndx) { |
wvd_vegt | 20:62318ba945de | 750 | return parms[ndx].val.f; |
wvd_vegt | 20:62318ba945de | 751 | } |
wvd_vegt | 20:62318ba945de | 752 | |
wvd_vegt | 20:62318ba945de | 753 | /** Typecasts parameter ndx to a string. |
wvd_vegt | 20:62318ba945de | 754 | * |
wvd_vegt | 20:62318ba945de | 755 | * @note spaces are not allowed as it makes parsing so much harder. |
wvd_vegt | 20:62318ba945de | 756 | * |
wvd_vegt | 20:62318ba945de | 757 | * mask: %s |
wvd_vegt | 20:62318ba945de | 758 | * |
wvd_vegt | 20:62318ba945de | 759 | * @parm the parameter index |
wvd_vegt | 20:62318ba945de | 760 | * |
wvd_vegt | 20:62318ba945de | 761 | * @return a string |
wvd_vegt | 20:62318ba945de | 762 | */ |
wvd_vegt | 20:62318ba945de | 763 | char* STRINGPARM(int ndx) { |
wvd_vegt | 20:62318ba945de | 764 | return parms[ndx].val.s; |
wvd_vegt | 20:62318ba945de | 765 | } |
wvd_vegt | 20:62318ba945de | 766 | |
wvd_vegt | 20:62318ba945de | 767 | bool present(char *cmdstr) { |
wvd_vegt | 20:62318ba945de | 768 | return cmdid_search(cmdstr)!=CID_LAST; |
wvd_vegt | 20:62318ba945de | 769 | } |
wvd_vegt | 20:62318ba945de | 770 | |
wvd_vegt | 20:62318ba945de | 771 | void replace(std::vector<cmd>& newcmds) { |
wvd_vegt | 20:62318ba945de | 772 | cmds.assign(newcmds.begin(), newcmds.end()); |
wvd_vegt | 20:62318ba945de | 773 | } |
wvd_vegt | 20:62318ba945de | 774 | |
wvd_vegt | 20:62318ba945de | 775 | |
wvd_vegt | 20:62318ba945de | 776 | int indexof(int cid) { |
wvd_vegt | 20:62318ba945de | 777 | return cmdid_index(cid); |
wvd_vegt | 20:62318ba945de | 778 | } |
wvd_vegt | 20:62318ba945de | 779 | |
wvd_vegt | 20:62318ba945de | 780 | //FAILS... |
wvd_vegt | 20:62318ba945de | 781 | /* |
wvd_vegt | 20:62318ba945de | 782 | void insert(int cid, cmd newcmd) { |
wvd_vegt | 20:62318ba945de | 783 | //Add Command (update our original and then assign/replace cmdb's copy)... |
wvd_vegt | 20:62318ba945de | 784 | vector<cmd>::iterator iter; |
wvd_vegt | 20:62318ba945de | 785 | |
wvd_vegt | 20:62318ba945de | 786 | std::vector<cmd> newcmds = std::vector<cmd>(cmds); |
wvd_vegt | 20:62318ba945de | 787 | |
wvd_vegt | 20:62318ba945de | 788 | iter = newcmds.begin(); |
wvd_vegt | 20:62318ba945de | 789 | |
wvd_vegt | 20:62318ba945de | 790 | newcmds.insert(iter+indexof(cid)+1,newcmd); |
wvd_vegt | 20:62318ba945de | 791 | |
wvd_vegt | 20:62318ba945de | 792 | replace(newcmds); |
wvd_vegt | 20:62318ba945de | 793 | |
wvd_vegt | 20:62318ba945de | 794 | printf("Index: %d\r\n", ndx); |
wvd_vegt | 20:62318ba945de | 795 | |
wvd_vegt | 20:62318ba945de | 796 | print("check #1\r\n"); |
wvd_vegt | 20:62318ba945de | 797 | print("check #2\r\n"); |
wvd_vegt | 20:62318ba945de | 798 | |
wvd_vegt | 20:62318ba945de | 799 | vector<cmd>::iterator it; |
wvd_vegt | 20:62318ba945de | 800 | it=newcmds.begin(); |
wvd_vegt | 20:62318ba945de | 801 | |
wvd_vegt | 20:62318ba945de | 802 | print("check #3\r\n"); |
wvd_vegt | 20:62318ba945de | 803 | ndx++; |
wvd_vegt | 20:62318ba945de | 804 | newcmds.insert(it, newcmd); |
wvd_vegt | 20:62318ba945de | 805 | print("check #4\r\n"); |
wvd_vegt | 20:62318ba945de | 806 | |
wvd_vegt | 20:62318ba945de | 807 | //cmds.push_back(c1); |
wvd_vegt | 20:62318ba945de | 808 | cmds.assign(newcmds.begin(), newcmds.end()); |
wvd_vegt | 20:62318ba945de | 809 | } |
wvd_vegt | 20:62318ba945de | 810 | */ |
wvd_vegt | 20:62318ba945de | 811 | |
wvd_vegt | 20:62318ba945de | 812 | private: |
wvd_vegt | 20:62318ba945de | 813 | |
wvd_vegt | 20:62318ba945de | 814 | /** Internal Serial Port Storage. |
wvd_vegt | 20:62318ba945de | 815 | */ |
wvd_vegt | 20:62318ba945de | 816 | Serial serial; |
wvd_vegt | 20:62318ba945de | 817 | |
wvd_vegt | 20:62318ba945de | 818 | /** Internal Command Table Vector Storage. |
wvd_vegt | 20:62318ba945de | 819 | * |
wvd_vegt | 20:62318ba945de | 820 | * @see http://www.cplusplus.com/reference/stl/vector/ |
wvd_vegt | 20:62318ba945de | 821 | */ |
wvd_vegt | 20:62318ba945de | 822 | std::vector<cmd> cmds; |
wvd_vegt | 20:62318ba945de | 823 | |
wvd_vegt | 20:62318ba945de | 824 | /** C callback function |
wvd_vegt | 20:62318ba945de | 825 | * |
wvd_vegt | 20:62318ba945de | 826 | * @see See http://www.newty.de/fpt/fpt.html#chapter2 for function pointers. |
wvd_vegt | 20:62318ba945de | 827 | * |
wvd_vegt | 20:62318ba945de | 828 | * C++ member equivalent would be void (Cmdb::*callback)(Cmdb&,int); |
wvd_vegt | 20:62318ba945de | 829 | */ |
wvd_vegt | 20:62318ba945de | 830 | void (*user_callback)(Cmdb&,int); |
wvd_vegt | 20:62318ba945de | 831 | |
wvd_vegt | 20:62318ba945de | 832 | /** Searches the escape code list for a match. |
wvd_vegt | 20:62318ba945de | 833 | * |
wvd_vegt | 20:62318ba945de | 834 | * @param char* escstr the escape code to lookup. |
wvd_vegt | 20:62318ba945de | 835 | * |
wvd_vegt | 20:62318ba945de | 836 | * @returns the index of the escape code or -1. |
wvd_vegt | 20:62318ba945de | 837 | */ |
wvd_vegt | 20:62318ba945de | 838 | int escid_search(char *escstr); |
wvd_vegt | 20:62318ba945de | 839 | |
wvd_vegt | 20:62318ba945de | 840 | /** Checks if the command table for a match. |
wvd_vegt | 20:62318ba945de | 841 | * |
wvd_vegt | 20:62318ba945de | 842 | * @param char* cmdstr the command to lookup. |
wvd_vegt | 20:62318ba945de | 843 | * |
wvd_vegt | 20:62318ba945de | 844 | * @returns the id of the command or -1. |
wvd_vegt | 20:62318ba945de | 845 | */ |
wvd_vegt | 20:62318ba945de | 846 | int cmdid_search(char *cmdstr); |
wvd_vegt | 20:62318ba945de | 847 | |
wvd_vegt | 20:62318ba945de | 848 | /** Converts an command id to an index of the command table. |
wvd_vegt | 20:62318ba945de | 849 | * |
wvd_vegt | 20:62318ba945de | 850 | * @param cmdid the command id to lookup. |
wvd_vegt | 20:62318ba945de | 851 | * |
wvd_vegt | 20:62318ba945de | 852 | * @returns the index of the command or -1. |
wvd_vegt | 20:62318ba945de | 853 | */ |
wvd_vegt | 20:62318ba945de | 854 | int cmdid_index(int cmdid); |
wvd_vegt | 20:62318ba945de | 855 | |
wvd_vegt | 20:62318ba945de | 856 | /** Writes a prompt to the serial port. |
wvd_vegt | 20:62318ba945de | 857 | * |
wvd_vegt | 20:62318ba945de | 858 | */ |
wvd_vegt | 20:62318ba945de | 859 | void prompt(void); |
wvd_vegt | 20:62318ba945de | 860 | |
wvd_vegt | 20:62318ba945de | 861 | /** Called by cmd_dispatch it parses the command against the command table. |
wvd_vegt | 20:62318ba945de | 862 | * |
wvd_vegt | 20:62318ba945de | 863 | * @param cmd the command and paramaters to parse. |
wvd_vegt | 20:62318ba945de | 864 | * |
wvd_vegt | 20:62318ba945de | 865 | * @returns the id of the parsed command. |
wvd_vegt | 20:62318ba945de | 866 | */ |
wvd_vegt | 20:62318ba945de | 867 | int parse(char *cmd); |
wvd_vegt | 20:62318ba945de | 868 | |
wvd_vegt | 20:62318ba945de | 869 | /** Called by scan it processes the arguments and dispatches the command. |
wvd_vegt | 20:62318ba945de | 870 | * |
wvd_vegt | 20:62318ba945de | 871 | * Note: This member calls the callback callback function. |
wvd_vegt | 20:62318ba945de | 872 | * |
wvd_vegt | 20:62318ba945de | 873 | * @param cmd the command to dispatch. |
wvd_vegt | 20:62318ba945de | 874 | */ |
wvd_vegt | 20:62318ba945de | 875 | void cmd_dispatcher(char *cmd); |
wvd_vegt | 20:62318ba945de | 876 | |
wvd_vegt | 20:62318ba945de | 877 | /** Generates Help from the command table and prints it. |
wvd_vegt | 20:62318ba945de | 878 | * |
wvd_vegt | 20:62318ba945de | 879 | * @param pre leading text |
wvd_vegt | 20:62318ba945de | 880 | * @param ndx the index of the command in the command table. |
wvd_vegt | 20:62318ba945de | 881 | * @param post trailing text. |
wvd_vegt | 20:62318ba945de | 882 | */ |
wvd_vegt | 20:62318ba945de | 883 | void cmd_help(char *pre, int ndx, char *post); |
wvd_vegt | 20:62318ba945de | 884 | |
wvd_vegt | 20:62318ba945de | 885 | /** Dumps all commands in ini file format. |
wvd_vegt | 20:62318ba945de | 886 | */ |
wvd_vegt | 20:62318ba945de | 887 | void cmd_dump(); |
wvd_vegt | 20:62318ba945de | 888 | |
wvd_vegt | 20:62318ba945de | 889 | /** memset wrapper. |
wvd_vegt | 20:62318ba945de | 890 | * |
wvd_vegt | 20:62318ba945de | 891 | * @param p The string to be cleared. |
wvd_vegt | 20:62318ba945de | 892 | * @param siz The string size. |
wvd_vegt | 20:62318ba945de | 893 | */ |
wvd_vegt | 20:62318ba945de | 894 | void zeromemory(char *p,unsigned int siz); |
wvd_vegt | 20:62318ba945de | 895 | |
wvd_vegt | 20:62318ba945de | 896 | /** Case insensitive compare. |
wvd_vegt | 20:62318ba945de | 897 | * |
wvd_vegt | 20:62318ba945de | 898 | * @see strcmp. |
wvd_vegt | 20:62318ba945de | 899 | * |
wvd_vegt | 20:62318ba945de | 900 | * @param s1 |
wvd_vegt | 20:62318ba945de | 901 | * @param s2 the second string to compare. |
wvd_vegt | 20:62318ba945de | 902 | * |
wvd_vegt | 20:62318ba945de | 903 | * @returns 0 if s1=s2, -1 if s1<s2 or +1 if s1>s2. |
wvd_vegt | 20:62318ba945de | 904 | */ |
wvd_vegt | 20:62318ba945de | 905 | int stricmp (char *s1, char *s2); |
wvd_vegt | 20:62318ba945de | 906 | |
wvd_vegt | 20:62318ba945de | 907 | /** Internal Echo Flag Storage. |
wvd_vegt | 20:62318ba945de | 908 | */ |
wvd_vegt | 20:62318ba945de | 909 | bool echo; |
wvd_vegt | 20:62318ba945de | 910 | |
wvd_vegt | 20:62318ba945de | 911 | /** Internal VT100 Bold Flag Storage. |
wvd_vegt | 20:62318ba945de | 912 | */ |
wvd_vegt | 20:62318ba945de | 913 | bool bold; |
wvd_vegt | 20:62318ba945de | 914 | |
wvd_vegt | 20:62318ba945de | 915 | /** Internal Command Table Length Storage. |
wvd_vegt | 20:62318ba945de | 916 | */ |
wvd_vegt | 20:62318ba945de | 917 | //int CMD_TBL_LEN; |
wvd_vegt | 20:62318ba945de | 918 | |
wvd_vegt | 20:62318ba945de | 919 | //Macro's. |
wvd_vegt | 20:62318ba945de | 920 | /** Internal Macro Pointer. |
wvd_vegt | 20:62318ba945de | 921 | */ |
wvd_vegt | 20:62318ba945de | 922 | int macro_ptr; |
wvd_vegt | 20:62318ba945de | 923 | |
wvd_vegt | 20:62318ba945de | 924 | /** Internal Macro Buffer. |
wvd_vegt | 20:62318ba945de | 925 | */ |
wvd_vegt | 20:62318ba945de | 926 | char macro_buf[1 + MAX_CMD_LEN]; |
wvd_vegt | 20:62318ba945de | 927 | |
wvd_vegt | 20:62318ba945de | 928 | /** Used for parsing parameters. |
wvd_vegt | 20:62318ba945de | 929 | */ |
wvd_vegt | 20:62318ba945de | 930 | enum parmtype { |
wvd_vegt | 20:62318ba945de | 931 | PARM_UNUSED, //0 |
wvd_vegt | 20:62318ba945de | 932 | |
wvd_vegt | 20:62318ba945de | 933 | PARM_FLOAT, //1 (f) |
wvd_vegt | 20:62318ba945de | 934 | |
wvd_vegt | 20:62318ba945de | 935 | PARM_LONG, //2 (l/ul) |
wvd_vegt | 20:62318ba945de | 936 | PARM_INT, //3 (i/ui) |
wvd_vegt | 20:62318ba945de | 937 | PARM_SHORT, //4 (w/uw) |
wvd_vegt | 20:62318ba945de | 938 | |
wvd_vegt | 20:62318ba945de | 939 | PARM_CHAR, //5 (c/uc) |
wvd_vegt | 20:62318ba945de | 940 | PARM_STRING //6 (s) |
wvd_vegt | 20:62318ba945de | 941 | }; |
wvd_vegt | 20:62318ba945de | 942 | |
wvd_vegt | 20:62318ba945de | 943 | /** Used for parsing parameters. |
wvd_vegt | 20:62318ba945de | 944 | */ |
wvd_vegt | 20:62318ba945de | 945 | union value { |
wvd_vegt | 20:62318ba945de | 946 | float f; |
wvd_vegt | 20:62318ba945de | 947 | |
wvd_vegt | 20:62318ba945de | 948 | unsigned long ul; |
wvd_vegt | 20:62318ba945de | 949 | long l; |
wvd_vegt | 20:62318ba945de | 950 | |
wvd_vegt | 20:62318ba945de | 951 | int i; |
wvd_vegt | 20:62318ba945de | 952 | unsigned int ui; |
wvd_vegt | 20:62318ba945de | 953 | |
wvd_vegt | 20:62318ba945de | 954 | short w; |
wvd_vegt | 20:62318ba945de | 955 | unsigned short uw; |
wvd_vegt | 20:62318ba945de | 956 | |
wvd_vegt | 20:62318ba945de | 957 | char c; |
wvd_vegt | 20:62318ba945de | 958 | unsigned char uc; |
wvd_vegt | 20:62318ba945de | 959 | |
wvd_vegt | 20:62318ba945de | 960 | char s[MAX_PARM_LEN]; |
wvd_vegt | 20:62318ba945de | 961 | }; |
wvd_vegt | 20:62318ba945de | 962 | |
wvd_vegt | 20:62318ba945de | 963 | /** Used for parsing parameters. |
wvd_vegt | 20:62318ba945de | 964 | */ |
wvd_vegt | 20:62318ba945de | 965 | struct parm { |
wvd_vegt | 20:62318ba945de | 966 | enum parmtype type; |
wvd_vegt | 20:62318ba945de | 967 | union value val; |
wvd_vegt | 20:62318ba945de | 968 | }; |
wvd_vegt | 20:62318ba945de | 969 | |
wvd_vegt | 20:62318ba945de | 970 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 971 | //----Buffers & Storage. |
wvd_vegt | 20:62318ba945de | 972 | //------------------------------------------------------------------------------ |
wvd_vegt | 20:62318ba945de | 973 | |
wvd_vegt | 20:62318ba945de | 974 | /** Command Buffer. |
wvd_vegt | 20:62318ba945de | 975 | */ |
wvd_vegt | 20:62318ba945de | 976 | char cmdbuf [1 + MAX_CMD_LEN]; // command buffer |
wvd_vegt | 20:62318ba945de | 977 | |
wvd_vegt | 20:62318ba945de | 978 | /** Command Buffer Pointer. |
wvd_vegt | 20:62318ba945de | 979 | */ |
wvd_vegt | 20:62318ba945de | 980 | char cmdndx; // command index |
wvd_vegt | 20:62318ba945de | 981 | |
wvd_vegt | 20:62318ba945de | 982 | /** Last Command Buffer (Used when pressing Cursor Up). |
wvd_vegt | 20:62318ba945de | 983 | */ |
wvd_vegt | 20:62318ba945de | 984 | char lstbuf [1 + MAX_CMD_LEN]; // last command buffer |
wvd_vegt | 20:62318ba945de | 985 | |
wvd_vegt | 20:62318ba945de | 986 | /** Escape Code Buffer. |
wvd_vegt | 20:62318ba945de | 987 | */ |
wvd_vegt | 20:62318ba945de | 988 | char escbuf [1 + MAX_ESC_LEN]; |
wvd_vegt | 20:62318ba945de | 989 | |
wvd_vegt | 20:62318ba945de | 990 | /** Escape Code Buffer Pointer. |
wvd_vegt | 20:62318ba945de | 991 | */ |
wvd_vegt | 20:62318ba945de | 992 | unsigned char escndx; |
wvd_vegt | 20:62318ba945de | 993 | |
wvd_vegt | 20:62318ba945de | 994 | /** Storage for Parsed Parameters |
wvd_vegt | 20:62318ba945de | 995 | */ |
wvd_vegt | 20:62318ba945de | 996 | struct parm parms[MAX_ARGS]; |
wvd_vegt | 20:62318ba945de | 997 | |
wvd_vegt | 20:62318ba945de | 998 | /** Parsed Parameters Pointer. |
wvd_vegt | 20:62318ba945de | 999 | */ |
wvd_vegt | 20:62318ba945de | 1000 | int noparms; |
wvd_vegt | 20:62318ba945de | 1001 | |
wvd_vegt | 20:62318ba945de | 1002 | /** Current Selected Subsystem (-1 for Global). |
wvd_vegt | 20:62318ba945de | 1003 | */ |
wvd_vegt | 20:62318ba945de | 1004 | int subsystem; |
wvd_vegt | 20:62318ba945de | 1005 | |
wvd_vegt | 20:62318ba945de | 1006 | /** No of arguments found in command. |
wvd_vegt | 20:62318ba945de | 1007 | */ |
wvd_vegt | 20:62318ba945de | 1008 | int argcnt; |
wvd_vegt | 20:62318ba945de | 1009 | |
wvd_vegt | 20:62318ba945de | 1010 | /** No of arguments to find in parameter definition (Command Table). |
wvd_vegt | 20:62318ba945de | 1011 | */ |
wvd_vegt | 20:62318ba945de | 1012 | int argfnd; |
wvd_vegt | 20:62318ba945de | 1013 | |
wvd_vegt | 20:62318ba945de | 1014 | /** strtoXX() Error detection. |
wvd_vegt | 20:62318ba945de | 1015 | */ |
wvd_vegt | 20:62318ba945de | 1016 | int error; |
wvd_vegt | 20:62318ba945de | 1017 | }; |
wvd_vegt | 20:62318ba945de | 1018 | |
wvd_vegt | 20:62318ba945de | 1019 | extern "C" void mbed_reset(); |
wvd_vegt | 20:62318ba945de | 1020 | |
wvd_vegt | 20:62318ba945de | 1021 | #endif |