summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2011-03-18 19:49:46 -0700
committerKeith Packard <keithp@keithp.com>2011-03-18 19:49:46 -0700
commit32c51840c792a737019fbc9fe42f2ca073b71827 (patch)
treeed06a5f3a71445063d198802b2dc55c11945671a /src
parent62eae8a17d870e8ac6937ba23da01a5fbc652c6c (diff)
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 <keithp@keithp.com>
Diffstat (limited to 'src')
-rw-r--r--src/ao_log_tiny.c23
1 files changed, 17 insertions, 6 deletions
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);
}
}