diff options
| author | Keith Packard <keithp@keithp.com> | 2013-10-14 20:42:14 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-10-14 20:42:14 -0700 | 
| commit | db4cd8b3838d27bebdeb6a085a739a36f7634a91 (patch) | |
| tree | c1e2b489b2f1c50714fa6ac3ffbd380384a0e7a4 | |
| parent | 1bd9786802751391cca3b83ac3045029e00e39ee (diff) | |
altoslib,altosui: Be more robust when graphing bogus .telem files
Deal with files containing multiple serial number/flight number values
by preserving the boost_tick value across state resets.
Check for invalid state when computing actual boost time for the stats
window.
Ignore invalid speed/accel values when computing averages.
Signed-off-by: Keith Packard <keithp@keithp.com>
| -rw-r--r-- | altoslib/AltosState.java | 11 | ||||
| -rw-r--r-- | altoslib/AltosTelemetryIterable.java | 2 | ||||
| -rw-r--r-- | altosui/AltosFlightStats.java | 34 | 
3 files changed, 28 insertions, 19 deletions
| diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index a01cddb7..6d55b833 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -836,7 +836,9 @@ public class AltosState implements Cloneable {  		if (flight != AltosLib.MISSING && flight != 0) {  			if (this.flight != AltosLib.MISSING &&  			    this.flight != flight) { +				int bt = boost_tick;  				init(); +				boost_tick = bt;  			}  			this.flight = flight;  		} @@ -847,7 +849,9 @@ public class AltosState implements Cloneable {  		if (serial != AltosLib.MISSING) {  			if (this.serial != AltosLib.MISSING &&  			    this.serial != serial) { +				int bt = boost_tick;  				init(); +				boost_tick = bt;  			}  			this.serial = serial;  		} @@ -1017,10 +1021,9 @@ public class AltosState implements Cloneable {  		if (tick == AltosLib.MISSING)  			return 0.0; -		if (boost_tick != AltosLib.MISSING) { -			return (tick - boost_tick) / 100.0; -		} -		return tick / 100.0; +		if (boost_tick == AltosLib.MISSING) +			return tick / 100.0; +		return (tick - boost_tick) / 100.0;  	}  	public boolean valid() { diff --git a/altoslib/AltosTelemetryIterable.java b/altoslib/AltosTelemetryIterable.java index 9da3b0e6..bf30b4c8 100644 --- a/altoslib/AltosTelemetryIterable.java +++ b/altoslib/AltosTelemetryIterable.java @@ -68,7 +68,7 @@ public class AltosTelemetryIterable implements Iterable<AltosTelemetry> {  	public void add (AltosTelemetry telem) {  		int	t = telem.tick;  		if (!telems.isEmpty()) { -			while (t < tick - 32767) +			while (t < tick - 1000)  				t += 65536;  		}  		tick = t; diff --git a/altosui/AltosFlightStats.java b/altosui/AltosFlightStats.java index 11a3f1a9..552210c3 100644 --- a/altosui/AltosFlightStats.java +++ b/altosui/AltosFlightStats.java @@ -84,7 +84,7 @@ public class AltosFlightStats {  			state = s;  			if (state.acceleration() < 1)  				boost_time = state.time; -			if (state.state >= Altos.ao_flight_boost) +			if (state.state >= AltosLib.ao_flight_boost && state.state <= AltosLib.ao_flight_landed)  				break;  		}  		if (state == null) @@ -118,10 +118,12 @@ public class AltosFlightStats {  			if (state.rssi != AltosLib.MISSING)  				has_rssi = true;  			end_time = state.time; -			if (state.time >= boost_time && state.state < Altos.ao_flight_boost) -				state.state = Altos.ao_flight_boost; -			if (state.time >= landed_time && state.state < Altos.ao_flight_landed) -				state.state = Altos.ao_flight_landed; + +			int state_id = state.state; +			if (state.time >= boost_time && state_id < Altos.ao_flight_boost) +				state_id = Altos.ao_flight_boost; +			if (state.time >= landed_time && state_id < Altos.ao_flight_landed) +				state_id = Altos.ao_flight_landed;  			if (state.gps != null && state.gps.locked) {  				year = state.gps.year;  				month = state.gps.month; @@ -130,20 +132,24 @@ public class AltosFlightStats {  				minute = state.gps.minute;  				second = state.gps.second;  			} -			if (0 <= state.state && state.state < Altos.ao_flight_invalid) { -				state_accel[state.state] += state.acceleration(); -				state_speed[state.state] += state.speed(); -				state_count[state.state]++; -				if (state_start[state.state] == 0.0) -					state_start[state.state] = state.time; -				if (state_end[state.state] < state.time) -					state_end[state.state] = state.time; +			if (0 <= state_id && state_id < Altos.ao_flight_invalid) { +				double acceleration = state.acceleration(); +				double speed = state.speed(); +				if (acceleration != AltosLib.MISSING && speed != AltosLib.MISSING) { +					state_accel[state_id] += acceleration; +					state_speed[state_id] += speed; +					state_count[state_id]++; +				} +				if (state_start[state_id] == 0.0) +					state_start[state_id] = state.time; +				if (state_end[state_id] < state.time) +					state_end[state_id] = state.time;  				max_height = state.max_height();  				max_speed = state.max_speed();  				max_acceleration = state.max_acceleration();  			}  			if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) { -				if (state.state <= Altos.ao_flight_pad) { +				if (state_id <= Altos.ao_flight_pad) {  					pad_lat = state.gps.lat;  					pad_lon = state.gps.lon;  				} | 
