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;
12 import org.altusmetrum.AltosLib.*;
14 class AltosDataPointReader implements Iterable<AltosDataPoint> {
15 Iterator<AltosRecord> iter;
22 final static int MISSING = AltosRecord.MISSING;
24 public AltosDataPointReader(AltosRecordIterable reader) {
25 this.iter = reader.iterator();
27 has_accel = reader.has_accel();
28 has_gps = reader.has_gps();
29 has_ignite = reader.has_ignite();
32 private void read_next_record()
33 throws NoSuchElementException
36 state = new AltosState(record, state);
39 private AltosDataPoint current_dp() {
40 assert this.record != null;
42 return new AltosDataPoint() {
43 public int version() { return record.version; }
44 public int serial() { return record.serial; }
45 public int flight() { return record.flight; }
46 public String callsign() { return record.callsign; }
47 public double time() { return record.time; }
48 public double rssi() { return record.rssi; }
50 public int state() { return record.state; }
51 public String state_name() { return record.state(); }
53 public double acceleration() { return record.acceleration(); }
54 public double pressure() { return record.raw_pressure(); }
55 public double altitude() { return record.raw_altitude(); }
56 public double height() { return record.raw_height(); }
57 public double accel_speed() { return record.accel_speed(); }
58 public double baro_speed() { return state.baro_speed; }
59 public double temperature() { return record.temperature(); }
60 public double battery_voltage() { return record.battery_voltage(); }
61 public double drogue_voltage() { return record.drogue_voltage(); }
62 public double main_voltage() { return record.main_voltage(); }
63 public boolean has_accel() { return has_accel; }
67 public Iterator<AltosDataPoint> iterator() {
68 return new Iterator<AltosDataPoint>() {
69 public void remove() {
70 throw new UnsupportedOperationException();
72 public boolean hasNext() {
73 if (record != null && record.state == Altos.ao_flight_landed)
75 return iter.hasNext();
77 public AltosDataPoint next() {
80 } while (record.time < -1.0 && hasNext());