altosui: Generalize and centralize telemetry constants, parse v0.8 telemetry
authorKeith Packard <keithp@keithp.com>
Sun, 17 Jul 2011 00:38:00 +0000 (17:38 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 17 Jul 2011 00:48:51 +0000 (17:48 -0700)
Move telemetry constants to Altos class, adding functions to compute
names and lengths. Generalize users of these values to use all of the
known values.

Add support for v0.8 TeleMetrum telemetry

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/Altos.java
altosui/AltosFlightUI.java
altosui/AltosPreferences.java
altosui/AltosScanUI.java
altosui/AltosSerial.java
altosui/AltosTelemetryRecordLegacy.java
altosui/AltosTelemetryRecordRaw.java

index 9626379730a16f806170f487f1945047a7a35822..8d5916ad4653a2ebb553496739815541f9a27ab8 100644 (file)
@@ -70,11 +70,23 @@ public class Altos {
 
        /* Telemetry modes */
        static final int ao_telemetry_off = 0;
 
        /* Telemetry modes */
        static final int ao_telemetry_off = 0;
-       static final int ao_telemetry_legacy = 1;
-       static final int ao_telemetry_split = 2;
+       static final int ao_telemetry_min = 1;
+       static final int ao_telemetry_standard = 1;
+       static final int ao_telemetry_0_9 = 2;
+       static final int ao_telemetry_0_8 = 3;
+       static final int ao_telemetry_max = 3;
+
+       static final String[] ao_telemetry_name = {
+               "Off", "Standard Telemetry", "TeleMetrum v0.9", "TeleMetrum v0.8"
+       };
+
+       static final int ao_telemetry_standard_len = 32;
+       static final int ao_telemetry_0_9_len = 95;
+       static final int ao_telemetry_0_8_len = 94;
 
 
-       static final int ao_telemetry_split_len = 32;
-       static final int ao_telemetry_legacy_len = 95;
+       static final int[] ao_telemetry_len = {
+               0, 32, 95, 94
+       };
 
        static HashMap<String,Integer>  string_to_state = new HashMap<String,Integer>();
 
 
        static HashMap<String,Integer>  string_to_state = new HashMap<String,Integer>();
 
@@ -103,6 +115,20 @@ public class Altos {
                map_initialized = true;
        }
 
                map_initialized = true;
        }
 
+       static int telemetry_len(int telemetry) {
+               if (telemetry <= ao_telemetry_max)
+                       return ao_telemetry_len[telemetry];
+               throw new IllegalArgumentException(String.format("Invalid telemetry %d",
+                                                                telemetry));
+       }
+
+       static String telemetry_name(int telemetry) {
+               if (telemetry <= ao_telemetry_max)
+                       return ao_telemetry_name[telemetry];
+               throw new IllegalArgumentException(String.format("Invalid telemetry %d",
+                                                                telemetry));
+       }
+       
        static String[] state_to_string = {
                "startup",
                "idle",
        static String[] state_to_string = {
                "startup",
                "idle",
index 9536c4bbdf1fef7ad6ae52146822c4cf6f832be4..04bfc90dff237b1ed740bcfbaefaae8c4449f6ca 100644 (file)
@@ -156,14 +156,14 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
 
                        // Telemetry format menu
                        telemetries = new JComboBox();
 
                        // Telemetry format menu
                        telemetries = new JComboBox();
-                       telemetries.addItem("Original TeleMetrum Telemetry");
-                       telemetries.addItem("Standard AltOS Telemetry");
-                       int telemetry = 1;
-                       telemetry = AltosPreferences.telemetry(serial);
-                       if (telemetry > Altos.ao_telemetry_split)
-                               telemetry = Altos.ao_telemetry_split;
+                       for (int i = 1; i <= Altos.ao_telemetry_max; i++)
+                               telemetries.addItem(Altos.telemetry_name(i));
+                       int telemetry = AltosPreferences.telemetry(serial);
+                       if (telemetry <= Altos.ao_telemetry_off ||
+                           telemetry > Altos.ao_telemetry_max)
+                               telemetry = Altos.ao_telemetry_standard;
                        telemetries.setSelectedIndex(telemetry - 1);
                        telemetries.setSelectedIndex(telemetry - 1);
-                       telemetries.setMaximumRowCount(2);
+                       telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
                        telemetries.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                int telemetry = telemetries.getSelectedIndex() + 1;
                        telemetries.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                int telemetry = telemetries.getSelectedIndex() + 1;
index 5029aff631aa0f8a35a5746621a573237284dcf4..c8dee743f2318950efc834da3a917d92aa5d0ddd 100644 (file)
@@ -216,7 +216,7 @@ class AltosPreferences {
                if (telemetries.containsKey(serial))
                        return telemetries.get(serial);
                int telemetry = preferences.getInt(String.format(telemetryPreferenceFormat, serial),
                if (telemetries.containsKey(serial))
                        return telemetries.get(serial);
                int telemetry = preferences.getInt(String.format(telemetryPreferenceFormat, serial),
-                                                  Altos.ao_telemetry_split);
+                                                  Altos.ao_telemetry_standard);
                telemetries.put(serial, telemetry);
                return telemetry;
        }
                telemetries.put(serial, telemetry);
                return telemetry;
        }
index d94ac3aec2f12c3be4c91c55048da6d5a7ada5bd..54be4f5275037f43266c51e22fe4433b69c807b7 100644 (file)
@@ -35,13 +35,12 @@ class AltosScanResult {
        int     flight;
        int     channel;
        int     telemetry;
        int     flight;
        int     channel;
        int     telemetry;
-       static final String[] short_monitor_names = { "Standard", "Original" };
        
        boolean interrupted = false;
        
        public String toString() {
        
        boolean interrupted = false;
        
        public String toString() {
-               return String.format("%-9.9s serial %-4d flight %-4d (channel %-2d telemetry %s)",
-                                    callsign, serial, flight, channel, short_monitor_names[telemetry]);
+               return String.format("%-9.9s serial %-4d flight %-4d (channel %-2d %s)",
+                                    callsign, serial, flight, channel, Altos.telemetry_name(telemetry));
        }
 
        public String toShortString() {
        }
 
        public String toShortString() {
@@ -116,9 +115,7 @@ public class AltosScanUI
        javax.swing.Timer               timer;
        AltosScanResults                results = new AltosScanResults();
 
        javax.swing.Timer               timer;
        AltosScanResults                results = new AltosScanResults();
 
-       static final String[]           monitor_names = { "Standard AltOS Telemetry", "Original TeleMetrum Telemetry" };
-       static final int[]              monitors = { 2, 1 };
-       int                             monitor;
+       int                             telemetry;
        int                             channel;
 
        final static int                timeout = 1200;
        int                             channel;
 
        final static int                timeout = 1200;
@@ -171,7 +168,7 @@ public class AltosScanUI
                                                                                                     record.serial,
                                                                                                     record.flight,
                                                                                                     channel,
                                                                                                     record.serial,
                                                                                                     record.flight,
                                                                                                     channel,
-                                                                                                    monitor);
+                                                                                                    telemetry);
                                                        Runnable r = new Runnable() {
                                                                        public void run() {
                                                                                results.add(result);
                                                        Runnable r = new Runnable() {
                                                                        public void run() {
                                                                                results.add(result);
@@ -195,7 +192,7 @@ public class AltosScanUI
        void set_label() {
                scanning_label.setText(String.format("Scanning: channel %d %s",
                                                     channel,
        void set_label() {
                scanning_label.setText(String.format("Scanning: channel %d %s",
                                                     channel,
-                                                    monitor_names[monitor]));
+                                                    Altos.telemetry_name(telemetry)));
        }
 
        void next() {
        }
 
        void next() {
@@ -207,10 +204,10 @@ public class AltosScanUI
                ++channel;
                if (channel > 9) {
                        channel = 0;
                ++channel;
                if (channel > 9) {
                        channel = 0;
-                       ++monitor;
-                       if (monitor == monitors.length)
-                               monitor = 0;
-                       reader.serial.set_telemetry(monitors[monitor]);
+                       ++telemetry;
+                       if (telemetry > Altos.ao_telemetry_max)
+                               telemetry = Altos.ao_telemetry_min;
+                       reader.serial.set_telemetry(telemetry);
                }
                reader.serial.set_channel(channel);
                set_label();
                }
                reader.serial.set_channel(channel);
                set_label();
@@ -251,7 +248,7 @@ public class AltosScanUI
                        if (r != null) {
                                if (device != null) {
                                        if (reader != null) {
                        if (r != null) {
                                if (device != null) {
                                        if (reader != null) {
-                                               reader.set_telemetry(monitors[r.telemetry]);
+                                               reader.set_telemetry(r.telemetry);
                                                reader.set_channel(r.channel);
                                                owner.telemetry_window(device);
                                        }
                                                reader.set_channel(r.channel);
                                                owner.telemetry_window(device);
                                        }
@@ -282,7 +279,7 @@ public class AltosScanUI
                try {
                        reader = new AltosTelemetryReader(device);
                        reader.serial.set_channel(channel);
                try {
                        reader = new AltosTelemetryReader(device);
                        reader.serial.set_channel(channel);
-                       reader.serial.set_telemetry(monitors[monitor]);
+                       reader.serial.set_telemetry(telemetry);
                        handler = new TelemetryHandler();
                        thread = new Thread(handler);
                        thread.start();
                        handler = new TelemetryHandler();
                        thread = new Thread(handler);
                        thread.start();
@@ -329,6 +326,9 @@ public class AltosScanUI
 
                pane.setLayout(new GridBagLayout());
 
 
                pane.setLayout(new GridBagLayout());
 
+               channel = 0;
+               telemetry = Altos.ao_telemetry_min;
+
                scanning_label = new JLabel("Scanning:");
                
                set_label();
                scanning_label = new JLabel("Scanning:");
                
                set_label();
index 3666cb4142e65b9d3de42c344271b5d9faa2ea29..2e8ce8702ad557a0d691067caf5dc4f02754d20b 100644 (file)
@@ -326,13 +326,7 @@ public class AltosSerial implements Runnable {
        }
 
        private int telemetry_len() {
        }
 
        private int telemetry_len() {
-               switch (telemetry) {
-               case 1:
-               default:
-                       return Altos.ao_telemetry_legacy_len;
-               case 2:
-                       return Altos.ao_telemetry_split_len;
-               }
+               return Altos.telemetry_len(telemetry);
        }
 
        public void set_channel(int in_channel) {
        }
 
        public void set_channel(int in_channel) {
@@ -404,7 +398,7 @@ public class AltosSerial implements Runnable {
                line = "";
                monitor_mode = false;
                frame = null;
                line = "";
                monitor_mode = false;
                frame = null;
-               telemetry = Altos.ao_telemetry_split;
+               telemetry = Altos.ao_telemetry_standard;
                monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> ();
                reply_queue = new LinkedBlockingQueue<AltosLine> ();
                open();
                monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> ();
                reply_queue = new LinkedBlockingQueue<AltosLine> ();
                open();
index e3751ee77fd4e6ca2bd498cb68bc4efb5a2f37e2..756f3ec9ac5f4b92318f619e99d3e405fdc818a9 100644 (file)
@@ -385,24 +385,25 @@ public class AltosTelemetryRecordLegacy extends AltosRecord implements AltosTele
         */
 
        int[]   bytes;
         */
 
        int[]   bytes;
+       int     adjust;
 
        private int int8(int i) {
 
        private int int8(int i) {
-               return Altos.int8(bytes, i + 1);
+               return Altos.int8(bytes, i + 1 + adjust);
        }
        private int uint8(int i) {
        }
        private int uint8(int i) {
-               return Altos.uint8(bytes, i + 1);
+               return Altos.uint8(bytes, i + 1 + adjust);
        }
        private int int16(int i) {
        }
        private int int16(int i) {
-               return Altos.int16(bytes, i + 1);
+               return Altos.int16(bytes, i + 1 + adjust);
        }
        private int uint16(int i) {
        }
        private int uint16(int i) {
-               return Altos.uint16(bytes, i + 1);
+               return Altos.uint16(bytes, i + 1 + adjust);
        }
        private int uint32(int i) {
        }
        private int uint32(int i) {
-               return Altos.uint32(bytes, i + 1);
+               return Altos.uint32(bytes, i + 1 + adjust);
        }
        private String string(int i, int l) {
        }
        private String string(int i, int l) {
-               return Altos.string(bytes, i + 1, l);
+               return Altos.string(bytes, i + 1 + adjust, l);
        }
 
        static final int AO_GPS_NUM_SAT_MASK    = (0xf << 0);
        }
 
        static final int AO_GPS_NUM_SAT_MASK    = (0xf << 0);
@@ -428,8 +429,13 @@ public class AltosTelemetryRecordLegacy extends AltosRecord implements AltosTele
                }
                }
                version = 4;
                }
                }
                version = 4;
-               callsign = string(62, 8);
+               adjust = 0;
                serial = uint16(0);
                serial = uint16(0);
+
+               if (bytes.length == Altos.ao_telemetry_0_8_len + 4)
+                       adjust = -1;
+               
+               callsign = string(62, 8);
                flight = uint16(2);
                rssi = in_rssi;
                status = in_status;
                flight = uint16(2);
                rssi = in_rssi;
                status = in_status;
index e6c4cfc8af44ddf3ba5c3424df4b44b7cf7ef48e..4b34f017f1c58e3b5f3bb4250c5344956820d6b2 100644 (file)
@@ -72,7 +72,7 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord {
 
                /* length, data ..., rssi, status, checksum -- 4 bytes extra */
                switch (bytes.length) {
 
                /* length, data ..., rssi, status, checksum -- 4 bytes extra */
                switch (bytes.length) {
-               case Altos.ao_telemetry_split_len + 4:
+               case Altos.ao_telemetry_standard_len + 4:
                        int     type = Altos.uint8(bytes, 4 + 1);
                        switch (type) {
                        case packet_type_TM_sensor:
                        int     type = Altos.uint8(bytes, 4 + 1);
                        switch (type) {
                        case packet_type_TM_sensor:
@@ -94,7 +94,10 @@ public class AltosTelemetryRecordRaw implements AltosTelemetryRecord {
                                break;
                        }
                        break;
                                break;
                        }
                        break;
-               case Altos.ao_telemetry_legacy_len + 4:
+               case Altos.ao_telemetry_0_9_len + 4:
+                       r = new AltosTelemetryRecordLegacy(bytes, rssi, status);
+                       break;
+               case Altos.ao_telemetry_0_8_len + 4:
                        r = new AltosTelemetryRecordLegacy(bytes, rssi, status);
                        break;
                default:
                        r = new AltosTelemetryRecordLegacy(bytes, rssi, status);
                        break;
                default: