altoslib: Don't crash if there's no GPS coord to write KML
[fw/altos] / altoslib / AltosFlightListener.java
1 /*
2  * Copyright © 2017 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
15 package org.altusmetrum.altoslib_12;
16
17 public abstract class AltosFlightListener {
18
19         public int      flight;
20         public int      serial;
21         public int      tick;
22         public int      boost_tick;
23         public int      state;
24
25         public double   accel_plus_g;
26         public double   accel_minus_g;
27         public double   accel;
28
29         public double   ground_pressure;
30         public double   ground_altitude;
31
32         AltosGPS        temp_gps;
33         int             temp_gps_sat_tick;
34         int             gps_sequence;
35
36         /* AltosEepromRecord */
37         public void set_boost_tick(int boost_tick) {
38                 if (boost_tick != AltosLib.MISSING)
39                         this.boost_tick = boost_tick;
40         }
41
42         public void set_tick(int tick) {
43                 if (tick != AltosLib.MISSING)
44                         this.tick = tick;
45         }
46
47         public double time() {
48                 if (tick == AltosLib.MISSING)
49                         return AltosLib.MISSING;
50                 if (boost_tick != AltosLib.MISSING)
51                         return (tick - boost_tick) / 100.0;
52                 else
53                         return tick / 100.0;
54         }
55
56         public double boost_time() {
57                 if (boost_tick == AltosLib.MISSING)
58                         return AltosLib.MISSING;
59                 return boost_tick / 100.0;
60         }
61
62         public abstract void set_rssi(int rssi, int status);
63         public abstract void set_received_time(long received_time);
64
65         /* AltosEepromRecordFull */
66
67         public void set_serial(int serial) {
68                 if (serial != AltosLib.MISSING)
69                         this.serial = serial;
70         }
71
72         public void set_state(int state) {
73                 if (state != AltosLib.MISSING)
74                         this.state = state;
75         }
76
77         public int state() { return state; }
78
79         public abstract void set_ground_accel(double ground_accel);
80         public void set_flight(int flight) {
81                 if (flight != AltosLib.MISSING)
82                         this.flight = flight;
83         }
84         public int flight() {
85                 return flight;
86         }
87
88         public abstract void set_accel(double accel);
89         public abstract void set_acceleration(double accel);
90         public abstract void set_accel_g(double accel_plus_g, double accel_minus_g);
91         public abstract void set_pressure(double pa);
92         public abstract void set_thrust(double N);
93
94         public abstract void set_temperature(double deg_c);
95         public abstract void set_battery_voltage(double volts);
96
97         public abstract void set_apogee_voltage(double volts);
98         public abstract void set_main_voltage(double volts);
99
100         public void set_temp_gps() {
101                 temp_gps = null;
102         }
103
104         public boolean gps_pending() {
105                 return temp_gps != null;
106         }
107
108         public AltosGPS make_temp_gps(boolean sats) {
109                 if (temp_gps == null) {
110                         temp_gps = new AltosGPS();
111                 }
112                 if (sats) {
113                         if (tick != temp_gps_sat_tick)
114                                 temp_gps.cc_gps_sat = null;
115                         temp_gps_sat_tick = tick;
116                 }
117                 return temp_gps;
118         }
119
120         public void set_ground_pressure(double ground_pressure) {
121                 if (ground_pressure != AltosLib.MISSING) {
122                         this.ground_pressure = ground_pressure;
123                         this.ground_altitude = AltosConvert.pressure_to_altitude(ground_pressure);
124                 }
125         }
126
127         public abstract void set_accel_ground(double along, double across, double through);
128         public abstract void set_gyro_zero(double roll, double pitch, double yaw);
129         public abstract void check_imu_wrap(AltosIMU imu);
130         public abstract void set_imu(AltosIMU imu);
131         public abstract void set_mag(AltosMag mag);
132         public abstract void set_pyro_voltage(double volts);
133         public abstract void set_igniter_voltage(double[] voltage);
134         public abstract void set_pyro_fired(int pyro_mask);
135
136         public void copy(AltosFlightListener old) {
137                 flight = old.flight;
138                 serial = old.serial;
139                 tick = old.tick;
140                 boost_tick = old.boost_tick;
141                 accel_plus_g = old.accel_plus_g;
142                 accel_minus_g = old.accel_minus_g;
143                 ground_pressure = old.ground_pressure;
144                 ground_altitude = old.ground_altitude;
145                 temp_gps = old.temp_gps;
146                 temp_gps_sat_tick = old.temp_gps_sat_tick;
147         }
148
149         public void init() {
150                 flight = AltosLib.MISSING;
151                 serial = AltosLib.MISSING;
152                 tick = AltosLib.MISSING;
153                 boost_tick = AltosLib.MISSING;
154                 accel_plus_g = AltosLib.MISSING;
155                 accel_minus_g = AltosLib.MISSING;
156                 accel = AltosLib.MISSING;
157                 ground_pressure = AltosLib.MISSING;
158                 ground_altitude = AltosLib.MISSING;
159                 temp_gps = null;
160                 temp_gps_sat_tick = AltosLib.MISSING;
161         }
162 }