A UNIX emulation shell to access the underlying SDCard FileSystem through a terminal interface

Dependents:   Waldo_Embed_V2

Information

SDShell does not change the com baudrate. Access is made using the baud as initialized by the Serial object when passed into the SDShell object

Example

#include "mbed.h"
#include "SDFileSystem.h"
#include "SDShell.h"

Serial com(USBTX, USBRX);
SDFileSystem sd(p11, p12, p13, p14, "sd");
SDShell emulate;

int main()
{
    emulate.init();
    emulate.shell(com, sd, "/sd");
}
Revision:
5:3417ba8cb1e4
Parent:
4:6ff0a3d92778
Child:
6:743600852c66
--- a/SDShell.cpp	Sun May 05 18:39:35 2013 +0000
+++ b/SDShell.cpp	Mon May 06 04:04:18 2013 +0000
@@ -18,7 +18,7 @@
     _cmds.attachMsg("pwd"  , this, &SDShell::pwd);
     _cmds.attachMsg("head" , this, &SDShell::head);
     _cmds.attachMsg("cat"  , this, &SDShell::cat);
-    _cmds.attachMsg("catb" , this, &SDShell::catb);
+    _cmds.attachMsg("bcat" , this, &SDShell::bcat);
     _cmds.attachMsg("mkdir", this, &SDShell::create);
     _cmds.attachMsg("touch", this, &SDShell::touch);
     _cmds.attachMsg("rm"   , this, &SDShell::rm);
@@ -296,15 +296,20 @@
     return (char *)OK;
 }
 
-char *SDShell::catb(char *cmd)
+char *SDShell::bcat(char *cmd)
 {
+    char buf[2] = {NULL};
     FILE *fp= fopen(_newpath, "rb");
     if (fp != NULL)
     {
         while (!feof(fp))
         {
             fread(_buf, 1, 1, fp);
-            _com->printf("%c", _buf);
+            buf[1] = btoa(_buf[0]);
+            buf[0] = btoa(_buf[0]>>4);
+            //_com->printf("%c%c", buf[0], buf[1]);
+            _com->putc(buf[0]);
+            _com->putc(buf[1]);
         }
         fclose(fp);
     }
@@ -312,7 +317,6 @@
     {
         _com->printf("%s: No such file\n", _newpath);
     }
-    
     return (char *)OK;
 }
 
@@ -358,6 +362,11 @@
     return (char *)OK;
 }
 
+char SDShell::btoa(uint8_t b)
+{
+    return ((b&0xf) < 0xa) ? ((b&0xf)+0x30) : ((b&0xf)+0x37);
+}
 
 
 
+