Merge branch 'prefs_interface' into altosdroid
[fw/altos] / altoslib / AltosTelemetryRecordSensor.java
1 /*
2  * Copyright © 2011 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
21 public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw {
22         int     state;
23         int     accel;
24         int     pres;
25         int     temp;
26         int     v_batt;
27         int     sense_d;
28         int     sense_m;
29
30         int     acceleration;
31         int     speed;
32         int     height;
33
34         int     ground_accel;
35         int     ground_pres;
36         int     accel_plus_g;
37         int     accel_minus_g;
38
39         int     rssi;
40
41         public AltosTelemetryRecordSensor(int[] in_bytes, int in_rssi) {
42                 super(in_bytes);
43                 state         = uint8(5);
44
45                 accel         = int16(6);
46                 pres          = int16(8);
47                 temp          = int16(10);
48                 v_batt        = int16(12);
49                 sense_d       = int16(14);
50                 sense_m       = int16(16);
51
52                 acceleration  = int16(18);
53                 speed         = int16(20);
54                 height        = int16(22);
55
56                 ground_pres   = int16(24);
57                 ground_accel  = int16(26);
58                 accel_plus_g  = int16(28);
59                 accel_minus_g = int16(30);
60
61                 rssi          = in_rssi;
62         }
63
64         public AltosRecord update_state(AltosRecord prev) {
65                 AltosRecord     n = super.update_state(prev);
66
67                 AltosRecordTM   next;
68                 if (!(n instanceof AltosRecordTM))
69                         next = new AltosRecordTM(n);
70                 else
71                         next = (AltosRecordTM) n;
72
73                 next.state = state;
74                 if (type == packet_type_TM_sensor)
75                         next.accel = accel;
76                 else
77                         next.accel = AltosRecord.MISSING;
78                 next.pres = pres;
79                 next.temp = temp;
80                 next.batt = v_batt;
81                 if (type == packet_type_TM_sensor || type == packet_type_Tm_sensor) {
82                         next.drogue = sense_d;
83                         next.main = sense_m;
84                 } else {
85                         next.drogue = AltosRecord.MISSING;
86                         next.main = AltosRecord.MISSING;
87                 }
88
89                 next.acceleration = acceleration / 16.0;
90                 next.speed = speed / 16.0;
91                 next.height = height;
92
93                 next.ground_pres = ground_pres;
94                 if (type == packet_type_TM_sensor) {
95                         next.ground_accel = ground_accel;
96                         next.accel_plus_g = accel_plus_g;
97                         next.accel_minus_g = accel_minus_g;
98                 } else {
99                         next.ground_accel = AltosRecord.MISSING;
100                         next.accel_plus_g = AltosRecord.MISSING;
101                         next.accel_minus_g = AltosRecord.MISSING;
102                 }
103
104                 next.rssi = rssi;
105
106                 next.seen |= AltosRecord.seen_sensor | AltosRecord.seen_temp_volt;
107
108                 return next;
109         }
110 }