summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-03-30 01:33:49 -0700
committerKeith Packard <keithp@keithp.com>2013-03-30 01:33:49 -0700
commit649999863c7228ead0225968752d068dc0d30091 (patch)
tree6f3ac2cdab37a2b6975b0ead08f7d92bd6f587cb
parentb3d8956df3a3ecb3918b5db4d78b057d68541c33 (diff)
altos: Add logging and telem to telegps
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>
-rw-r--r--ao-tools/ao-telem/ao-telem.c9
-rw-r--r--src/core/ao_gps_report_mega.c1
-rw-r--r--src/core/ao_telemetry.c3
-rw-r--r--src/drivers/ao_log_fat.c74
-rw-r--r--src/telegps-v0.1/Makefile5
-rw-r--r--src/telegps-v0.1/ao_telegps.c9
6 files changed, 97 insertions, 4 deletions
diff --git a/ao-tools/ao-telem/ao-telem.c b/ao-tools/ao-telem/ao-telem.c
index e7fc8e26..d2dae5a7 100644
--- a/ao-tools/ao-telem/ao-telem.c
+++ b/ao-tools/ao-telem/ao-telem.c
@@ -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;
}
diff --git a/src/core/ao_gps_report_mega.c b/src/core/ao_gps_report_mega.c
index 47891cab..e3af4307 100644
--- a/src/core/ao_gps_report_mega.c
+++ b/src/core/ao_gps_report_mega.c
@@ -16,6 +16,7 @@
*/
#include "ao.h"
+#include "ao_log.h"
void
ao_gps_report_mega(void)
diff --git a/src/core/ao_telemetry.c b/src/core/ao_telemetry.c
index 8d440e15..3aa315c7 100644
--- a/src/core/ao_telemetry.c
+++ b/src/core/ao_telemetry.c
@@ -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
index 00000000..684148b7
--- /dev/null
+++ b/src/drivers/ao_log_fat.c
@@ -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;
+}
diff --git a/src/telegps-v0.1/Makefile b/src/telegps-v0.1/Makefile
index ae36c9fd..8e610db7 100644
--- a/src/telegps-v0.1/Makefile
+++ b/src/telegps-v0.1/Makefile
@@ -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
diff --git a/src/telegps-v0.1/ao_telegps.c b/src/telegps-v0.1/ao_telegps.c
index 2f1f38f2..91796c21 100644
--- a/src/telegps-v0.1/ao_telegps.c
+++ b/src/telegps-v0.1/ao_telegps.c
@@ -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();