Simple embedded shell with runtime pluggable commands.

Dependents:   DataBus2018

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

Files at this revision

API Documentation at this revision

Comitter:
shimniok
Date:
Wed Dec 12 18:30:49 2018 +0000
Parent:
7:b58450c94d32
Child:
9:05eb118e66d9
Commit message:
Added built-in help shell cmd, removed debug prints, display help on start.

Changed in this revision

SimpleShell.cpp Show annotated file Show diff for this revision Revisions of this file
SimpleShell.h Show annotated file Show diff for this revision Revisions of this file
--- a/SimpleShell.cpp	Wed Dec 12 17:58:27 2018 +0000
+++ b/SimpleShell.cpp	Wed Dec 12 18:30:49 2018 +0000
@@ -4,8 +4,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;
@@ -15,6 +29,7 @@
     strcpy(_cwd, "/log");
 
     printf("Type help for assistance.\n");
+    help();   
     while (!done) {
         printPrompt();
         readCommand();
@@ -39,10 +54,6 @@
         lookup[lookupEnd].command = command;
         lookupEnd++;
     }
-    
-    for (int i=0; i < lookupEnd; i++) {
-        printf("%s\n", lookup[i].command);
-    }
         
     return;
 }
--- a/SimpleShell.h	Wed Dec 12 17:58:27 2018 +0000
+++ b/SimpleShell.h	Wed Dec 12 18:30:49 2018 +0000
@@ -59,6 +59,9 @@
      * @return Callback to a function returning void
      */
     Callback<void()> findCommand();  
+    
+    /// Built-in shell command to display list of commands
+    void help();
 
     /// Prints command prompt
     void printPrompt(void);