Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
SimpleShell.h@3:ebb4893f033d, 2018-12-02 (annotated)
- Committer:
- shimniok
- Date:
- Sun Dec 02 17:14:28 2018 +0000
- Revision:
- 3:ebb4893f033d
- Parent:
- 2:4f0affdb7db9
- Child:
- 4:8b8fa59d0015
Stubbed command lookup
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 | 3:ebb4893f033d | 13 | void run(); |
shimniok | 1:998a7ed04f10 | 14 | void attach(Callback<void()> cb, char *command); |
shimniok | 3:ebb4893f033d | 15 | Callback<void()> findCommand(); |
shimniok | 0:49820d5a38c9 | 16 | |
shimniok | 0:49820d5a38c9 | 17 | private: |
shimniok | 0:49820d5a38c9 | 18 | static const int MAXBUF=128; |
shimniok | 2:4f0affdb7db9 | 19 | static const int MAXLOOKUP=32; |
shimniok | 0:49820d5a38c9 | 20 | void printPrompt(void); |
shimniok | 0:49820d5a38c9 | 21 | void readCommand(); |
shimniok | 2:4f0affdb7db9 | 22 | command_entry_t lookup[MAXLOOKUP]; |
shimniok | 2:4f0affdb7db9 | 23 | int lookupEnd; |
shimniok | 0:49820d5a38c9 | 24 | char cmd[MAXBUF]; |
shimniok | 0:49820d5a38c9 | 25 | char _cwd[MAXBUF]; |
shimniok | 0:49820d5a38c9 | 26 | }; // class |