Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
SimpleShell.h@2:4f0affdb7db9, 2018-12-02 (annotated)
- Committer:
- shimniok
- Date:
- Sun Dec 02 17:09:08 2018 +0000
- Revision:
- 2:4f0affdb7db9
- Parent:
- 1:998a7ed04f10
- Child:
- 3:ebb4893f033d
implemented attach command basics
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:49820d5a38c9 | 1 | #include "mbed.h" |
shimniok | 0:49820d5a38c9 | 2 | |
shimniok | 2:4f0affdb7db9 | 3 | typedef struct { |
shimniok | 2:4f0affdb7db9 | 4 | char *command; |
shimniok | 2:4f0affdb7db9 | 5 | Callback<void()> cb; |
shimniok | 2:4f0affdb7db9 | 6 | } command_entry_t; |
shimniok | 2:4f0affdb7db9 | 7 | |
shimniok | 2:4f0affdb7db9 | 8 | |
shimniok | 0:49820d5a38c9 | 9 | class SimpleShell { |
shimniok | 0:49820d5a38c9 | 10 | public: |
shimniok | 0:49820d5a38c9 | 11 | SimpleShell(); |
shimniok | 0:49820d5a38c9 | 12 | |
shimniok | 1:998a7ed04f10 | 13 | void attach(Callback<void()> cb, char *command); |
shimniok | 0:49820d5a38c9 | 14 | |
shimniok | 0:49820d5a38c9 | 15 | // void registerCommand(char *commandString, char *helpText, Callback<void(float)> cb); |
shimniok | 0:49820d5a38c9 | 16 | void run(); |
shimniok | 0:49820d5a38c9 | 17 | |
shimniok | 0:49820d5a38c9 | 18 | private: |
shimniok | 0:49820d5a38c9 | 19 | static const int MAXBUF=128; |
shimniok | 2:4f0affdb7db9 | 20 | static const int MAXLOOKUP=32; |
shimniok | 0:49820d5a38c9 | 21 | void printPrompt(void); |
shimniok | 0:49820d5a38c9 | 22 | void readCommand(); |
shimniok | 2:4f0affdb7db9 | 23 | command_entry_t lookup[MAXLOOKUP]; |
shimniok | 2:4f0affdb7db9 | 24 | int lookupEnd; |
shimniok | 0:49820d5a38c9 | 25 | char cmd[MAXBUF]; |
shimniok | 0:49820d5a38c9 | 26 | char _cwd[MAXBUF]; |
shimniok | 0:49820d5a38c9 | 27 | }; // class |