changes in preparation for upload to Debian
[fw/altos] / src / ao_cmd.c
index 6007773c96cdaba0a8eb6ca63ea4c83580bc7b9f..1442ebea8eafc9a32e31ae18006bf61ef2af9316 100644 (file)
 
 #include "ao.h"
 
-__xdata uint16_t ao_cmd_lex_i;
-__xdata uint32_t ao_cmd_lex_u32;
-__xdata char   ao_cmd_lex_c;
-__xdata enum ao_cmd_status ao_cmd_status;
-static __xdata uint8_t lex_echo;
+__pdata uint16_t ao_cmd_lex_i;
+__pdata uint32_t ao_cmd_lex_u32;
+__pdata char   ao_cmd_lex_c;
+__pdata enum ao_cmd_status ao_cmd_status;
 
 #define CMD_LEN        32
 
 static __xdata char    cmd_line[CMD_LEN];
-static __xdata uint8_t cmd_len;
-static __xdata uint8_t cmd_i;
+static __pdata uint8_t cmd_len;
+static __pdata uint8_t cmd_i;
 
 static void
-put_string(char *s)
+put_string(__code char *s)
 {
-       __xdata char    c;
+       char    c;
        while (c = *s++)
                putchar(c);
 }
@@ -40,8 +39,8 @@ put_string(char *s)
 static void
 readline(void)
 {
-       __xdata char c;
-       if (lex_echo)
+       __pdata char c;
+       if (ao_echo())
                put_string("> ");
        cmd_len = 0;
        for (;;) {
@@ -50,7 +49,7 @@ readline(void)
                /* backspace/delete */
                if (c == '\010' || c == '\177') {
                        if (cmd_len != 0) {
-                               if (lex_echo)
+                               if (ao_echo())
                                        put_string("\010 \010");
                                --cmd_len;
                        }
@@ -60,7 +59,7 @@ readline(void)
                /* ^U */
                if (c == '\025') {
                        while (cmd_len != 0) {
-                               if (lex_echo)
+                               if (ao_echo())
                                        put_string("\010 \010");
                                --cmd_len;
                        }
@@ -72,18 +71,18 @@ readline(void)
                        c = '\n';
 
                if (c == '\n') {
-                       if (lex_echo)
+                       if (ao_echo())
                                putchar('\n');
                        break;
                }
 
                if (cmd_len >= CMD_LEN - 2) {
-                       if (lex_echo)
+                       if (ao_echo())
                                putchar('\007');
                        continue;
                }
                cmd_line[cmd_len++] = c;
-               if (lex_echo)
+               if (ao_echo())
                        putchar(c);
        }
        cmd_line[cmd_len++] = '\n';
@@ -111,9 +110,8 @@ putnibble(uint8_t v)
 void
 ao_cmd_put16(uint16_t v)
 {
-       int8_t i;
-       for (i = 3; i >= 0; i--)
-               putnibble((v >> (i << 2)) & 0xf);
+       ao_cmd_put8(v >> 8);
+       ao_cmd_put8(v);
 }
 
 void
@@ -133,19 +131,21 @@ ao_cmd_white(void)
 void
 ao_cmd_hex(void)
 {
-       __xdata uint8_t r = ao_cmd_lex_error;
+       __pdata uint8_t r = ao_cmd_lex_error;
+       uint8_t n;
 
        ao_cmd_lex_i = 0;
        ao_cmd_white();
        for(;;) {
                if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9')
-                       ao_cmd_lex_i = (ao_cmd_lex_i << 4) | (ao_cmd_lex_c - '0');
+                       n = (ao_cmd_lex_c - '0');
                else if ('a' <= ao_cmd_lex_c && ao_cmd_lex_c <= 'f')
-                       ao_cmd_lex_i = (ao_cmd_lex_i << 4) | (ao_cmd_lex_c - 'a' + 10);
+                       n = (ao_cmd_lex_c - 'a' + 10);
                else if ('A' <= ao_cmd_lex_c && ao_cmd_lex_c <= 'F')
-                       ao_cmd_lex_i = (ao_cmd_lex_i << 4) | (ao_cmd_lex_c - 'A' + 10);
+                       n = (ao_cmd_lex_c - 'A' + 10);
                else
                        break;
+               ao_cmd_lex_i = (ao_cmd_lex_i << 4) | n;
                r = ao_cmd_success;
                ao_cmd_lex();
        }
@@ -156,7 +156,7 @@ ao_cmd_hex(void)
 void
 ao_cmd_decimal(void)
 {
-       __xdata uint8_t r = ao_cmd_lex_error;
+       __pdata uint8_t r = ao_cmd_lex_error;
 
        ao_cmd_lex_u32 = 0;
        ao_cmd_white();
@@ -198,7 +198,8 @@ static void
 echo(void)
 {
        ao_cmd_hex();
-       lex_echo = ao_cmd_lex_i != 0;
+       if (ao_cmd_status == ao_cmd_success)
+               ao_stdios[ao_cur_stdio].echo = ao_cmd_lex_i != 0;
 }
 
 static void
@@ -218,23 +219,24 @@ version(void)
        printf("manufacturer     %s\n", ao_manufacturer);
        printf("product          %s\n", ao_product);
        printf("serial-number    %u\n", ao_serial_number);
+#if HAS_EEPROM
+       printf("log-format       %u\n", ao_log_format);
+#endif
        printf("software-version %s\n", ao_version);
 }
 
-static const char help_txt[] = "All numbers are in hex";
-
 #define NUM_CMDS       11
 
 static __code struct ao_cmds   *__xdata (ao_cmds[NUM_CMDS]);
-static __xdata uint8_t         ao_ncmds;
+static __pdata uint8_t         ao_ncmds;
 
 static void
 help(void)
 {
-       __xdata uint8_t cmds;
-       __xdata uint8_t cmd;
-       __code struct ao_cmds * __xdata cs;
-       puts(help_txt);
+       register uint8_t cmds;
+       register uint8_t cmd;
+       register __code struct ao_cmds * cs;
+
        for (cmds = 0; cmds < ao_ncmds; cmds++) {
                cs = ao_cmds[cmds];
                for (cmd = 0; cs[cmd].func; cmd++)
@@ -267,12 +269,11 @@ ao_cmd_register(__code struct ao_cmds *cmds)
 void
 ao_cmd(void)
 {
-       __xdata char    c;
-       __xdata uint8_t cmd, cmds;
+       char    c;
+       uint8_t cmd, cmds;
        __code struct ao_cmds * __xdata cs;
        void (*__xdata func)(void);
 
-       lex_echo = 1;
        for (;;) {
                readline();
                ao_cmd_lex();
@@ -303,11 +304,11 @@ ao_cmd(void)
 __xdata struct ao_task ao_cmd_task;
 
 __code struct ao_cmds  ao_base_cmds[] = {
-       { help,         "?\0Print this message" },
-       { ao_task_info, "T\0Show task states" },
-       { echo,         "E <0 off, 1 on>\0Set command echo mode" },
+       { help,         "?\0Help" },
+       { ao_task_info, "T\0Show tasks" },
+       { echo,         "E <0 off, 1 on>\0Set echo mode" },
        { ao_reboot,    "r eboot\0Reboot" },
-       { version,      "v\0Show version" },
+       { version,      "v\0Version" },
        { 0,    NULL },
 };