summaryrefslogtreecommitdiff
path: root/ao-tools/lib
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2009-09-05 22:45:49 -0700
committerKeith Packard <keithp@keithp.com>2009-09-05 22:45:49 -0700
commit6d018ab933832e2d80bb1564c339d9fb18b57be2 (patch)
tree918ddb35a65374c6dd52fe726ae9989e12876bcd /ao-tools/lib
parentc46e832b28820d7c5be4efaacbbd7c0607927fe5 (diff)
Handle vageries of .telem files in ao-postflight
Telem files have multiple entries of the same state, and sometimes long gaps between recordings. Deal with this as best as possible. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools/lib')
-rw-r--r--ao-tools/lib/cc-analyse.c8
-rw-r--r--ao-tools/lib/cc-logfile.c35
-rw-r--r--ao-tools/lib/cc.h3
3 files changed, 40 insertions, 6 deletions
diff --git a/ao-tools/lib/cc-analyse.c b/ao-tools/lib/cc-analyse.c
index 6fd36cdc..fc8a8417 100644
--- a/ao-tools/lib/cc-analyse.c
+++ b/ao-tools/lib/cc-analyse.c
@@ -22,11 +22,11 @@ cc_timedata_min(struct cc_timedata *d, double min_time, double max_time)
{
int i;
int set = 0;
- int min_i;
+ int min_i = -1;
double min;
if (d->num == 0)
- return 0;
+ return -1;
for (i = 0; i < d->num; i++)
if (min_time <= d->data[i].time && d->data[i].time <= max_time)
if (!set || d->data[i].value < min) {
@@ -42,11 +42,11 @@ cc_timedata_max(struct cc_timedata *d, double min_time, double max_time)
{
int i;
double max;
- int max_i;
+ int max_i = -1;
int set = 0;
if (d->num == 0)
- return 0;
+ return -1;
for (i = 0; i < d->num; i++)
if (min_time <= d->data[i].time && d->data[i].time <= max_time)
if (!set || d->data[i].value > max) {
diff --git a/ao-tools/lib/cc-logfile.c b/ao-tools/lib/cc-logfile.c
index 444ff089..4abf7eb6 100644
--- a/ao-tools/lib/cc-logfile.c
+++ b/ao-tools/lib/cc-logfile.c
@@ -18,6 +18,7 @@
#include "cc.h"
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
static int
timedata_add(struct cc_timedata *data, double time, double value)
@@ -35,8 +36,11 @@ timedata_add(struct cc_timedata *data, double time, double value)
data->size = newsize;
data->data = newdata;
}
- if (data->num && data->data[data->num-1].time > time)
+ time += data->time_offset;
+ if (data->num && data->data[data->num-1].time > time) {
+ data->time_offset += 65536;
time += 65536;
+ }
data->data[data->num].time = time;
data->data[data->num].value = value;
data->num++;
@@ -66,6 +70,11 @@ gpsdata_add(struct cc_gpsdata *data, struct cc_gpselt *elt)
data->size = newsize;
data->data = newdata;
}
+ elt->time += data->time_offset;
+ if (data->num && data->data[data->num-1].time > elt->time) {
+ data->time_offset += 65536;
+ elt->time += 65536;
+ }
data->data[data->num] = *elt;
data->num++;
return 1;
@@ -156,6 +165,29 @@ read_eeprom(const char *line, struct cc_flightraw *f, double *ground_pres, int *
return 1;
}
+static const char *state_names[] = {
+ "startup",
+ "idle",
+ "pad",
+ "boost",
+ "fast",
+ "coast",
+ "drogue",
+ "main",
+ "landed",
+ "invalid"
+};
+
+static enum ao_flight_state
+state_name_to_state(char *state_name)
+{
+ enum ao_flight_state state;
+ for (state = ao_flight_startup; state < ao_flight_invalid; state++)
+ if (!strcmp(state_names[state], state_name))
+ return state;
+ return ao_flight_invalid;
+}
+
static int
read_telem(const char *line, struct cc_flightraw *f)
{
@@ -172,6 +204,7 @@ read_telem(const char *line, struct cc_flightraw *f)
timedata_add(&f->volt, telem.tick, telem.batt);
timedata_add(&f->drogue, telem.tick, telem.drogue);
timedata_add(&f->main, telem.tick, telem.main);
+ timedata_add(&f->state, telem.tick, state_name_to_state(telem.state));
if (telem.gps.gps_locked) {
gps.time = telem.tick;
gps.lat = telem.gps.lat;
diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h
index 3975cf1b..57f80b8d 100644
--- a/ao-tools/lib/cc.h
+++ b/ao-tools/lib/cc.h
@@ -75,6 +75,7 @@ struct cc_timedata {
int num;
int size;
struct cc_timedataelt *data;
+ double time_offset;
};
@@ -92,8 +93,8 @@ struct cc_gpselt {
struct cc_gpsdata {
int num;
int size;
- double time_offset;
struct cc_gpselt *data;
+ double time_offset;
};
/*