2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
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.
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.
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.
18 package org.altusmetrum.AltosLib;
20 public class AltosRecord implements Comparable <AltosRecord>, Cloneable {
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;
33 public final static int MISSING = 0x7fffffff;
35 /* Every AltosRecord implementation provides these fields */
38 public String callsign;
46 /* Current flight dynamic state */
47 public double acceleration; /* m/s² */
48 public double speed; /* m/s */
49 public double height; /* m */
52 public boolean new_gps;
54 public double time; /* seconds since boost */
56 public int device_type;
57 public int config_major;
58 public int config_minor;
59 public int apogee_delay;
60 public int main_deploy;
61 public int flight_log_max;
62 public String firmware_version;
64 public AltosRecordCompanion companion;
67 * Abstract methods that convert record data
78 public double raw_pressure() { return MISSING; }
80 public double filtered_pressure() { return MISSING; }
82 public double ground_pressure() { return MISSING; }
84 public double battery_voltage() { return MISSING; }
86 public double main_voltage() { return MISSING; }
88 public double drogue_voltage() { return MISSING; }
90 public double temperature() { return MISSING; }
92 public double acceleration() { return MISSING; }
94 public double accel_speed() { return MISSING; }
96 public AltosIMU imu() { return null; }
98 public AltosMag mag() { return null; }
101 * Convert various pressure values to altitude
104 public double raw_altitude() {
105 double p = raw_pressure();
108 return AltosConvert.pressure_to_altitude(p);
111 public double ground_altitude() {
112 double p = ground_pressure();
115 return AltosConvert.pressure_to_altitude(p);
118 public double filtered_altitude() {
119 double ga = ground_altitude();
120 if (height != MISSING && ga != MISSING)
123 double p = filtered_pressure();
125 return raw_altitude();
126 return AltosConvert.pressure_to_altitude(p);
129 public double filtered_height() {
130 if (height != MISSING)
133 double f = filtered_altitude();
134 double g = ground_altitude();
135 if (f == MISSING || g == MISSING)
140 public double raw_height() {
141 double r = raw_altitude();
142 double g = ground_altitude();
144 if (r == MISSING || g == MISSING)
149 public String state() {
150 return AltosLib.state_name(state);
153 public int compareTo(AltosRecord o) {
154 return tick - o.tick;
157 public void copy(AltosRecord old) {
159 version = old.version;
160 callsign = old.callsign;
167 acceleration = old.acceleration;
170 gps = new AltosGPS(old.gps);
171 new_gps = old.new_gps;
172 companion = old.companion;
175 public AltosRecord clone() {
177 AltosRecord n = (AltosRecord) super.clone();
180 } catch (CloneNotSupportedException e) {
185 public AltosRecord() {
193 state = AltosLib.ao_flight_startup;
195 acceleration = MISSING;
198 gps = new AltosGPS();