diff options
| author | Anthony Towns <aj@erisian.com.au> | 2010-11-25 09:10:50 +1000 | 
|---|---|---|
| committer | Anthony Towns <aj@erisian.com.au> | 2010-11-25 09:10:50 +1000 | 
| commit | f01096c4b42f9a4720ed0414826c2a283a992545 (patch) | |
| tree | 0d9bebaa5e1b4b171abe6aa642ff7a33a72c6146 /altosui/AltosDataPointReader.java | |
| parent | 357826aa9c7b42c59f5d52b8eb016d73b6da0c7f (diff) | |
| parent | 3fbefb3eea981d34a09496cf8abf0119de2e35bf (diff) | |
Merge branch 'buttonbox' of git://git.gag.com/fw/altos into buttonbox
Diffstat (limited to 'altosui/AltosDataPointReader.java')
| -rw-r--r-- | altosui/AltosDataPointReader.java | 72 | 
1 files changed, 72 insertions, 0 deletions
| diff --git a/altosui/AltosDataPointReader.java b/altosui/AltosDataPointReader.java new file mode 100644 index 00000000..7704310b --- /dev/null +++ b/altosui/AltosDataPointReader.java @@ -0,0 +1,72 @@ + +// Copyright (c) 2010 Anthony Towns +// GPL v2 or later + +package altosui; + +import java.io.IOException; +import java.text.ParseException; +import java.lang.UnsupportedOperationException; +import java.util.NoSuchElementException; +import java.util.Iterator; + +class AltosDataPointReader implements Iterable<AltosDataPoint> { +    Iterator<AltosRecord> iter; +    AltosState state; +    AltosRecord record; + +    public AltosDataPointReader(Iterable<AltosRecord> reader) { +        this.iter = reader.iterator(); +        this.state = null; +    } + +    private void read_next_record()  +        throws NoSuchElementException +    { +        record = iter.next(); +        state = new AltosState(record, state); +    } + +    private AltosDataPoint current_dp() { +        assert this.record != null; +         +        return new AltosDataPoint() { +            public int version() { return record.version; } +            public int serial() { return record.serial; } +            public int flight() { return record.flight; } +            public String callsign() { return record.callsign; } +            public double time() { return record.time; } +            public double rssi() { return record.rssi; } + +            public int state() { return record.state; } +            public String state_name() { return record.state(); } + +            public double acceleration() { return record.acceleration(); } +            public double pressure() { return record.raw_pressure(); } +            public double altitude() { return record.raw_altitude(); } +            public double height() { return record.raw_height(); } +            public double accel_speed() { return record.accel_speed(); } +            public double baro_speed() { return state.baro_speed; } +            public double temperature() { return record.temperature(); } +            public double battery_voltage() { return record.battery_voltage(); } +            public double drogue_voltage() { return record.drogue_voltage(); } +            public double main_voltage() { return record.main_voltage(); } +        }; +    } + +    public Iterator<AltosDataPoint> iterator() { +        return new Iterator<AltosDataPoint>() { +            public void remove() {  +                throw new UnsupportedOperationException();  +            } +            public boolean hasNext() { +                return iter.hasNext(); +            } +            public AltosDataPoint next() { +                read_next_record(); +                return current_dp(); +            } +        }; +    } +} + | 
