Decrease telemetry rate on the pad to 1/sec instead of 20/sec
[fw/altos] / ao_cmd.c
index 13def7c20d7ef4b88e9ff436f2bce513ed5f5551..827545d0ee8842a94ed41fb376e1d0da38cc0de9 100644 (file)
--- a/ao_cmd.c
+++ b/ao_cmd.c
 #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);
 }
@@ -39,7 +39,7 @@ put_string(char *s)
 static void
 readline(void)
 {
-       __xdata uint8_t c;
+       __xdata char c;
        if (lex_echo)
                put_string("> ");
        cmd_len = 0;
@@ -152,9 +152,8 @@ ao_cmd_hex(void)
                ao_cmd_status = r;
 }
 
-#if 0
-static void
-decimal(void)
+void
+ao_cmd_decimal(void)
 {
        __xdata uint8_t r = ao_cmd_lex_error;
        
@@ -162,7 +161,7 @@ decimal(void)
        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;
@@ -171,7 +170,6 @@ decimal(void)
        if (r != ao_cmd_success)
                ao_cmd_status = r;
 }
-#endif
 
 static void
 eol(void)
@@ -214,9 +212,18 @@ echo(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;
@@ -226,10 +233,13 @@ help(void)
 {
        __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
@@ -255,8 +265,10 @@ ao_cmd_register(__code struct ao_cmds *cmds)
 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;
@@ -268,16 +280,19 @@ ao_cmd(void *parameters)
                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();
@@ -288,9 +303,10 @@ __xdata struct ao_task ao_cmd_task;
 
 __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 },
 };