altosui: Parse remaining standard telemetry packets
authorKeith Packard <keithp@keithp.com>
Wed, 6 Jul 2011 04:41:44 +0000 (21:41 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 6 Jul 2011 04:41:44 +0000 (21:41 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/Altos.java
altosui/AltosLog.java
altosui/AltosRecord.java
altosui/AltosTelemetryRecordConfiguration.java [new file with mode: 0644]
altosui/AltosTelemetryRecordGeneral.java
altosui/AltosTelemetryRecordLocation.java [new file with mode: 0644]
altosui/AltosTelemetryRecordRaw.java
altosui/AltosTelemetryRecordSatellite.java [new file with mode: 0644]
altosui/AltosTelemetryRecordSensor.java
altosui/Makefile.am

index 25d97bcf2b5c6fc35c145c201e12ee5c440caea1..37a4f67bfdb278188b7a78c42dcd6091f2edd098 100644 (file)
@@ -231,10 +231,21 @@ public class Altos {
        static final Charset    unicode_set = Charset.forName("UTF-8");
 
        static String string(int[] bytes, int s, int l) {
        static final Charset    unicode_set = Charset.forName("UTF-8");
 
        static String string(int[] bytes, int s, int l) {
-               byte[]  b = new byte[bytes.length];
+               if (s + l > bytes.length) {
+                       if (s > bytes.length) {
+                               s = bytes.length;
+                               l = 0;
+                       } else {
+                               l = bytes.length - s;
+                       }
+               }
+
+               byte[]  b = new byte[l];
+
                for (int i = 0; i < l; i++)
                        b[i] = (byte) bytes[s+i];
                for (int i = 0; i < l; i++)
                        b[i] = (byte) bytes[s+i];
-               return new String(b, unicode_set);
+               String n = new String(b, unicode_set);
+               return n;
        }
 
        static int hexbyte(String s, int i) {
        }
 
        static int hexbyte(String s, int i) {
index 64275f32e4a9868e4a336d6808babb3c11d94fe2..855ee2b4a724fd22963a02a54db3fd60b2a6b346 100644 (file)
@@ -82,7 +82,9 @@ class AltosLog implements Runnable {
                                        continue;
                                try {
                                        AltosRecord     telem = AltosTelemetry.parse(line.line, previous);
                                        continue;
                                try {
                                        AltosRecord     telem = AltosTelemetry.parse(line.line, previous);
-                                       if (telem.serial != serial || telem.flight != flight || log_file == null) {
+                                       if (telem.serial != 0 && telem.flight != 0 &&
+                                           (telem.serial != serial || telem.flight != flight || log_file == null))
+                                       {
                                                close_log_file();
                                                serial = telem.serial;
                                                flight = telem.flight;
                                                close_log_file();
                                                serial = telem.serial;
                                                flight = telem.flight;
index 8976edf05b90cdb007a6a3e3517beeed58967145..144b1c3c5a1a94caa847ab4bf8b11655082e0677 100644 (file)
@@ -67,6 +67,13 @@ public class AltosRecord {
 
        double  time;   /* seconds since boost */
 
 
        double  time;   /* seconds since boost */
 
+       int     device_type;
+       int     config_major;
+       int     config_minor;
+       int     apogee_delay;
+       int     main_deploy;
+       int     flight_log_max;
+       String  firmware_version;
        /*
         * Values for our MP3H6115A pressure sensor
         *
        /*
         * Values for our MP3H6115A pressure sensor
         *
diff --git a/altosui/AltosTelemetryRecordConfiguration.java b/altosui/AltosTelemetryRecordConfiguration.java
new file mode 100644 (file)
index 0000000..98dc6ab
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+
+public class AltosTelemetryRecordConfiguration extends AltosTelemetryRecordRaw {
+       int     device_type;
+       int     flight;
+       int     config_major;
+       int     config_minor;
+       int     apogee_delay;
+       int     main_deploy;
+       int     flight_log_max;
+       String  callsign;
+       String  version;
+
+       public AltosTelemetryRecordConfiguration(int[] in_bytes) {
+               super(in_bytes);
+
+               device_type    = uint8(5);
+               flight         = uint16(6);
+               config_major   = uint8(8);
+               config_minor   = uint8(9);
+               apogee_delay   = uint16(10);
+               main_deploy    = uint16(12);
+               flight_log_max = uint16(14);
+               callsign       = string(16, 8);
+               version        = string(24, 8);
+       }
+
+       public AltosRecord update_state(AltosRecord previous) {
+               AltosRecord     next = super.update_state(previous);
+
+               next.device_type = device_type;
+               next.flight = flight;
+               next.config_major = config_major;
+               next.config_minor = config_minor;
+               next.apogee_delay = apogee_delay;
+               next.main_deploy = main_deploy;
+               next.flight_log_max = flight_log_max;
+
+               next.callsign = callsign;
+               next.firmware_version = version;
+
+               next.seen |= AltosRecord.seen_deploy;
+
+               return next;
+       }
+}
index 55f6c495098ef6006da5ccee377c66dfc902f5ca..722baba32a60f872c6117bf15ba668e3687b1843 100644 (file)
@@ -34,7 +34,6 @@ public class AltosTelemetryRecordGeneral {
                        throw new AltosCRCException(AltosParse.parse_int(word[i++]));
                }
 
                        throw new AltosCRCException(AltosParse.parse_int(word[i++]));
                }
 
-               System.out.printf("First word \"%s\"\n", word[i]);
                if (word[i].equals("TELEM"))
                        r = AltosTelemetryRecordRaw.parse(word[i+1]);
                else
                if (word[i].equals("TELEM"))
                        r = AltosTelemetryRecordRaw.parse(word[i+1]);
                else
diff --git a/altosui/AltosTelemetryRecordLocation.java b/altosui/AltosTelemetryRecordLocation.java
new file mode 100644 (file)
index 0000000..76bd106
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+
+public class AltosTelemetryRecordLocation extends AltosTelemetryRecordRaw {
+       int     flags;
+       int     altitude;
+       int     latitude;
+       int     longitude;
+       int     year;
+       int     month;
+       int     day;
+       int     hour;
+       int     minute;
+       int     second;
+       int     pdop;
+       int     hdop;
+       int     vdop;
+       int     mode;
+       int     ground_speed;
+       int     climb_rate;
+       int     course;
+
+       public AltosTelemetryRecordLocation(int[] in_bytes) {
+               super(in_bytes);
+
+               flags          = uint8(5);
+               altitude       = int16(6);
+               latitude       = uint32(8);
+               longitude      = uint32(12);
+               year           = uint8(16);
+               month          = uint8(17);
+               day            = uint8(18);
+               hour           = uint8(19);
+               minute         = uint8(20);
+               second         = uint8(21);
+               pdop           = uint8(22);
+               hdop           = uint8(23);
+               vdop           = uint8(24);
+               mode           = uint8(25);
+               ground_speed   = uint16(26);
+               climb_rate     = int16(28);
+               course         = uint8(30);
+       }
+
+       public AltosRecord update_state(AltosRecord previous) {
+               AltosRecord     next = super.update_state(previous);
+
+               if (next.gps == null)
+                       next.gps = new AltosGPS();
+
+               next.gps.nsat = flags & 0xf;
+               next.gps.locked = (flags & (1 << 4)) != 0;
+               next.gps.connected = (flags & (1 << 5)) != 0;
+
+               if (next.gps.locked) {
+                       next.gps.lat = latitude * 1.0e-7;
+                       next.gps.lon = longitude * 1.0e-7;
+                       next.gps.alt = altitude;
+                       next.gps.year = 2000 + year;
+                       next.gps.month = month;
+                       next.gps.day = day;
+                       next.gps.hour = hour;
+                       next.gps.minute = minute;
+                       next.gps.second = second;
+                       next.gps.ground_speed = ground_speed * 1.0e-2;
+                       next.gps.course = course * 2;
+                       next.gps.climb_rate = climb_rate * 1.0e-2;
+                       next.gps.hdop = hdop;
+                       next.gps.vdop = vdop;
+                       next.seen |= AltosRecord.seen_gps_time | AltosRecord.seen_gps_lat | AltosRecord.seen_gps_lon;
+               }
+
+               return next;
+       }
+}
index 35796a22fd5a9606a7958af266e2c7b86ceb4e1d..e6c4cfc8af44ddf3ba5c3424df4b44b7cf7ef48e 100644 (file)
@@ -30,9 +30,9 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord {
        final static int packet_type_TM_sensor = 0x01;
        final static int packet_type_Tm_sensor = 0x02;
        final static int packet_type_Tn_sensor = 0x03;
        final static int packet_type_TM_sensor = 0x01;
        final static int packet_type_Tm_sensor = 0x02;
        final static int packet_type_Tn_sensor = 0x03;
-       final static int packet_type_config = 0x04;
-       final static int packet_type_GPS_location = 0x05;
-       final static int packet_type_GPS_satellites = 0x06;
+       final static int packet_type_configuration = 0x04;
+       final static int packet_type_location = 0x05;
+       final static int packet_type_satellite = 0x06;
        
        final static int PKT_APPEND_STATUS_1_CRC_OK             = (1 << 7);
        final static int PKT_APPEND_STATUS_1_LQI_MASK           = (0x7f);
        
        final static int PKT_APPEND_STATUS_1_CRC_OK             = (1 << 7);
        final static int PKT_APPEND_STATUS_1_LQI_MASK           = (0x7f);
@@ -43,8 +43,6 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord {
                for (int i = 1; i < bytes.length - 1; i++)
                        sum += bytes[i];
                sum &= 0xff;
                for (int i = 1; i < bytes.length - 1; i++)
                        sum += bytes[i];
                sum &= 0xff;
-               System.out.printf("%d bytes sum 0x%x last byte 0x%x\n",
-                                 bytes.length, sum, bytes[bytes.length - 1]);
                return sum == bytes[bytes.length - 1];
        }
 
                return sum == bytes[bytes.length - 1];
        }
 
@@ -69,10 +67,6 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord {
                int     rssi = Altos.int8(bytes, bytes.length - 3) / 2 - 74;
                int     status = Altos.uint8(bytes, bytes.length - 2);
 
                int     rssi = Altos.int8(bytes, bytes.length - 3) / 2 - 74;
                int     status = Altos.uint8(bytes, bytes.length - 2);
 
-               System.out.printf ("rssi 0x%x = %d status 0x%x\n",
-                                  Altos.uint8(bytes, bytes.length - 3),
-                                  rssi, status);
-
                if ((status & PKT_APPEND_STATUS_1_CRC_OK) == 0)
                        throw new AltosCRCException(rssi);
 
                if ((status & PKT_APPEND_STATUS_1_CRC_OK) == 0)
                        throw new AltosCRCException(rssi);
 
@@ -84,12 +78,22 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord {
                        case packet_type_TM_sensor:
                        case packet_type_Tm_sensor:
                        case packet_type_Tn_sensor:
                        case packet_type_TM_sensor:
                        case packet_type_Tm_sensor:
                        case packet_type_Tn_sensor:
-                               r = new AltosTelemetryRecordSensor(bytes);
+                               r = new AltosTelemetryRecordSensor(bytes, rssi);
+                               break;
+                       case packet_type_configuration:
+                               r = new AltosTelemetryRecordConfiguration(bytes);
+                               break;
+                       case packet_type_location:
+                               r = new AltosTelemetryRecordLocation(bytes);
+                               break;
+                       case packet_type_satellite:
+                               r = new AltosTelemetryRecordSatellite(bytes);
                                break;
                        default:
                                r = new AltosTelemetryRecordRaw(bytes);
                                break;
                        }
                                break;
                        default:
                                r = new AltosTelemetryRecordRaw(bytes);
                                break;
                        }
+                       break;
                case Altos.ao_telemetry_legacy_len + 4:
                        r = new AltosTelemetryRecordLegacy(bytes, rssi, status);
                        break;
                case Altos.ao_telemetry_legacy_len + 4:
                        r = new AltosTelemetryRecordLegacy(bytes, rssi, status);
                        break;
@@ -119,6 +123,10 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord {
                return Altos.uint32(bytes, off + 1);
        }
 
                return Altos.uint32(bytes, off + 1);
        }
 
+       public String string(int off, int l) {
+               return Altos.string(bytes, off + 1, l);
+       }
+
        public AltosTelemetryRecordRaw(int[] in_bytes) {
                bytes = in_bytes;
                serial = uint16(0);
        public AltosTelemetryRecordRaw(int[] in_bytes) {
                bytes = in_bytes;
                serial = uint16(0);
@@ -127,9 +135,13 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord {
        }
 
        public AltosRecord update_state(AltosRecord previous) {
        }
 
        public AltosRecord update_state(AltosRecord previous) {
+               AltosRecord     next;
                if (previous != null)
                if (previous != null)
-                       return new AltosRecord(previous);
+                       next = new AltosRecord(previous);
                else
                else
-                       return new AltosRecord();
+                       next = new AltosRecord();
+               next.serial = serial;
+               next.tick = tick;
+               return next;
        }
 }
        }
 }
diff --git a/altosui/AltosTelemetryRecordSatellite.java b/altosui/AltosTelemetryRecordSatellite.java
new file mode 100644 (file)
index 0000000..2dd782a
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+public class AltosTelemetryRecordSatellite extends AltosTelemetryRecordRaw {
+       int             channels;
+       AltosGPSSat[]   sats;
+
+       public AltosTelemetryRecordSatellite(int[] in_bytes) {
+               super(in_bytes);
+
+               channels = uint8(5);
+               if (channels > 12)
+                       channels = 12;
+               if (channels == 0)
+                       sats = null;
+               else {
+                       sats = new AltosGPSSat[channels];
+                       for (int i = 0; i < channels; i++) {
+                               int     svid =  uint8(6 + i * 2 + 0);
+                               int     c_n_1 = uint8(6 + i * 2 + 1);
+                               sats[i] = new AltosGPSSat(svid, c_n_1);
+                       }
+               }
+       }
+
+       public AltosRecord update_state(AltosRecord previous) {
+               AltosRecord     next = super.update_state(previous);
+
+               if (next.gps == null)
+                       next.gps = new AltosGPS();
+
+               next.gps.cc_gps_sat = sats;
+
+               return next;
+       }
+}
index 5ae9f8912b3fc792dde96724c3fce4e154de0ca3..3998437b6c86dcc46b9e73e2d9767dff745f18a6 100644 (file)
@@ -36,7 +36,9 @@ public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw {
        int     accel_plus_g;
        int     accel_minus_g;
 
        int     accel_plus_g;
        int     accel_minus_g;
 
-       public AltosTelemetryRecordSensor(int[] in_bytes) {
+       int     rssi;
+
+       public AltosTelemetryRecordSensor(int[] in_bytes, int in_rssi) {
                super(in_bytes);
                state         = uint8(5);
 
                super(in_bytes);
                state         = uint8(5);
 
@@ -51,14 +53,53 @@ public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw {
                speed         = int16(20);
                height        = int16(22);
 
                speed         = int16(20);
                height        = int16(22);
 
-               ground_accel  = int16(24);
-               ground_pres   = int16(26);
+               ground_pres   = int16(24);
+               ground_accel  = int16(26);
                accel_plus_g  = int16(28);
                accel_minus_g = int16(30);
                accel_plus_g  = int16(28);
                accel_minus_g = int16(30);
+
+               rssi          = in_rssi;
        }
 
        public AltosRecord update_state(AltosRecord previous) {
                AltosRecord     next = super.update_state(previous);
        }
 
        public AltosRecord update_state(AltosRecord previous) {
                AltosRecord     next = super.update_state(previous);
+
+               next.state = state;
+               if (type == packet_type_TM_sensor)
+                       next.accel = accel;
+               else
+                       next.accel = AltosRecord.MISSING;
+               next.pres = pres;
+               next.temp = temp;
+               next.batt = v_batt;
+               if (type == packet_type_TM_sensor || type == packet_type_Tm_sensor) {
+                       next.drogue = sense_d;
+                       next.main = sense_m;
+               } else {
+                       next.drogue = AltosRecord.MISSING;
+                       next.main = AltosRecord.MISSING;
+               }
+
+               next.acceleration = acceleration / 16.0;
+               next.speed = speed / 16.0;
+               next.height = height;
+
+               next.ground_pres = ground_pres;
+               if (type == packet_type_TM_sensor) {
+                       next.ground_accel = ground_accel;
+                       next.accel_plus_g = accel_plus_g;
+                       next.accel_minus_g = accel_minus_g;
+               } else {
+                       next.ground_accel = AltosRecord.MISSING;
+                       next.accel_plus_g = AltosRecord.MISSING;
+                       next.accel_minus_g = AltosRecord.MISSING;
+               }
+
+               next.rssi = rssi;
+
+               next.seen |= AltosRecord.seen_sensor | AltosRecord.seen_temp_volt;
+
+               System.out.printf("Sensor record update - rssi %d\n", rssi);
                return next;
        }
 }
                return next;
        }
 }
index 6a4d9d17503a9945d3f09a424369722e1d712eb6..6e64acab1e95c06cbfafc1c9db3e8b1967c7ba27 100644 (file)
@@ -75,6 +75,9 @@ altosui_JAVA = \
        AltosTelemetryRecordGeneral.java \
        AltosTelemetryRecordRaw.java \
        AltosTelemetryRecordSensor.java \
        AltosTelemetryRecordGeneral.java \
        AltosTelemetryRecordRaw.java \
        AltosTelemetryRecordSensor.java \
+       AltosTelemetryRecordConfiguration.java \
+       AltosTelemetryRecordLocation.java \
+       AltosTelemetryRecordSatellite.java \
        AltosTelemetryRecordLegacy.java \
        AltosTelemetryMap.java \
        AltosReplayReader.java \
        AltosTelemetryRecordLegacy.java \
        AltosTelemetryMap.java \
        AltosReplayReader.java \