diff options
| author | Keith Packard <keithp@keithp.com> | 2013-08-31 01:48:02 -0500 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-08-31 01:48:58 -0500 | 
| commit | f07f6d55edf5b97020680b3ce1d9e00bb3df64a6 (patch) | |
| tree | d701ad9e7a598d2436eb66d3cd958409c364a374 /altoslib/AltosTelemetryFile.java | |
| parent | de8d9c5630ae46378c50faf97f7d2e97fe139e30 (diff) | |
altoslib/altosui: Get legacy telem working with new AltosState structure
Make AltosTelemetry work without AltosRecord
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosTelemetryFile.java')
| -rw-r--r-- | altoslib/AltosTelemetryFile.java | 94 | 
1 files changed, 94 insertions, 0 deletions
| diff --git a/altoslib/AltosTelemetryFile.java b/altoslib/AltosTelemetryFile.java new file mode 100644 index 00000000..9e992576 --- /dev/null +++ b/altoslib/AltosTelemetryFile.java @@ -0,0 +1,94 @@ +/* + * Copyright © 2013 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. + */ + +package org.altusmetrum.altoslib_1; + +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; +	} + +	public void remove () { +	} + +	public AltosTelemetryIterator(AltosState start, Iterator<AltosTelemetry> telems) { +		this.state = start; +		this.telems = telems; +		this.seen = false; +	} +} + +public class AltosTelemetryFile extends AltosStateIterable { + +	AltosTelemetryIterable	telems; +	AltosState		start; + +	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(); + +		for (AltosTelemetry telem : telems) { +			telem.update_state(state); +			if (state.state >= AltosLib.ao_flight_boost) { +				start.set_boost_tick(state.tick); +				break; +			} +		} +	} + +	public Iterator<AltosState> iterator() { +		AltosState			state = start.clone(); +		Iterator<AltosTelemetry>  	i = telems.iterator(); + +		while (i.hasNext() && !state.valid()) { +			AltosTelemetry	t = i.next(); +			t.update_state(state); +		} +		return new AltosTelemetryIterator(state, i); +	} +}
\ No newline at end of file | 
