altoslib, altosui: Restructured state management now does TM eeprom files
[fw/altos] / altoslib / AltosRecord.java
1 /*
2  * Copyright © 2010 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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.altoslib_1;
19
20 public class AltosRecord implements Comparable <AltosRecord>, Cloneable {
21
22         public static final int seen_flight = 1;
23         public static final int seen_sensor = 2;
24         public static final int seen_temp_volt = 4;
25         public static final int seen_deploy = 8;
26         public static final int seen_gps_time = 16;
27         public static final int seen_gps_lat = 32;
28         public static final int seen_gps_lon = 64;
29         public static final int seen_companion = 128;
30
31         public int      seen;
32         
33         public final static int MISSING = 0x7fffffff;
34
35         /* Every AltosRecord implementation provides these fields */
36         
37         public int      version;
38         public String   callsign;
39         public int      serial;
40         public int      flight;
41         public int      rssi;
42         public int      status;
43         public int      state;
44         public int      tick;
45
46         public AltosGPS gps;
47         public int      gps_sequence;
48
49         public double   time;   /* seconds since boost */
50
51         public int      device_type;
52         public int      config_major;
53         public int      config_minor;
54         public int      apogee_delay;
55         public int      main_deploy;
56         public int      flight_log_max;
57         public String   firmware_version;
58
59         public double   accel_plus_g, accel_minus_g;
60         public double   ground_accel;
61         public double   accel;
62
63         public AltosRecordCompanion companion;
64
65         /* Telemetry sources have these values recorded from the flight computer */
66         public double   kalman_height;
67         public double   kalman_speed;
68         public double   kalman_acceleration;
69
70         /*
71          * Abstract methods that convert record data
72          * to standard units:
73          *
74          *      pressure:       Pa
75          *      voltage:        V
76          *      acceleration:   m/s²
77          *      speed:          m/s
78          *      height:         m
79          *      temperature:    °C
80          */
81
82         public double pressure() { return MISSING; }
83         public double ground_pressure() { return MISSING; }
84         public double acceleration() { return MISSING; }
85
86         public double altitude() {
87                 double  p = pressure();
88
89                 if (p == MISSING)
90                         return MISSING;
91                 return AltosConvert.pressure_to_altitude(p);
92         }
93
94         public double ground_altitude() {
95                 double  p = ground_pressure();
96
97                 if (p == MISSING)
98                         return MISSING;
99                 return AltosConvert.pressure_to_altitude(p);
100         }
101
102         public double height() {
103                 double  g = ground_altitude();
104                 double  a = altitude();
105
106                 if (g == MISSING)
107                         return MISSING;
108                 if (a == MISSING)
109                         return MISSING;
110                 return a - g;
111         }
112
113         public double battery_voltage() { return MISSING; }
114
115         public double main_voltage() { return MISSING; }
116
117         public double drogue_voltage() { return MISSING; }
118
119         public double temperature() { return MISSING; }
120         
121         public AltosIMU imu() { return null; }
122
123         public AltosMag mag() { return null; }
124
125         public String state() {
126                 return AltosLib.state_name(state);
127         }
128
129         public int compareTo(AltosRecord o) {
130                 return tick - o.tick;
131         }
132
133         public AltosRecord clone() {
134                 AltosRecord n = new AltosRecord();
135                 n.copy(this);
136                 return n;
137         }
138
139         public void copy(AltosRecord old) {
140                 seen = old.seen;
141                 version = old.version;
142                 callsign = old.callsign;
143                 serial = old.serial;
144                 flight = old.flight;
145                 rssi = old.rssi;
146                 status = old.status;
147                 state = old.state;
148                 tick = old.tick;
149                 gps = new AltosGPS(old.gps);
150                 gps_sequence = old.gps_sequence;
151                 companion = old.companion;
152                 kalman_acceleration = old.kalman_acceleration;
153                 kalman_speed = old.kalman_speed;
154                 kalman_height = old.kalman_height;
155         }
156
157         public AltosRecord() {
158                 seen = 0;
159                 version = 0;
160                 callsign = "N0CALL";
161                 serial = MISSING;
162                 flight = MISSING;
163                 rssi = 0;
164                 status = 0;
165                 state = AltosLib.ao_flight_startup;
166                 tick = 0;
167                 gps = null;
168                 gps_sequence = 0;
169                 companion = null;
170
171                 kalman_acceleration = MISSING;
172                 kalman_speed = MISSING;
173                 kalman_height = MISSING;
174
175                 accel_plus_g = MISSING;
176                 accel_minus_g = MISSING;
177                 
178         }
179 }