AltosSiteMap: add targeting circles around landing site
[fw/altos] / ao-tools / altosui / AltosTelemetry.java
1 /*
2  * Copyright © 2010 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 altosui;
19
20 import java.lang.*;
21 import java.text.*;
22 import java.util.HashMap;
23 import altosui.AltosConvert;
24 import altosui.AltosRecord;
25 import altosui.AltosGPS;
26 import altosui.AltosCRCException;
27
28 /*
29  * Telemetry data contents
30  */
31
32
33 /*
34  * The telemetry data stream is a bit of a mess at present, with no consistent
35  * formatting. In particular, the GPS data is formatted for viewing instead of parsing.
36  * However, the key feature is that every telemetry line contains all of the information
37  * necessary to describe the current rocket state, including the calibration values
38  * for accelerometer and barometer.
39  *
40  * GPS unlocked:
41  *
42  * VERSION 2 CALL KB0G SERIAL  51 FLIGHT     2 RSSI  -68 STATUS ff STATE     pad  1001 \
43  *    a: 16032 p: 21232 t: 20284 v: 25160 d:   204 m:   204 fa: 16038 ga: 16032 fv:       0 \
44  *    fp: 21232 gp: 21230 a+: 16049 a-: 16304 GPS  0 sat unlocked SAT 1   15  30
45  *
46  * GPS locked:
47  *
48  * VERSION 2 CALL KB0G SERIAL  51 FLIGHT     2 RSSI  -71 STATUS ff STATE     pad  2504 \
49  *     a: 16028 p: 21220 t: 20360 v: 25004 d:   208 m:   200 fa: 16031 ga: 16032 fv:     330 \
50  *     fp: 21231 gp: 21230 a+: 16049 a-: 16304 \
51  *     GPS  9 sat 2010-02-13 17:16:51 35°20.0803'N 106°45.2235'W  1790m  \
52  *     0.00m/s(H) 0°     0.00m/s(V) 1.0(hdop)     0(herr)     0(verr) \
53  *     SAT 10   29  30  24  28   5  25  21  20  15  33   1  23  30  24  18  26  10  29   2  26
54  */
55
56 public class AltosTelemetry extends AltosRecord {
57         public AltosTelemetry(String line) throws ParseException, AltosCRCException {
58                 String[] words = line.split("\\s+");
59                 int     i = 0;
60
61                 if (words[i].equals("CRC") && words[i+1].equals("INVALID")) {
62                         i += 2;
63                         AltosParse.word(words[i++], "RSSI");
64                         rssi = AltosParse.parse_int(words[i++]);
65                         throw new AltosCRCException(rssi);
66                 }
67                 if (words[i].equals("CALL")) {
68                         version = 0;
69                 } else {
70                         AltosParse.word (words[i++], "VERSION");
71                         version = AltosParse.parse_int(words[i++]);
72                 }
73
74                 AltosParse.word (words[i++], "CALL");
75                 callsign = words[i++];
76
77                 AltosParse.word (words[i++], "SERIAL");
78                 serial = AltosParse.parse_int(words[i++]);
79
80                 if (version >= 2) {
81                         AltosParse.word (words[i++], "FLIGHT");
82                         flight = AltosParse.parse_int(words[i++]);
83                 } else
84                         flight = 0;
85
86                 AltosParse.word(words[i++], "RSSI");
87                 rssi = AltosParse.parse_int(words[i++]);
88
89                 /* Older telemetry data had mis-computed RSSI value */
90                 if (version <= 2)
91                         rssi = (rssi + 74) / 2 - 74;
92
93                 AltosParse.word(words[i++], "STATUS");
94                 status = AltosParse.parse_hex(words[i++]);
95
96                 AltosParse.word(words[i++], "STATE");
97                 state = Altos.state(words[i++]);
98
99                 tick = AltosParse.parse_int(words[i++]);
100
101                 AltosParse.word(words[i++], "a:");
102                 accel = AltosParse.parse_int(words[i++]);
103
104                 AltosParse.word(words[i++], "p:");
105                 pres = AltosParse.parse_int(words[i++]);
106
107                 AltosParse.word(words[i++], "t:");
108                 temp = AltosParse.parse_int(words[i++]);
109
110                 AltosParse.word(words[i++], "v:");
111                 batt = AltosParse.parse_int(words[i++]);
112
113                 AltosParse.word(words[i++], "d:");
114                 drogue = AltosParse.parse_int(words[i++]);
115
116                 AltosParse.word(words[i++], "m:");
117                 main = AltosParse.parse_int(words[i++]);
118
119                 AltosParse.word(words[i++], "fa:");
120                 flight_accel = AltosParse.parse_int(words[i++]);
121
122                 AltosParse.word(words[i++], "ga:");
123                 ground_accel = AltosParse.parse_int(words[i++]);
124
125                 AltosParse.word(words[i++], "fv:");
126                 flight_vel = AltosParse.parse_int(words[i++]);
127
128                 AltosParse.word(words[i++], "fp:");
129                 flight_pres = AltosParse.parse_int(words[i++]);
130
131                 AltosParse.word(words[i++], "gp:");
132                 ground_pres = AltosParse.parse_int(words[i++]);
133
134                 if (version >= 1) {
135                         AltosParse.word(words[i++], "a+:");
136                         accel_plus_g = AltosParse.parse_int(words[i++]);
137
138                         AltosParse.word(words[i++], "a-:");
139                         accel_minus_g = AltosParse.parse_int(words[i++]);
140                 } else {
141                         accel_plus_g = ground_accel;
142                         accel_minus_g = ground_accel + 530;
143                 }
144
145                 gps = new AltosGPS(words, i, version);
146         }
147 }