Merge branch 'micropeak-1.1'
[fw/altos] / src / core / ao_cmd.c
index fbf0c34778094ae08ec176525bc58d49318a2ec8..3d086a57e106d8f0110e0da6ad8a309fe985552d 100644 (file)
@@ -36,10 +36,16 @@ put_string(__code char *s)
                putchar(c);
 }
 
+static void
+backspace(void)
+{
+       put_string ("\010 \010");
+}
+
 static void
 readline(void)
 {
-       __pdata char c;
+       char c;
        if (ao_echo())
                put_string("> ");
        cmd_len = 0;
@@ -50,7 +56,7 @@ readline(void)
                if (c == '\010' || c == '\177') {
                        if (cmd_len != 0) {
                                if (ao_echo())
-                                       put_string("\010 \010");
+                                       backspace();
                                --cmd_len;
                        }
                        continue;
@@ -60,7 +66,7 @@ readline(void)
                if (c == '\025') {
                        while (cmd_len != 0) {
                                if (ao_echo())
-                                       put_string("\010 \010");
+                                       backspace();
                                --cmd_len;
                        }
                        continue;
@@ -76,11 +82,8 @@ readline(void)
                        break;
                }
 
-               if (cmd_len >= CMD_LEN - 2) {
-                       if (ao_echo())
-                               putchar('\007');
+               if (cmd_len >= CMD_LEN - 2)
                        continue;
-               }
                cmd_line[cmd_len++] = c;
                if (ao_echo())
                        putchar(c);
@@ -107,6 +110,22 @@ putnibble(uint8_t v)
                putchar(v + ('a' - 10));
 }
 
+uint8_t
+ao_getnibble(void)
+{
+       char    c;
+
+       c = getchar();
+       if ('0' <= c && c <= '9')
+               return c - '0';
+       if ('a' <= c && c <= 'f')
+               return c - ('a' - 10);
+       if ('A' <= c && c <= 'F')
+               return c - ('A' - 10);
+       ao_cmd_status = ao_cmd_lex_error;
+       return 0;
+}
+
 void
 ao_cmd_put16(uint16_t v)
 {
@@ -246,12 +265,25 @@ ao_reboot(void)
 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("manufacturer     %s\n"
+              "product          %s\n"
+              "serial-number    %u\n"
+#if HAS_FLIGHT
+              "current-flight   %u\n"
+#endif
 #if HAS_LOG
-       printf("log-format       %u\n", ao_log_format);
+              "log-format       %u\n"
+#endif
+              , ao_manufacturer
+              , ao_product
+              , ao_serial_number
+#if HAS_FLIGHT
+              , ao_flight_number
 #endif
+#if HAS_LOG
+              , ao_log_format
+#endif
+               );
 #if HAS_MS5607
        ao_ms5607_info();
 #endif
@@ -271,13 +303,14 @@ help(void)
        __pdata uint8_t cmds;
        __pdata uint8_t cmd;
        __code struct ao_cmds * __pdata cs;
+       const char *h;
 
        for (cmds = 0; cmds < ao_ncmds; cmds++) {
                cs = ao_cmds[cmds];
-               for (cmd = 0; cs[cmd].func; cmd++)
-                       printf("%-45s %s\n",
-                              cs[cmd].help,
-                              cs[cmd].help+1+strlen(cs[cmd].help));
+               for (cmd = 0; cs[cmd].func; cmd++) {
+                       h = cs[cmd].help;
+                       printf("%-45s %s\n", h, h + 1 + strlen(h));
+               }
        }
 }