Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
SimpleShell.h@6:4da092220ba8, 2018-12-12 (annotated)
- Committer:
- shimniok
- Date:
- Wed Dec 12 17:46:29 2018 +0000
- Revision:
- 6:4da092220ba8
- Parent:
- 4:8b8fa59d0015
- Child:
- 7:b58450c94d32
Added documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 6:4da092220ba8 | 1 | #ifndef __SIMPLESHELL_H |
shimniok | 6:4da092220ba8 | 2 | #define __SIMPLESHELL_H |
shimniok | 6:4da092220ba8 | 3 | |
shimniok | 0:49820d5a38c9 | 4 | #include "mbed.h" |
shimniok | 0:49820d5a38c9 | 5 | |
shimniok | 6:4da092220ba8 | 6 | /** SimpleShell |
shimniok | 6:4da092220ba8 | 7 | * A simple, flexible, embedded shell with dynamically added shell commands. |
shimniok | 6:4da092220ba8 | 8 | */ |
shimniok | 0:49820d5a38c9 | 9 | class SimpleShell { |
shimniok | 0:49820d5a38c9 | 10 | public: |
shimniok | 6:4da092220ba8 | 11 | /// Create a new shell instance |
shimniok | 0:49820d5a38c9 | 12 | SimpleShell(); |
shimniok | 0:49820d5a38c9 | 13 | |
shimniok | 6:4da092220ba8 | 14 | /// Call this to run the shell in a thread |
shimniok | 3:ebb4893f033d | 15 | void run(); |
shimniok | 6:4da092220ba8 | 16 | |
shimniok | 6:4da092220ba8 | 17 | /** Attaches a shell command |
shimniok | 6:4da092220ba8 | 18 | * @param cb is the callback function that implements the command |
shimniok | 6:4da092220ba8 | 19 | * @param command is the string used to invoke the command in the shell |
shimniok | 6:4da092220ba8 | 20 | */ |
shimniok | 1:998a7ed04f10 | 21 | void attach(Callback<void()> cb, char *command); |
shimniok | 6:4da092220ba8 | 22 | |
shimniok | 6:4da092220ba8 | 23 | /** finds and eturns the callback for a command |
shimniok | 6:4da092220ba8 | 24 | * @return Callback to a function returning void |
shimniok | 6:4da092220ba8 | 25 | */ |
shimniok | 3:ebb4893f033d | 26 | Callback<void()> findCommand(); |
shimniok | 0:49820d5a38c9 | 27 | |
shimniok | 0:49820d5a38c9 | 28 | private: |
shimniok | 6:4da092220ba8 | 29 | typedef struct { |
shimniok | 6:4da092220ba8 | 30 | char *command; |
shimniok | 6:4da092220ba8 | 31 | Callback<void()> cb; |
shimniok | 6:4da092220ba8 | 32 | } command_entry_t; |
shimniok | 6:4da092220ba8 | 33 | |
shimniok | 4:8b8fa59d0015 | 34 | static const int MAXBUF=32; |
shimniok | 2:4f0affdb7db9 | 35 | static const int MAXLOOKUP=32; |
shimniok | 0:49820d5a38c9 | 36 | void printPrompt(void); |
shimniok | 0:49820d5a38c9 | 37 | void readCommand(); |
shimniok | 2:4f0affdb7db9 | 38 | command_entry_t lookup[MAXLOOKUP]; |
shimniok | 2:4f0affdb7db9 | 39 | int lookupEnd; |
shimniok | 0:49820d5a38c9 | 40 | char cmd[MAXBUF]; |
shimniok | 0:49820d5a38c9 | 41 | char _cwd[MAXBUF]; |
shimniok | 6:4da092220ba8 | 42 | }; // class |
shimniok | 6:4da092220ba8 | 43 | |
shimniok | 6:4da092220ba8 | 44 | #endif |