altosui: Make teledongle callsign configurable
authorKeith Packard <keithp@keithp.com>
Sun, 22 Aug 2010 00:57:31 +0000 (17:57 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 22 Aug 2010 00:57:31 +0000 (17:57 -0700)
Teledongle uses the callsign in packet mode; this provides a way to
set that.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/AltosPreferences.java
ao-tools/altosui/AltosSerial.java
ao-tools/altosui/AltosUI.java

index 297e1aae77ba0819a71af5ef53718a648cf2f727..690f8f1ed5e60eff6e2f858147d7c66fc5ae4e8f 100644 (file)
@@ -37,6 +37,9 @@ class AltosPreferences {
        /* voice preference name */
        final static String voicePreference = "VOICE";
 
        /* voice preference name */
        final static String voicePreference = "VOICE";
 
+       /* callsign preference name */
+       final static String callsignPreference = "CALLSIGN";
+
        /* Default logdir is ~/TeleMetrum */
        final static String logdirName = "TeleMetrum";
 
        /* Default logdir is ~/TeleMetrum */
        final static String logdirName = "TeleMetrum";
 
@@ -52,6 +55,8 @@ class AltosPreferences {
        /* Voice preference */
        static boolean voice;
 
        /* Voice preference */
        static boolean voice;
 
+       static String callsign;
+
        public static void init(Component ui) {
                preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
 
        public static void init(Component ui) {
                preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
 
@@ -71,6 +76,8 @@ class AltosPreferences {
                channel = preferences.getInt(channelPreference, 0);
 
                voice = preferences.getBoolean(voicePreference, true);
                channel = preferences.getInt(channelPreference, 0);
 
                voice = preferences.getBoolean(voicePreference, true);
+
+               callsign = preferences.get(callsignPreference,"N0CALL");
        }
 
        static void flush_preferences() {
        }
 
        static void flush_preferences() {
@@ -154,4 +161,16 @@ class AltosPreferences {
        public static boolean voice() {
                return voice;
        }
        public static boolean voice() {
                return voice;
        }
+
+       public static void set_callsign(String new_callsign) {
+               callsign = new_callsign;
+               synchronized(preferences) {
+                       preferences.put(callsignPreference, callsign);
+                       flush_preferences();
+               }
+       }
+
+       public static String callsign() {
+               return callsign;
+       }
 }
 }
index efa63f681819e2ed9f3d22ebfac66d79e47f7750..ba00b55e98d3b4674974e3dab4fa2d7fa323f588 100644 (file)
@@ -154,6 +154,11 @@ public class AltosSerial implements Runnable {
                        printf("m 0\nc r %d\nm 1\n", channel);
        }
 
                        printf("m 0\nc r %d\nm 1\n", channel);
        }
 
+       public void set_callsign(String callsign) {
+               if (altos != null)
+                       printf ("c c %s\n", callsign);
+       }
+
        public AltosSerial() {
                altos = null;
                input_thread = null;
        public AltosSerial() {
                altos = null;
                input_thread = null;
index b96e16a612d0c05e2d39a7c273b1bb5ca7ac1a16..33ce274a26d7393f31e2fc2f43f150fcb82b3e8d 100644 (file)
@@ -420,6 +420,7 @@ public class AltosUI extends JFrame {
                                serial_line.open(device);
                                DeviceThread thread = new DeviceThread(serial_line);
                                serial_line.set_channel(AltosPreferences.channel());
                                serial_line.open(device);
                                DeviceThread thread = new DeviceThread(serial_line);
                                serial_line.set_channel(AltosPreferences.channel());
+                               serial_line.set_callsign(AltosPreferences.callsign());
                                run_display(thread);
                        } catch (FileNotFoundException ee) {
                                JOptionPane.showMessageDialog(AltosUI.this,
                                run_display(thread);
                        } catch (FileNotFoundException ee) {
                                JOptionPane.showMessageDialog(AltosUI.this,
@@ -440,6 +441,18 @@ public class AltosUI extends JFrame {
                stop_display();
        }
 
                stop_display();
        }
 
+       void ConfigureCallsign() {
+               String  result;
+               result = JOptionPane.showInputDialog(AltosUI.this,
+                                                    "Configure Callsign",
+                                                    AltosPreferences.callsign());
+               if (result != null) {
+                       AltosPreferences.set_callsign(result);
+                       if (serial_line != null)
+                               serial_line.set_callsign(result);
+               }
+       }
+
        /*
         * Open an existing telemetry file and replay it in realtime
         */
        /*
         * Open an existing telemetry file and replay it in realtime
         */
@@ -556,6 +569,22 @@ public class AltosUI extends JFrame {
                        menu.setMnemonic(KeyEvent.VK_F);
                        menubar.add(menu);
 
                        menu.setMnemonic(KeyEvent.VK_F);
                        menubar.add(menu);
 
+                       item = new JMenuItem("Replay File",KeyEvent.VK_R);
+                       item.addActionListener(new ActionListener() {
+                                       public void actionPerformed(ActionEvent e) {
+                                               Replay();
+                                       }
+                               });
+                       menu.add(item);
+
+                       item = new JMenuItem("Save Flight Data",KeyEvent.VK_S);
+                       item.addActionListener(new ActionListener() {
+                                       public void actionPerformed(ActionEvent e) {
+                                               SaveFlightData();
+                                       }
+                               });
+                       menu.add(item);
+
                        item = new JMenuItem("Quit",KeyEvent.VK_Q);
                        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
                                                                   ActionEvent.CTRL_MASK));
                        item = new JMenuItem("Quit",KeyEvent.VK_Q);
                        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
                                                                   ActionEvent.CTRL_MASK));
@@ -591,20 +620,13 @@ public class AltosUI extends JFrame {
 
                        menu.addSeparator();
 
 
                        menu.addSeparator();
 
-                       item = new JMenuItem("Save Flight Data",KeyEvent.VK_S);
+                       item = new JMenuItem("Set Callsign",KeyEvent.VK_S);
                        item.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                        item.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
-                                               SaveFlightData();
+                                               ConfigureCallsign();
                                        }
                                });
                                        }
                                });
-                       menu.add(item);
 
 
-                       item = new JMenuItem("Replay",KeyEvent.VK_R);
-                       item.addActionListener(new ActionListener() {
-                                       public void actionPerformed(ActionEvent e) {
-                                               Replay();
-                                       }
-                               });
                        menu.add(item);
                }
                // Log menu
                        menu.add(item);
                }
                // Log menu