2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
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.
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.
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.
22 import java.util.HashMap;
23 import altosui.AltosConvert;
24 import altosui.AltosGPS;
27 * Telemetry data contents
32 * The telemetry data stream is a bit of a mess at present, with no consistent
33 * formatting. In particular, the GPS data is formatted for viewing instead of parsing.
34 * However, the key feature is that every telemetry line contains all of the information
35 * necessary to describe the current rocket state, including the calibration values
36 * for accelerometer and barometer.
40 * VERSION 2 CALL KB0G SERIAL 51 FLIGHT 2 RSSI -68 STATUS ff STATE pad 1001 \
41 * a: 16032 p: 21232 t: 20284 v: 25160 d: 204 m: 204 fa: 16038 ga: 16032 fv: 0 \
42 * fp: 21232 gp: 21230 a+: 16049 a-: 16304 GPS 0 sat unlocked SAT 1 15 30
46 * VERSION 2 CALL KB0G SERIAL 51 FLIGHT 2 RSSI -71 STATUS ff STATE pad 2504 \
47 * a: 16028 p: 21220 t: 20360 v: 25004 d: 208 m: 200 fa: 16031 ga: 16032 fv: 330 \
48 * fp: 21231 gp: 21230 a+: 16049 a-: 16304 \
49 * GPS 9 sat 2010-02-13 17:16:51 35°20.0803'N 106°45.2235'W 1790m \
50 * 0.00m/s(H) 0° 0.00m/s(V) 1.0(hdop) 0(herr) 0(verr) \
51 * SAT 10 29 30 24 28 5 25 21 20 15 33 1 23 30 24 18 26 10 29 2 26
54 public class AltosTelemetry {
78 public static final int ao_flight_startup = 0;
79 public static final int ao_flight_idle = 1;
80 public static final int ao_flight_pad = 2;
81 public static final int ao_flight_boost = 3;
82 public static final int ao_flight_fast = 4;
83 public static final int ao_flight_coast = 5;
84 public static final int ao_flight_drogue = 6;
85 public static final int ao_flight_main = 7;
86 public static final int ao_flight_landed = 8;
87 public static final int ao_flight_invalid = 9;
89 static HashMap<String,Integer> states = new HashMap<String,Integer>();
91 states.put("startup", ao_flight_startup);
92 states.put("idle", ao_flight_idle);
93 states.put("pad", ao_flight_pad);
94 states.put("boost", ao_flight_boost);
95 states.put("fast", ao_flight_fast);
96 states.put("coast", ao_flight_coast);
97 states.put("drogue", ao_flight_drogue);
98 states.put("main", ao_flight_main);
99 states.put("landed", ao_flight_landed);
100 states.put("invalid", ao_flight_invalid);
104 if (states.containsKey(state))
105 return states.get(state);
106 return ao_flight_invalid;
109 public double altitude() {
110 return AltosConvert.cc_pressure_to_altitude(AltosConvert.cc_barometer_to_pressure(pres));
113 public double pad_altitude() {
114 return AltosConvert.cc_pressure_to_altitude(AltosConvert.cc_barometer_to_pressure(ground_pres));
117 public AltosTelemetry(String line) throws ParseException {
118 String[] words = line.split("\\s+");
122 AltosParse.word (words[i++], "VERSION");
123 version = AltosParse.parse_int(words[i++]);
125 AltosParse.word (words[i++], "CALL");
126 callsign = words[i++];
128 AltosParse.word (words[i++], "SERIAL");
129 serial = AltosParse.parse_int(words[i++]);
131 AltosParse.word (words[i++], "FLIGHT");
132 flight = AltosParse.parse_int(words[i++]);
134 AltosParse.word(words[i++], "RSSI");
135 rssi = AltosParse.parse_int(words[i++]);
137 AltosParse.word(words[i++], "STATUS");
138 status = AltosParse.parse_hex(words[i++]);
140 AltosParse.word(words[i++], "STATE");
143 tick = AltosParse.parse_int(words[i++]);
145 AltosParse.word(words[i++], "a:");
146 accel = AltosParse.parse_int(words[i++]);
148 AltosParse.word(words[i++], "p:");
149 pres = AltosParse.parse_int(words[i++]);
151 AltosParse.word(words[i++], "t:");
152 temp = AltosParse.parse_int(words[i++]);
154 AltosParse.word(words[i++], "v:");
155 batt = AltosParse.parse_int(words[i++]);
157 AltosParse.word(words[i++], "d:");
158 drogue = AltosParse.parse_int(words[i++]);
160 AltosParse.word(words[i++], "m:");
161 main = AltosParse.parse_int(words[i++]);
163 AltosParse.word(words[i++], "fa:");
164 flight_accel = AltosParse.parse_int(words[i++]);
166 AltosParse.word(words[i++], "ga:");
167 ground_accel = AltosParse.parse_int(words[i++]);
169 AltosParse.word(words[i++], "fv:");
170 flight_vel = AltosParse.parse_int(words[i++]);
172 AltosParse.word(words[i++], "fp:");
173 flight_pres = AltosParse.parse_int(words[i++]);
175 AltosParse.word(words[i++], "gp:");
176 ground_pres = AltosParse.parse_int(words[i++]);
178 AltosParse.word(words[i++], "a+:");
179 accel_plus_g = AltosParse.parse_int(words[i++]);
181 AltosParse.word(words[i++], "a-:");
182 accel_minus_g = AltosParse.parse_int(words[i++]);
184 gps = new AltosGPS(words, i);