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
Diff: cmdb.h
- Revision:
- 17:7e6a723d65de
- Parent:
- 16:ec8147828286
- Child:
- 18:7a4dc478d022
--- a/cmdb.h Thu Mar 24 21:40:58 2011 +0000
+++ b/cmdb.h Mon Sep 05 10:05:49 2011 +0000
@@ -150,7 +150,7 @@
parmdescr = (char*)malloc(strlen(_parmdescr)+1);
strcpy(parmdescr,_parmdescr);
-
+
//printf("%d:%d\r\n", subs, cid);
}
};
@@ -382,30 +382,30 @@
/** The Command Interpreter Version.
*/
-#define CMDB_VERSION 0.77
+#define CMDB_VERSION 0.78
//------------------------------------------------------------------------------
/** 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);
+ * 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 main.cpp for a demo.
*/
class Cmdb {
@@ -419,7 +419,7 @@
* @param serial a Serial port used for communication.
* @param cmds a vector with the command table.
*/
- Cmdb(const Serial& serial, const std::vector<cmd>& cmds, void (*callback)(Cmdb&,int) );
+ Cmdb(const Serial& _serial, std::vector<cmd>& _cmds, void (*_callback)(Cmdb&,int) );
/** The version of the Command Interpreter.
*
@@ -645,8 +645,63 @@
return parms[ndx].val.s;
}
+ bool present(char *cmdstr) {
+ return cmdid_search(cmdstr)!=CID_LAST;
+ }
+
+ void replace(std::vector<cmd>& newcmds) {
+ cmds.assign(newcmds.begin(), newcmds.end());
+ }
+
+
+ int indexof(int cid) {
+ return cmdid_index(cid);
+ }
+
+ //FAILS...
+ /*
+ void insert(int cid, cmd newcmd) {
+ //Add Command (update our original and then assign/replace cmdb's copy)...
+ vector<cmd>::iterator iter;
+
+ std::vector<cmd> newcmds = std::vector<cmd>(cmds);
+
+ iter = newcmds.begin();
+
+ newcmds.insert(iter+indexof(cid)+1,newcmd);
+
+ replace(newcmds);
+
+ printf("Index: %d\r\n", ndx);
+
+ print("check #1\r\n");
+ print("check #2\r\n");
+
+ vector<cmd>::iterator it;
+ it=newcmds.begin();
+
+ print("check #3\r\n");
+ ndx++;
+ newcmds.insert(it, newcmd);
+ print("check #4\r\n");
+
+ //cmds.push_back(c1);
+ cmds.assign(newcmds.begin(), newcmds.end());
+ }
+ */
+
private:
+ /** Internal Serial Port Storage.
+ */
+ Serial serial;
+
+ /** Internal Command Table Vector Storage.
+ *
+ * @see http://www.cplusplus.com/reference/stl/vector/
+ */
+ std::vector<cmd> cmds;
+
/** C callback function
*
* @see See http://www.newty.de/fpt/fpt.html#chapter2 for function pointers.
@@ -730,16 +785,6 @@
*/
int stricmp (char *s1, char *s2);
- /** Internal Serial Port Storage.
- */
- Serial serial;
-
- /** Internal Command Table Vector Storage.
- *
- * @see http://www.cplusplus.com/reference/stl/vector/
- */
- std::vector<cmd> cmds;
-
/** Internal Echo Flag Storage.
*/
bool echo;
