2 // Copyright (c) 2010 Anthony Towns
7 import java.lang.UnsupportedOperationException;
8 import java.util.NoSuchElementException;
9 import java.util.Iterator;
10 import org.altusmetrum.AltosLib.*;
12 class AltosDataPointReader implements Iterable<AltosDataPoint> {
13 Iterator<AltosRecord> iter;
19 final static int MISSING = AltosRecord.MISSING;
21 public AltosDataPointReader(AltosRecordIterable reader) {
22 this.iter = reader.iterator();
25 has_gps = reader.has_gps();
26 has_ignite = reader.has_ignite();
29 private void read_next_record()
30 throws NoSuchElementException
32 state = new AltosState(iter.next(), state);
35 private AltosDataPoint current_dp() {
36 assert this.state != null;
38 return new AltosDataPoint() {
39 public int version() { return state.data.version; }
40 public int serial() { return state.data.serial; }
41 public int flight() { return state.data.flight; }
42 public String callsign() { return state.data.callsign; }
43 public double time() { return state.data.time; }
44 public double rssi() { return state.data.rssi; }
46 public int state() { return state.state; }
47 public String state_name() { return state.data.state(); }
49 public double acceleration() { return state.acceleration; }
50 public double height() { return state.height; }
51 public double speed() { return state.speed(); }
52 public double temperature() { return state.temperature; }
53 public double battery_voltage() { return state.battery; }
54 public double drogue_voltage() { return state.drogue_sense; }
55 public double main_voltage() { return state.main_sense; }
56 public boolean has_accel() { return true; } // return state.acceleration != AltosRecord.MISSING; }
60 public Iterator<AltosDataPoint> iterator() {
61 return new Iterator<AltosDataPoint>() {
62 public void remove() {
63 throw new UnsupportedOperationException();
65 public boolean hasNext() {
66 if (state != null && state.state == Altos.ao_flight_landed)
68 return iter.hasNext();
70 public AltosDataPoint next() {
73 } while (state.data.time < -1.0 && hasNext());