Make sure full log is written and flushed on landing.
authorKeith Packard <keithp@keithp.com>
Sun, 26 Apr 2009 08:37:02 +0000 (01:37 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 26 Apr 2009 08:37:02 +0000 (01:37 -0700)
The final state change to landing is recorded in the logging thread, so have
that turn off logging once it has recorded that state. Then make it go to
sleep.

ao_flight.c
ao_gps_report.c
ao_log.c

index 01bbcce..37c138f 100644 (file)
@@ -408,9 +408,6 @@ ao_flight(void)
                                /* turn off the ADC capture */
                                ao_timer_set_adc_interval(0);
 
-                               /* stop logging data */
-                               ao_log_stop();
-
                                ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
                        }
                        break;
index 494714b..1b5402a 100644 (file)
@@ -29,6 +29,9 @@ ao_gps_report(void)
                memcpy(&gps_data, &ao_gps_data, sizeof (struct ao_gps_data));
                ao_mutex_put(&ao_gps_mutex);
 
+               if (!(gps_data.flags & AO_GPS_VALID))
+                       continue;
+
                gps_log.tick = ao_time();
                gps_log.type = AO_LOG_GPS_TIME;
                gps_log.u.gps_time.hour = gps_data.hour;
index c74893f..bcd852c 100644 (file)
--- a/ao_log.c
+++ b/ao_log.c
@@ -125,15 +125,9 @@ ao_log(void)
        log.u.flight.flight = ao_log_dump_flight + 1;
        ao_log_data(&log);
        for (;;) {
-               /* Write state change to EEPROM */
-               if (ao_flight_state != ao_log_state) {
-                       ao_log_state = ao_flight_state;
-                       log.type = AO_LOG_STATE;
-                       log.tick = ao_flight_tick;
-                       log.u.state.state = ao_log_state;
-                       log.u.state.reason = 0;
-                       ao_log_data(&log);
-               }
+               while (!ao_log_running)
+                       ao_sleep(&ao_log_running);
+
                /* Write samples to EEPROM */
                while (ao_log_adc_pos != ao_adc_head) {
                        log.type = AO_LOG_SENSOR;
@@ -155,6 +149,18 @@ ao_log(void)
                        }
                        ao_log_adc_pos = ao_adc_ring_next(ao_log_adc_pos);
                }
+               /* Write state change to EEPROM */
+               if (ao_flight_state != ao_log_state) {
+                       ao_log_state = ao_flight_state;
+                       log.type = AO_LOG_STATE;
+                       log.tick = ao_flight_tick;
+                       log.u.state.state = ao_log_state;
+                       log.u.state.reason = 0;
+                       ao_log_data(&log);
+
+                       if (ao_log_state == ao_flight_landed)
+                               ao_log_stop();
+               }
                
                /* Wait for a while */
                ao_delay(AO_MS_TO_TICKS(100));