Skip to content

Commit 7191eaf

Browse files
committed
Improved documentation, added library metadata for arduino and improved library by storing command names in Flash
1 parent 95e00b9 commit 7191eaf

File tree

5 files changed

+226
-124
lines changed

5 files changed

+226
-124
lines changed

Shell.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ static void shell_prompt();
7777
*/
7878
static void shell_format(const char * fmt, va_list va);
7979

80-
8180
bool shell_init(shell_reader_t reader, shell_writer_t writer, char * msg)
8281
{
8382
if (reader == 0 || writer == 0)
@@ -141,7 +140,7 @@ void shell_print_error(int error, const char * field)
141140
{
142141
#ifdef ARDUINO
143142
if (field != 0) {
144-
shell_print_pm(PSTR("#ERROR-FIELD:"));
143+
shell_print_pm(PSTR("#ERROR-PARAM:"));
145144
shell_print(field);
146145
shell_print_pm(PSTR("\r\n"));
147146
}
@@ -174,24 +173,24 @@ void shell_print_error(int error, const char * field)
174173
}
175174
#else
176175
if (field != 0) {
177-
shell_print((const char *) "#ERROR-FIELD:");
176+
shell_print((const char *) "#ERROR-PARAM:");
178177
shell_print(field);
179178
shell_print("\r\n");
180179
}
181180

182181
shell_print((const char *) "#ERROR-TYPE:");
183182
switch (error) {
184183
case E_SHELL_ERR_ARGCOUNT:
185-
shell_print((const char *) "ARG_COUNT");
184+
shell_print((const char *) "ARG-COUNT");
186185
break;
187186
case E_SHELL_ERR_OUTOFRANGE:
188-
shell_print((const char *) "OUT_OF_RANGE");
187+
shell_print((const char *) "OUT-OF-RANGE");
189188
break;
190189
case E_SHELL_ERR_VALUE:
191-
shell_print((const char *) "INVALID_VALUE");
190+
shell_print((const char *) "INVALID-VALUE");
192191
break;
193192
case E_SHELL_ERR_ACTION:
194-
shell_print((const char *) "INVALID_ACTION");
193+
shell_print((const char *) "INVALID-ACTION");
195194
break;
196195
case E_SHELL_ERR_PARSE:
197196
shell_print((const char *) "PARSING");
@@ -216,6 +215,7 @@ void shell_print(const char * string)
216215
}
217216

218217
#ifdef ARDUINO
218+
219219
void shell_print_pm(const char * string)
220220
{
221221
uint8_t c;
@@ -234,7 +234,7 @@ void shell_println(const char * string)
234234
#ifdef ARDUINO
235235
shell_print_pm(PSTR("\r\n"));
236236
#else
237-
shell_print((const char *)"\r\n");
237+
shell_print((const char *) "\r\n");
238238
#endif
239239
}
240240

@@ -258,7 +258,7 @@ void shell_printf(const char * fmt, ...)
258258
void shell_printf_pm(const char * fmt, ...)
259259
{
260260
// First copy to RAM
261-
memcpy_P(shellfmtbuf, fmt, strlen_P(fmt)+1);
261+
memcpy_P(shellfmtbuf, fmt, strlen_P(fmt) + 1);
262262
va_list argl;
263263
va_start(argl, shellfmtbuf);
264264
shell_format(shellfmtbuf, argl);
@@ -326,7 +326,11 @@ void shell_task()
326326
if (list[i].shell_program == 0)
327327
continue;
328328
// If string matches one on the list
329+
#ifdef ARDUINO
330+
if (!strcmp_P(argv_list[0], list[i].shell_command_string)) {
331+
#else
329332
if (!strcmp(argv_list[0], list[i].shell_command_string)) {
333+
#endif
330334
// Run the appropiate function
331335
retval = list[i].shell_program(argc, argv_list);
332336
finished = 0;
@@ -348,6 +352,7 @@ void shell_task()
348352

349353
/*-------------------------------------------------------------*/
350354
/* Internal functions */
355+
351356
/*-------------------------------------------------------------*/
352357
static int shell_parse(char * buf, char ** argv, unsigned short maxargs)
353358
{

0 commit comments

Comments
 (0)