Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
Revision 23:b1e49cfcaef6, committed 2018-12-24
- Comitter:
- shimniok
- Date:
- Mon Dec 24 18:35:29 2018 +0000
- Parent:
- 22:b0e6d416ce99
- Child:
- 24:004e33abce37
- Commit message:
- add send command
Changed in this revision
SimpleShell.cpp | Show annotated file Show diff for this revision Revisions of this file |
SimpleShell.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SimpleShell.cpp Mon Dec 24 17:44:29 2018 +0000 +++ b/SimpleShell.cpp Mon Dec 24 18:35:29 2018 +0000 @@ -28,6 +28,12 @@ } +char *SimpleShell::basename(char *path) { + return path; +} + + + SimpleShell::SimpleShell() { lookupEnd = 0; @@ -40,6 +46,7 @@ attach(callback(this, &SimpleShell::rm), "rm"); attach(callback(this, &SimpleShell::touch), "touch"); attach(callback(this, &SimpleShell::ls), "ls"); + attach(callback(this, &SimpleShell::send), "send"); } @@ -168,6 +175,27 @@ } +void SimpleShell::send(int argc, char **argv) +{ + const char SOF=0x01; + const char ETX=0x03; + const char EOT=0x04; + const char ACK=0x07; + const char NACK=0x18; + FILE *fp; + + int i = 1; + if (argc >= 2) { + if ((fp = fopen(canon(argv[i]), "r")) == 0) { + printf("%s: can't open file\n", basename(argv[i])); + } else { + } + } else { + puts("usage: send file1 [file2 ...]"); + } +} + + void SimpleShell::run() { bool done=false;
--- a/SimpleShell.h Mon Dec 24 17:44:29 2018 +0000 +++ b/SimpleShell.h Mon Dec 24 18:35:29 2018 +0000 @@ -63,6 +63,9 @@ /// canonicalize path char *canon(char *path); + /// return basename of path + char *basename(char *path); + /** finds and eturns the callback for a command * @return Callback to a function returning void */ @@ -88,6 +91,9 @@ /// Built-in shell command to display contents of file void cat(int argc, char **argv); + + /// Built-in shell command to display contents of file + void send(int argc, char **argv); /// Prints command prompt void printPrompt(void);