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:
Sun Dec 02 17:09:08 2018 +0000
Parent:
1:998a7ed04f10
Child:
3:ebb4893f033d
Commit message:
implemented attach command basics

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	Sun Dec 02 16:50:40 2018 +0000
+++ b/SimpleShell.cpp	Sun Dec 02 17:09:08 2018 +0000
@@ -2,6 +2,7 @@
 
 SimpleShell::SimpleShell()
 {
+    lookupEnd = 0;
 }
 
 void SimpleShell::run()
@@ -21,7 +22,19 @@
 }
 
 
-void SimpleShell::attach(Callback<void()> cb, char *command) {
+void SimpleShell::attach(Callback<void()> cb, char *command) 
+{  
+    if (lookupEnd < MAXLOOKUP) {
+        lookup[lookupEnd].cb = cb;
+        lookup[lookupEnd].command = command;
+        lookupEnd++;
+    }
+    
+    for (int i=0; i < lookupEnd; i++) {
+        printf("%s\n", lookup[i].command);
+    }
+        
+    return;
 }
 
 
@@ -30,6 +43,8 @@
     fputc('(', stdout);
     fputs(_cwd, stdout);
     fputs(")# ", stdout);
+    
+    return;
 }
 
 
@@ -60,5 +75,5 @@
     } while (!done);
     fputc('\n', stdout);
 
-
+    return;
 }
\ No newline at end of file
--- a/SimpleShell.h	Sun Dec 02 16:50:40 2018 +0000
+++ b/SimpleShell.h	Sun Dec 02 17:09:08 2018 +0000
@@ -1,5 +1,11 @@
 #include "mbed.h"
 
+typedef struct {
+    char *command;
+    Callback<void()> cb;
+} command_entry_t;
+
+
 class SimpleShell {
 public:  
     SimpleShell();
@@ -11,8 +17,11 @@
     
 private:
     static const int MAXBUF=128;
+    static const int MAXLOOKUP=32;
     void printPrompt(void);
     void readCommand();
+    command_entry_t lookup[MAXLOOKUP];
+    int lookupEnd;
     char cmd[MAXBUF];
     char _cwd[MAXBUF];
 }; // class
\ No newline at end of file