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