diff options
| author | Bdale Garbee <bdale@gag.com> | 2017-07-21 17:44:03 -0600 | 
|---|---|---|
| committer | Bdale Garbee <bdale@gag.com> | 2017-07-21 17:44:03 -0600 | 
| commit | c8dbcaf69cd538a31ab6e2b568237ae7c8656a9a (patch) | |
| tree | 213ec02db2e80f2e8c39772c0bde95d802900e53 /altoslib/AltosTelemetryFile.java | |
| parent | 0cbfa444a9f9159cb509bb47ca5590fc1d709f64 (diff) | |
| parent | ea3b5815b27005b2f4c3034715f656d28ea8534e (diff) | |
Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
Diffstat (limited to 'altoslib/AltosTelemetryFile.java')
| -rw-r--r-- | altoslib/AltosTelemetryFile.java | 145 | 
1 files changed, 94 insertions, 51 deletions
| diff --git a/altoslib/AltosTelemetryFile.java b/altoslib/AltosTelemetryFile.java index 9c5f8dae..135b0284 100644 --- a/altoslib/AltosTelemetryFile.java +++ b/altoslib/AltosTelemetryFile.java @@ -16,82 +16,125 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altoslib_11; +package org.altusmetrum.altoslib_12;  import java.io.*;  import java.util.*;  import java.text.*; -class AltosTelemetryIterator implements Iterator<AltosState> { -	AltosState			state; -	Iterator<AltosTelemetry>	telems; -	AltosTelemetry			next; -	boolean				seen; - -	public boolean hasNext() { -		return !seen || telems.hasNext(); -	} - -	public AltosState next() { -		if (seen) { -			AltosState	n = state.clone(); -			AltosTelemetry	t = telems.next(); - -			t.update_state(n); -			state = n; -		} -		seen = true; -		return state; +class AltosTelemetryNullListener extends AltosDataListener { +	public void set_rssi(int rssi, int status) { } +	public void set_received_time(long received_time) { } + +	public void set_acceleration(double accel) { } +	public void set_pressure(double pa) { } +	public void set_thrust(double N) { } + +	public void set_kalman(double height, double speed, double accel) { } + +	public void set_temperature(double deg_c) { } +	public void set_battery_voltage(double volts) { } + +	public void set_apogee_voltage(double volts) { } +	public void set_main_voltage(double volts) { } + +	public void set_gps(AltosGPS gps) { } + +	public void set_orient(double orient) { } +	public void set_gyro(double roll, double pitch, double yaw) { } +	public void set_accel_ground(double along, double across, double through) { } +	public void set_accel(double along, double across, double through) { } +	public void set_mag(double along, double across, double through) { } +	public void set_pyro_voltage(double volts) { } +	public void set_igniter_voltage(double[] voltage) { } +	public void set_pyro_fired(int pyro_mask) { } +	public void set_companion(AltosCompanion companion) { } + +	public boolean cal_data_complete() { +		/* All telemetry packets */ +		AltosCalData cal_data = cal_data(); + +		if (cal_data.serial == AltosLib.MISSING) +			return false; + +		if (cal_data.boost_tick == AltosLib.MISSING) +			return false; + +		/* +		 * TelemetryConfiguration: +		 * +		 * device_type, flight, config version, log max, +		 * flight params, callsign and version +		 */ +		if (cal_data.device_type == AltosLib.MISSING) +			return false; + +		/* +		 * TelemetrySensor or TelemetryMegaData: +		 * +		 * ground_accel, accel+/-, ground pressure +		 */ +		if (cal_data.ground_pressure == AltosLib.MISSING) +			return false; + +		/* +		 * TelemetryLocation +		 */ +		if (AltosLib.has_gps(cal_data.device_type) && cal_data.gps_pad == null) +			return false; + +		return true;  	} -	public void remove () { -	} - -	public AltosTelemetryIterator(AltosState start, Iterator<AltosTelemetry> telems) { -		this.state = start; -		this.telems = telems; -		this.seen = false; +	public AltosTelemetryNullListener(AltosCalData cal_data) { +		super(cal_data);  	}  } -public class AltosTelemetryFile extends AltosStateIterable { +public class AltosTelemetryFile implements AltosRecordSet {  	AltosTelemetryIterable	telems; -	AltosState		start; +	AltosCalData		cal_data;  	public void write_comments(PrintStream out) {  	}  	public void write(PrintStream out) { -  	} -	public AltosTelemetryFile(FileInputStream input) { -		telems = new AltosTelemetryIterable(input); -		start = new AltosState(); - -		/* Find boost tick */ -		AltosState	state = start.clone(); +	/* Construct cal data by walking through the telemetry data until we've found everything available */ +	public AltosCalData cal_data() { +		if (cal_data == null) { +			cal_data = new AltosCalData(); +			AltosTelemetryNullListener l = new AltosTelemetryNullListener(cal_data); -		for (AltosTelemetry telem : telems) { -			telem.update_state(state); -			state.finish_update(); -			if (state.state() != AltosLib.ao_flight_invalid && state.state() >= AltosLib.ao_flight_boost) { -				start.set_boost_tick(state.tick); -				break; +			for (AltosTelemetry telem : telems) { +				telem.provide_data(l); +				if (l.cal_data_complete()) +					break;  			}  		} +		return cal_data;  	} -	public Iterator<AltosState> iterator() { -		AltosState			state = start.clone(); -		Iterator<AltosTelemetry>  	i = telems.iterator(); +	public void capture_series(AltosDataListener listener) { +		AltosCalData	cal_data = cal_data(); + +		cal_data.reset(); +		for (AltosTelemetry telem : telems) { +			int tick = telem.tick(); +			cal_data.set_tick(tick); -		while (i.hasNext() && !state.valid()) { -			AltosTelemetry	t = i.next(); -			t.update_state(state); -			state.finish_update(); +			/* Try to pick up at least one pre-boost value */ +			if (cal_data.time() >= -2) +				telem.provide_data(listener); +			if (listener.state == AltosLib.ao_flight_landed) +				break;  		} -		return new AltosTelemetryIterator(state, i); +		listener.finish(); +	} + +	public AltosTelemetryFile(FileInputStream input) throws IOException { +		telems = new AltosTelemetryIterable(input);  	}  } | 
