]> git.gag.com Git - fw/altos/blob - altoslib/AltosTelemetryFile.java
Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / altoslib / AltosTelemetryFile.java
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.altoslib_14;
20
21 import java.io.*;
22 import java.util.*;
23 import java.text.*;
24
25 class AltosTelemetryNullListener extends AltosDataListener {
26         public void set_rssi(int rssi, int status) { }
27         public void set_received_time(long received_time) { }
28
29         public void set_acceleration(double accel) { }
30         public void set_pressure(double pa) { }
31         public void set_thrust(double N) { }
32
33         public void set_kalman(double height, double speed, double accel) { }
34
35         public void set_temperature(double deg_c) { }
36         public void set_battery_voltage(double volts) { }
37
38         public void set_apogee_voltage(double volts) { }
39         public void set_main_voltage(double volts) { }
40
41         public void set_gps(AltosGPS gps) { }
42
43         public void set_orient(double orient) { }
44         public void set_gyro(double roll, double pitch, double yaw) { }
45         public void set_accel_ground(double along, double across, double through) { }
46         public void set_accel(double along, double across, double through) { }
47         public void set_mag(double along, double across, double through) { }
48         public void set_pyro_voltage(double volts) { }
49         public void set_igniter_voltage(double[] voltage) { }
50         public void set_pyro_fired(int pyro_mask) { }
51         public void set_companion(AltosCompanion companion) { }
52         public void set_motor_pressure(double motor_pressure) { }
53
54         public boolean cal_data_complete() {
55                 /* All telemetry packets */
56                 AltosCalData cal_data = cal_data();
57
58                 if (cal_data.serial == AltosLib.MISSING)
59                         return false;
60
61                 if (cal_data.boost_tick == AltosLib.MISSING)
62                         return false;
63
64                 /*
65                  * TelemetryConfiguration:
66                  *
67                  * device_type, flight, config version, log max,
68                  * flight params, callsign and version
69                  */
70                 if (cal_data.device_type == AltosLib.MISSING)
71                         return false;
72
73                 /*
74                  * TelemetrySensor or TelemetryMegaData:
75                  *
76                  * ground_accel, accel+/-, ground pressure
77                  */
78                 if (cal_data.ground_pressure == AltosLib.MISSING)
79                         return false;
80
81                 /*
82                  * TelemetryLocation
83                  */
84                 if (AltosLib.has_gps(cal_data.device_type) && cal_data.gps_pad == null)
85                         return false;
86
87                 return true;
88         }
89
90         public AltosTelemetryNullListener(AltosCalData cal_data) {
91                 super(cal_data);
92         }
93 }
94
95 public class AltosTelemetryFile implements AltosRecordSet {
96
97         AltosTelemetryIterable  telems;
98         AltosCalData            cal_data;
99         int                     first_state;
100
101         public void write_comments(PrintStream out) {
102         }
103
104         public void write(PrintStream out) {
105         }
106
107         /* Construct cal data by walking through the telemetry data until we've found everything available */
108         public AltosCalData cal_data() {
109                 if (cal_data == null) {
110                         cal_data = new AltosCalData();
111                         AltosTelemetryNullListener l = new AltosTelemetryNullListener(cal_data);
112
113                         first_state = AltosLib.ao_flight_startup;
114                         for (AltosTelemetry telem : telems) {
115                                 telem.provide_data(l);
116                                 if (cal_data.state == AltosLib.ao_flight_pad)
117                                         first_state = cal_data.state;
118                                 if (l.cal_data_complete())
119                                         break;
120                         }
121                 }
122                 return cal_data;
123         }
124
125         public boolean valid() {
126                 return true;
127         }
128
129         public void capture_series(AltosDataListener listener) {
130                 cal_data();
131                 cal_data.reset();
132                 cal_data.state = first_state;
133                 for (AltosTelemetry telem : telems) {
134                         telem.provide_data(listener);
135                         if (listener.state() == AltosLib.ao_flight_landed)
136                                 break;
137                 }
138                 listener.finish();
139         }
140
141         public AltosTelemetryFile(FileInputStream input) throws IOException {
142                 telems = new AltosTelemetryIterable(input);
143         }
144 }