]> git.gag.com Git - fw/altos/blob - altosui/AltosDataPointReader.java
altosui: Check for JRE 1.7 in Windows installer
[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 import org.altusmetrum.AltosLib.*;
13
14 class AltosDataPointReader implements Iterable<AltosDataPoint> {
15     Iterator<AltosRecord> iter;
16     AltosState state;
17     AltosRecord record;
18     boolean has_gps;
19     boolean has_accel;
20     boolean has_ignite;
21
22     final static int MISSING = AltosRecord.MISSING;
23
24     public AltosDataPointReader(AltosRecordIterable reader) {
25         this.iter = reader.iterator();
26         this.state = null;
27         has_accel = reader.has_accel();
28         has_gps = reader.has_gps();
29         has_ignite = reader.has_ignite();
30     }
31
32     private void read_next_record() 
33         throws NoSuchElementException
34     {
35         record = iter.next();
36         state = new AltosState(record, state);
37     }
38
39     private AltosDataPoint current_dp() {
40         assert this.record != null;
41         
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; }
49
50             public int state() { return record.state; }
51             public String state_name() { return record.state(); }
52
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; }
64         };
65     }
66
67     public Iterator<AltosDataPoint> iterator() {
68         return new Iterator<AltosDataPoint>() {
69             public void remove() { 
70                 throw new UnsupportedOperationException(); 
71             }
72             public boolean hasNext() {
73                 if (record != null && record.state == Altos.ao_flight_landed)
74                     return false;
75                 return iter.hasNext();
76             }
77             public AltosDataPoint next() {
78                 do {
79                     read_next_record();
80                 } while (record.time < -1.0 && hasNext());
81                 return current_dp();
82             }
83         };
84     }
85 }
86