A UNIX emulation shell to access the underlying SDCard FileSystem through a terminal interface
Information
Dependencies not included with library:
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"); }
Diff: SDShell.cpp
- Revision:
- 4:6ff0a3d92778
- Parent:
- 2:b3107e463974
- Child:
- 5:3417ba8cb1e4
--- a/SDShell.cpp Sun May 05 16:58:01 2013 +0000 +++ b/SDShell.cpp Sun May 05 18:39:35 2013 +0000 @@ -18,6 +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("mkdir", this, &SDShell::create); _cmds.attachMsg("touch", this, &SDShell::touch); _cmds.attachMsg("rm" , this, &SDShell::rm); @@ -62,8 +63,7 @@ { uint32_t cnt = 1; LOG("Unknown Message from Terminal: Options are\n"); - do - { + do{ result = _cmds.messageLookup(cnt++); _com->printf(" %s\n", result); } while(result != NULL); @@ -296,6 +296,26 @@ return (char *)OK; } +char *SDShell::catb(char *cmd) +{ + FILE *fp= fopen(_newpath, "rb"); + if (fp != NULL) + { + while (!feof(fp)) + { + fread(_buf, 1, 1, fp); + _com->printf("%c", _buf); + } + fclose(fp); + } + else + { + _com->printf("%s: No such file\n", _newpath); + } + + return (char *)OK; +} + char *SDShell::touch(char *cmd) { FILE *fp = fopen(_newpath, "w");