#include "ao.h"
__xdata uint16_t ao_cmd_lex_i;
-__xdata uint8_t ao_cmd_lex_c;
+__xdata char ao_cmd_lex_c;
__xdata enum ao_cmd_status ao_cmd_status;
static __xdata uint8_t lex_echo;
#define CMD_LEN 32
-static __xdata uint8_t cmd_line[CMD_LEN];
+static __xdata char cmd_line[CMD_LEN];
static __xdata uint8_t cmd_len;
static __xdata uint8_t cmd_i;
static void
put_string(char *s)
{
- __xdata uint8_t c;
+ __xdata char c;
while (c = *s++)
putchar(c);
}
static void
readline(void)
{
- __xdata uint8_t c;
+ __xdata char c;
if (lex_echo)
put_string("> ");
cmd_len = 0;
ao_cmd_status = r;
}
-#if 0
-static void
-decimal(void)
+void
+ao_cmd_decimal(void)
{
__xdata uint8_t r = ao_cmd_lex_error;
ao_cmd_white();
for(;;) {
if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9')
- ao_cmd_lex_i = (ao_cmd_lex_i * 10 ) | (ao_cmd_lex_c - '0');
+ ao_cmd_lex_i = (ao_cmd_lex_i * 10) + (ao_cmd_lex_c - '0');
else
break;
r = ao_cmd_success;
if (r != ao_cmd_success)
ao_cmd_status = r;
}
-#endif
static void
eol(void)
lex_echo = ao_cmd_lex_i != 0;
}
-static const uint8_t help_txt[] = "All numbers are in hex";
+static void
+version(void)
+{
+ printf("manufacturer %s\n", ao_manufacturer);
+ printf("product %s\n", ao_product);
+ printf("serial-number %u\n", ao_serial_number);
+ printf("software-version %s\n", ao_version);
+}
+
+static const char help_txt[] = "All numbers are in hex";
-#define NUM_CMDS 8
+#define NUM_CMDS 11
static __code struct ao_cmds *__xdata (ao_cmds[NUM_CMDS]);
static __xdata uint8_t ao_ncmds;
{
__xdata uint8_t cmds;
__xdata uint8_t cmd;
+ __code struct ao_cmds * __xdata cs;
puts(help_txt);
- for (cmds = 0; cmds < ao_ncmds; cmds++)
- for (cmd = 0; ao_cmds[cmds][cmd].cmd; cmd++)
- puts(ao_cmds[cmds][cmd].help);
+ for (cmds = 0; cmds < ao_ncmds; cmds++) {
+ cs = ao_cmds[cmds];
+ for (cmd = 0; cs[cmd].cmd != '\0'; cmd++)
+ puts(cs[cmd].help);
+ }
}
static void
void
ao_cmd(void *parameters)
{
- __xdata uint8_t c;
+ __xdata char c;
__xdata uint8_t cmd, cmds;
+ __code struct ao_cmds * __xdata cs;
+ void (*__xdata func)(void);
(void) parameters;
lex_echo = 1;
ao_cmd_lex();
if (c == '\r' || c == '\n')
continue;
- cmd = 0;
+ func = (void (*)(void)) NULL;
for (cmds = 0; cmds < ao_ncmds; cmds++) {
- for (cmd = 0; ao_cmds[cmds][cmd].cmd != '\0'; cmd++)
- if (ao_cmds[cmds][cmd].cmd == c)
+ cs = ao_cmds[cmds];
+ for (cmd = 0; cs[cmd].cmd != '\0'; cmd++)
+ if (cs[cmd].cmd == c) {
+ func = cs[cmd].func;
break;
- if (ao_cmds[cmds][cmd].cmd)
+ }
+ if (func)
break;
}
- if (ao_cmds[cmds][cmd].cmd)
- (*ao_cmds[cmds][cmd].func);
+ if (func)
+ (*func)();
else
ao_cmd_status = ao_cmd_syntax_error;
report();
__code struct ao_cmds ao_base_cmds[] = {
{ '?', help, "? Print this message" },
- { 'T', ao_task_info, "T Show task states\n" },
- { 'E', echo, "E <0 off, 1 on> Set command echo mode\n" },
- { 'd', dump, "d <start> <end> Dump memory\n" },
+ { 'T', ao_task_info, "T Show task states" },
+ { 'E', echo, "E <0 off, 1 on> Set command echo mode" },
+ { 'd', dump, "d <start> <end> Dump memory" },
+ { 'v', version, "v Show version" },
{ 0, help, NULL },
};