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;
22 import java.util.HashMap;
25 public class AltosRecord implements Comparable <AltosRecord>, Cloneable {
27 public static final int seen_flight = 1;
28 public static final int seen_sensor = 2;
29 public static final int seen_temp_volt = 4;
30 public static final int seen_deploy = 8;
31 public static final int seen_gps_time = 16;
32 public static final int seen_gps_lat = 32;
33 public static final int seen_gps_lon = 64;
34 public static final int seen_companion = 128;
38 public final static int MISSING = 0x7fffffff;
40 /* Every AltosRecord implementation provides these fields */
43 public String callsign;
51 /* Current flight dynamic state */
52 public double acceleration; /* m/s² */
53 public double speed; /* m/s */
54 public double height; /* m */
57 public boolean new_gps;
59 public double time; /* seconds since boost */
61 public int device_type;
62 public int config_major;
63 public int config_minor;
64 public int apogee_delay;
65 public int main_deploy;
66 public int flight_log_max;
67 public String firmware_version;
69 public AltosRecordCompanion companion;
72 * Abstract methods that convert record data
83 public double raw_pressure() { return MISSING; }
85 public double filtered_pressure() { return MISSING; }
87 public double ground_pressure() { return MISSING; }
89 public double battery_voltage() { return MISSING; }
91 public double main_voltage() { return MISSING; }
93 public double drogue_voltage() { return MISSING; }
95 public double temperature() { return MISSING; }
97 public double acceleration() { return MISSING; }
99 public double accel_speed() { return MISSING; }
101 public AltosIMU imu() { return null; }
103 public AltosMag mag() { return null; }
106 * Convert various pressure values to altitude
109 public double raw_altitude() {
110 double p = raw_pressure();
113 return AltosConvert.pressure_to_altitude(p);
116 public double ground_altitude() {
117 double p = ground_pressure();
120 return AltosConvert.pressure_to_altitude(p);
123 public double filtered_altitude() {
124 double ga = ground_altitude();
125 if (height != MISSING && ga != MISSING)
128 double p = filtered_pressure();
131 return AltosConvert.pressure_to_altitude(p);
134 public double filtered_height() {
135 if (height != MISSING)
138 double f = filtered_altitude();
139 double g = ground_altitude();
140 if (f == MISSING || g == MISSING)
145 public double raw_height() {
146 double r = raw_altitude();
147 double g = ground_altitude();
149 if (r == MISSING || g == MISSING)
154 public String state() {
155 return AltosLib.state_name(state);
158 public int compareTo(AltosRecord o) {
159 return tick - o.tick;
162 public void copy(AltosRecord old) {
164 version = old.version;
165 callsign = old.callsign;
172 acceleration = old.acceleration;
175 gps = new AltosGPS(old.gps);
177 companion = old.companion;
180 public AltosRecord clone() {
182 AltosRecord n = (AltosRecord) super.clone();
185 } catch (CloneNotSupportedException e) {
190 public AltosRecord() {
198 state = AltosLib.ao_flight_startup;
200 acceleration = MISSING;
203 gps = new AltosGPS();