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