Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed_controller_demo
Fork of CMDB by
main.cpp
- Committer:
- wvd_vegt
- Date:
- 2011-02-11
- Revision:
- 7:269c2445b8f5
- Child:
- 8:83edd6addbd5
File content as of revision 7:269c2445b8f5:
#include <vector>
#include "mbed.h"
#include "cmdb.h"
DigitalOut myled(LED1);
//We'll be using the Usb Serial port
Serial serial(USBTX, USBRX); //tx, rx
#define CID_TEST 1
#define CID_INT 2
/** Sample User Command Dispatcher.
*
* @parm cmdb the command interpreter object.
* @parm cid the command id.
*/
void my_dispatcher(Cmdb& cmdb, int cid) {
cmdb.printf("my_dispatcher: cid=%d\r\n", cid);
switch (cid) {
case CID_INT :
cmdb.printf("my_dispatcher: parm 0=%d\r\n",cmdb.INTPARM(0));
break;
}
}
const cmd c1("Test",SUBSYSTEM,CID_TEST,"" ,"* Test Subsystem");
const cmd c2("Int" ,CID_TEST ,CID_INT ,"%i","* Int as parameter" ,"dummy");
int main() {
// Set the Baudrate.
serial.baud(115200);
// Test the serial connection by
serial.printf("\r\n\r\nCmdb Command Interpreter Demo Version %0.2f.\r\n\r\n", Cmdb::version());
//Create a Command Table Vector.
std::vector<cmd> cmds;
//Add some of our own first...
cmds.push_back(c1); //Test Subsystem is handled by Cmdb internally.
cmds.push_back(c2); //The Int Command is handled by our 'my_dispatcher' method.
//Add some predefined...
cmds.push_back(BOOT); //Handled by Cmdb internally.
cmds.push_back(ECHO); //Handled by Cmdb internally.
cmds.push_back(BOLD); //Handled by Cmdb internally.
cmds.push_back(CLS); //Handled by Cmdb internally.
//Add some predefined and mandatory...
cmds.push_back(IDLE); //Handled by Cmdb internally.
cmds.push_back(HELP); //Handled by Cmdb internally.
//Create and initialize the Command Interpreter.
Cmdb cmdb(serial, cmds, &my_dispatcher);
while (1) {
//Check for input...
if (cmdb.hasnext()==true) {
//Supply input to Command Interpreter
if (cmdb.scan(cmdb.next())) {
//Flash led when a command has been parsed and dispatched.
myled = 1;
wait(0.2);
//cmdb.print("Command Parsed and Dispatched\r\n");
myled = 0;
wait(0.2);
}
}
}
}
