altoslib: Move computed state from AltosRecord to AltosState
[fw/altos] / altoslib / AltosTelemetryRecordMegaData.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 AltosTelemetryRecordMegaData extends AltosTelemetryRecordRaw {
22
23         int     state;
24         
25         int     v_batt;
26         int     v_pyro;
27         int     sense[];
28
29         int     ground_pres;
30         int     ground_accel;
31         int     accel_plus_g;
32         int     accel_minus_g;
33
34         int     acceleration;
35         int     speed;
36         int     height;
37
38         public AltosTelemetryRecordMegaData(int[] in_bytes) {
39                 super(in_bytes);
40
41                 state = int8(5);
42
43                 v_batt = int16(6);
44                 v_pyro = int16(8);
45
46                 sense = new int[6];     
47
48                 for (int i = 0; i < 6; i++) {
49                         sense[i] = int8(10 + i) << 4;
50                         sense[i] |= sense[i] >> 8;
51                 }
52
53                 ground_pres = int32(16);
54                 ground_accel = int16(20);
55                 accel_plus_g = int16(22);
56                 accel_minus_g = int16(24);
57
58                 acceleration = int16(26);
59                 speed = int16(28);
60                 height = int16(30);
61         }
62
63         public AltosRecord update_state(AltosRecord previous) {
64                 AltosRecord     n = super.update_state(previous);
65
66                 AltosRecordMM   next;
67                 if (!(n instanceof AltosRecordMM)) {
68                         next = new AltosRecordMM(n);
69                 } else {
70                         next = (AltosRecordMM) n;
71                 }
72
73                 next.state = state;
74
75                 next.v_batt = v_batt;
76                 next.v_pyro = v_pyro;
77
78                 for (int i = 0; i < 6; i++)
79                         next.sense[i] = sense[i];
80
81                 next.ground_accel = ground_accel;
82                 next.ground_pres = ground_pres;
83                 next.accel_plus_g = accel_plus_g;
84                 next.accel_minus_g = accel_minus_g;
85
86                 next.kalman_acceleration = acceleration / 16.0;
87                 next.kalman_speed = speed / 16.0;
88                 next.kalman_height = height;
89
90                 next.seen |= AltosRecord.seen_flight | AltosRecord.seen_temp_volt;
91
92                 return next;
93         }
94 }