Fix compile error of CMDB which occurred by mbed-src modification.
Dependents:
mbed_controller_demo
Fork of
CMDB
by Wim van der Vegt
« Back to documentation index
Cmdb Class Reference
Command Interpreter class.
More...
#include <cmdb.h >
Public Member Functions
Cmdb (Serial &_serial, std::vector< cmd > &_cmds, void(*_callback)(Cmdb &, int))
Create a Command Interpreter.
bool macro_hasnext ()
Checks if the macro buffer has any characters left.
char macro_next ()
Gets the next character from the macro buffer and advances the macro buffer pointer.
char macro_peek ()
Gets the next character from the macro buffer but does not advance the macro buffer pointer.
void macro_reset ()
Resets the macro buffer and macro buffer pointer.
bool hasnext ()
Checks if the serial port has any characters left to read by calling serial.readable().
char next ()
Gets the next character from the serial port by calling serial.getc().
bool scan (const char c)
Add a character to the command being processed.
int printf (const char *format,...)
printf substitute using the serial parameter passed to the constructor.
int print (const char *msg)
print is simply printf without parameters using the serial parameter passed to the constructor.
int println (const char *msg)
println is simply printf without parameters using the serial parameter passed to the constructor.
char printch (const char ch)
printch is simply putc subsitute using the serial parameter passed to the constructor.
int printsection (const char *section)
printsection prints an inifile Section Header like:
int printmsg (const char *msg)
printmsg prints an inifile Msg Key=Value pair.
int printerror (const char *errormsg)
printerror prints an inifile Error Section Header and Error Msg Key=Value pair.
int printerrorf (const char *format,...)
printerror prints an inifile Error Section Header and Error Msg Key=Value pair.
int printvaluef (const char *key, const int width, const char *comment, const char *format,...)
printvalue prints an inifile Key/Value Pair like:
int printvaluef (const char *key, const char *format,...)
printvalue prints an inifile Key/Value Pair like:
int printvalue (const char *key, const char *value, const char *comment=NoComment , const int width=DefComPos )
printvalue prints an inifile Key/Value Pair like:
void init (const char full)
Initializes the parser (called by the constructor).
bool BOOLPARM (int ndx)
Typecasts parameter ndx to a bool.
unsigned char BYTEPARM (int ndx)
Typecasts parameter ndx to a byte/unsigned char.
char CHARPARM (int ndx)
Typecasts parameter ndx to a char.
unsigned int WORDPARM (int ndx)
Typecasts parameter ndx to word/unsigned int.
unsigned int UINTPARM (int ndx)
Typecasts parameter ndx to a unsigned int.
int INTPARM (int ndx)
Typecasts parameter ndx to a int.
unsigned long DWORDPARM (int ndx)
Typecasts parameter ndx to a bool.
long LONGPARM (int ndx)
Typecasts parameter ndx to a long.
float FLOATPARM (int ndx)
Typecasts parameter ndx to a float.
char * STRINGPARM (int ndx)
Typecasts parameter ndx to a string.
Static Public Member Functions
static float version ()
The version of the Command Interpreter.
Static Public Attributes
static const char * NoComment
NULL is used as No Comment Value.
static int DefComPos
Column 72 is used as Default Comment Starting Position.
Detailed Description
Command Interpreter class.
Steps to take:
1) Create a std::vector<cmd> and fill it with at least the mandatory commands IDLE and HELP.
2) Create an Cmdb class instance and pass it the vector, a Serial port object like Serial serial(USBTX, USBRX); and finally a command dispatcher function.
3) Feed the interpreter with characters received from your serial port. Note: Cmdb self does not retrieve input it must be handed to it. It implements basic members for checking/reading the serial port.
4) Handle commands added by the application by the Cid and parameters passed.
Note: Predefined commands and all subsystems transitions are handled by the internal dispatcher. So the passed dispatcher only has to handle user/application defined commands'.
See also: main.cpp for a demo.
Definition at line 409 of file cmdb.h .
Constructor & Destructor Documentation
Cmdb
(
Serial &
_serial ,
std::vector< cmd > &
_cmds ,
void(*)(Cmdb &, int)
_callback
)
Member Function Documentation
bool BOOLPARM
(
int
ndx )
Typecasts parameter ndx to a bool.
mask: bu
the parameter index
Returns: a bool
Definition at line 653 of file cmdb.h .
unsigned char BYTEPARM
(
int
ndx )
Typecasts parameter ndx to a byte/unsigned char.
mask: bu
the parameter index
Returns: a byte/unsigned char
Definition at line 665 of file cmdb.h .
char CHARPARM
(
int
ndx )
Typecasts parameter ndx to a char.
mask: c
the parameter index
Returns: a char
Definition at line 677 of file cmdb.h .
unsigned long DWORDPARM
(
int
ndx )
Typecasts parameter ndx to a bool.
mask: lu
the parameter index
Returns: a bool
Definition at line 725 of file cmdb.h .
float FLOATPARM
(
int
ndx )
Typecasts parameter ndx to a float.
mask: f
the parameter index
Returns: a float
Definition at line 749 of file cmdb.h .
Checks if the serial port has any characters left to read by calling serial.readable().
Returns: true if any characters available.
Definition at line 126 of file cmdb.cpp .
void init
(
const char
full )
Initializes the parser (called by the constructor).
full if true the macro buffer is also cleared else only the command interpreter is reset.
Definition at line 378 of file cmdb.cpp .
Typecasts parameter ndx to a int.
mask: i
the parameter index
Returns: a int
Definition at line 713 of file cmdb.h .
long LONGPARM
(
int
ndx )
Typecasts parameter ndx to a long.
mask: li
the parameter index
Returns: a long
Definition at line 737 of file cmdb.h .
Checks if the macro buffer has any characters left.
Returns: true if any characters left.
Definition at line 93 of file cmdb.cpp .
Gets the next character from the macro buffer and advances the macro buffer pointer.
Note: Do not call if no more characters are left!
Returns: the next character.
Definition at line 97 of file cmdb.cpp .
Gets the next character from the macro buffer but does not advance the macro buffer pointer.
Note: Do not call if no more characters are left!
Returns: the next character.
Definition at line 115 of file cmdb.cpp .
Resets the macro buffer and macro buffer pointer.
Definition at line 119 of file cmdb.cpp .
Gets the next character from the serial port by calling serial.getc().
Do not call if no characters are left!
Returns: the next character.
Definition at line 130 of file cmdb.cpp .
int print
(
const char *
msg )
print is simply printf without parameters using the serial parameter passed to the constructor.
msg the string to print.
Returns: the printf return value.
Definition at line 270 of file cmdb.cpp .
char printch
(
const char
ch )
printch is simply putc subsitute using the serial parameter passed to the constructor.
msg the string to print.
Returns: the printf return value.
Definition at line 369 of file cmdb.cpp .
int printerror
(
const char *
errormsg )
printerror prints an inifile Error Section Header and Error Msg Key=Value pair.
like:
[Error]={errormsg}
Usage: cmdb.printerror("Data Size Incorrect");
errormsg the error msg to print.
Returns: the printf return value.
Definition at line 286 of file cmdb.cpp .
int printerrorf
(
const char *
format ,
...
)
printerror prints an inifile Error Section Header and Error Msg Key=Value pair.
like:
[Error]={errormsg}
Usage: cmdb.printerrorf("Data Size Incorrect %d", 15);
format the error msg to print. parameter to print.
Returns: the printf return value.
Definition at line 291 of file cmdb.cpp .
int printf
(
const char *
format ,
...
)
int println
(
const char *
msg )
println is simply printf without parameters using the serial parameter passed to the constructor.
msg the string to print followed by a crlf.
Returns: the printf return value.
Definition at line 274 of file cmdb.cpp .
int printmsg
(
const char *
msg )
printmsg prints an inifile Msg Key=Value pair.
like:
Msg={msg}
Usage: cmdb.printmsg("Validation successfull");
msg the msg to print.
Returns: the printf return value.
Definition at line 282 of file cmdb.cpp .
int printsection
(
const char *
section )
printsection prints an inifile Section Header like:
[Section]
Usage: cmdb.printsection("GP");
section the section to print.
Returns: the printf return value.
Definition at line 278 of file cmdb.cpp .
int printvalue
(
const char *
key ,
const char *
value ,
const char *
comment = NoComment ,
const int
width = DefComPos
)
printvalue prints an inifile Key/Value Pair like:
Key=Value ;comment
Note the Comment is (if present) located at position 72.
key the key to print. value the value to print. comment the comment to print. width the location of the comment to print.
Returns: the printf return value.
Definition at line 346 of file cmdb.cpp .
int printvaluef
(
const char *
key ,
const int
width ,
const char *
comment ,
const char *
format ,
...
)
printvalue prints an inifile Key/Value Pair like:
Key=Value ;comment
Note: the Comment is (if present) located at position 72.
Usage: cmdb.printvaluef("Value", Cmdb::DefComPos , "Hex", "0x%8.8X", LPC_RTC->GPREG0);
key the key to print. comment the comment to print. width the location of the comment to print. format the value to print. parameter to print.
Returns: the printf return value.
Definition at line 319 of file cmdb.cpp .
int printvaluef
(
const char *
key ,
const char *
format ,
...
)
printvalue prints an inifile Key/Value Pair like:
Key=Value
Usage: cmdb.printvaluef("Value", "0x%8.8X", LPC_RTC->GPREG0);
key the key to print. format the value to print. parameter to print.
Returns: the printf return value.
Definition at line 306 of file cmdb.cpp .
bool scan
(
const char
c )
Add a character to the command being processed.
If a cr is added, the command is parsed and executed if possible If supported special keys are encountered (like backspace, delete and cursor up) they are processed.
Parameters:
Returns: true if a command was recognized and executed.
Definition at line 136 of file cmdb.cpp .
char* STRINGPARM
(
int
ndx )
Typecasts parameter ndx to a string.
Note: spaces are not allowed as it makes parsing so much harder.
mask: s
the parameter index
Returns: a string
Definition at line 763 of file cmdb.h .
unsigned int UINTPARM
(
int
ndx )
Typecasts parameter ndx to a unsigned int.
mask: u
the parameter index
Returns: a unsigned int
Definition at line 701 of file cmdb.h .
static float version
(
)
[static]
The version of the Command Interpreter.
returns the version.
Definition at line 426 of file cmdb.h .
unsigned int WORDPARM
(
int
ndx )
Typecasts parameter ndx to word/unsigned int.
mask: hu
the parameter index
Returns: a word/unsigned int
Definition at line 689 of file cmdb.h .
Field Documentation
Column 72 is used as Default Comment Starting Position.
Definition at line 436 of file cmdb.h .
NULL is used as No Comment Value.
Definition at line 432 of file cmdb.h .