summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-02-10 14:17:04 -0800
committerKeith Packard <keithp@keithp.com>2013-02-10 14:17:04 -0800
commitc2701ae646124f0668c5f2d1df3fc80f0075a9d7 (patch)
tree6b29d8d8f76ed58b13cd3d0796fcca5889731767
parentcc0ea39fee73417ecd69c020d9eca723ebb2cf65 (diff)
altosui: Interrupt MonitorIdle when changing frequency/callsign
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>
-rw-r--r--altoslib/AltosIdleMonitor.java19
-rw-r--r--altoslib/AltosLink.java3
-rw-r--r--altosui/AltosIdleMonitorUI.java14
3 files changed, 29 insertions, 7 deletions
diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java
index 6b20b3f1..f2f75bbb 100644
--- a/altoslib/AltosIdleMonitor.java
+++ b/altoslib/AltosIdleMonitor.java
@@ -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 (;;) {
diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java
index 2b5909aa..9eb25ce0 100644
--- a/altoslib/AltosLink.java
+++ b/altoslib/AltosLink.java
@@ -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 = "";
}
}
diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java
index 462bff18..8c883eeb 100644
--- a/altosui/AltosIdleMonitorUI.java
+++ b/altosui/AltosIdleMonitorUI.java
@@ -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) {