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;
20 final static int MISSING = AltosRecord.MISSING;
22 public AltosDataPointReader(AltosRecordIterable reader) {
23 this.iter = reader.iterator();
25 has_accel = reader.has_accel();
26 has_gps = reader.has_gps();
27 has_ignite = reader.has_ignite();
30 private void read_next_record()
31 throws NoSuchElementException
34 state = new AltosState(record, state);
37 private AltosDataPoint current_dp() {
38 assert this.record != null;
40 return new AltosDataPoint() {
41 public int version() { return record.version; }
42 public int serial() { return record.serial; }
43 public int flight() { return record.flight; }
44 public String callsign() { return record.callsign; }
45 public double time() { return record.time; }
46 public double rssi() { return record.rssi; }
48 public int state() { return record.state; }
49 public String state_name() { return record.state(); }
51 public double acceleration() { return record.acceleration(); }
52 public double pressure() { return record.raw_pressure(); }
53 public double altitude() { return record.raw_altitude(); }
54 public double height() { return record.raw_height(); }
55 public double accel_speed() { return record.accel_speed(); }
56 public double baro_speed() { return state.baro_speed; }
57 public double temperature() { return record.temperature(); }
58 public double battery_voltage() { return record.battery_voltage(); }
59 public double drogue_voltage() { return record.drogue_voltage(); }
60 public double main_voltage() { return record.main_voltage(); }
61 public boolean has_accel() { return has_accel; }
65 public Iterator<AltosDataPoint> iterator() {
66 return new Iterator<AltosDataPoint>() {
67 public void remove() {
68 throw new UnsupportedOperationException();
70 public boolean hasNext() {
71 if (record != null && record.state == Altos.ao_flight_landed)
73 return iter.hasNext();
75 public AltosDataPoint next() {
78 } while (record.time < -1.0 && hasNext());