altosui: remove un-used import
[fw/altos] / altosui / AltosDataPointReader.java
1
2 // Copyright (c) 2010 Anthony Towns
3 // GPL v2 or later
4
5 package altosui;
6
7 import java.lang.UnsupportedOperationException;
8 import java.util.NoSuchElementException;
9 import java.util.Iterator;
10 import org.altusmetrum.AltosLib.*;
11
12 class AltosDataPointReader implements Iterable<AltosDataPoint> {
13     Iterator<AltosRecord> iter;
14     AltosState state;
15     AltosRecord record;
16     boolean has_gps;
17     boolean has_accel;
18     boolean has_ignite;
19
20     final static int MISSING = AltosRecord.MISSING;
21
22     public AltosDataPointReader(AltosRecordIterable reader) {
23         this.iter = reader.iterator();
24         this.state = null;
25         has_accel = reader.has_accel();
26         has_gps = reader.has_gps();
27         has_ignite = reader.has_ignite();
28     }
29
30     private void read_next_record() 
31         throws NoSuchElementException
32     {
33         record = iter.next();
34         state = new AltosState(record, state);
35     }
36
37     private AltosDataPoint current_dp() {
38         assert this.record != null;
39         
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; }
47
48             public int state() { return record.state; }
49             public String state_name() { return record.state(); }
50
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; }
62         };
63     }
64
65     public Iterator<AltosDataPoint> iterator() {
66         return new Iterator<AltosDataPoint>() {
67             public void remove() { 
68                 throw new UnsupportedOperationException(); 
69             }
70             public boolean hasNext() {
71                 if (record != null && record.state == Altos.ao_flight_landed)
72                     return false;
73                 return iter.hasNext();
74             }
75             public AltosDataPoint next() {
76                 do {
77                     read_next_record();
78                 } while (record.time < -1.0 && hasNext());
79                 return current_dp();
80             }
81         };
82     }
83 }
84