altos: mark gps date written only after it gets into eeprom
authorKeith Packard <keithp@keithp.com>
Fri, 27 Aug 2010 06:37:29 +0000 (23:37 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 27 Aug 2010 06:37:29 +0000 (23:37 -0700)
Data logging doesn't start until boost detect occurs. As the GPS date
is only logged once, if that happens before logging is written to the
flash, then the GPS date will never get saved.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao.h
src/ao_gps_report.c
src/ao_log.c

index d289ced1adf8b9abac41e116dc46e77f6cae4cde..8db22799f24df6fca7ec59fb30cc54416572d504 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -564,6 +564,7 @@ struct ao_log_record {
                        uint8_t         year;
                        uint8_t         month;
                        uint8_t         day;
+                       uint8_t         extra;
                } gps_date;
                struct {
                        uint16_t        d0;
@@ -573,7 +574,7 @@ struct ao_log_record {
 };
 
 /* Write a record to the eeprom log */
-void
+uint8_t
 ao_log_data(__xdata struct ao_log_record *log) __reentrant;
 
 /* Flush the log */
index cceb79ffeb82be0b03e72b73f53b3ca2cdb2db5c..7abc93f5d8e868cda3c5542a75b06a9e73846f4e 100644 (file)
@@ -51,12 +51,12 @@ ao_gps_report(void)
                gps_log.u.gps_altitude.unused = 0xffff;
                ao_log_data(&gps_log);
                if (!date_reported && (gps_data.flags & AO_GPS_DATE_VALID)) {
-                       date_reported = 1;
                        gps_log.type = AO_LOG_GPS_DATE;
                        gps_log.u.gps_date.year = gps_data.year;
                        gps_log.u.gps_date.month = gps_data.month;
                        gps_log.u.gps_date.day = gps_data.day;
-                       ao_log_data(&gps_log);
+                       gps_log.u.gps_date.extra = 0;
+                       date_reported = ao_log_data(&gps_log);
                }
        }
 }
index d550d40850cde2a8eef8b71c8d4828f7ea49306c..18bdb8c8d4f63cdca7b370d6c40cf0445322ffa7 100644 (file)
@@ -33,14 +33,16 @@ ao_log_csum(__xdata uint8_t *b) __reentrant
        return -sum;
 }
 
-void
+uint8_t
 ao_log_data(__xdata struct ao_log_record *log) __reentrant
 {
+       uint8_t wrote = 0;
        /* set checksum */
        log->csum = 0;
        log->csum = ao_log_csum((__xdata uint8_t *) log);
        ao_mutex_get(&ao_log_mutex); {
                if (ao_log_running) {
+                       wrote = 1;
                        ao_ee_write(ao_log_current_pos,
                                    (uint8_t *) log,
                                    sizeof (struct ao_log_record));
@@ -51,6 +53,7 @@ ao_log_data(__xdata struct ao_log_record *log) __reentrant
                                ao_log_running = 0;
                }
        } ao_mutex_put(&ao_log_mutex);
+       return wrote;
 }
 
 void