2 // Copyright (c) 2010 Anthony Towns
7 import java.io.IOException;
8 import java.text.ParseException;
9 import java.lang.UnsupportedOperationException;
10 import java.util.NoSuchElementException;
11 import java.util.Iterator;
13 class AltosDataPointReader implements Iterable<AltosDataPoint> {
14 Iterator<AltosRecord> iter;
21 final static int MISSING = AltosRecord.MISSING;
23 public AltosDataPointReader(AltosRecordIterable reader) {
24 this.iter = reader.iterator();
26 has_accel = reader.has_accel();
27 has_gps = reader.has_gps();
28 has_ignite = reader.has_ignite();
31 private void read_next_record()
32 throws NoSuchElementException
35 state = new AltosState(record, state);
38 private AltosDataPoint current_dp() {
39 assert this.record != null;
41 return new AltosDataPoint() {
42 public int version() { return record.version; }
43 public int serial() { return record.serial; }
44 public int flight() { return record.flight; }
45 public String callsign() { return record.callsign; }
46 public double time() { return record.time; }
47 public double rssi() { return record.rssi; }
49 public int state() { return record.state; }
50 public String state_name() { return record.state(); }
52 public double acceleration() { return record.acceleration(); }
53 public double pressure() { return record.raw_pressure(); }
54 public double altitude() { return record.raw_altitude(); }
55 public double height() { return record.raw_height(); }
56 public double accel_speed() { return record.accel_speed(); }
57 public double baro_speed() { return state.baro_speed; }
58 public double temperature() { return record.temperature(); }
59 public double battery_voltage() { return record.battery_voltage(); }
60 public double drogue_voltage() { return record.drogue_voltage(); }
61 public double main_voltage() { return record.main_voltage(); }
62 public boolean has_accel() { return has_accel; }
66 public Iterator<AltosDataPoint> iterator() {
67 return new Iterator<AltosDataPoint>() {
68 public void remove() {
69 throw new UnsupportedOperationException();
71 public boolean hasNext() {
72 if (record != null && record.state == Altos.ao_flight_landed)
74 return iter.hasNext();
76 public AltosDataPoint next() {
79 } while (record.time < -1.0 && hasNext());