diff options
| author | Bdale Garbee <bdale@gag.com> | 2014-06-15 17:47:41 -0600 | 
|---|---|---|
| committer | Bdale Garbee <bdale@gag.com> | 2014-06-15 17:47:41 -0600 | 
| commit | c5cfc0d6e507d093987741b6ffaf69ebb24caa4b (patch) | |
| tree | a75b83343939e96592ac07178f2011d82ea6ded8 /src/kernel/ao_log_telem.c | |
| parent | 1b3d07ede530fa40cb7257fb1725c969ba60e0f0 (diff) | |
| parent | 9ab3a1de95b705783c31a7e16447f52c10b6b480 (diff) | |
Merge branch 'branch-1.4' into debian
Diffstat (limited to 'src/kernel/ao_log_telem.c')
| -rw-r--r-- | src/kernel/ao_log_telem.c | 131 | 
1 files changed, 131 insertions, 0 deletions
diff --git a/src/kernel/ao_log_telem.c b/src/kernel/ao_log_telem.c new file mode 100644 index 00000000..095aca37 --- /dev/null +++ b/src/kernel/ao_log_telem.c @@ -0,0 +1,131 @@ +/* + * Copyright © 2011 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include <ao.h> +#include <ao_flight.h> +#include <ao_sample.h> + +__code uint8_t ao_log_format = AO_LOG_FORMAT_TELEMETRY; + +static __data uint8_t			ao_log_monitor_pos; +__pdata enum ao_flight_state		ao_flight_state; +__xdata int16_t				ao_max_height;	/* max of ao_height */ +__pdata int16_t				sense_d, sense_m; +__pdata uint8_t				ao_igniter_present; + +static void +ao_log_telem_track() { +	if (ao_monitoring == sizeof (union ao_telemetry_all)) { +		switch (ao_log_single_write_data.telemetry.generic.type) { +		case AO_TELEMETRY_SENSOR_TELEMETRUM: +		case AO_TELEMETRY_SENSOR_TELEMINI: +			/* fall through ... */ +		case AO_TELEMETRY_SENSOR_TELENANO: +			if (ao_log_single_write_data.telemetry.generic.type == AO_TELEMETRY_SENSOR_TELENANO) { +				ao_igniter_present = 0; +			} else { +				sense_d = ao_log_single_write_data.telemetry.sensor.sense_d; +				sense_m = ao_log_single_write_data.telemetry.sensor.sense_m; +				ao_igniter_present = 1; +			} +			if (ao_log_single_write_data.telemetry.sensor.height > ao_max_height) { +				ao_max_height = ao_log_single_write_data.telemetry.sensor.height; +			} +			if (ao_log_single_write_data.telemetry.sensor.state != ao_flight_state) { +				ao_flight_state = ao_log_single_write_data.telemetry.sensor.state; +				if (ao_flight_state == ao_flight_pad) +					ao_max_height = 0; +				ao_wakeup(DATA_TO_XDATA(&ao_flight_state)); +			} +		} +	} +} + +enum ao_igniter_status +ao_igniter_status(enum ao_igniter igniter) +{ +	int16_t	value; + +	switch (igniter) { +	case ao_igniter_drogue: +		value = sense_d; +		break; +	case ao_igniter_main: +		value = sense_m; +		break; +	default: +		value = 0; +		break; +	} +	if (value < AO_IGNITER_OPEN) +		return ao_igniter_open; +	else if (value > AO_IGNITER_CLOSED) +		return ao_igniter_ready; +	else +		return ao_igniter_unknown; +} + +void +ao_log_single(void) +{ +	ao_storage_setup(); + +	/* This can take a while, so let the rest +	 * of the system finish booting before we start +	 */ +	ao_delay(AO_SEC_TO_TICKS(2)); + +	ao_log_running = 1; +	ao_log_single_restart(); +	ao_flight_state = ao_flight_startup; +	ao_monitor_set(sizeof(struct ao_telemetry_generic)); + +	for (;;) { +		while (!ao_log_running) +			ao_sleep(&ao_log_running); + +		ao_log_monitor_pos = ao_monitor_head; +		while (ao_log_running) { +			/* Write samples to EEPROM */ +			while (ao_log_monitor_pos != ao_monitor_head) { +				ao_xmemcpy(&ao_log_single_write_data.telemetry, +					   &ao_monitor_ring[ao_log_monitor_pos], +					   AO_LOG_SINGLE_SIZE); +				ao_log_single_write(); +				ao_log_monitor_pos = ao_monitor_ring_next(ao_log_monitor_pos); +				ao_log_telem_track(); +			} +			/* Wait for more telemetry data to arrive */ +			ao_sleep(DATA_TO_XDATA(&ao_monitor_head)); +		} +	} +} + +void +ao_log_single_list(void) +{ +	if (ao_log_current_pos != 0) +		printf("flight 1 start %x end %x\n", +		       0, +		       (uint16_t) ((ao_log_current_pos + 0xff) >> 8)); +	printf ("done\n"); +} + +void +ao_log_single_extra_query(void) +{ +}  | 
