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"); }
SDShell.h
- Committer:
- sam_grove
- Date:
- 2013-04-27
- Revision:
- 1:514f321aa528
- Parent:
- 0:618e98bf18ce
- Child:
- 2:b3107e463974
File content as of revision 1:514f321aa528:
#ifndef SDSHELL_H #define SDSHELL_H #include "mbed.h" #include "SDFileSystem.h" #include "CommHandler.h" class SDShell { private: Serial *_com; SDFileSystem *_storage; CommHandler _cmds; #define SHELL_BUF_SIZE 64 #define SHELL_BUF_MASK (SHELL_BUF_SIZE-1) char _cwd[SHELL_BUF_SIZE]; // char _arg[SHELL_BUF_SIZE]; char _buf[128]; char _new_path[SHELL_BUF_SIZE]; char _cmd[SHELL_BUF_SIZE]; char _cmd_line[SHELL_BUF_SIZE]; char _path_to_file[SHELL_BUF_SIZE]; char *_arg; uint32_t _debug; void shellInput(void); char *split(char *dest, char *src, int max, char delim); void resolveDirectory(char *newpath, char *path); void splitName(char *path, char *dirname, char *basename); uint32_t match(char *arg1, char *arg2); void ls(char *path, Serial *pc) ; void cd(char *path); void pwd(Serial *pc); void head(char *path, Serial *pc); void cat(char *path, Serial *pc); void touch(char *path, Serial *pc); // char *ls(char *); // char *cd(char *); // char *pwd(char *); // char *head(char *); // char *cat(char *); // char *mkdir(char *); // char *touch(char *); // char *remove(char *); // char *resolvePath(char *string); public: SDShell(); void init(void); void shell(Serial &com, SDFileSystem &storage, char *cwd); }; #endif //void SDShell::shell(Serial &com, SDFileSystem &storage, char *cwd) //{ // // should check on the device here // _com = &com; // strcpy(_cwd, cwd); // // _com->printf("%s \n", _cwd); // print out the directory that we're in // while(1) // { // char c = _com->getc(); // if (c == '\r') // look for something to do // { // _cmds.serviceMessage(_rxbuf.data); // _com->printf("\nECHO: %s \n", _rxbuf.data); // // memset(_rxbuf.data, 0, _rxbuf.loc-1); // _rxbuf.loc = 0; // } // else if (c == 0x7f) // backspace // { // if (_rxbuf.loc > 0) // { // _rxbuf.loc--; // _com->printf("\b \b"); // } // } // else // { // _com->putc(c); // _rxbuf.data[_rxbuf.loc++] = c; // _rxbuf.loc &= SHELL_RXBUF_MASK; // } // } // return; //} // //// not working - need to pick back up here //char *SDShell::ls(char *string) //{ // //ls: lists files in the current working directory // _com->printf(" %s\n", _cwd); // // DIR *d = opendir(_cwd); // <- problem here?? // _com->printf(" %s\n", _cwd); // if(d != NULL) // { // struct dirent *p; // _com->printf(" %s\n", _cwd); // do // { // p = readdir(d); // doesn't take parameter?? where does this go? // _com->printf(" file: %s\n", p->d_name); // } // while(p != NULL); // // closedir(d); // } // else // { // _com->printf("%s: No such directory\n", _cwd); // } // // return string; //} // //char *SDShell::cd(char *string){ return string;} //char *SDShell::pwd(char *string){ return string;} //char *SDShell::head(char *string){ return string;} // //char *SDShell::cat(char *string) //{ // // display the content of a file eg: cat readme.txt // resolvePath((string+4)); // // FILE *fp = fopen(_path_to_file, "r"); // if(NULL != fp) // { // char *buf = new char [1024]; // while (!feof(fp)) // { // fgets(buf, sizeof(buf), fp); // _com->printf("%s", buf); // } // fclose(fp); // delete [] buf; // } // else // { // _com->printf("\n%s: No such file\n", _path_to_file); // } // // return string; // } // //char *SDShell::mkdir(char *string){ return string;} //char *SDShell::touch(char *string){ return string;} //char *SDShell::remove(char *string){ return string;} // //char *SDShell::resolvePath(char *string) //{ // strcpy(_path_to_file, _cwd); // strcat(_path_to_file, "/"); // strcat(_path_to_file, string); // // return _path_to_file; //}