altosui: Add telemetry format menu and preferences
authorKeith Packard <keithp@keithp.com>
Wed, 23 Mar 2011 23:08:43 +0000 (08:08 +0900)
committerKeith Packard <keithp@keithp.com>
Wed, 23 Mar 2011 23:08:43 +0000 (08:08 +0900)
Switches the TeleDongle between full and tiny telemetry packet
formats, saving the last used format for each teledongle in the
application preferences.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/Altos.java
altosui/AltosFlightReader.java
altosui/AltosFlightUI.java
altosui/AltosPreferences.java
altosui/AltosSerial.java
altosui/AltosState.java
altosui/AltosTelemetry.java
altosui/AltosTelemetryReader.java

index 8ee94e04b0b7bcd6d83815c5c3541ec231e378a9..9d5b2e02369d3eef870ac083be1fd881f2c31e04 100644 (file)
@@ -63,6 +63,11 @@ public class Altos {
        static final int ao_flight_landed = 8;
        static final int ao_flight_invalid = 9;
 
+       /* Telemetry modes */
+       static final int ao_telemetry_off = 0;
+       static final int ao_telemetry_full = 1;
+       static final int ao_telemetry_tiny = 2;
+
        static HashMap<String,Integer>  string_to_state = new HashMap<String,Integer>();
 
        static boolean map_initialized = false;
index 3d59de9a82c22ef4f4354a812651df469d2250dd..f665bda8e4419270aafd61b40e8b0cb07b56c22f 100644 (file)
@@ -34,5 +34,7 @@ public class AltosFlightReader {
 
        void set_channel(int channel) { }
 
+       void set_telemetry(int telemetry) { }
+
        void update(AltosState state) throws InterruptedException { }
 }
index 68e0ef874fe7363928898352f35f2d0d5151715d..286b2a4eeb3519e19a8fdfecfdb167b8e3cc5b80 100644 (file)
@@ -119,6 +119,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
 
        Container       bag;
        JComboBox       channels;
+       JComboBox       telemetries;
 
        public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
                AltosPreferences.init(this);
@@ -149,8 +150,28 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
                        });
                        c.gridx = 0;
                        c.gridy = 0;
+                       c.insets = new Insets(3, 3, 3, 3);
                        c.anchor = GridBagConstraints.WEST;
                        bag.add (channels, c);
+
+                       // Telemetry format menu
+                       telemetries = new JComboBox();
+                       telemetries.addItem("TeleMetrum");
+                       telemetries.addItem("TeleMini/TeleNano");
+                       telemetries.setSelectedIndex(AltosPreferences.telemetry(serial) - 1);
+                       telemetries.setMaximumRowCount(2);
+                       telemetries.addActionListener(new ActionListener() {
+                                       public void actionPerformed(ActionEvent e) {
+                                               int telemetry = telemetries.getSelectedIndex();
+                                               reader.set_telemetry(telemetry);
+                                       }
+                               });
+                       c.gridx = 1;
+                       c.gridy = 0;
+                       c.fill = GridBagConstraints.NONE;
+                       c.anchor = GridBagConstraints.WEST;
+                       bag.add (telemetries, c);
+                       c.insets = new Insets(0, 0, 0, 0);
                }
 
                /* Flight status is always visible */
@@ -159,7 +180,9 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
                c.gridy = 1;
                c.fill = GridBagConstraints.HORIZONTAL;
                c.weightx = 1;
+               c.gridwidth = 2;
                bag.add(flightStatus, c);
+               c.gridwidth = 1;
 
                /* The rest of the window uses a tabbed pane to
                 * show one of the alternate data views
@@ -190,6 +213,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
                c.fill = GridBagConstraints.BOTH;
                c.weightx = 1;
                c.weighty = 1;
+               c.gridwidth = 2;
                bag.add(pane, c);
 
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
index d4df4e163efecaf18462fc0f49fce012564f138a..5f82765569dae85f0a69211c41bc0d1ed04b119f 100644 (file)
@@ -34,6 +34,9 @@ class AltosPreferences {
        /* channel preference name */
        final static String channelPreferenceFormat = "CHANNEL-%d";
 
+       /* telemetry format preference name */
+       final static String telemetryPreferenceFormat = "TELEMETRY-%d";
+
        /* voice preference name */
        final static String voicePreference = "VOICE";
 
@@ -61,6 +64,9 @@ class AltosPreferences {
        /* Channel (map serial to channel) */
        static Hashtable<Integer, Integer> channels;
 
+       /* Telemetry (map serial to telemetry format) */
+       static Hashtable<Integer, Integer> telemetries;
+
        /* Voice preference */
        static boolean voice;
 
@@ -94,6 +100,8 @@ class AltosPreferences {
 
                channels = new Hashtable<Integer,Integer>();
 
+               telemetries = new Hashtable<Integer,Integer>();
+
                voice = preferences.getBoolean(voicePreference, true);
 
                callsign = preferences.get(callsignPreference,"N0CALL");
@@ -189,6 +197,23 @@ class AltosPreferences {
                return channel;
        }
 
+       public static void set_telemetry(int serial, int new_telemetry) {
+               telemetries.put(serial, new_telemetry);
+               synchronized (preferences) {
+                       preferences.putInt(String.format(telemetryPreferenceFormat, serial), new_telemetry);
+                       flush_preferences();
+               }
+       }
+
+       public static int telemetry(int serial) {
+               if (telemetries.containsKey(serial))
+                       return telemetries.get(serial);
+               int telemetry = preferences.getInt(String.format(telemetryPreferenceFormat, serial),
+                                                  Altos.ao_telemetry_full);
+               telemetries.put(serial, telemetry);
+               return telemetry;
+       }
+
        public static void set_voice(boolean new_voice) {
                voice = new_voice;
                synchronized (preferences) {
index f9f9e6e425232436d9e8ce4fe6788496b5dc4cb4..a8ba66bde009acc49f7c1c03d71741e7e7110fd2 100644 (file)
@@ -47,6 +47,8 @@ public class AltosSerial implements Runnable {
        byte[] line_bytes;
        int line_count;
        boolean monitor_mode;
+       int telemetry;
+       int channel;
        static boolean debug;
        boolean remote;
        LinkedList<String> pending_output = new LinkedList<String>();
@@ -231,25 +233,37 @@ public class AltosSerial implements Runnable {
        }
 
        public void set_radio() {
-               set_channel(AltosPreferences.channel(device.getSerial()));
+               telemetry = AltosPreferences.telemetry(device.getSerial());
+               channel = AltosPreferences.channel(device.getSerial());
+               set_channel(channel);
                set_callsign(AltosPreferences.callsign());
        }
 
-       public void set_channel(int channel) {
+       public void set_channel(int in_channel) {
+               channel = in_channel;
                if (altos != null) {
                        if (monitor_mode)
-                               printf("m 0\nc r %d\nm 1\n", channel);
+                               printf("m 0\nc r %d\nm %d\n", channel, telemetry);
                        else
                                printf("c r %d\n", channel);
                        flush_output();
                }
        }
 
+       public void set_telemetry(int in_telemetry) {
+               telemetry = in_telemetry;
+               if (altos != null) {
+                       if (monitor_mode)
+                               printf("m 0\nm %d\n", telemetry);
+                       flush_output();
+               }
+       }
+
        void set_monitor(boolean monitor) {
                monitor_mode = monitor;
                if (altos != null) {
                        if (monitor)
-                               printf("m 1\n");
+                               printf("m %d\n", telemetry);
                        else
                                printf("m 0\n");
                        flush_output();
@@ -285,6 +299,7 @@ public class AltosSerial implements Runnable {
                device = in_device;
                line = "";
                monitor_mode = false;
+               telemetry = Altos.ao_telemetry_full;
                monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> ();
                reply_queue = new LinkedBlockingQueue<AltosLine> ();
                open();
index 4e165f8093550ea4ea0fe74fb552d3d3073084a4..0ff2479e6334d7295a3b7eeebe52df378bc18655 100644 (file)
@@ -80,7 +80,6 @@ public class AltosState {
 
                ground_altitude = data.ground_altitude();
                height = data.filtered_height();
-               System.out.printf("height %g\n", height);
 
                report_time = System.currentTimeMillis();
 
index 3eb0efa8eea8e5defa4185a887cca358d0fc98fa..91b6d0481436c536ae8f5d46f3ac1e04e91e4b2a 100644 (file)
@@ -253,12 +253,8 @@ public class AltosTelemetry extends AltosRecord {
                accel_minus_g = map.get_int(AO_TELEM_CAL_ACCEL_MINUS, MISSING);
 
                /* flight computer values */
-               acceleration = map.get_int(AO_TELEM_KALMAN_ACCEL, MISSING);
-               if (acceleration != MISSING)
-                       acceleration /= 16.0;
-               speed = map.get_int(AO_TELEM_KALMAN_SPEED, MISSING);
-               if (speed != MISSING)
-                       speed /= 16.0;
+               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);
index 6c5a93978c69a4156e0e44fe3b94b3ea7a9c92c0..980391b437476add2ca092b27ad0d00e6c89a2a2 100644 (file)
@@ -47,6 +47,11 @@ class AltosTelemetryReader extends AltosFlightReader {
                AltosPreferences.set_channel(device.getSerial(), channel);
        }
 
+       void set_telemetry(int telemetry) {
+               serial.set_telemetry(telemetry);
+               AltosPreferences.set_telemetry(device.getSerial(), telemetry);
+       }
+
        public AltosTelemetryReader (AltosDevice in_device)
                throws FileNotFoundException, AltosSerialInUseException, IOException {
                device = in_device;