diff options
author | Keith Packard <keithp@keithp.com> | 2011-06-28 01:03:00 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2011-06-28 01:03:00 -0700 |
commit | 7fd9b8f720add559b262e81d61ededc9df16ca94 (patch) | |
tree | ae32f830c27c99aacdfd6fb231e70a3ceee0f3ff /altosui/AltosTelemetry.java | |
parent | cb239b7161feea8646425b1f5788c3c82ae24321 (diff) |
altosui: Support raw telemetry from TeleDongle
Use raw telemetry frames when TeleDongle supports them, this involves
parsing the hex dump of the packet instead of having teledongle take
the packet apart. Only the legacy format is working at this point; the
altos bits for the new split telemetry frames is not written yet.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosui/AltosTelemetry.java')
-rw-r--r-- | altosui/AltosTelemetry.java | 153 |
1 files changed, 8 insertions, 145 deletions
diff --git a/altosui/AltosTelemetry.java b/altosui/AltosTelemetry.java index 7d68b5b5..a05269f4 100644 --- a/altosui/AltosTelemetry.java +++ b/altosui/AltosTelemetry.java @@ -27,6 +27,10 @@ import java.util.HashMap; /* + * The packet format is a simple hex dump of the raw telemetry frame. + * It starts with 'TELEM', then contains hex digits with a checksum as the last + * byte on the line. + * * Version 4 is a replacement with consistent syntax. Each telemetry line * contains a sequence of space-separated names and values, the values are * either integers or strings. The names are all unique. All values are @@ -81,6 +85,7 @@ import java.util.HashMap; */ public class AltosTelemetry extends AltosRecord { + /* * General header fields * @@ -228,151 +233,9 @@ public class AltosTelemetry extends AltosRecord { final static String AO_TELEM_SAT_SVID = "s_v"; final static String AO_TELEM_SAT_C_N_0 = "s_c"; - private void parse_v4(String[] words, int i) throws ParseException { - AltosTelemetryMap map = new AltosTelemetryMap(words, i); - - callsign = map.get_string(AO_TELEM_CALL, "N0CALL"); - serial = map.get_int(AO_TELEM_SERIAL, MISSING); - flight = map.get_int(AO_TELEM_FLIGHT, MISSING); - rssi = map.get_int(AO_TELEM_RSSI, MISSING); - state = Altos.state(map.get_string(AO_TELEM_STATE, "invalid")); - tick = map.get_int(AO_TELEM_TICK, 0); - - /* raw sensor values */ - accel = map.get_int(AO_TELEM_RAW_ACCEL, MISSING); - pres = map.get_int(AO_TELEM_RAW_BARO, MISSING); - temp = map.get_int(AO_TELEM_RAW_THERMO, MISSING); - batt = map.get_int(AO_TELEM_RAW_BATT, MISSING); - drogue = map.get_int(AO_TELEM_RAW_DROGUE, MISSING); - main = map.get_int(AO_TELEM_RAW_MAIN, MISSING); - - /* sensor calibration information */ - ground_accel = map.get_int(AO_TELEM_CAL_ACCEL_GROUND, MISSING); - ground_pres = map.get_int(AO_TELEM_CAL_BARO_GROUND, MISSING); - accel_plus_g = map.get_int(AO_TELEM_CAL_ACCEL_PLUS, MISSING); - accel_minus_g = map.get_int(AO_TELEM_CAL_ACCEL_MINUS, MISSING); - - /* flight computer values */ - acceleration = map.get_double(AO_TELEM_KALMAN_ACCEL, MISSING, 1/16.0); - speed = map.get_double(AO_TELEM_KALMAN_SPEED, MISSING, 1/16.0); - height = map.get_int(AO_TELEM_KALMAN_HEIGHT, MISSING); - - flight_accel = map.get_int(AO_TELEM_ADHOC_ACCEL, MISSING); - flight_vel = map.get_int(AO_TELEM_ADHOC_SPEED, MISSING); - flight_pres = map.get_int(AO_TELEM_ADHOC_BARO, MISSING); - - if (map.has(AO_TELEM_GPS_STATE)) - gps = new AltosGPS(map); - else - gps = null; - } - - private void parse_legacy(String[] words, int i) throws ParseException { - - AltosParse.word (words[i++], "CALL"); - callsign = words[i++]; - - AltosParse.word (words[i++], "SERIAL"); - serial = AltosParse.parse_int(words[i++]); - - if (version >= 2) { - AltosParse.word (words[i++], "FLIGHT"); - flight = AltosParse.parse_int(words[i++]); - } else - flight = 0; - - AltosParse.word(words[i++], "RSSI"); - rssi = AltosParse.parse_int(words[i++]); - - /* Older telemetry data had mis-computed RSSI value */ - if (version <= 2) - rssi = (rssi + 74) / 2 - 74; - - AltosParse.word(words[i++], "STATUS"); - status = AltosParse.parse_hex(words[i++]); - - AltosParse.word(words[i++], "STATE"); - state = Altos.state(words[i++]); - - tick = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "a:"); - accel = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "p:"); - pres = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "t:"); - temp = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "v:"); - batt = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "d:"); - drogue = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "m:"); - main = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "fa:"); - flight_accel = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "ga:"); - ground_accel = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "fv:"); - flight_vel = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "fp:"); - flight_pres = AltosParse.parse_int(words[i++]); - - /* Old TeleDongle code with kalman-reporting TeleMetrum code */ - if ((flight_vel & 0xffff0000) == 0x80000000) { - speed = ((short) flight_vel) / 16.0; - acceleration = flight_accel / 16.0; - height = flight_pres; - flight_vel = MISSING; - flight_pres = MISSING; - flight_accel = MISSING; - } - - AltosParse.word(words[i++], "gp:"); - ground_pres = AltosParse.parse_int(words[i++]); - - if (version >= 1) { - AltosParse.word(words[i++], "a+:"); - accel_plus_g = AltosParse.parse_int(words[i++]); - - AltosParse.word(words[i++], "a-:"); - accel_minus_g = AltosParse.parse_int(words[i++]); - } else { - accel_plus_g = ground_accel; - accel_minus_g = ground_accel + 530; - } - - gps = new AltosGPS(words, i, version); - } - - public AltosTelemetry(String line) throws ParseException, AltosCRCException { - String[] words = line.split("\\s+"); - int i = 0; - - if (words[i].equals("CRC") && words[i+1].equals("INVALID")) { - i += 2; - AltosParse.word(words[i++], "RSSI"); - rssi = AltosParse.parse_int(words[i++]); - throw new AltosCRCException(rssi); - } - if (words[i].equals("CALL")) { - version = 0; - } else { - AltosParse.word (words[i++], "VERSION"); - version = AltosParse.parse_int(words[i++]); - } + static public AltosRecord parse(String line, AltosRecord previous) throws ParseException, AltosCRCException { + AltosTelemetryRecord r = AltosTelemetryRecordGeneral.parse(line); - if (version < 4) - parse_legacy(words, i); - else - parse_v4(words, i); + return r.update_state(previous); } } |