Simple embedded shell with runtime pluggable commands.

Dependents:   DataBus2018

Implements a simple unix-like shell for embedded systems with a pluggable command architecture.

Revision:
15:242626d8d104
Parent:
14:75b5918090ae
Child:
16:f2b9b7b2c71e
--- a/SimpleShell.cpp	Wed Dec 19 00:29:05 2018 +0000
+++ b/SimpleShell.cpp	Wed Dec 19 18:25:12 2018 +0000
@@ -25,7 +25,7 @@
 }
 
 
-void SimpleShell::help()
+void SimpleShell::help(int argc, char **argv)
 {
     printf("Available commands: ");
     for (int i=0; i < lookupEnd; i++) {
@@ -35,7 +35,7 @@
 }
 
 
-void SimpleShell::pwd()
+void SimpleShell::pwd(int argc, char **argv)
 {
     puts(_cwd);
     return;
@@ -45,7 +45,7 @@
 void SimpleShell::run()
 {
     bool done=false;
-    Callback<void()> cb;
+    callback_t cb;
     //int status; // TODO implement command status return
     std::string x;
     
@@ -53,13 +53,13 @@
     strncpy(_cwd, "/log", MAXBUF);
 
     printf("Type help for assistance.\n");
-    help();   
+    help(0, NULL);   
     while (!done) {
         printPrompt();
         readCommand();
         if (argv[0]) { // skip blank command
             if (cb = findCommand()) {
-                cb.call();
+                cb.call(argc, argv);
             } else {
                 printf("command <%s> not found\n", argv[0]);
             }
@@ -71,7 +71,7 @@
 }
 
 
-void SimpleShell::attach(Callback<void()> cb, char *command) 
+void SimpleShell::attach(callback_t cb, char *command) 
 {  
     if (lookupEnd < MAXLOOKUP) {
         lookup[lookupEnd].cb = cb;
@@ -83,9 +83,9 @@
 }
 
 
-Callback<void()> SimpleShell::findCommand()
+SimpleShell::callback_t SimpleShell::findCommand()
 {
-    Callback<void()> cb=NULL;
+    SimpleShell::callback_t cb=NULL;
     
     for (int i=0; i < lookupEnd; i++) {
         if (strncmp(argv[0], lookup[i].command, MAXBUF) == 0) {
@@ -193,10 +193,6 @@
         argv[argc++] = t;
         t = strtok(NULL, " ");
     }
-    // Print out argv
-    for (int i=0; i < argc; i++) {
-        printf("argv[%d] = <%s>\n", i, argv[i]);
-    }
 
     return;
 }
\ No newline at end of file