Merge branch 'master' into new-state
[fw/altos] / altoslib / AltosRecordMini.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_1;
19
20 public class AltosRecordMini extends AltosRecord {
21
22         /* Sensor values */
23         public int      pres;
24         public int      temp;
25         
26         public int      sense_a;
27         public int      sense_m;
28         public int      v_batt;
29
30         public int      ground_pres;
31
32         public int      flight_accel;
33         public int      flight_vel;
34         public int      flight_height;
35
36         public int      flight_pres;
37
38         static double adc(int raw) {
39                 return raw / 4095.0;
40         }
41
42         public double pressure() {
43                 if (pres != MISSING)
44                         return pres;
45                 return MISSING;
46         }
47
48         public double temperature() {
49                 if (temp != MISSING)
50                         return temp;
51                 return MISSING;
52         }
53
54         public double ground_pressure() {
55                 if (ground_pres != MISSING)
56                         return ground_pres;
57                 return MISSING;
58         }
59
60         public double battery_voltage() {
61                 if (v_batt != MISSING)
62                         return 3.3 * adc(v_batt) * (15.0 + 27.0) / 27.0;
63                 return MISSING;
64         }
65
66         static double pyro(int raw) {
67                 if (raw != MISSING)
68                         return 3.3 * adc(raw) * (100.0 + 27.0) / 27.0;
69                 return MISSING;
70         }
71
72         public double main_voltage() {
73                 return pyro(sense_m);
74         }
75
76         public double apogee_voltage() {
77                 return pyro(sense_a);
78         }
79
80         public void copy (AltosRecordMini old) {
81                 super.copy(old);
82
83                 pres = old.pres;
84                 temp = old.temp;
85
86                 sense_a = old.sense_a;
87                 sense_m = old.sense_m;
88                 v_batt = old.v_batt;
89
90                 ground_pres = old.ground_pres;
91                 
92                 flight_accel = old.flight_accel;
93                 flight_vel = old.flight_vel;
94                 flight_height = old.flight_height;
95                 flight_pres = old.flight_pres;
96         }
97
98
99
100         public AltosRecordMini clone() {
101                 return new AltosRecordMini(this);
102         }
103
104         void make_missing() {
105
106                 pres = MISSING;
107
108                 sense_a = MISSING;
109                 sense_m = MISSING;
110                 v_batt = MISSING;
111
112                 ground_pres = MISSING;
113
114                 flight_accel = 0;
115                 flight_vel = 0;
116                 flight_height = 0;
117                 flight_pres = 0;
118         }
119
120         public AltosRecordMini(AltosRecord old) {
121                 super.copy(old);
122                 make_missing();
123         }
124
125         public AltosRecordMini(AltosRecordMini old) {
126                 copy(old);
127         }
128
129         public AltosRecordMini() {
130                 super();
131                 make_missing();
132         }
133 }