Parse GPS data locally. Add 'g' command to display recent GPS results.
[fw/altos] / ao_cmd.c
index 74cbb7b12f7727a91487688a595cca93fa11e775..6e91a72d5b452c31e75a01140afd9a4af20fd4a4 100644 (file)
--- a/ao_cmd.c
+++ b/ao_cmd.c
@@ -3,8 +3,7 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation; version 2 of the License.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -253,6 +252,34 @@ adc_dump(void)
        put_string("\n");
 }
 
+static void
+gps_dump(void) __reentrant
+{
+       ao_mutex_get(&ao_gps_mutex);
+       if (ao_gps_data.flags & AO_GPS_VALID) {
+               printf("GPS %2d:%02d:%02d %2d°%2d.%04d'%c %2d°%2d.%04d'%c %5dm %2d sat\n",
+                      ao_gps_data.hour,
+                      ao_gps_data.minute,
+                      ao_gps_data.second,
+                      ao_gps_data.latitude.degrees,
+                      ao_gps_data.latitude.minutes,
+                      ao_gps_data.latitude.minutes_fraction,
+                      (ao_gps_data.flags & AO_GPS_LATITUDE_MASK) == AO_GPS_LATITUDE_NORTH ?
+                      'N' : 'S',
+                      ao_gps_data.longitude.degrees,
+                      ao_gps_data.longitude.minutes,
+                      ao_gps_data.longitude.minutes_fraction,
+                      (ao_gps_data.flags & AO_GPS_LONGITUDE_MASK) == AO_GPS_LONGITUDE_WEST ?
+                      'W' : 'E',
+                      ao_gps_data.altitude,
+                      (ao_gps_data.flags & AO_GPS_NUM_SAT_MASK) >> AO_GPS_NUM_SAT_SHIFT);
+       } else {
+               printf("GPS %2d sat\n",
+                      (ao_gps_data.flags & AO_GPS_NUM_SAT_MASK) >> AO_GPS_NUM_SAT_SHIFT);;
+       }
+       ao_mutex_put(&ao_gps_mutex);
+}
+
 static void
 dump(void)
 {
@@ -342,17 +369,16 @@ echo(void)
        lex_echo = lex_i != 0;
 }
 
-#if INCLUDE_REMOTE_DEBUG
 static void
 debug_enable(void)
 {
-       dbg_debug_mode();
+       ao_dbg_debug_mode();
 }
 
 static void
 debug_reset(void)
 {
-       dbg_reset();
+       ao_dbg_reset();
 }
 
 static void
@@ -365,7 +391,7 @@ debug_put(void)
                hex();
                if (lex_status != SUCCESS)
                        break;
-               dbg_send_byte(lex_i);
+               ao_dbg_send_byte(lex_i);
        }
 }
 
@@ -386,7 +412,7 @@ debug_get(void)
        for (i = 0; i < count; i++) {
                if (i && (i & 7) == 0)
                        put_string("\n");
-               byte = dbg_recv_byte();
+               byte = ao_dbg_recv_byte();
                put8(byte);
                putchar(' ');
        }
@@ -423,15 +449,15 @@ debug_input(void)
        addr = lex_i;
        if (lex_status != SUCCESS)
                return;
-       dbg_start_transfer(addr);
+       ao_dbg_start_transfer(addr);
        i = 0;
        while (count--) {
                if (!(i++ & 7))
                        put_string("\n");
-               b = dbg_read_byte();
+               b = ao_dbg_read_byte();
                put8(b);
        }
-       dbg_end_transfer();
+       ao_dbg_end_transfer();
        put_string("\n");
 }
 
@@ -448,17 +474,16 @@ debug_output(void)
        addr = lex_i;
        if (lex_status != SUCCESS)
                return;
-       dbg_start_transfer(addr);
+       ao_dbg_start_transfer(addr);
        while (count--) {
                b = getnibble() << 4;
                b |= getnibble();
                if (lex_status != SUCCESS)
                        return;
-               dbg_write_byte(b);
+               ao_dbg_write_byte(b);
        }
-       dbg_end_transfer();
+       ao_dbg_end_transfer();
 }
-#endif
 
 static void
 dump_log(void)
@@ -477,16 +502,28 @@ dump_log(void)
        }
 }
 
+static void
+send_serial(void)
+{
+       white();
+       while (lex_c != '\n') {
+               ao_serial_putchar(lex_c);
+               lex();
+       }
+}
+
 static const uint8_t help_txt[] = 
        "All numbers are in hex\n"
        "?                                  Print this message\n"
        "a                                  Display current ADC values\n"
+       "g                                  Display current GPS values\n"
        "d <start> <end>                    Dump memory\n"
        "e <block>                          Dump a block of EEPROM data\n"
        "w <block> <start> <len> <data> ... Write data to EEPROM\n"
        "l                                  Dump last flight log\n"
        "E <0 off, 1 on>                    Set command echo mode\n"
-#if INCLUDE_REMOTE_DEBUG
+       "S<data>                            Send data to serial line\n"
+       "T                                  Show task states\n"
         "\n"
         "Target debug commands:\n"
        "D                                  Enable debug mode\n"
@@ -495,7 +532,6 @@ static const uint8_t help_txt[] =
        "G <count>                          Get data from debug port\n"
        "O <count> <addr>                   Output <count> bytes to target at <addr>\n"
        "I <count> <addr>                   Input <count> bytes to target at <addr>\n"
-#endif
 ;
 
 static void
@@ -539,6 +575,9 @@ ao_cmd(void *parameters)
                case 'a':
                        adc_dump();
                        break;
+               case 'g':
+                       gps_dump();
+                       break;
                case 'e':
                        ee_dump();
                        break;
@@ -548,10 +587,15 @@ ao_cmd(void *parameters)
                case 'l':
                        dump_log();
                        break;
+               case 'T':
+                       ao_task_info();
+                       break;
+               case 'S':
+                       send_serial();
+                       break;
                case 'E':
                        echo();
                        break;
-#if INCLUDE_REMOTE_DEBUG
                case 'D':
                        debug_enable();
                        break;
@@ -570,7 +614,6 @@ ao_cmd(void *parameters)
                case 'O':
                        debug_output();
                        break;
-#endif
                case '\r':
                case '\n':
                        break;
@@ -588,5 +631,5 @@ __xdata struct ao_task ao_cmd_task;
 void
 ao_cmd_init(void)
 {
-       ao_add_task(&ao_cmd_task, ao_cmd);
+       ao_add_task(&ao_cmd_task, ao_cmd, "cmd");
 }