amiro-os / os / core / inc / aos_shell.h @ bc5cdb79
History | View | Annotate | Download (4.372 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
#ifndef _AMIROOS_SHELL_H_
|
20 |
#define _AMIROOS_SHELL_H_
|
21 |
|
22 |
#include <hal.h> |
23 |
#include <aos_types.h> |
24 |
|
25 |
/**
|
26 |
* @brief Shell event flag that is emitted when the thread starts.
|
27 |
*/
|
28 |
#define AOS_SHELL_EVTFLAG_START ((eventflags_t)(1 << 0)) |
29 |
|
30 |
/**
|
31 |
* @brief Shell event flag that is emitted when a command is executed.
|
32 |
*/
|
33 |
#define AOS_SHELL_EVTFLAG_EXEC ((eventflags_t)(1 << 1)) |
34 |
|
35 |
/**
|
36 |
* @brief Shell event flag that is emitted when a command execution finished.
|
37 |
*/
|
38 |
#define AOS_SHELL_EVTFLAG_DONE ((eventflags_t)(1 << 2)) |
39 |
|
40 |
/**
|
41 |
* @brief Shell event flag that is emitted when the shread stops.
|
42 |
*/
|
43 |
#define AOS_SHELL_EVTFLAG_EXIT ((eventflags_t)(1 << 3)) |
44 |
|
45 |
/**
|
46 |
* @brief Shell event flag that is emitted when an I/O error occurred.
|
47 |
*/
|
48 |
#define AOS_SHELL_EVTFLAG_IOERROR ((eventflags_t)(1 << 4)) |
49 |
|
50 |
/**
|
51 |
* @brief Shell input configuration for replacing content by user input.
|
52 |
*/
|
53 |
#define AOS_SHELL_CONFIG_INPUT_OVERWRITE (1 << 0) |
54 |
|
55 |
/**
|
56 |
* @brief Shell prompt configuration print a minimalistic prompt.
|
57 |
*/
|
58 |
#define AOS_SHELL_CONFIG_PROMPT_MINIMAL (1 << 1) |
59 |
|
60 |
/**
|
61 |
* @brief Shell prompt configuration to additionally print the system uptime with the prompt.
|
62 |
*/
|
63 |
#define AOS_SHELL_CONFIG_PROMPT_UPTIME (1 << 2) |
64 |
|
65 |
/**
|
66 |
* @brief Shell prompt configuration to additionally print the system uptime with the prompt.
|
67 |
*/
|
68 |
#define AOS_SHELL_CONFIG_MATCH_CASE (1 << 3) |
69 |
|
70 |
/**
|
71 |
* @brief Shell command calback type.
|
72 |
*/
|
73 |
typedef int (*aos_shellcmdcb_t)(BaseSequentialStream* stream, int argc, char* argv[]); |
74 |
|
75 |
/**
|
76 |
* @brief Shell command structure.
|
77 |
*/
|
78 |
typedef struct aos_shellcommand { |
79 |
/**
|
80 |
* @brief Command name.
|
81 |
*/
|
82 |
const char* name; |
83 |
|
84 |
/**
|
85 |
* @brief Callback function.
|
86 |
*/
|
87 |
aos_shellcmdcb_t callback; |
88 |
|
89 |
/**
|
90 |
* @brief Pointer to next command in a singly linked list.
|
91 |
*/
|
92 |
struct aos_shellcommand* next;
|
93 |
} aos_shellcommand_t; |
94 |
|
95 |
/**
|
96 |
* @brief Execution status of a shell command.
|
97 |
*/
|
98 |
typedef struct aos_shellexecstatus { |
99 |
aos_shellcommand_t* command; /**< Pointer to the command that was executed. */
|
100 |
int retval; /**< Return value of the executed command. */ |
101 |
} aos_shellexecstatus_t; |
102 |
|
103 |
/**
|
104 |
* @brief Shell structure.
|
105 |
*/
|
106 |
typedef struct aos_shell { |
107 |
/**
|
108 |
* @brief Pointer to the thread object.
|
109 |
*/
|
110 |
thread_t* thread; |
111 |
|
112 |
/**
|
113 |
* @brief Event source.
|
114 |
*/
|
115 |
event_source_t eventSource; |
116 |
|
117 |
/**
|
118 |
* @brief Stream for user I/O.
|
119 |
*/
|
120 |
BaseSequentialStream* stream; |
121 |
|
122 |
/**
|
123 |
* @brief String to printed as prompt.
|
124 |
*/
|
125 |
const char* prompt; |
126 |
|
127 |
/**
|
128 |
* @brief Pointer to the first element of the singly linked list of commands.
|
129 |
* @details Commands are ordered alphabetically in the list.
|
130 |
*/
|
131 |
aos_shellcommand_t* commands; |
132 |
|
133 |
/**
|
134 |
* @brief Execution status of the most recent command.
|
135 |
*/
|
136 |
aos_shellexecstatus_t execstatus; |
137 |
|
138 |
/**
|
139 |
* @brief Input buffer.
|
140 |
*/
|
141 |
char* line;
|
142 |
|
143 |
/**
|
144 |
* @brief Size of the input buffer.
|
145 |
*/
|
146 |
size_t linesize; |
147 |
|
148 |
/**
|
149 |
* @brief Argument buffer.
|
150 |
*/
|
151 |
char** arglist;
|
152 |
|
153 |
/**
|
154 |
* @brief Size of the argument buffer.
|
155 |
*/
|
156 |
size_t arglistsize; |
157 |
|
158 |
/**
|
159 |
* @brief Configuration flags.
|
160 |
*/
|
161 |
uint8_t config; |
162 |
} aos_shell_t; |
163 |
|
164 |
#ifdef __cplusplus
|
165 |
extern "C" { |
166 |
#endif
|
167 |
void aosShellInit(aos_shell_t* shell, BaseSequentialStream* stream, const char* prompt, char* line, size_t linesize, char** arglist, size_t arglistsize); |
168 |
aos_status_t aosShellAddCommand(aos_shell_t* shell, aos_shellcommand_t* cmd); |
169 |
aos_status_t aosShellRemoveCommand(aos_shell_t* shell, char* cmd, aos_shellcommand_t** removed);
|
170 |
THD_FUNCTION(aosShellThread, shell); |
171 |
#ifdef __cplusplus
|
172 |
} |
173 |
#endif
|
174 |
|
175 |
#endif /* _AMIROOS_SHELL_H_ */ |