altos: Add logging and telem to telegps
authorKeith Packard <keithp@keithp.com>
Sat, 30 Mar 2013 08:33:49 +0000 (01:33 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 30 Mar 2013 08:33:49 +0000 (01:33 -0700)
This turns on telemetry, APRS, RDF and data logging for telegps.

Data is logged as soon as GPS has a date to create the right
filename, using files of the form YYYYMMDD.LOG which just barely fits
in a FAT filename.

Telemetry/RDF/APRS are all separately controllable.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-telem/ao-telem.c
src/core/ao_gps_report_mega.c
src/core/ao_telemetry.c
src/drivers/ao_log_fat.c [new file with mode: 0644]
src/telegps-v0.1/Makefile
src/telegps-v0.1/ao_telegps.c

index e7fc8e268712c5251aa1cbf126d6c13b76b7efe6..d2dae5a7a14068cbdcc5e21552bc64e61f79b31e 100644 (file)
@@ -24,6 +24,7 @@
 #include "cc.h"
 
 static const struct option options[] = {
+       { .name = "crc", .has_arg = 0, .val = 'c' },
        { 0, 0, 0, 0},
 };
 
@@ -44,8 +45,12 @@ main (int argc, char **argv)
        char *s;
        FILE *file;
        int serial;
-       while ((c = getopt_long(argc, argv, "", options, NULL)) != -1) {
+       int ignore_crc = 0;
+       while ((c = getopt_long(argc, argv, "c", options, NULL)) != -1) {
                switch (c) {
+               case 'c':
+                       ignore_crc = 1;
+                       break;
                default:
                        usage(argv[0]);
                        break;
@@ -74,7 +79,7 @@ main (int argc, char **argv)
                                printf ("serial %5d rssi %d status %02x tick %5d type %3d ",
                                        telem.generic.serial, rssi, telem.generic.status,
                                        telem.generic.tick, telem.generic.type);
-                               if ((telem.generic.status & (1 << 7)) == 0) {
+                               if (!ignore_crc && (telem.generic.status & (1 << 7)) == 0) {
                                        printf ("CRC error\n");
                                        continue;
                                }
index 47891cabe9db8c3f878e85c9941d7b6c8828c5d4..e3af43079728033740513c6c7dc057c0eb313bec 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include "ao.h"
+#include "ao_log.h"
 
 void
 ao_gps_report_mega(void)
index 8d440e15410ff4bd7833bcd5da6e1380d8ba46f9..3aa315c765926cfa9e8cacf81c487fd1fc21caea 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include "ao.h"
+#include "ao_log.h"
 #include "ao_product.h"
 
 static __pdata uint16_t ao_telemetry_interval;
@@ -306,12 +307,14 @@ ao_telemetry(void)
 #ifdef AO_SEND_ALL_BARO
                                ao_send_baro();
 #endif
+#if HAS_FLIGHT
 #ifdef AO_SEND_MEGA
                                ao_send_mega_sensor();
                                ao_send_mega_data();
 #else
                                ao_send_sensor();
 #endif
+#endif
 
 #if HAS_COMPANION
                                if (ao_companion_running)
diff --git a/src/drivers/ao_log_fat.c b/src/drivers/ao_log_fat.c
new file mode 100644 (file)
index 0000000..684148b
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.com>
+ *
+ * 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.
+ */
+
+#include "ao.h"
+#include "ao_log.h"
+#include "ao_fat.h"
+
+static uint8_t log_year, log_month, log_day;
+static uint8_t log_running;
+static uint8_t log_mutex;
+
+static void
+ao_log_open(void)
+{
+       char    name[12];
+
+       sprintf(name,"%04d%02d%02dLOG", 2000 + log_year, log_month, log_day);
+       if (ao_fat_open(name, AO_FAT_OPEN_WRITE) == AO_FAT_SUCCESS)
+               log_running = 1;
+}
+
+static void
+ao_log_close(void)
+{
+       log_running = 0;
+       ao_fat_close();
+}
+
+uint8_t
+ao_log_full(void)
+{
+       return ao_fat_full();
+}
+
+uint8_t
+ao_log_mega(struct ao_log_mega *log)
+{
+       uint8_t wrote = 0;
+       ao_mutex_get(&log_mutex);
+       if (log->type == AO_LOG_GPS_TIME) {
+               if (log_running &&
+                   (log_year != log->u.gps.year ||
+                    log_month != log->u.gps.month ||
+                    log_day != log->u.gps.day)) {
+                       ao_log_close();
+               }
+               if (!log_running) {
+                       log_year = log->u.gps.year;
+                       log_month = log->u.gps.month;
+                       log_day = log->u.gps.day;
+                       ao_log_open();
+               }
+       }
+       if (log_running) {
+               wrote = ao_fat_write(log, sizeof (*log)) == AO_FAT_SUCCESS;
+               ao_fat_sync();
+       }
+       ao_mutex_put(&log_mutex);
+       return wrote;
+}
index ae36c9fda7fec8c24300a436a8b59131e3400b43..8e610db7594cec3e2eb21cd36affa42a3ce02c21 100644 (file)
@@ -55,7 +55,10 @@ ALTOS_SRC = \
        ao_eeprom_stm.c \
        ao_sdcard.c \
        ao_bufio.c \
-       ao_fat.c
+       ao_fat.c \
+       ao_log_fat.c \
+       ao_gps_report_mega.c \
+       ao_telemetry.c
 
 PRODUCT=TeleGPS-v0.1
 PRODUCT_DEF=-DTELEGPS
index 2f1f38f2004b112beee93c3b4deb58ba405167f5..91796c21082e983bcde7bcbd508dabdd125a5cd5 100644 (file)
@@ -19,6 +19,8 @@
 #include <ao_exti.h>
 #include <ao_fat.h>
 
+uint16_t       ao_flight_number = 1;
+
 int
 main(void)
 {
@@ -47,9 +49,14 @@ main(void)
        ao_usb_init();
        ao_radio_init();
 
+       ao_fat_init();
+
        ao_gps_init();
+       ao_gps_report_mega_init();
 
-       ao_fat_init();
+       ao_telemetry_init();
+       ao_telemetry_set_interval(AO_SEC_TO_TICKS(1));
+       ao_rdf_set(1);
 
        ao_config_init();