]> git.gag.com Git - fw/altos/blob - altosui/AltosDataPointReader.java
Revert "altos: Don't abort radio transmissions with ao_radio_abort"
[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.io.IOException;
8 import java.text.ParseException;
9 import java.lang.UnsupportedOperationException;
10 import java.util.NoSuchElementException;
11 import java.util.Iterator;
12
13 class AltosDataPointReader implements Iterable<AltosDataPoint> {
14     Iterator<AltosRecord> iter;
15     AltosState state;
16     AltosRecord record;
17
18     public AltosDataPointReader(Iterable<AltosRecord> reader) {
19         this.iter = reader.iterator();
20         this.state = null;
21     }
22
23     private void read_next_record() 
24         throws NoSuchElementException
25     {
26         record = iter.next();
27         state = new AltosState(record, state);
28     }
29
30     private AltosDataPoint current_dp() {
31         assert this.record != null;
32         
33         return new AltosDataPoint() {
34             public int version() { return record.version; }
35             public int serial() { return record.serial; }
36             public int flight() { return record.flight; }
37             public String callsign() { return record.callsign; }
38             public double time() { return record.time; }
39             public double rssi() { return record.rssi; }
40
41             public int state() { return record.state; }
42             public String state_name() { return record.state(); }
43
44             public double acceleration() { return record.acceleration(); }
45             public double pressure() { return record.raw_pressure(); }
46             public double altitude() { return record.raw_altitude(); }
47             public double height() { return record.raw_height(); }
48             public double accel_speed() { return record.accel_speed(); }
49             public double baro_speed() { return state.baro_speed; }
50             public double temperature() { return record.temperature(); }
51             public double battery_voltage() { return record.battery_voltage(); }
52             public double drogue_voltage() { return record.drogue_voltage(); }
53             public double main_voltage() { return record.main_voltage(); }
54         };
55     }
56
57     public Iterator<AltosDataPoint> iterator() {
58         return new Iterator<AltosDataPoint>() {
59             public void remove() { 
60                 throw new UnsupportedOperationException(); 
61             }
62             public boolean hasNext() {
63                 return iter.hasNext();
64             }
65             public AltosDataPoint next() {
66                 read_next_record();
67                 return current_dp();
68             }
69         };
70     }
71 }
72