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@13:6c520cfc50b2, 2013-05-27 (annotated)
- Committer:
- sam_grove
- Date:
- Mon May 27 15:00:05 2013 +0000
- Revision:
- 13:6c520cfc50b2
- Parent:
- 10:f269775edfdf
updated bcat to read 512 byte blocks
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:618e98bf18ce | 1 | |
sam_grove | 2:b3107e463974 | 2 | /** |
sam_grove | 10:f269775edfdf | 3 | * @file SDShell.h |
sam_grove | 2:b3107e463974 | 4 | * @brief SD Card Utility - Emulate a basic UNIX terminal interface |
sam_grove | 2:b3107e463974 | 5 | * @author sam grove |
sam_grove | 2:b3107e463974 | 6 | * @version 1.0 |
sam_grove | 2:b3107e463974 | 7 | * @see |
sam_grove | 2:b3107e463974 | 8 | * |
sam_grove | 2:b3107e463974 | 9 | * Copyright (c) 2013 |
sam_grove | 2:b3107e463974 | 10 | * |
sam_grove | 2:b3107e463974 | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sam_grove | 2:b3107e463974 | 12 | * you may not use this file except in compliance with the License. |
sam_grove | 2:b3107e463974 | 13 | * You may obtain a copy of the License at |
sam_grove | 2:b3107e463974 | 14 | * |
sam_grove | 2:b3107e463974 | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
sam_grove | 2:b3107e463974 | 16 | * |
sam_grove | 2:b3107e463974 | 17 | * Unless required by applicable law or agreed to in writing, software |
sam_grove | 2:b3107e463974 | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
sam_grove | 2:b3107e463974 | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sam_grove | 2:b3107e463974 | 20 | * See the License for the specific language governing permissions and |
sam_grove | 2:b3107e463974 | 21 | * limitations under the License. |
sam_grove | 2:b3107e463974 | 22 | */ |
sam_grove | 2:b3107e463974 | 23 | |
sam_grove | 0:618e98bf18ce | 24 | #ifndef SDSHELL_H |
sam_grove | 0:618e98bf18ce | 25 | #define SDSHELL_H |
sam_grove | 0:618e98bf18ce | 26 | |
sam_grove | 0:618e98bf18ce | 27 | #include "mbed.h" |
sam_grove | 0:618e98bf18ce | 28 | #include "SDFileSystem.h" |
sam_grove | 0:618e98bf18ce | 29 | #include "CommHandler.h" |
sam_grove | 10:f269775edfdf | 30 | #include "crc.h" |
sam_grove | 0:618e98bf18ce | 31 | |
sam_grove | 2:b3107e463974 | 32 | /** Example using the CommHandler class |
sam_grove | 2:b3107e463974 | 33 | * @code |
sam_grove | 2:b3107e463974 | 34 | * #include "mbed.h" |
sam_grove | 2:b3107e463974 | 35 | * #include "SDFileSystem.h" |
sam_grove | 2:b3107e463974 | 36 | * #include "SDShell.h" |
sam_grove | 2:b3107e463974 | 37 | * |
sam_grove | 2:b3107e463974 | 38 | * Serial com(USBTX, USBRX); |
sam_grove | 2:b3107e463974 | 39 | * SDFileSystem sd(p11, p12, p13, p14, "sd"); |
sam_grove | 2:b3107e463974 | 40 | * SDShell emulate; |
sam_grove | 2:b3107e463974 | 41 | * |
sam_grove | 2:b3107e463974 | 42 | * int main() |
sam_grove | 2:b3107e463974 | 43 | * { |
sam_grove | 2:b3107e463974 | 44 | * emulate.init(); |
sam_grove | 2:b3107e463974 | 45 | * emulate.shell(com, sd, "/sd"); |
sam_grove | 2:b3107e463974 | 46 | * } |
sam_grove | 2:b3107e463974 | 47 | * @endcode |
sam_grove | 2:b3107e463974 | 48 | */ |
sam_grove | 2:b3107e463974 | 49 | |
sam_grove | 2:b3107e463974 | 50 | /** |
sam_grove | 2:b3107e463974 | 51 | * @class SDShell |
sam_grove | 2:b3107e463974 | 52 | * @brief API abstraction for a UNIX terminal enumator to the SDFileSystem |
sam_grove | 2:b3107e463974 | 53 | */ |
sam_grove | 0:618e98bf18ce | 54 | class SDShell |
sam_grove | 0:618e98bf18ce | 55 | { |
sam_grove | 2:b3107e463974 | 56 | public: |
sam_grove | 2:b3107e463974 | 57 | |
sam_grove | 2:b3107e463974 | 58 | /** Create the SDShell object |
sam_grove | 2:b3107e463974 | 59 | */ |
sam_grove | 2:b3107e463974 | 60 | SDShell(); |
sam_grove | 2:b3107e463974 | 61 | |
sam_grove | 2:b3107e463974 | 62 | /** Initialize members and compenents of the class |
sam_grove | 2:b3107e463974 | 63 | */ |
sam_grove | 2:b3107e463974 | 64 | void init(void); |
sam_grove | 2:b3107e463974 | 65 | |
sam_grove | 2:b3107e463974 | 66 | /** Run the UNIX terminal emulator |
sam_grove | 2:b3107e463974 | 67 | * @param com - Address of an initialized Serial object |
sam_grove | 2:b3107e463974 | 68 | * @param storage - Address of an initialized SDFileSystem object |
sam_grove | 2:b3107e463974 | 69 | * @cwd - The name used to access the virtual filesystem |
sam_grove | 2:b3107e463974 | 70 | */ |
sam_grove | 2:b3107e463974 | 71 | void shell(Serial &com, SDFileSystem &storage, char const *cwd); |
sam_grove | 2:b3107e463974 | 72 | |
sam_grove | 0:618e98bf18ce | 73 | private: |
sam_grove | 0:618e98bf18ce | 74 | Serial *_com; |
sam_grove | 0:618e98bf18ce | 75 | SDFileSystem *_storage; |
sam_grove | 0:618e98bf18ce | 76 | CommHandler _cmds; |
sam_grove | 0:618e98bf18ce | 77 | |
sam_grove | 1:514f321aa528 | 78 | #define SHELL_BUF_SIZE 64 |
sam_grove | 1:514f321aa528 | 79 | #define SHELL_BUF_MASK (SHELL_BUF_SIZE-1) |
sam_grove | 1:514f321aa528 | 80 | char _cwd[SHELL_BUF_SIZE]; |
sam_grove | 2:b3107e463974 | 81 | char _buf[512]; |
sam_grove | 2:b3107e463974 | 82 | char _newpath[SHELL_BUF_SIZE]; |
sam_grove | 1:514f321aa528 | 83 | char _cmd[SHELL_BUF_SIZE]; |
sam_grove | 2:b3107e463974 | 84 | char _cmdline[SHELL_BUF_SIZE]; |
sam_grove | 1:514f321aa528 | 85 | char *_arg; |
sam_grove | 1:514f321aa528 | 86 | uint32_t _debug; |
sam_grove | 0:618e98bf18ce | 87 | |
sam_grove | 2:b3107e463974 | 88 | enum {UNKNOWN = 0, OK = '1', EXIT = '2'}; |
sam_grove | 2:b3107e463974 | 89 | |
sam_grove | 2:b3107e463974 | 90 | // helper functions that build the interface |
sam_grove | 1:514f321aa528 | 91 | void shellInput(void); |
sam_grove | 1:514f321aa528 | 92 | char *split(char *dest, char *src, int max, char delim); |
sam_grove | 1:514f321aa528 | 93 | void resolveDirectory(char *newpath, char *path); |
sam_grove | 1:514f321aa528 | 94 | void splitName(char *path, char *dirname, char *basename); |
sam_grove | 5:3417ba8cb1e4 | 95 | uint32_t match(char *arg1, char *arg2); |
sam_grove | 1:514f321aa528 | 96 | |
sam_grove | 2:b3107e463974 | 97 | // handler functions for each known input |
sam_grove | 2:b3107e463974 | 98 | char *ls(char *cmd); |
sam_grove | 2:b3107e463974 | 99 | char *cd(char *cmd); |
sam_grove | 2:b3107e463974 | 100 | char *pwd(char *cmd); |
sam_grove | 2:b3107e463974 | 101 | char *head(char *cmd); |
sam_grove | 2:b3107e463974 | 102 | char *cat(char *cmd); |
sam_grove | 5:3417ba8cb1e4 | 103 | char *bcat(char *cmd); |
sam_grove | 2:b3107e463974 | 104 | char *touch(char *cmd); |
sam_grove | 2:b3107e463974 | 105 | char *create(char *cmd); |
sam_grove | 2:b3107e463974 | 106 | char *rm(char *cmd); |
sam_grove | 2:b3107e463974 | 107 | char *exit(char *cmd); |
sam_grove | 9:5e1764ff5dfa | 108 | char *debug(char *cmd); |
sam_grove | 9:5e1764ff5dfa | 109 | char *du(char *cmd); |
sam_grove | 10:f269775edfdf | 110 | char *cksum(char* cmd); |
sam_grove | 0:618e98bf18ce | 111 | }; |
sam_grove | 0:618e98bf18ce | 112 | |
sam_grove | 0:618e98bf18ce | 113 | #endif |