#include <command_handler.hpp>
Public Member Functions | |
CommandProcessor (int numCmds=8) | |
void | addHandler (CmdHandlerFuncPtr pFunc, const char *pPersistantCmdStr, const char *pPersistentCmdHelpStr=0, void *pDataParam=0) |
void | enableShortCmds (bool en) |
bool | handleCommand (str &cmd, CharDev &out) |
Detailed Description
Command Processor Class
This class allows users to add a command string and associated handler for commands. When user inputs a command, it will call the mapped handler. Note that command input is capitalized to make this class case insensitive.
One handler is already part of this class:
- "help" : Get list of supported commands
The "help" handler lists out supported commands, "HELP <command>" will show the help-text associated with the given command.
Example Usage:
Constructor & Destructor Documentation
|
inline |
Constructor
- Parameters
-
numCmds Optional: Initial list of vector size to avoid memory re-allocation
- Note
- addHandler() will grow the vector of command handlers if more commands are added later
Member Function Documentation
void CommandProcessor::addHandler | ( | CmdHandlerFuncPtr | pFunc, |
const char * | pPersistantCmdStr, | ||
const char * | pPersistentCmdHelpStr = 0 , |
||
void * | pDataParam = 0 |
||
) |
Adds a command to the command handler list
- Parameters
-
pFunc The function pointer of the handler of this command pPersistantCmdStr The persistent data pointer of a command's text pPersistentCmdHelpStr The persistent data pointer of this command's help text pDataParam Optional Param: The data parameter pointer to pass to your handler when it gets called
- Warning
- pPersistentCmdStr and pPersistentCmdHelp must always exist in memory without going out of scope because these strings are not copied internally but their pointer is referenced during comparison
- Note
- command is matched while ignoring case.
|
inline |
Enables short-hand commands. If a registered command is "information", and a command comes in as "info", then it will be handled by "information" handler. First command that matches first two characters will take precedence.
- Note
- This option is enabled by default.
Command handling functions Handles an incoming command and
- Returns
- null terminated string of the command output
- Parameters
-
cmd Input command either as char* pointer or str object
- Returns
- char* pointer containing the command's response
- Note
- "HELP" command will output the list of supported commands.
If command not matched, try to partially match a command. ie: If command is "magic", match "m" as command
Check here if pCommandStr contains partial command :
- regCmd may be "thermostat", when input is "th" or "th on"
- So accept this command as shorthand command
The documentation for this class was generated from the following files:
- /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L3_Utils/command_handler.hpp
- /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L3_Utils/src/command_handler.cpp