From 5e9193f6375be27e5f7a0321fd34b6acfe81247f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 14 May 2013 09:12:29 -0700 Subject: [PATCH 1/1] altos: Add 'g' command to ublox GPS code. Take the gps_dump function from ao_gps_skytraq.c and move it to a new file so it can be shared with the u-blox driver. That affects every skytraq and u-blox user as they need to include the new file. Signed-off-by: Keith Packard --- src/core/ao.h | 3 +++ src/core/ao_gps_show.c | 39 ++++++++++++++++++++++++++++++++ src/drivers/ao_gps_skytraq.c | 21 +---------------- src/drivers/ao_gps_ublox.c | 6 +++++ src/telegps-v0.1/Makefile | 1 + src/telemega-v0.1/Makefile | 1 + src/telemega-v0.3/Makefile | 1 + src/telemetrum-v0.1-sky/Makefile | 1 + src/telemetrum-v1.0/Makefile | 1 + src/telemetrum-v1.1/Makefile | 1 + src/telemetrum-v1.2/Makefile | 1 + src/teleterra-v0.2/Makefile | 3 ++- src/test/Makefile | 4 ++-- src/test/ao_gps_test_skytraq.c | 12 ++++++---- src/test/ao_gps_test_ublox.c | 11 +++++---- 15 files changed, 74 insertions(+), 32 deletions(-) create mode 100644 src/core/ao_gps_show.c diff --git a/src/core/ao.h b/src/core/ao.h index 0ad3e4aa..71bfb6a1 100644 --- a/src/core/ao.h +++ b/src/core/ao.h @@ -379,6 +379,9 @@ ao_gps_print(__xdata struct ao_gps_orig *gps_data); void ao_gps_tracking_print(__xdata struct ao_gps_tracking_orig *gps_tracking_data); +void +ao_gps_show(void) __reentrant; + void ao_gps_init(void); diff --git a/src/core/ao_gps_show.c b/src/core/ao_gps_show.c new file mode 100644 index 00000000..3a05e35a --- /dev/null +++ b/src/core/ao_gps_show.c @@ -0,0 +1,39 @@ +/* + * Copyright © 2013 Keith Packard + * + * 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; 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef AO_GPS_TEST +#include +#endif + +void +ao_gps_show(void) __reentrant +{ + uint8_t i; + ao_mutex_get(&ao_gps_mutex); + printf ("Date: %02d/%02d/%02d\n", ao_gps_data.year, ao_gps_data.month, ao_gps_data.day); + printf ("Time: %02d:%02d:%02d\n", ao_gps_data.hour, ao_gps_data.minute, ao_gps_data.second); + printf ("Lat/Lon: %ld %ld\n", (long) ao_gps_data.latitude, (long) ao_gps_data.longitude); + printf ("Alt: %d\n", ao_gps_data.altitude); + printf ("Flags: 0x%x\n", ao_gps_data.flags); + printf ("Sats: %d", ao_gps_tracking_data.channels); + for (i = 0; i < ao_gps_tracking_data.channels; i++) + printf (" %d %d", + ao_gps_tracking_data.sats[i].svid, + ao_gps_tracking_data.sats[i].c_n_1); + printf ("\ndone\n"); + ao_mutex_put(&ao_gps_mutex); +} diff --git a/src/drivers/ao_gps_skytraq.c b/src/drivers/ao_gps_skytraq.c index d2f67e6b..9a9dff75 100644 --- a/src/drivers/ao_gps_skytraq.c +++ b/src/drivers/ao_gps_skytraq.c @@ -483,25 +483,6 @@ ao_gps(void) __reentrant __xdata struct ao_task ao_gps_task; -static void -gps_dump(void) __reentrant -{ - uint8_t i; - ao_mutex_get(&ao_gps_mutex); - printf ("Date: %02d/%02d/%02d\n", ao_gps_data.year, ao_gps_data.month, ao_gps_data.day); - printf ("Time: %02d:%02d:%02d\n", ao_gps_data.hour, ao_gps_data.minute, ao_gps_data.second); - printf ("Lat/Lon: %ld %ld\n", (long) ao_gps_data.latitude, (long) ao_gps_data.longitude); - printf ("Alt: %d\n", ao_gps_data.altitude); - printf ("Flags: 0x%x\n", ao_gps_data.flags); - printf ("Sats: %d", ao_gps_tracking_data.channels); - for (i = 0; i < ao_gps_tracking_data.channels; i++) - printf (" %d %d", - ao_gps_tracking_data.sats[i].svid, - ao_gps_tracking_data.sats[i].c_n_1); - printf ("\ndone\n"); - ao_mutex_put(&ao_gps_mutex); -} - static __code uint8_t ao_gps_115200[] = { SKYTRAQ_MSG_3(5,0,5,0) /* Set to 115200 baud */ }; @@ -532,7 +513,7 @@ gps_update(void) __reentrant } __code struct ao_cmds ao_gps_cmds[] = { - { gps_dump, "g\0Display GPS" }, + { ao_gps_show, "g\0Display GPS" }, { gps_update, "U\0Update GPS firmware" }, { 0, NULL }, }; diff --git a/src/drivers/ao_gps_ublox.c b/src/drivers/ao_gps_ublox.c index 22300df3..24e70ee3 100644 --- a/src/drivers/ao_gps_ublox.c +++ b/src/drivers/ao_gps_ublox.c @@ -695,10 +695,16 @@ ao_gps(void) __reentrant } } +__code struct ao_cmds ao_gps_cmds[] = { + { ao_gps_show, "g\0Display GPS" }, + { 0, NULL }, +}; + __xdata struct ao_task ao_gps_task; void ao_gps_init(void) { + ao_cmd_register(&ao_gps_cmds[0]); ao_add_task(&ao_gps_task, ao_gps, "gps"); } diff --git a/src/telegps-v0.1/Makefile b/src/telegps-v0.1/Makefile index 2c41235b..64deddc6 100644 --- a/src/telegps-v0.1/Makefile +++ b/src/telegps-v0.1/Makefile @@ -52,6 +52,7 @@ ALTOS_SRC = \ ao_exti_stm.c \ ao_serial_stm.c \ ao_gps_skytraq.c \ + ao_gps_show.c \ ao_cc115l.c \ ao_fec_tx.c \ ao_rfpa0133.c \ diff --git a/src/telemega-v0.1/Makefile b/src/telemega-v0.1/Makefile index a72d08f2..bf756e96 100644 --- a/src/telemega-v0.1/Makefile +++ b/src/telemega-v0.1/Makefile @@ -59,6 +59,7 @@ ALTOS_SRC = \ ao_mutex.c \ ao_serial_stm.c \ ao_gps_skytraq.c \ + ao_gps_show.c \ ao_gps_report_mega.c \ ao_ignite.c \ ao_freq.c \ diff --git a/src/telemega-v0.3/Makefile b/src/telemega-v0.3/Makefile index 398c7dab..f2c0625f 100644 --- a/src/telemega-v0.3/Makefile +++ b/src/telemega-v0.3/Makefile @@ -59,6 +59,7 @@ ALTOS_SRC = \ ao_mutex.c \ ao_serial_stm.c \ ao_gps_ublox.c \ + ao_gps_show.c \ ao_gps_report_mega.c \ ao_ignite.c \ ao_freq.c \ diff --git a/src/telemetrum-v0.1-sky/Makefile b/src/telemetrum-v0.1-sky/Makefile index 69cd3461..a6634c29 100644 --- a/src/telemetrum-v0.1-sky/Makefile +++ b/src/telemetrum-v0.1-sky/Makefile @@ -11,6 +11,7 @@ TM_INC = \ TM_SRC = \ ao_gps_skytraq.c \ + ao_gps_show.c \ ao_25lc1024.c include ../product/Makefile.telemetrum diff --git a/src/telemetrum-v1.0/Makefile b/src/telemetrum-v1.0/Makefile index 4aae84c8..476a3b0a 100644 --- a/src/telemetrum-v1.0/Makefile +++ b/src/telemetrum-v1.0/Makefile @@ -11,6 +11,7 @@ TM_INC = \ TM_SRC = \ ao_companion.c \ ao_gps_skytraq.c \ + ao_gps_show.c \ ao_at45db161d.c include ../product/Makefile.telemetrum diff --git a/src/telemetrum-v1.1/Makefile b/src/telemetrum-v1.1/Makefile index 4bea03db..e44be7f9 100644 --- a/src/telemetrum-v1.1/Makefile +++ b/src/telemetrum-v1.1/Makefile @@ -11,6 +11,7 @@ TM_INC = TM_SRC = \ ao_companion.c \ ao_gps_skytraq.c \ + ao_gps_show.c \ ao_m25.c include ../product/Makefile.telemetrum diff --git a/src/telemetrum-v1.2/Makefile b/src/telemetrum-v1.2/Makefile index 4b650adf..f2285fbe 100644 --- a/src/telemetrum-v1.2/Makefile +++ b/src/telemetrum-v1.2/Makefile @@ -11,6 +11,7 @@ TM_INC = TM_SRC = \ ao_companion.c \ ao_gps_skytraq.c \ + ao_gps_show.c \ ao_m25.c include ../product/Makefile.telemetrum diff --git a/src/teleterra-v0.2/Makefile b/src/teleterra-v0.2/Makefile index 65db57ce..68a8d1b6 100644 --- a/src/teleterra-v0.2/Makefile +++ b/src/teleterra-v0.2/Makefile @@ -52,7 +52,8 @@ CC1111_SRC = \ DRIVER_SRC = \ ao_m25.c \ ao_lcd.c \ - ao_gps_skytraq.c + ao_gps_skytraq.c \ + ao_gps_show.c PRODUCT_SRC = \ ao_teleterra_0_2.c \ diff --git a/src/test/Makefile b/src/test/Makefile index 169c1dc6..8032a163 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -35,10 +35,10 @@ ao_flight_test_mm: ao_flight_test.c ao_host.h ao_flight.c ao_sample.c ao_kalman. ao_gps_test: ao_gps_test.c ao_gps_sirf.c ao_gps_print.c ao_host.h cc $(CFLAGS) -o $@ $< -ao_gps_test_skytraq: ao_gps_test_skytraq.c ao_gps_skytraq.c ao_gps_print.c ao_host.h +ao_gps_test_skytraq: ao_gps_test_skytraq.c ao_gps_skytraq.c ao_gps_print.c ao_gps_show.c ao_host.h cc $(CFLAGS) -o $@ $< -ao_gps_test_ublox: ao_gps_test_ublox.c ao_gps_ublox.c ao_gps_print.c ao_host.h ao_gps_ublox.h +ao_gps_test_ublox: ao_gps_test_ublox.c ao_gps_ublox.c ao_gps_print.c ao_gps_show.c ao_host.h ao_gps_ublox.h cc $(CFLAGS) -o $@ $< ao_convert_test: ao_convert_test.c ao_convert.c altitude.h diff --git a/src/test/ao_gps_test_skytraq.c b/src/test/ao_gps_test_skytraq.c index 81008b39..89cbd767 100644 --- a/src/test/ao_gps_test_skytraq.c +++ b/src/test/ao_gps_test_skytraq.c @@ -75,6 +75,11 @@ struct ao_gps_tracking_orig { #define ao_telemetry_satellite ao_gps_tracking_orig #define ao_telemetry_satellite_info ao_gps_sat_orig +extern __xdata struct ao_telemetry_location ao_gps_data; +extern __xdata struct ao_telemetry_satellite ao_gps_tracking_data; + +uint8_t ao_gps_mutex; + void ao_mutex_get(uint8_t *mutex) { @@ -432,17 +437,14 @@ uint8_t ao_task_minimize_latency; #define ao_usb_getchar() 0 #include "ao_gps_print.c" +#include "ao_gps_show.c" #include "ao_gps_skytraq.c" void ao_dump_state(void *wchan) { if (wchan == &ao_gps_data) - ao_gps_print(&ao_gps_data); - else - ao_gps_tracking_print(&ao_gps_tracking_data); - putchar('\n'); - return; + ao_gps_show(); } int diff --git a/src/test/ao_gps_test_ublox.c b/src/test/ao_gps_test_ublox.c index 80671735..afd4dba4 100644 --- a/src/test/ao_gps_test_ublox.c +++ b/src/test/ao_gps_test_ublox.c @@ -77,6 +77,11 @@ struct ao_telemetry_satellite { #define ao_gps_tracking_orig ao_telemetry_satellite #define ao_gps_sat_orig ao_telemetry_satellite_info +extern __xdata struct ao_telemetry_location ao_gps_data; +extern __xdata struct ao_telemetry_satellite ao_gps_tracking_data; + +uint8_t ao_gps_mutex; + void ao_mutex_get(uint8_t *mutex) { @@ -224,6 +229,7 @@ uint8_t ao_task_minimize_latency; #define ao_usb_getchar() 0 #include "ao_gps_print.c" +#include "ao_gps_show.c" #include "ao_gps_ublox.c" static void @@ -342,10 +348,7 @@ void ao_dump_state(void *wchan) { if (wchan == &ao_gps_data) - ao_gps_print(&ao_gps_data); - else - ao_gps_tracking_print(&ao_gps_tracking_data); - putchar('\n'); + ao_gps_show(); return; } -- 2.30.2