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:
- 9:5e1764ff5dfa
- Parent:
- 8:30aa615d4508
- Child:
- 10:f269775edfdf
--- a/SDShell.cpp Wed May 08 06:16:46 2013 +0000 +++ b/SDShell.cpp Tue May 14 12:49:18 2013 +0000 @@ -6,6 +6,7 @@ SDShell::SDShell() { _debug = 0; + memset(_cwd, 0, SHELL_BUF_SIZE); return; } @@ -24,6 +25,7 @@ _cmds.attachMsg("rm" , this, &SDShell::rm); _cmds.attachMsg("exit" , this, &SDShell::exit); _cmds.attachMsg("debug", this, &SDShell::debug); + _cmds.attachMsg("du" , this, &SDShell::du); return; } @@ -41,6 +43,9 @@ while(0 == done) { + memset(_cmd , 0, SHELL_BUF_SIZE); + memset(_cmdline, 0, SHELL_BUF_SIZE); + memset(_newpath, 0, SHELL_BUF_SIZE); // gather input from the Serial object shellInput(); // break up the command line arguemnt @@ -278,6 +283,7 @@ char *SDShell::cat(char *cmd) { + memset(_buf, 0, 512); FILE *fp= fopen(_newpath, "r"); if (fp != NULL) { @@ -358,11 +364,28 @@ return (char *)OK; } -char SDShell::btoa(uint8_t b) +char *SDShell::du(char *cmd) { - return ((b&0xf) < 0xa) ? ((b&0xf)+0x30) : ((b&0xf)+0x37); + uint32_t file_size = 0; + memset(_buf, 0, 512); + + FILE *fp= fopen(_newpath, "rb"); + if (fp != NULL) + { + while (!feof(fp)) + { + uint32_t tmp = fread(_buf, 1, 512, fp); + file_size += tmp; + } + fclose(fp); + _com->printf(" %d (bytes) %s\n", file_size, _newpath); + } + else + { + _com->printf("%s: No such file\n", _newpath); + } + return (char *)OK; } -