From: Keith Packard Date: Sat, 19 Mar 2011 02:49:46 +0000 (-0700) Subject: altos: Tiny logging fixes. Scan at start, stop when land or full. X-Git-Tag: 0.9.3~134 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=32c51840c792a737019fbc9fe42f2ca073b71827;hp=62eae8a17d870e8ac6937ba23da01a5fbc652c6c altos: Tiny logging fixes. Scan at start, stop when land or full. Initialize the flight log for tiny systems by scanning the log area to find the current flight number and log area bounds. Stop logging data when the flight is over, or when the log area is full. Signed-off-by: Keith Packard --- diff --git a/src/ao_log_tiny.c b/src/ao_log_tiny.c index 877c1033..157073d4 100644 --- a/src/ao_log_tiny.c +++ b/src/ao_log_tiny.c @@ -18,7 +18,6 @@ #include "ao.h" static __data uint16_t ao_log_tiny_interval; -static __data uint32_t ao_log_tiny_pos; #define AO_LOG_TINY_INTERVAL_ASCENT AO_MS_TO_TICKS(100) #define AO_LOG_TINY_INTERVAL_DEFAULT AO_MS_TO_TICKS(1000) @@ -31,11 +30,16 @@ ao_log_tiny_set_interval(uint16_t ticks) static __xdata uint16_t ao_log_tiny_data_temp; -#define ao_log_tiny_data(d) do { \ - ao_log_tiny_data_temp = (d); \ - ao_storage_write(ao_log_tiny_pos, &ao_log_tiny_data_temp, 2); \ - ao_log_tiny_pos += 2; \ - } while (0) +static void ao_log_tiny_data(uint16_t d) +{ + if (ao_log_current_pos >= ao_log_end_pos && ao_log_running) + ao_log_stop(); + if (ao_log_running) { + ao_log_tiny_data_temp = (d); + ao_storage_write(ao_log_current_pos, &ao_log_tiny_data_temp, 2); + ao_log_current_pos += 2; + } +} void ao_log(void) @@ -46,6 +50,8 @@ ao_log(void) ao_storage_setup(); + ao_log_scan(); + ao_log_tiny_state = ao_flight_invalid; ao_log_tiny_interval = AO_LOG_TINY_INTERVAL_DEFAULT; while (!ao_log_running) @@ -60,12 +66,17 @@ ao_log(void) ao_log_tiny_interval = AO_LOG_TINY_INTERVAL_DEFAULT; if (ao_log_tiny_state <= ao_flight_coast) ao_log_tiny_interval = AO_LOG_TINY_INTERVAL_ASCENT; + if (ao_log_tiny_state == ao_flight_landed) + ao_log_stop(); } ao_log_tiny_data(ao_flight_pres); // XXX change to alt time += ao_log_tiny_interval; delay = time - ao_time(); if (delay > 0) ao_delay(delay); + /* Stop logging when told to */ + while (!ao_log_running) + ao_sleep(&ao_log_running); } }