diff options
| author | Keith Packard <keithp@keithp.com> | 2009-09-05 22:45:49 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2009-09-05 22:45:49 -0700 | 
| commit | 6d018ab933832e2d80bb1564c339d9fb18b57be2 (patch) | |
| tree | 918ddb35a65374c6dd52fe726ae9989e12876bcd /ao-tools/lib/cc-logfile.c | |
| parent | c46e832b28820d7c5be4efaacbbd7c0607927fe5 (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/cc-logfile.c')
| -rw-r--r-- | ao-tools/lib/cc-logfile.c | 35 | 
1 files changed, 34 insertions, 1 deletions
| 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; | 
