The CommandProcessor is the interface to install a run-time menu into an embedded system.

Dependents:   A_CANAdapter USB2I2C

Committer:
WiredHome
Date:
Wed Jun 15 12:50:56 2011 +0000
Revision:
13:e1880be590c4
Parent:
12:a8c56bf811b9
Child:
14:7971c8bd3f11
v1.03 minor documentation updates.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:198f53da1bc8 1 /// @file CommandProcessor.h defined the interface to the CommandProcessor
WiredHome 0:198f53da1bc8 2 ///
WiredHome 10:9e52bd1a4a71 3 /// @mainpage The CommandProcessor
WiredHome 10:9e52bd1a4a71 4 ///
WiredHome 0:198f53da1bc8 5 /// The CommandProcessor is the interface to install a run-time menu into an embedded system.
WiredHome 0:198f53da1bc8 6 /// This contains the complete interface to the CommandProcessor.
WiredHome 0:198f53da1bc8 7 ///
WiredHome 12:a8c56bf811b9 8 /// @version 1.03
WiredHome 0:198f53da1bc8 9 ///
WiredHome 0:198f53da1bc8 10 /// @note The CommandProcessor is text-based, because it is intended to interact with a
WiredHome 0:198f53da1bc8 11 /// user.
WiredHome 0:198f53da1bc8 12 ///
WiredHome 0:198f53da1bc8 13 /// The menu is designed to be interactively accessed, perhaps via a console interface
WiredHome 0:198f53da1bc8 14 /// or a serial port. The actual interface to the user is provided by the application
WiredHome 0:198f53da1bc8 15 /// during initialization, so it can be connected to a serial port, or it could
WiredHome 0:198f53da1bc8 16 /// be interface to CAN, telnet, or by some other method.
WiredHome 0:198f53da1bc8 17 ///
WiredHome 0:198f53da1bc8 18 /// The CommandProcessor has a few special features:
WiredHome 0:198f53da1bc8 19 /// \li If the minimum number of characters of a command have been entered, the
WiredHome 0:198f53da1bc8 20 /// user does not have to type the entire command. (e.g. 'He' will execute
WiredHome 0:198f53da1bc8 21 /// the command for 'Help', if no other command beings with 'He').
WiredHome 0:198f53da1bc8 22 /// \li If the user does not type the entire set of characters, the command
WiredHome 0:198f53da1bc8 23 /// will be rewritten to the output device with the entire command word.
WiredHome 0:198f53da1bc8 24 /// \li The user is not permitted to enter an incorrect command (e.g. If 'Help'
WiredHome 0:198f53da1bc8 25 /// is the only command started with 'Hel', the user cannot enter 'Heu'.
WiredHome 0:198f53da1bc8 26 /// The CommandProcessor will trap the 'u' and issue a beep).
WiredHome 0:198f53da1bc8 27 /// \li Simple editing of parameters to commands is permitted with \<bs\> to
WiredHome 0:198f53da1bc8 28 /// erase incorrect text.
WiredHome 0:198f53da1bc8 29 /// \li Tab completion of a command is available - so long as the user has
WiredHome 4:283e35536097 30 /// typed at least the minimum number of unique characters. (e.g. 'He\<tab\>'
WiredHome 0:198f53da1bc8 31 /// will be replaced with 'Help')
WiredHome 13:e1880be590c4 32 /// \li Command cancellation is available - just enter the \<esc\> key and
WiredHome 0:198f53da1bc8 33 /// the buffer is erased.
WiredHome 0:198f53da1bc8 34 /// \li The user is not permitted to enter text longer than the defined buffer,
WiredHome 0:198f53da1bc8 35 /// to avoid buffer overrun and the possible memory damaging results.
WiredHome 0:198f53da1bc8 36 ///
WiredHome 0:198f53da1bc8 37 /// The CommandProcessor is designed as a set of C functions, which makes it
WiredHome 0:198f53da1bc8 38 /// reusable in more systems (as C++ compilers are not always available for
WiredHome 0:198f53da1bc8 39 /// all micros).
WiredHome 0:198f53da1bc8 40 ///
WiredHome 0:198f53da1bc8 41 /// Example:
WiredHome 0:198f53da1bc8 42 /// @code
WiredHome 0:198f53da1bc8 43 /// extern "C" {
WiredHome 0:198f53da1bc8 44 /// #include "CommandProcessor.h"
WiredHome 0:198f53da1bc8 45 /// }
WiredHome 0:198f53da1bc8 46 ///
WiredHome 10:9e52bd1a4a71 47 /// RUNRESULT_T SignOnBanner(char *p);
WiredHome 10:9e52bd1a4a71 48 /// const CMD_T SignOnBannerCmd = {
WiredHome 10:9e52bd1a4a71 49 /// "About", "About this program ('About ?' for more details)",
WiredHome 10:9e52bd1a4a71 50 /// SignOnBanner, invisible};
WiredHome 10:9e52bd1a4a71 51 ///
WiredHome 0:198f53da1bc8 52 /// RUNRESULT_T Who(char *p);
WiredHome 7:0f058d664b21 53 /// const CMD_T WhoCmd = {
WiredHome 10:9e52bd1a4a71 54 /// "who", "Shows who is logged on, or 'who id' for specifics",
WiredHome 10:9e52bd1a4a71 55 /// Who, visible};
WiredHome 10:9e52bd1a4a71 56 ///
WiredHome 10:9e52bd1a4a71 57 /// RUNRESULT_T SignOnBanner(char *p)
WiredHome 10:9e52bd1a4a71 58 /// {
WiredHome 12:a8c56bf811b9 59 /// puts("\r\nThis great program was built " __DATE__ " " __TIME__ ".");
WiredHome 10:9e52bd1a4a71 60 /// if (*p == '?')
WiredHome 10:9e52bd1a4a71 61 /// puts("\r\nMore details shown here.\r\n");
WiredHome 12:a8c56bf811b9 62 /// return runok;
WiredHome 10:9e52bd1a4a71 63 /// }
WiredHome 0:198f53da1bc8 64 /// RUNRESULT_T Who(char *p)
WiredHome 0:198f53da1bc8 65 /// {
WiredHome 4:283e35536097 66 /// printf("\r\nwho...\r\n");
WiredHome 4:283e35536097 67 /// if (*p)
WiredHome 4:283e35536097 68 /// printf(" Sorry, no help for [%s]\r\n", p);
WiredHome 4:283e35536097 69 /// return runok;
WiredHome 0:198f53da1bc8 70 /// }
WiredHome 0:198f53da1bc8 71 ///
WiredHome 0:198f53da1bc8 72 /// int main(int argc, char* argv[])
WiredHome 0:198f53da1bc8 73 /// {
WiredHome 4:283e35536097 74 /// CMDP_T * cp = GetCommandProcessor();
WiredHome 10:9e52bd1a4a71 75 /// cp->Init(&SignOnBanner,
WiredHome 10:9e52bd1a4a71 76 /// CFG_ENABLE_TERMINATE | CFG_ENABLE_SYSTEM,
WiredHome 10:9e52bd1a4a71 77 /// 50, _kbhit, _getch, _putch, printf);
WiredHome 4:283e35536097 78 /// cp->Add(&WhoCmd);
WiredHome 0:198f53da1bc8 79 ///
WiredHome 4:283e35536097 80 /// while (cp->Run())
WiredHome 4:283e35536097 81 /// {
WiredHome 4:283e35536097 82 /// ;
WiredHome 4:283e35536097 83 /// }
WiredHome 4:283e35536097 84 /// cp->End();
WiredHome 4:283e35536097 85 /// return 0;
WiredHome 0:198f53da1bc8 86 /// }
WiredHome 0:198f53da1bc8 87 /// @endcode
WiredHome 0:198f53da1bc8 88 ///
WiredHome 12:a8c56bf811b9 89 ///
WiredHome 12:a8c56bf811b9 90 /// @note Copyright &copr; 2011 by Smartware Computing, all rights reserved.
WiredHome 12:a8c56bf811b9 91 /// Individuals may use this application for evaluation or non-commercial
WiredHome 12:a8c56bf811b9 92 /// purposes. Within this restriction, changes may be made to this application
WiredHome 12:a8c56bf811b9 93 /// as long as this copyright notice is retained. The user shall make
WiredHome 12:a8c56bf811b9 94 /// clear that their work is a derived work, and not the original.
WiredHome 12:a8c56bf811b9 95 /// Users of this application and sources accept this application "as is" and
WiredHome 12:a8c56bf811b9 96 /// shall hold harmless Smartware Computing, for any undesired results while
WiredHome 12:a8c56bf811b9 97 /// using this application - whether real or imagined.
WiredHome 12:a8c56bf811b9 98 ///
WiredHome 12:a8c56bf811b9 99 /// @author David Smart, Smartware Computing
WiredHome 0:198f53da1bc8 100 ///
WiredHome 10:9e52bd1a4a71 101 /// @note
WiredHome 10:9e52bd1a4a71 102 /// History
WiredHome 12:a8c56bf811b9 103 /// v1.03 29 May 2011
WiredHome 12:a8c56bf811b9 104 /// \li Slightly improved internal documentation. No external interfaces affected.
WiredHome 12:a8c56bf811b9 105 /// v1.02 2 May 2011
WiredHome 12:a8c56bf811b9 106 /// \li Track the longest command when added, so that the help printout
WiredHome 12:a8c56bf811b9 107 /// is more nicely formatted.
WiredHome 10:9e52bd1a4a71 108 /// v1.01 22 April 2011
WiredHome 10:9e52bd1a4a71 109 /// \li Moving 'About' content into the extended help,
WiredHome 10:9e52bd1a4a71 110 /// to free 'About' for application code that uses this library.
WiredHome 10:9e52bd1a4a71 111 /// \li Altered the _init api to permit a signon banner of the users choice
WiredHome 10:9e52bd1a4a71 112 /// and a config parameter for other features.
WiredHome 10:9e52bd1a4a71 113 ///
WiredHome 10:9e52bd1a4a71 114 /// v1.0 March 2011
WiredHome 10:9e52bd1a4a71 115 /// \li Initial version
WiredHome 10:9e52bd1a4a71 116 ///
WiredHome 0:198f53da1bc8 117 #ifndef COMMANDPROCESSOR_H
WiredHome 0:198f53da1bc8 118 #define COMMANDPROCESSOR_H
WiredHome 0:198f53da1bc8 119
WiredHome 0:198f53da1bc8 120 #ifndef TRUE
WiredHome 4:283e35536097 121 #define TRUE 1 ///< Definition for TRUE, if not already provided
WiredHome 4:283e35536097 122 #define FALSE 0 ///< Definition for FALSE, if not already provided
WiredHome 0:198f53da1bc8 123 #endif
WiredHome 0:198f53da1bc8 124
WiredHome 0:198f53da1bc8 125 /// @brief This type determines if menu items are visible to the Help system, or hidden.
WiredHome 0:198f53da1bc8 126 /// @details This is used in the definition of the menu item.
WiredHome 0:198f53da1bc8 127 typedef enum
WiredHome 0:198f53da1bc8 128 {
WiredHome 4:283e35536097 129 invisible, ///< use this value to have invisible (hidden) a menu in the Help
WiredHome 4:283e35536097 130 visible ///< use this value to have visible a menu in the Help
WiredHome 4:283e35536097 131 } VISIBLE_T; ///< This determines if menu items are made visible in the Help system.
WiredHome 0:198f53da1bc8 132
WiredHome 0:198f53da1bc8 133 /// Callbacks that are executed return a value to indicate if the menu
WiredHome 0:198f53da1bc8 134 /// should remain active
WiredHome 0:198f53da1bc8 135 typedef enum
WiredHome 0:198f53da1bc8 136 {
WiredHome 4:283e35536097 137 runexit, ///< use this return value to cause the menu (perhaps the program) to exit
WiredHome 4:283e35536097 138 runok ///< use this return value to keep the menu running
WiredHome 0:198f53da1bc8 139 } RUNRESULT_T;
WiredHome 0:198f53da1bc8 140
WiredHome 0:198f53da1bc8 141 /// Adding items to the menu can succeed, or fail.
WiredHome 0:198f53da1bc8 142 typedef enum
WiredHome 0:198f53da1bc8 143 {
WiredHome 4:283e35536097 144 addfailed, ///< this indicates the menu was not added (usually failure to allocate memory)
WiredHome 4:283e35536097 145 addok ///< this indicates the menu was successfully added
WiredHome 0:198f53da1bc8 146 } ADDRESULT_T;
WiredHome 0:198f53da1bc8 147
WiredHome 0:198f53da1bc8 148 /// Initialization can succeed, or fail.
WiredHome 0:198f53da1bc8 149 typedef enum
WiredHome 0:198f53da1bc8 150 {
WiredHome 4:283e35536097 151 initfailed, ///< this indicates that the menu system was not initialized (usually failure to allocate memory)
WiredHome 4:283e35536097 152 initok ///< this indicates that the menu system was successfully initialized
WiredHome 0:198f53da1bc8 153 } INITRESULT_T;
WiredHome 0:198f53da1bc8 154
WiredHome 11:4a3cd3f2183b 155 /// Configuration options to control startup and some runtime behavior
WiredHome 11:4a3cd3f2183b 156 ///
WiredHome 11:4a3cd3f2183b 157 /// Permissible values are created by combining
WiredHome 11:4a3cd3f2183b 158 /// \li CFG_ENABLE_TERMINATE
WiredHome 11:4a3cd3f2183b 159 /// \li CFG_ENABLE_SYSTEM
WiredHome 11:4a3cd3f2183b 160 /// \li CFG_ECHO_ON
WiredHome 11:4a3cd3f2183b 161 /// \li CFG_CASE_INSENSITIVE
WiredHome 10:9e52bd1a4a71 162 typedef unsigned long CONFIG_T;
WiredHome 10:9e52bd1a4a71 163
WiredHome 11:4a3cd3f2183b 164 #define CFG_ENABLE_TERMINATE 0x0001 ///<- Enable the exit option
WiredHome 11:4a3cd3f2183b 165 #define CFG_ENABLE_SYSTEM 0x0002 ///<- Enable various system options (help, etc)
WiredHome 11:4a3cd3f2183b 166 #define CFG_ECHO_ON 0x2000 ///<- Initialize with command prompt Echo on
WiredHome 11:4a3cd3f2183b 167 #define CFG_CASE_INSENSITIVE 0x4000 ///<- Enable case insensitive command entry
WiredHome 10:9e52bd1a4a71 168
WiredHome 10:9e52bd1a4a71 169
WiredHome 0:198f53da1bc8 170 /// This is the type for the basic callback, when a menu pick is activated.
WiredHome 0:198f53da1bc8 171 ///
WiredHome 0:198f53da1bc8 172 /// The callback function is executed when a command is entered on the menu and \<enter\>
WiredHome 0:198f53da1bc8 173 /// is signaled. If there is any additional text entered on the commandline, it is
WiredHome 0:198f53da1bc8 174 /// passed to the callback.
WiredHome 0:198f53da1bc8 175 ///
WiredHome 0:198f53da1bc8 176 /// example:
WiredHome 4:283e35536097 177 /// "Test1 ab c 123 567"
WiredHome 0:198f53da1bc8 178 /// If "Test1" is a valid command, the corresponding function would be called
WiredHome 4:283e35536097 179 /// passing to that function the string "ab c 123 567". Note that the delimiter space
WiredHome 10:9e52bd1a4a71 180 /// was removed.
WiredHome 0:198f53da1bc8 181 ///
WiredHome 10:9e52bd1a4a71 182 /// @param p is a pointer to a character string
WiredHome 10:9e52bd1a4a71 183 /// @returns RUNRESULT_T to indicate if the CommandProcessor should continue
WiredHome 0:198f53da1bc8 184 ///
WiredHome 0:198f53da1bc8 185 typedef RUNRESULT_T (*MENU_CALLBACK)(char *p);
WiredHome 0:198f53da1bc8 186
WiredHome 0:198f53da1bc8 187 /// This defines the type for a single item to be added to the CommandProcessor menu.
WiredHome 0:198f53da1bc8 188 ///
WiredHome 0:198f53da1bc8 189 /// This is defined in the application code, and a pointer to this item is passed to the
WiredHome 0:198f53da1bc8 190 /// CommandProcessor to add this item to the menu system.
WiredHome 0:198f53da1bc8 191 ///
WiredHome 0:198f53da1bc8 192 /// example:
WiredHome 10:9e52bd1a4a71 193 /// @code
WiredHome 0:198f53da1bc8 194 /// const CMD_T WhoCmd = {"who", "Shows who is logged on, or 'who id' for specifics", Who, visible};
WiredHome 0:198f53da1bc8 195 /// @endcode
WiredHome 0:198f53da1bc8 196 ///
WiredHome 0:198f53da1bc8 197 typedef const struct
WiredHome 0:198f53da1bc8 198 {
WiredHome 4:283e35536097 199 char * command; ///< a pointer to the command to match (e.g. 'Help')
WiredHome 4:283e35536097 200 char * helptext; ///< a pointer to some text to show when user types 'Help'
WiredHome 4:283e35536097 201 MENU_CALLBACK callback; ///< the function to call when user enters this command
WiredHome 4:283e35536097 202 VISIBLE_T visible; ///< a flag that determines if this command is visible in Help.
WiredHome 0:198f53da1bc8 203 } CMD_T;
WiredHome 0:198f53da1bc8 204
WiredHome 0:198f53da1bc8 205 /// This is the CommandProcessor interface from the user application.
WiredHome 0:198f53da1bc8 206 ///
WiredHome 10:9e52bd1a4a71 207 /// The user aquires a handle to this set of functions with the GetCommandProcessor command.
WiredHome 0:198f53da1bc8 208 /// After this, the user may then initialize the CommandProcessor, add items to the menu,
WiredHome 0:198f53da1bc8 209 /// cause the CommandProcessor to run periodically, and if need be the application can end
WiredHome 0:198f53da1bc8 210 /// the CommandProcessor.
WiredHome 0:198f53da1bc8 211 ///
WiredHome 0:198f53da1bc8 212 typedef const struct
WiredHome 0:198f53da1bc8 213 {
WiredHome 4:283e35536097 214 /// Init is the first function to call to configure the CommandProcessor.
WiredHome 4:283e35536097 215 ///
WiredHome 4:283e35536097 216 /// This function has a number of parameters, which make the CommandProcessor quite flexible.
WiredHome 4:283e35536097 217 ///
WiredHome 12:a8c56bf811b9 218 /// @param SignOnBanner function, which is used as a signon banner
WiredHome 10:9e52bd1a4a71 219 /// @param config enables various default menu items, based on the bit values, combine the following:
WiredHome 12:a8c56bf811b9 220 /// \li CFG_ENABLE_TERMINATE - enables the Exit command
WiredHome 12:a8c56bf811b9 221 /// \li CFG_ENABLE_SYSTEM - enables system commands Echo, Help, etc.
WiredHome 12:a8c56bf811b9 222 /// \li CFG_ECHO_ON - initialize with echo on
WiredHome 12:a8c56bf811b9 223 /// \li CFG_CASE_INSENSITIVE - Command Parser is case insensitive
WiredHome 12:a8c56bf811b9 224 /// @param maxCmdLen sizes the buffer, and is the maximum number of characters in a single
WiredHome 12:a8c56bf811b9 225 /// command, including all command arguments
WiredHome 10:9e52bd1a4a71 226 /// @param kbhit is a user provided function to detect if a character is available for the CommandProcessor,
WiredHome 10:9e52bd1a4a71 227 /// and when using standard io, you can typically use kbhit, or _kbhit as your system provides.
WiredHome 10:9e52bd1a4a71 228 /// @param getch is a user provided function that provides a single character to the CommandProcessor
WiredHome 10:9e52bd1a4a71 229 /// @param putch is a user provided function that permits the CommandProcessor to output a character
WiredHome 10:9e52bd1a4a71 230 /// @param puts is a user provided function that permits the CommandProcessor to output a string
WiredHome 4:283e35536097 231 /// to which is automatically appended a \\n
WiredHome 4:283e35536097 232 /// @returns INITRESULT_T to indicate if the init was successful or failed
WiredHome 12:a8c56bf811b9 233 ///
WiredHome 4:283e35536097 234 INITRESULT_T (*Init)(
WiredHome 12:a8c56bf811b9 235 CMD_T *SignOnBanner,
WiredHome 10:9e52bd1a4a71 236 CONFIG_T config,
WiredHome 6:1a0512faa75d 237 int maxCmdLen,
WiredHome 4:283e35536097 238 int (*kbhit)(void),
WiredHome 4:283e35536097 239 int (*getch)(void),
WiredHome 4:283e35536097 240 int (*putch)(int ch),
WiredHome 4:283e35536097 241 int (*puts)(const char * s)
WiredHome 4:283e35536097 242 );
WiredHome 0:198f53da1bc8 243
WiredHome 4:283e35536097 244 /// Add is called to add an item to the CommandProcessor menu
WiredHome 4:283e35536097 245 ///
WiredHome 4:283e35536097 246 /// This passes in a reference to a user provided CMD_T item, which is
WiredHome 4:283e35536097 247 /// added to the menu system.
WiredHome 4:283e35536097 248 ///
WiredHome 6:1a0512faa75d 249 /// @param m is a pointer to the user provided menu
WiredHome 6:1a0512faa75d 250 /// @returns ADDRESULT_T to indicate if the add was successful or failed
WiredHome 4:283e35536097 251 ///
WiredHome 4:283e35536097 252 ADDRESULT_T (*Add)(CMD_T * m);
WiredHome 0:198f53da1bc8 253
WiredHome 4:283e35536097 254 /// Run is the primary runtime entry point for the CommandProcessor.
WiredHome 4:283e35536097 255 ///
WiredHome 4:283e35536097 256 /// This function should be called periodically - fast enough not to miss user input.
WiredHome 4:283e35536097 257 /// This function always returns, so if not character is available for the CommandProcessor
WiredHome 4:283e35536097 258 /// it will return very fast. If there is a character (as detected by the kbhit callback),
WiredHome 4:283e35536097 259 /// then it will process that character and determine what to do. It may then execute one
WiredHome 4:283e35536097 260 /// of the menu functions. In this case, CPU cycles spent are based on the function
WiredHome 4:283e35536097 261 /// being executed.
WiredHome 4:283e35536097 262 ///
WiredHome 4:283e35536097 263 /// @returns RUNRESULT_T to indicate if the CommandProcessor should remain active or if the
WiredHome 4:283e35536097 264 /// command that was executed is requesting the CommandProcessor to exit.
WiredHome 4:283e35536097 265 ///
WiredHome 4:283e35536097 266 RUNRESULT_T (*Run)(void);
WiredHome 6:1a0512faa75d 267
WiredHome 6:1a0512faa75d 268 /// Echo command permits turning the echo on and off
WiredHome 6:1a0512faa75d 269 ///
WiredHome 6:1a0512faa75d 270 /// When interactive with the user, it is best to have echo on, so they can see
WiredHome 6:1a0512faa75d 271 /// the prompt, but if this is simply slaved to another program, then the echo
WiredHome 6:1a0512faa75d 272 /// might need to be off to best manage the stream.
WiredHome 6:1a0512faa75d 273 ///
WiredHome 6:1a0512faa75d 274 /// @param echo turns the echo on (non-zero) or off (zero)
WiredHome 6:1a0512faa75d 275 /// @returns RUNRESULT_T to indicate if the CommandProcessor should remain active or if the
WiredHome 6:1a0512faa75d 276 /// command that was executed is requesting the CommandProcessor to exit.
WiredHome 6:1a0512faa75d 277 ///
WiredHome 6:1a0512faa75d 278 RUNRESULT_T (*Echo)(int echo);
WiredHome 0:198f53da1bc8 279
WiredHome 4:283e35536097 280 /// End if the function to be called when you want to gracefully end the CommandProcessor.
WiredHome 4:283e35536097 281 ///
WiredHome 4:283e35536097 282 /// Calling this function causes the CommandProcessor to free any memory that was previously
WiredHome 4:283e35536097 283 /// allocated by the Init and Add functions.
WiredHome 4:283e35536097 284 RUNRESULT_T (*End)(void); ///< Called to shutdown the processor
WiredHome 0:198f53da1bc8 285 } CMDP_T;
WiredHome 0:198f53da1bc8 286
WiredHome 3:7c9993cac92b 287
WiredHome 3:7c9993cac92b 288 /// The CommandProcessor is the interface to install a run-time menu into an embedded system.
WiredHome 3:7c9993cac92b 289 /// This contains the complete interface to the CommandProcessor.
WiredHome 3:7c9993cac92b 290 ///
WiredHome 3:7c9993cac92b 291 /// @version 1.0
WiredHome 3:7c9993cac92b 292 ///
WiredHome 3:7c9993cac92b 293 /// @note The CommandProcessor is text-based, because it is intended to interact with a
WiredHome 3:7c9993cac92b 294 /// user.
WiredHome 3:7c9993cac92b 295 ///
WiredHome 3:7c9993cac92b 296 /// The menu is designed to be interactively accessed, perhaps via a console interface
WiredHome 3:7c9993cac92b 297 /// or a serial port. The actual interface to the user is provided by the application
WiredHome 3:7c9993cac92b 298 /// during initialization, so it can be connected to a serial port, or it could
WiredHome 3:7c9993cac92b 299 /// be interface to CAN, telnet, or by some other method.
WiredHome 3:7c9993cac92b 300 ///
WiredHome 3:7c9993cac92b 301 /// The CommandProcessor has a few special features:
WiredHome 3:7c9993cac92b 302 /// \li If the minimum number of characters of a command have been entered, the
WiredHome 3:7c9993cac92b 303 /// user does not have to type the entire command. (e.g. 'He' will execute
WiredHome 3:7c9993cac92b 304 /// the command for 'Help', if no other command beings with 'He').
WiredHome 3:7c9993cac92b 305 /// \li If the user does not type the entire set of characters, the command
WiredHome 3:7c9993cac92b 306 /// will be rewritten to the output device with the entire command word.
WiredHome 3:7c9993cac92b 307 /// \li The user is not permitted to enter an incorrect command (e.g. If 'Help'
WiredHome 3:7c9993cac92b 308 /// is the only command started with 'Hel', the user cannot enter 'Heu'.
WiredHome 3:7c9993cac92b 309 /// The CommandProcessor will trap the 'u' and issue a beep).
WiredHome 3:7c9993cac92b 310 /// \li Simple editing of parameters to commands is permitted with \<bs\> to
WiredHome 3:7c9993cac92b 311 /// erase incorrect text.
WiredHome 3:7c9993cac92b 312 /// \li Tab completion of a command is available - so long as the user has
WiredHome 4:283e35536097 313 /// typed at least the minimum number of unique characters. (e.g. 'He\<tab\>'
WiredHome 3:7c9993cac92b 314 /// will be replaced with 'Help')
WiredHome 4:283e35536097 315 /// \li Command cancellation is available - just enter the \<esc\> key and
WiredHome 3:7c9993cac92b 316 /// the buffer is erased.
WiredHome 3:7c9993cac92b 317 /// \li The user is not permitted to enter text longer than the defined buffer,
WiredHome 3:7c9993cac92b 318 /// to avoid buffer overrun and the possible memory damaging results.
WiredHome 3:7c9993cac92b 319 ///
WiredHome 3:7c9993cac92b 320 /// The CommandProcessor is designed as a set of C functions, which makes it
WiredHome 3:7c9993cac92b 321 /// reusable in more systems (as C++ compilers are not always available for
WiredHome 3:7c9993cac92b 322 /// all micros).
WiredHome 3:7c9993cac92b 323 ///
WiredHome 3:7c9993cac92b 324 /// Example:
WiredHome 3:7c9993cac92b 325 /// @code
WiredHome 3:7c9993cac92b 326 /// extern "C" {
WiredHome 3:7c9993cac92b 327 /// #include "CommandProcessor.h"
WiredHome 3:7c9993cac92b 328 /// }
WiredHome 3:7c9993cac92b 329 ///
WiredHome 10:9e52bd1a4a71 330 /// RUNRESULT_T About(char *p);
WiredHome 10:9e52bd1a4a71 331 /// const CMD_T AboutCmd = {"About", "About this program", About, invisible};
WiredHome 3:7c9993cac92b 332 /// RUNRESULT_T Who(char *p);
WiredHome 3:7c9993cac92b 333 /// const CMD_T WhoCmd = {"who", "Shows who is logged on, or 'who id' for specifics", Who, visible};
WiredHome 3:7c9993cac92b 334 ///
WiredHome 10:9e52bd1a4a71 335 /// RUNRESULT_T About(char *p)
WiredHome 10:9e52bd1a4a71 336 /// {
WiredHome 10:9e52bd1a4a71 337 /// (void)p;
WiredHome 10:9e52bd1a4a71 338 /// puts("\r\nThis program does really good things for the user.\r\n");
WiredHome 10:9e52bd1a4a71 339 /// }
WiredHome 10:9e52bd1a4a71 340 ///
WiredHome 3:7c9993cac92b 341 /// RUNRESULT_T Who(char *p)
WiredHome 3:7c9993cac92b 342 /// {
WiredHome 4:283e35536097 343 /// printf("\r\nwho...\r\n");
WiredHome 4:283e35536097 344 /// if (*p)
WiredHome 4:283e35536097 345 /// printf(" Sorry, no help for [%s]\r\n", p);
WiredHome 4:283e35536097 346 /// return runok;
WiredHome 3:7c9993cac92b 347 /// }
WiredHome 3:7c9993cac92b 348 ///
WiredHome 3:7c9993cac92b 349 /// int main(int argc, char* argv[])
WiredHome 3:7c9993cac92b 350 /// {
WiredHome 4:283e35536097 351 /// CMDP_T * cp = GetCommandProcessor();
WiredHome 10:9e52bd1a4a71 352 /// cp->Init(AboutCmd, CFG_ENABLE_TERMINATE | CFG_ENABLE_SYSTEM | CFG_SIGNON_BANNER,
WiredHome 10:9e52bd1a4a71 353 /// 50,
WiredHome 10:9e52bd1a4a71 354 /// _kbhit, _getch, _putch, printf);
WiredHome 4:283e35536097 355 /// cp->Add(&WhoCmd);
WiredHome 3:7c9993cac92b 356 ///
WiredHome 4:283e35536097 357 /// while (cp->Run())
WiredHome 4:283e35536097 358 /// {
WiredHome 4:283e35536097 359 /// ;
WiredHome 4:283e35536097 360 /// }
WiredHome 4:283e35536097 361 /// cp->End();
WiredHome 4:283e35536097 362 /// return 0;
WiredHome 3:7c9993cac92b 363 /// }
WiredHome 3:7c9993cac92b 364 /// @endcode
WiredHome 3:7c9993cac92b 365 ///
WiredHome 3:7c9993cac92b 366 /// @note Copyright &copy; 2011 by Smartware Computing, all rights reserved.
WiredHome 3:7c9993cac92b 367 /// This program may be used by others as long as this copyright notice
WiredHome 3:7c9993cac92b 368 /// remains intact.
WiredHome 3:7c9993cac92b 369 /// @author David Smart
WiredHome 3:7c9993cac92b 370 ///
WiredHome 0:198f53da1bc8 371 /// GetCommandProcessor is called to get a handle to the CommandProcessor itself.
WiredHome 0:198f53da1bc8 372 ///
WiredHome 0:198f53da1bc8 373 /// Call this function to get a handle to the CommandProcessor. After this is done, then
WiredHome 0:198f53da1bc8 374 /// you can use that handle to activate the CommandProcessor methods.
WiredHome 0:198f53da1bc8 375 ///
WiredHome 0:198f53da1bc8 376 /// example:
WiredHome 0:198f53da1bc8 377 /// @code
WiredHome 4:283e35536097 378 /// CMDP_T * cp = GetCommandProcessor();
WiredHome 10:9e52bd1a4a71 379 /// cp->Init(AboutCmd, CFG_ENABLE_TERMINATE | CFG_ENABLE_SYSTEM | CFG_SIGNON_BANNER,
WiredHome 10:9e52bd1a4a71 380 /// 50,
WiredHome 10:9e52bd1a4a71 381 /// _kbhit, _getch, _putch, printf);
WiredHome 0:198f53da1bc8 382 /// @endcode
WiredHome 0:198f53da1bc8 383 ///
WiredHome 1:1c81feb2f8bd 384 /// @returns CMDP_T a handle to the CommandProcessor
WiredHome 0:198f53da1bc8 385 ///
WiredHome 0:198f53da1bc8 386 #ifdef WIN32
WiredHome 13:e1880be590c4 387 extern CMDP_T * GetCommandProcessor(void);
WiredHome 0:198f53da1bc8 388 #else // This is necessary for the mbed - not sure why.
WiredHome 0:198f53da1bc8 389 extern "C" CMDP_T * GetCommandProcessor(void);
WiredHome 0:198f53da1bc8 390 #endif
WiredHome 0:198f53da1bc8 391
WiredHome 4:283e35536097 392
WiredHome 4:283e35536097 393
WiredHome 8:25581f24f7f9 394 //int mystrnicmp(const char *l, const char *r, size_t n);
WiredHome 1:1c81feb2f8bd 395 #endif // COMMANDPROCESSOR_H