altosui: Interrupt MonitorIdle when changing frequency/callsign
authorKeith Packard <keithp@keithp.com>
Sun, 10 Feb 2013 22:17:04 +0000 (14:17 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 10 Feb 2013 22:17:04 +0000 (14:17 -0800)
When switching radio parameters, the local device needs to have the
parameters switched, so interrupt the current operation and start
over, the frequency and callsign will be set the next time through.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosIdleMonitor.java
altoslib/AltosLink.java
altosui/AltosIdleMonitorUI.java

index 6b20b3f17342b0b3f528969e973a946a57da537b..f2f75bbb60f80dc21cf388a70459e7c239c76b37 100644 (file)
@@ -27,6 +27,7 @@ public class AltosIdleMonitor extends Thread {
        AltosState              state;
        boolean                 remote;
        double                  frequency;
+       String                  callsign;
        AltosState              previous_state;
        AltosConfigData         config_data;
        AltosGPS                gps;
@@ -87,6 +88,7 @@ public class AltosIdleMonitor extends Thread {
                try {
                        if (remote) {
                                link.set_radio_frequency(frequency);
+                               link.set_callsign(callsign);
                                link.start_remote();
                        } else
                                link.flush_input();
@@ -126,12 +128,29 @@ public class AltosIdleMonitor extends Thread {
 
        public void set_frequency(double in_frequency) {
                frequency = in_frequency;
+               link.abort_reply();
+       }
+
+       public void set_callsign(String in_callsign) {
+               callsign = in_callsign;
+               link.abort_reply();
        }
 
        public void post_state() {
                listener.update(state);
        }
 
+       public void abort() {
+               if (isAlive()) {
+                       interrupt();
+                       link.abort_reply();
+                       try {
+                               join();
+                       } catch (InterruptedException ie) {
+                       }
+               }
+       }
+
        public void run() {
                try {
                        for (;;) {
index 2b5909aa26b377cd86b5c3ae309e506709ff37d5..9eb25ce0ac47b53092e706606e88be0104d15f20 100644 (file)
@@ -249,6 +249,7 @@ public abstract class AltosLink implements Runnable {
        public boolean monitor_mode = false;
        public int telemetry = AltosLib.ao_telemetry_standard;
        public double frequency;
+       public String callsign;
        AltosConfigData config_data;
 
        private int telemetry_len() {
@@ -330,6 +331,7 @@ public abstract class AltosLink implements Runnable {
        }
 
        public void set_callsign(String callsign) {
+               this.callsign = callsign;
                printf ("c c %s\n", callsign);
                flush_output();
        }
@@ -363,5 +365,6 @@ public abstract class AltosLink implements Runnable {
        }
 
        public AltosLink() {
+               callsign = "";
        }
 }
index 462bff181a3613fa4783162d9742b2f51cde842c..8c883eebfc0cd8a5fdda2cf44d9e8095824c96e3 100644 (file)
@@ -37,11 +37,8 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl
        boolean                 remote;
 
        void stop_display() {
-               if (thread != null && thread.isAlive()) {
-                       thread.interrupt();
-                       try {
-                               thread.join();
-                       } catch (InterruptedException ie) {}
+               if (thread != null) {
+                       thread.abort();
                }
                thread = null;
        }
@@ -92,8 +89,11 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl
 
        /* DocumentListener interface methods */
        public void changedUpdate(DocumentEvent e) {
-               if (callsign_value != null)
-                       AltosUIPreferences.set_callsign(callsign_value.getText());
+               if (callsign_value != null) {
+                       String  callsign = callsign_value.getText();
+                       thread.set_callsign(callsign);
+                       AltosUIPreferences.set_callsign(callsign);
+               }
        }
 
        public void insertUpdate(DocumentEvent e) {