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:
Thu Dec 13 23:26:34 2018 +0000
Parent:
12:ecf3fc049bca
Child:
14:75b5918090ae
Commit message:
fixed special key handling, added pwd

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	Thu Dec 13 09:19:51 2018 +0000
+++ b/SimpleShell.cpp	Thu Dec 13 23:26:34 2018 +0000
@@ -1,5 +1,6 @@
 #include "SimpleShell.h"
 #include <ctype.h>
+#include <string>
 
 #define ESC     0x1b
 #define UP      0x41
@@ -17,9 +18,10 @@
 SimpleShell::SimpleShell()
 {
     lookupEnd = 0;
+
     // Built-in shell commands
     attach(callback(this, &SimpleShell::help), "help");
-    // TODO: cd
+    attach(callback(this, &SimpleShell::pwd), "pwd");
 }
 
 
@@ -33,13 +35,22 @@
 }
 
 
+void SimpleShell::pwd()
+{
+    puts(_cwd);
+    return;
+}
+
+
 void SimpleShell::run()
 {
     bool done=false;
     Callback<void()> cb;
     //int status; // TODO implement command status return
+    std::string x;
     
-    strcpy(_cwd, "/log");
+    // Set current working directory
+    strncpy(_cwd, "/log", MAXBUF);
 
     printf("Type help for assistance.\n");
     help();   
--- a/SimpleShell.h	Thu Dec 13 09:19:51 2018 +0000
+++ b/SimpleShell.h	Thu Dec 13 23:26:34 2018 +0000
@@ -64,6 +64,9 @@
     /// Built-in shell command to display list of commands
     void help();
 
+    /// Built-in shell command to print working directory
+    void pwd();
+
     /// Prints command prompt
     void printPrompt(void);