add a paragraph about forcing TM back to idle mode if an accel cal goes badly
[fw/altos] / ao-tools / 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 import altosui.AltosDataPoint;
14 import altosui.AltosRecordIterable;
15 import altosui.AltosRecord;
16 import altosui.AltosState;
17
18 class AltosDataPointReader implements Iterable<AltosDataPoint> {
19     Iterator<AltosRecord> iter;
20     AltosState state;
21     AltosRecord record;
22
23     public AltosDataPointReader(Iterable<AltosRecord> reader) {
24         this.iter = reader.iterator();
25         this.state = null;
26     }
27
28     private void read_next_record() 
29         throws NoSuchElementException
30     {
31         record = iter.next();
32         state = new AltosState(record, state);
33     }
34
35     private AltosDataPoint current_dp() {
36         assert this.record != null;
37         
38         return new AltosDataPoint() {
39             public int version() { return record.version; }
40             public int serial() { return record.serial; }
41             public int flight() { return record.flight; }
42             public String callsign() { return record.callsign; }
43             public double time() { return record.time; }
44             public double rssi() { return record.rssi; }
45
46             public int state() { return record.state; }
47             public String state_name() { return record.state(); }
48
49             public double acceleration() { return record.acceleration(); }
50             public double pressure() { return record.raw_pressure(); }
51             public double altitude() { return record.raw_altitude(); }
52             public double height() { return record.raw_height(); }
53             public double accel_speed() { return record.accel_speed(); }
54             public double baro_speed() { return state.baro_speed; }
55             public double temperature() { return record.temperature(); }
56             public double battery_voltage() { return record.battery_voltage(); }
57             public double drogue_voltage() { return record.drogue_voltage(); }
58             public double main_voltage() { return record.main_voltage(); }
59         };
60     }
61
62     public Iterator<AltosDataPoint> iterator() {
63         return new Iterator<AltosDataPoint>() {
64             public void remove() { 
65                 throw new UnsupportedOperationException(); 
66             }
67             public boolean hasNext() {
68                 return iter.hasNext();
69             }
70             public AltosDataPoint next() {
71                 read_next_record();
72                 return current_dp();
73             }
74         };
75     }
76 }
77