use multimaint-merge to make Debian changelogs less ugly
[fw/altos] / altosui / AltosTelemetry.java
index 91b6d0481436c536ae8f5d46f3ac1e04e91e4b2a..a05269f4d305c7f5d3c9ad62587b5ed5cd0ea453 100644 (file)
@@ -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,141 +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++]);
-
-               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);
        }
 }