Simple embedded shell with runtime pluggable commands.

Dependents:   DataBus2018

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

Revision:
11:23f61057d877
Parent:
10:c3faa7ffd23b
Parent:
8:41b7274a9753
Child:
12:ecf3fc049bca
--- a/SimpleShell.cpp	Thu Dec 13 08:56:58 2018 +0000
+++ b/SimpleShell.cpp	Thu Dec 13 09:00:28 2018 +0000
@@ -6,8 +6,22 @@
 SimpleShell::SimpleShell()
 {
     lookupEnd = 0;
+    // Built-in shell commands
+    attach(callback(this, &SimpleShell::help), "help");
+    // TODO: cd
 }
 
+
+void SimpleShell::help()
+{
+    printf("Available commands: ");
+    for (int i=0; i < lookupEnd; i++) {
+        printf("%s ", lookup[i].command);
+    }
+    printf("\n\n");
+}
+
+
 void SimpleShell::run()
 {
     bool done=false;
@@ -17,6 +31,7 @@
     strcpy(_cwd, "/log");
 
     printf("Type help for assistance.\n");
+    help();   
     while (!done) {
         printPrompt();
         readCommand();
@@ -41,10 +56,6 @@
         lookup[lookupEnd].command = command;
         lookupEnd++;
     }
-    
-    for (int i=0; i < lookupEnd; i++) {
-        printf("%s\n", lookup[i].command);
-    }
         
     return;
 }