altosui: Create .dmg file for Mac OS X installations
[fw/altos] / altoslib / AltosRecordTM.java
1 /*
2  * Copyright © 2012 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;
19
20 public class AltosRecordTM extends AltosRecord {
21
22         /* Sensor values */
23         public int      accel;
24         public int      pres;
25         public int      temp;
26         public int      batt;
27         public int      drogue;
28         public int      main;
29
30         public int      ground_accel;
31         public int      ground_pres;
32         public int      accel_plus_g;
33         public int      accel_minus_g;
34
35         public int      flight_accel;
36         public int      flight_vel;
37         public int      flight_pres;
38
39         /*
40          * Values for our MP3H6115A pressure sensor
41          *
42          * From the data sheet:
43          *
44          * Pressure range: 15-115 kPa
45          * Voltage at 115kPa: 2.82
46          * Output scale: 27mV/kPa
47          *
48          *
49          * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa
50          * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa
51          */
52
53         static final double counts_per_kPa = 27 * 2047 / 3300;
54         static final double counts_at_101_3kPa = 1674.0;
55
56         static double
57         barometer_to_pressure(double count)
58         {
59                 return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
60         }
61
62         public double pressure() {
63                 if (pres == MISSING)
64                         return MISSING;
65                 return barometer_to_pressure(pres);
66         }
67
68         public double ground_pressure() {
69                 if (ground_pres == MISSING)
70                         return MISSING;
71                 return barometer_to_pressure(ground_pres);
72         }
73
74         public double battery_voltage() {
75                 if (batt == MISSING)
76                         return MISSING;
77                 return AltosConvert.cc_battery_to_voltage(batt);
78         }
79
80         public double main_voltage() {
81                 if (main == MISSING)
82                         return MISSING;
83                 return AltosConvert.cc_ignitor_to_voltage(main);
84         }
85
86         public double drogue_voltage() {
87                 if (drogue == MISSING)
88                         return MISSING;
89                 return AltosConvert.cc_ignitor_to_voltage(drogue);
90         }
91
92         /* Value for the CC1111 built-in temperature sensor
93          * Output voltage at 0°C = 0.755V
94          * Coefficient = 0.00247V/°C
95          * Reference voltage = 1.25V
96          *
97          * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
98          *      = (value - 19791.268) / 32768 * 1.25 / 0.00247
99          */
100
101         static double
102         thermometer_to_temperature(double thermo)
103         {
104                 return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
105         }
106
107         public double temperature() {
108                 if (temp == MISSING)
109                         return MISSING;
110                 return thermometer_to_temperature(temp);
111         }
112
113         double accel_counts_per_mss() {
114                 double  counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
115
116                 return counts_per_g / 9.80665;
117         }
118
119         public double acceleration() {
120                 if (ground_accel == MISSING || accel == MISSING)
121                         return MISSING;
122                 return (ground_accel - accel) / accel_counts_per_mss();
123         }
124
125         public void copy(AltosRecordTM old) {
126                 super.copy(old);
127
128                 version = old.version;
129                 callsign = old.callsign;
130                 serial = old.serial;
131                 flight = old.flight;
132                 rssi = old.rssi;
133                 status = old.status;
134                 state = old.state;
135                 tick = old.tick;
136                 accel = old.accel;
137                 pres = old.pres;
138                 temp = old.temp;
139                 batt = old.batt;
140                 drogue = old.drogue;
141                 main = old.main;
142                 flight_accel = old.flight_accel;
143                 ground_accel = old.ground_accel;
144                 flight_vel = old.flight_vel;
145                 flight_pres = old.flight_pres;
146                 ground_pres = old.ground_pres;
147                 accel_plus_g = old.accel_plus_g;
148                 accel_minus_g = old.accel_minus_g;
149         }
150
151         public AltosRecordTM clone() {
152                 AltosRecordTM   n = (AltosRecordTM) super.clone();
153                 n.copy(this);
154                 return n;
155         }
156
157         void make_missing() {
158                 accel = MISSING;
159                 pres = MISSING;
160                 temp = MISSING;
161                 batt = MISSING;
162                 drogue = MISSING;
163                 main = MISSING;
164
165                 flight_accel = MISSING;
166                 flight_vel = MISSING;
167                 flight_pres = MISSING;
168
169                 ground_accel = MISSING;
170                 ground_pres = MISSING;
171                 accel_plus_g = MISSING;
172                 accel_minus_g = MISSING;
173         }
174
175         public AltosRecordTM(AltosRecord old) {
176                 super.copy(old);
177                 make_missing();
178         }
179
180         public AltosRecordTM() {
181                 super();
182                 make_missing();
183         }
184 }