|
29 | 29 | /*-------------------------------------------------------------*/ |
30 | 30 | /* Macros and definitions */ |
31 | 31 | /*-------------------------------------------------------------*/ |
| 32 | +#if !defined(CONFIG_SHELL_MAX_COMMANDS) |
| 33 | +/** |
| 34 | + * Defines the maximum number of commands that can be registered |
| 35 | + */ |
| 36 | +#define CONFIG_SHELL_MAX_COMMANDS 5 |
| 37 | +#endif |
| 38 | +#if !defined(CONFIG_SHELL_MAX_INPUT) |
| 39 | +/** |
| 40 | + * Defines the maximum characters that the input buffer can accept |
| 41 | + */ |
| 42 | +#define CONFIG_SHELL_MAX_INPUT 100 |
| 43 | +#endif |
| 44 | +#if !defined(CONFIG_SHELL_MAX_COMMAND_ARGS) |
| 45 | +/** |
| 46 | + * Configures the maximum number of arguments per command tha can be accepted |
| 47 | + */ |
| 48 | +#define CONFIG_SHELL_MAX_COMMAND_ARGS 10 |
| 49 | +#endif |
32 | 50 |
|
33 | 51 | #define SHELL_ASCII_NUL 0x00 |
34 | 52 | #define SHELL_ASCII_BEL 0x07 |
|
49 | 67 | #define SHELL_RET_FAILURE 1 |
50 | 68 | #define SHELL_RET_IOPENDING -1 |
51 | 69 |
|
52 | | -#if !defined(CONFIG_SHELL_MAX_COMMANDS) |
53 | | -/** |
54 | | - * Defines the maximum number of commands that can be registered |
55 | | - */ |
56 | | -#define CONFIG_SHELL_MAX_COMMANDS 5 |
57 | | -#endif |
58 | | -#if !defined(CONFIG_SHELL_MAX_INPUT) |
59 | | -/** |
60 | | - * Defines the maximum characters that the input buffer can accept |
61 | | - */ |
62 | | -#define CONFIG_SHELL_MAX_INPUT 100 |
63 | | -#endif |
64 | | -#if !defined(CONFIG_SHELL_MAX_COMMAND_ARGS) |
65 | | -/** |
66 | | - * Configures the maximum number of arguments per command tha can be accepted |
67 | | - */ |
68 | | -#define CONFIG_SHELL_MAX_COMMAND_ARGS 10 |
69 | | -#endif |
70 | | - |
71 | 70 | /*-------------------------------------------------------------*/ |
72 | 71 | /* Typedefs enums & structs */ |
73 | 72 | /*-------------------------------------------------------------*/ |
@@ -94,13 +93,13 @@ typedef int (*shell_reader_t) (char *); |
94 | 93 | * shell |
95 | 94 | */ |
96 | 95 | enum shell_errors { |
97 | | - E_SHELL_ERR_ARGCOUNT = 0, |
98 | | - E_SHELL_ERR_OUTOFRANGE, |
99 | | - E_SHELL_ERR_VALUE, |
100 | | - E_SHELL_ERR_ACTION, |
101 | | - E_SHELL_ERR_PARSE, |
102 | | - E_SHELL_ERR_STORAGE, |
103 | | - E_SHELL_ERR_IO, |
| 96 | + E_SHELL_ERR_ARGCOUNT = 0, //!< There are missing arguments for the command |
| 97 | + E_SHELL_ERR_OUTOFRANGE, //!< The program received an argument that is out of range |
| 98 | + E_SHELL_ERR_VALUE, //!< The program received an argument with a value different than expected |
| 99 | + E_SHELL_ERR_ACTION, //!< Invalid action requested for the current state |
| 100 | + E_SHELL_ERR_PARSE, //!< Cannot parse the user input |
| 101 | + E_SHELL_ERR_STORAGE, //!< Cannot access storage device or memory device |
| 102 | + E_SHELL_ERR_IO, //!< IO device error caused program interruption |
104 | 103 | }; |
105 | 104 |
|
106 | 105 | /** |
@@ -118,97 +117,114 @@ struct shell_command_entry { |
118 | 117 | #ifdef __cplusplus |
119 | 118 | extern "C" { |
120 | 119 | #endif |
| 120 | +/** |
| 121 | + * @brief Prepares the command line interface |
| 122 | + * |
| 123 | + * Initializes the resources used by the command line interface. This function |
| 124 | + * also tries to start the command line task if the option is enabled. The main |
| 125 | + * program for the command line interface where all the data is handled is |
| 126 | + * shell_task(). |
| 127 | + * |
| 128 | + * @param reader The callback function used to get a character from the stream. |
| 129 | + * |
| 130 | + * @param writer The callback function used to write a character to the stream. |
| 131 | + * |
| 132 | + * @param msg The message to display upon startup of the program |
| 133 | + * |
| 134 | + * @return Returns TRUE if the shell was succesfully initialized, returns FALSE |
| 135 | + * otherwise. |
| 136 | + */ |
| 137 | +uint8_t shell_init(shell_reader_t reader, shell_writer_t writer, char * msg); |
121 | 138 |
|
122 | | - /** |
123 | | - * @brief Prepares the command line interface |
124 | | - * |
125 | | - * Initializes the resources used by the command line interface. This function |
126 | | - * also tries to start the command line task if the option is enabled. The main |
127 | | - * program for the command line interface where all the data is handled is |
128 | | - * shell_task(). |
129 | | - * |
130 | | - * @param reader The callback function used to get a character from the stream. |
131 | | - * |
132 | | - * @param writer The callback function used to write a character to the stream. |
133 | | - * |
134 | | - * @param msg The message to display upon startup of the program |
135 | | - * |
136 | | - * @return Returns TRUE if the shell was succesfully initialized, returns FALSE |
137 | | - * otherwise. |
138 | | - */ |
139 | | - uint8_t shell_init(shell_reader_t reader, shell_writer_t writer, char * msg); |
140 | | - |
141 | | - /** |
142 | | - * @brief Register a command with the command interpreter |
143 | | - * |
144 | | - * Registers a command on the available command list. The name of the command |
145 | | - * and the function that implements it´s functionality should be provided. |
146 | | - * |
147 | | - * @param program The type shell_program_t is a pointer to a function |
148 | | - * that is executed when the written command matches the associated name |
149 | | - * |
150 | | - * @param string A string containing the name of the command to be registered. |
151 | | - * |
152 | | - * @return Returns TRUE if command was successfully added to the command list, |
153 | | - * or returns FALSE if something fails (no more commands can be registered). |
154 | | - */ |
155 | | - uint8_t shell_register(shell_program_t program, const char * string); |
156 | | - |
157 | | - /** |
158 | | - * @brief Unregister all commands |
159 | | - * |
160 | | - * Errases all entries on the command list, returning it to it´s default status. |
161 | | - */ |
162 | | - void shell_unregister_all(); |
163 | | - |
164 | | - /** |
165 | | - * @brief Prints the list of registered commands |
166 | | - * |
167 | | - * Prints a list of available commands to the terminal using the callback |
168 | | - * functions provided on initialization. |
169 | | - */ |
170 | | - void shell_print_commands(); |
171 | | - |
172 | | - /** |
173 | | - * @brief Prints error messages to the terminal screen |
174 | | - * |
175 | | - * @param error The code (ID) of the error to print |
176 | | - * |
177 | | - * @param field The name of the parameter or variable where the error was |
178 | | - * detected. |
179 | | - */ |
180 | | - void shell_print_error(int error, const char * field); |
181 | | - |
182 | | - /** |
183 | | - * @brief Prints a null terminated string to the terminal |
184 | | - * |
185 | | - * Displays a string on the terminal. The string should be null terminated. |
186 | | - * |
187 | | - * @param string The string to send to the terminal |
188 | | - */ |
189 | | - void shell_print(const char * string); |
190 | | - |
191 | | - /** |
192 | | - * @brief Prints a string and moves the cursor to the next line |
193 | | - * |
194 | | - * @param string The string to send to the terminal |
195 | | - */ |
196 | | - void shell_println(const char * string); |
197 | | - |
198 | | - /** |
199 | | - * |
200 | | - */ |
201 | | - void shell_printf(char * fmt, ...); |
202 | | - |
203 | | - /** |
204 | | - * |
205 | | - * @brief Main Shell processing loop |
206 | | - * |
207 | | - * This function implements the main functionality of the command line interface |
208 | | - * this function should be called frequently so it can handle the input from the |
209 | | - * data stream. |
210 | | - */ |
211 | | - void shell_task(); |
| 139 | +/** |
| 140 | + * @brief Register a command with the command interpreter |
| 141 | + * |
| 142 | + * Registers a command on the available command list. The name of the command |
| 143 | + * and the function that implements it´s functionality should be provided. |
| 144 | + * |
| 145 | + * @param program The type shell_program_t is a pointer to a function |
| 146 | + * that is executed when the written command matches the associated name |
| 147 | + * |
| 148 | + * @param string A string containing the name of the command to be registered. |
| 149 | + * |
| 150 | + * @return Returns TRUE if command was successfully added to the command list, |
| 151 | + * or returns FALSE if something fails (no more commands can be registered). |
| 152 | + */ |
| 153 | +uint8_t shell_register(shell_program_t program, const char * string); |
| 154 | + |
| 155 | +/** |
| 156 | + * @brief Unregister all commands |
| 157 | + * |
| 158 | + * Errases all entries on the command list, returning it to it´s default status. |
| 159 | + */ |
| 160 | +void shell_unregister_all(); |
| 161 | + |
| 162 | +/** |
| 163 | + * @brief Prints the list of registered commands |
| 164 | + * |
| 165 | + * Prints a list of available commands to the terminal using the callback |
| 166 | + * functions provided on initialization. |
| 167 | + */ |
| 168 | +void shell_print_commands(); |
| 169 | + |
| 170 | +/** |
| 171 | + * @brief Prints error messages to the terminal screen |
| 172 | + * |
| 173 | + * This function presents an alternative for displaying program errors in a |
| 174 | + * uniform format. |
| 175 | + * |
| 176 | + * @param error The code (ID) of the error to print |
| 177 | + * |
| 178 | + * @param field The name of the parameter or variable where the error was |
| 179 | + * detected. |
| 180 | + */ |
| 181 | +void shell_print_error(int error, const char * field); |
| 182 | + |
| 183 | +/** |
| 184 | + * @brief Prints a null terminated string to the terminal |
| 185 | + * |
| 186 | + * Displays a string on the terminal. The string should be null terminated. |
| 187 | + * |
| 188 | + * @param string The string to send to the terminal |
| 189 | + */ |
| 190 | +void shell_print(const char * string); |
| 191 | + |
| 192 | +/** |
| 193 | + * @brief Prints a string and moves the cursor to the next line |
| 194 | + * |
| 195 | + * Displays a string on the terminal and moves the cursor to the next line. The |
| 196 | + * string should be null terminated. |
| 197 | + * |
| 198 | + * @param string The string to send to the terminal |
| 199 | + */ |
| 200 | +void shell_println(const char * string); |
| 201 | + |
| 202 | +/** |
| 203 | + * @brief Prints formatted text to the terminal |
| 204 | + * |
| 205 | + * Displays a string (fmt) on the terminal. If the string includes format |
| 206 | + * specifiers (subsequences beginning with '%'), the additional arguments |
| 207 | + * following format are formatted and inserted in the resulting string |
| 208 | + * replacing their respective specifiers. |
| 209 | + * |
| 210 | + * This function implements it´s own mechanism for text formatting. It doesn´t |
| 211 | + * rely on the native print functions. |
| 212 | + * |
| 213 | + * @param fmt The string to send to the terminal, the string can include format |
| 214 | + * specifiers in a similar fashion to printf standard function. |
| 215 | + * |
| 216 | + * @param ... Aditional arguments that are inserted on the string as text |
| 217 | + */ |
| 218 | +void shell_printf(char * fmt, ...); |
| 219 | + |
| 220 | +/** |
| 221 | + * @brief Main Shell processing loop |
| 222 | + * |
| 223 | + * This function implements the main functionality of the command line interface |
| 224 | + * this function should be called frequently so it can handle the input from the |
| 225 | + * data stream. |
| 226 | + */ |
| 227 | +void shell_task(); |
212 | 228 |
|
213 | 229 | #ifdef __cplusplus |
214 | 230 | } |
|