altoslib: Pass InterruptedException up the stack instead of hiding it
authorKeith Packard <keithp@keithp.com>
Wed, 18 Dec 2013 09:14:11 +0000 (01:14 -0800)
committerKeith Packard <keithp@keithp.com>
Wed, 18 Dec 2013 09:14:11 +0000 (01:14 -0800)
When interrupting a thread that is talking to a serial device, it's
important not to have that thread discard the InterruptedException so
that it will actually terminate. This patch removes a bunch of places
that were discarding InterruptedExceptions and lets higher level code
see them so that they can exit cleanly.

Signed-off-by: Keith Packard <keithp@keithp.com>
27 files changed:
altoslib/AltosDebug.java
altoslib/AltosFlash.java
altoslib/AltosFlightReader.java
altoslib/AltosGPS.java
altoslib/AltosIMU.java
altoslib/AltosIdleFetch.java
altoslib/AltosIdleMonitor.java
altoslib/AltosIgnite.java
altoslib/AltosLink.java
altoslib/AltosLog.java
altoslib/AltosMag.java
altoslib/AltosMma655x.java
altoslib/AltosMs5607.java
altoslib/AltosProgrammer.java
altoslib/AltosSelfFlash.java
altoslib/AltosSensorEMini.java
altoslib/AltosSensorMega.java
altoslib/AltosSensorMetrum.java
altoslib/AltosSensorTM.java
altoslib/AltosSensorTMini.java
altoslib/AltosStateUpdate.java
altoslib/AltosTelemetryReader.java
altosui/AltosBTManage.java
altosui/AltosConfig.java
altosui/AltosFlashUI.java
altosui/AltosIdleMonitorUI.java
altosui/AltosSerial.java

index 8faab03bdc19a406d0362fd90a731162ac9466fd..fb11d39abac0b49e01abf532eabaca4429cb1b89 100644 (file)
@@ -56,13 +56,10 @@ public class AltosDebug {
 
        boolean debug_mode;
 
-       void ensure_debug_mode() {
+       void ensure_debug_mode() throws InterruptedException {
                if (!debug_mode) {
                        link.printf("D\n");
-                       try {
-                               link.flush_input();
-                       } catch (InterruptedException ie) {
-                       }
+                       link.flush_input();
                        debug_mode = true;
                }
        }
@@ -81,13 +78,16 @@ public class AltosDebug {
        }
 
        public void close() {
-               link.close();
+               try {
+                       link.close();
+               } catch (InterruptedException ie) {
+               }
        }
 
        /*
         * Write target memory
         */
-       public void write_memory(int address, byte[] bytes, int start, int len) {
+       public void write_memory(int address, byte[] bytes, int start, int len) throws InterruptedException {
                ensure_debug_mode();
 //             dump_memory("write_memory", address, bytes, start, len);
                link.printf("O %x %x\n", len, address);
@@ -95,7 +95,7 @@ public class AltosDebug {
                        link.printf("%02x", bytes[start + i]);
        }
 
-       public void write_memory(int address, byte[] bytes) {
+       public void write_memory(int address, byte[] bytes) throws InterruptedException {
                write_memory(address, bytes, 0, bytes.length);
        }
 
@@ -132,7 +132,7 @@ public class AltosDebug {
        /*
         * Write raw bytes to the debug link using the 'P' command
         */
-       public void write_bytes(byte[] bytes) throws IOException {
+       public void write_bytes(byte[] bytes) throws IOException, InterruptedException {
                int i = 0;
                ensure_debug_mode();
                while (i < bytes.length) {
@@ -147,7 +147,7 @@ public class AltosDebug {
                }
        }
 
-       public void write_byte(byte b) throws IOException {
+       public void write_byte(byte b) throws IOException, InterruptedException {
                byte[] bytes = { b };
                write_bytes(bytes);
        }
@@ -257,13 +257,12 @@ public class AltosDebug {
                return true;
        }
 
-       public AltosRomconfig romconfig() {
+       public AltosRomconfig romconfig() throws InterruptedException {
                try {
                        byte[] bytes = read_memory(0xa0, 10);
                        AltosHexfile hexfile = new AltosHexfile (bytes, 0xa0);
                        return new AltosRomconfig(hexfile);
                } catch (IOException ie) {
-               } catch (InterruptedException ie) {
                }
                return new AltosRomconfig();
        }
index 0906f2ef0ffe74c40be2190241f4619d9f5055c2..0977070e2a2883adba4a49b772712c5c6dd436b0 100644 (file)
@@ -318,7 +318,7 @@ public class AltosFlash extends AltosProgrammer {
                close();
        }
 
-       public boolean check_rom_config() {
+       public boolean check_rom_config() throws InterruptedException {
                if (debug == null)
                        return true;
                if (rom_config == null)
@@ -330,7 +330,7 @@ public class AltosFlash extends AltosProgrammer {
                rom_config = romconfig;
        }
 
-       public AltosRomconfig romconfig() {
+       public AltosRomconfig romconfig() throws InterruptedException {
                if (!check_rom_config())
                        return null;
                return rom_config;
index 4a722e42ac5b0e6f27c1b96e9de484e14cc43029..b251e7ccdd53ad37394d11f16251408b611c0813 100644 (file)
@@ -46,7 +46,7 @@ public class AltosFlightReader {
 
        public File backing_file() { return null; }
 
-       public boolean has_monitor_battery() { return false; }
+       public boolean has_monitor_battery() throws InterruptedException { return false; }
 
-       public double monitor_battery() { return AltosLib.MISSING; }
+       public double monitor_battery() throws InterruptedException { return AltosLib.MISSING; }
 }
index 1d5b0755982a0d9a194d492dd6d22ec4322d7308..f5162225ac200c08edb3359f8865545e5024075d 100644 (file)
@@ -348,7 +348,7 @@ public class AltosGPS implements Cloneable {
                }
        }
 
-       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
                try {
                        AltosGPS        gps = new AltosGPS(link, config_data);
 
@@ -357,7 +357,6 @@ public class AltosGPS implements Cloneable {
                                return;
                        }
                } catch (TimeoutException te) {
-               } catch (InterruptedException ie) {
                }
                state.set_gps(null, 0);
        }
index c231dda74c6f8f9cc2a76c1a8e123478e2d9a232..6d88ccae9a45f6a45926444528db9debc04993b4 100644 (file)
@@ -58,14 +58,13 @@ public class AltosIMU implements Cloneable {
                return n;
        }
 
-       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
                try {
                        AltosIMU        imu = new AltosIMU(link);
 
                        if (imu != null)
                                state.set_imu(imu);
                } catch (TimeoutException te) {
-               } catch (InterruptedException ie) {
                }
        }
 
index 64c421f4f3e5db5858a9f921eaa98446ff67d08d..4adc6c41d9d619feb5700c733bcc252d9b6a05d0 100644 (file)
@@ -125,7 +125,7 @@ public class AltosIdleFetch implements AltosStateUpdate {
        double                  frequency;
        String                  callsign;
 
-       public void update_state(AltosState state) {
+       public void update_state(AltosState state) throws InterruptedException {
                try {
                        AltosConfigData config_data = new AltosConfigData(link);
                        state.set_state(AltosLib.ao_flight_startup);
@@ -140,7 +140,6 @@ public class AltosIdleFetch implements AltosStateUpdate {
                                }
                        }
                        state.set_received_time(System.currentTimeMillis());
-               } catch (InterruptedException ie) {
                } catch (TimeoutException te) {
                }
                
index d858845a1af0dbe0ea10837191cfa053507439d7..c816c202cc44533463a7763fb943fe9219e938fe 100644 (file)
@@ -90,15 +90,16 @@ public class AltosIdleMonitor extends Thread {
                link.abort_reply();
        }
 
-       public void abort() {
-               if (isAlive()) {
+       public void abort() throws InterruptedException {
+               System.out.printf("Attempting to abort monitor thread\n");
+               while (isAlive()) {
+                       System.out.printf("Interrupting\n");
                        interrupt();
                        link.abort_reply();
-                       try {
-                               join();
-                       } catch (InterruptedException ie) {
-                       }
+                       Thread.sleep(100);
                }
+               System.out.printf("Appears to be dead now\n");
+               join();
        }
 
        public void run() {
@@ -115,7 +116,10 @@ public class AltosIdleMonitor extends Thread {
                        }
                } catch (InterruptedException ie) {
                }
-               link.close();
+               try {
+                       link.close();
+               } catch (InterruptedException ie) {
+               }
        }
 
        public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote)
index 42169989b00eb797b307df5d7ebca671ed160933..fc9599b65ce4cb8aa44ed66dc31011240d5b5b7f 100644 (file)
@@ -141,7 +141,7 @@ public class AltosIgnite {
                }
        }
 
-       public void fire(int igniter) {
+       public void fire(int igniter) throws InterruptedException {
                if (link == null)
                        return;
                try {
@@ -154,21 +154,14 @@ public class AltosIgnite {
                                link.printf("i DoIt drogue\n");
                                break;
                        }
-               } catch (InterruptedException ie) {
                } catch (TimeoutException te) {
                } finally {
-                       try {
-                               stop_link();
-                       } catch (InterruptedException ie) {
-                       }
+                       stop_link();
                }
        }
 
-       public void close() {
-               try {
-                       stop_link();
-               } catch (InterruptedException ie) {
-               }
+       public void close() throws InterruptedException {
+               stop_link();
                link.close();
                link = null;
        }
index ba557a72581eef9adb5ecf2cd615075f897bec04..ee1f9785bb7a111158edceb3cc249afa0f5f3014 100644 (file)
@@ -26,10 +26,10 @@ public abstract class AltosLink implements Runnable {
        public final static int ERROR = -1;
        public final static int TIMEOUT = -2;
 
-       public abstract int getchar();
-       public abstract void print(String data);
+       public abstract int getchar() throws InterruptedException;
+       public abstract void print(String data) throws InterruptedException;
        public abstract void putchar(byte c);
-       public abstract void close();
+       public abstract void close() throws InterruptedException;
 
        public static boolean debug = false;
        public static void set_debug(boolean in_debug) { debug = in_debug; }
@@ -57,7 +57,11 @@ public abstract class AltosLink implements Runnable {
                String  line = String.format(format, arguments);
                if (debug)
                        pending_output.add(line);
-               print(line);
+               try {
+                       print(line);
+               } catch (InterruptedException ie) {
+
+               }
        }
 
        public String get_reply_no_dialog(int timeout) throws InterruptedException, TimeoutException {
@@ -233,7 +237,7 @@ public abstract class AltosLink implements Runnable {
                try {
                        add_telem (new AltosLine());
                        add_reply (new AltosLine());
-               } catch (InterruptedException e) {
+               } catch (InterruptedException ie) {
                }
        }
 
@@ -399,33 +403,27 @@ public abstract class AltosLink implements Runnable {
                flush_output();
        }
 
-       public boolean is_loader() {
+       public boolean is_loader() throws InterruptedException {
                boolean ret = false;
                printf("v\n");
-               try {
-                       for (;;) {
-                               String line = get_reply();
-
-                               if (line == null)
-                                       return false;
-                               if (line.startsWith("software-version"))
-                                       break;
-                               if (line.startsWith("altos-loader"))
-                                       ret = true;
-                       }
-               } catch (InterruptedException ie) {
+               for (;;) {
+                       String line = get_reply();
+
+                       if (line == null)
+                               return false;
+                       if (line.startsWith("software-version"))
+                               break;
+                       if (line.startsWith("altos-loader"))
+                               ret = true;
                }
                return ret;
        }
 
-       public void to_loader() {
+       public void to_loader() throws InterruptedException {
                printf("X\n");
                flush_output();
                close();
-               try {
-                       Thread.sleep(1000);
-               } catch (InterruptedException ie) {
-               }
+               Thread.sleep(1000);
        }
 
        public boolean remote;
@@ -490,7 +488,7 @@ public abstract class AltosLink implements Runnable {
                return config_data.has_monitor_battery();
        }
 
-       public double monitor_battery() {
+       public double monitor_battery() throws InterruptedException {
                int monitor_batt = AltosLib.MISSING;
 
                if (config_data.has_monitor_battery()) {
@@ -504,7 +502,6 @@ public abstract class AltosLink implements Runnable {
                                }
                                i++;
                        }
-                       } catch (InterruptedException ie) {
                        } catch (TimeoutException te) {
                        }
                }
index 015d9f65aa13ad28ef3aadef04bcf044becabf12..d4fbee97bc47e491a326bf33135a6e9424fb7039 100644 (file)
@@ -59,18 +59,15 @@ public class AltosLog implements Runnable {
                return file;
        }
 
-       boolean open (AltosState state) throws IOException {
+       boolean open (AltosState state) throws IOException, InterruptedException {
                AltosFile       a = new AltosFile(state);
 
                log_file = new FileWriter(a, true);
                if (log_file != null) {
                        while (!pending_queue.isEmpty()) {
-                               try {
-                                       String s = pending_queue.take();
-                                       log_file.write(s);
-                                       log_file.write('\n');
-                               } catch (InterruptedException ie) {
-                               }
+                               String s = pending_queue.take();
+                               log_file.write(s);
+                               log_file.write('\n');
                        }
                        log_file.flush();
                        file = a;
index 56add8f3445da8d0de9fee7d2ec2f5150d4ee739..89e72bd6e5983153dcacb499011a254369aa946f 100644 (file)
@@ -25,6 +25,11 @@ public class AltosMag implements Cloneable {
        public int              z;
 
        public boolean parse_string(String line) {
+//             if (line.startsWith("Syntax error")) {
+//                     x = y = z = 0;
+//                     return true;
+//             }
+
                if (!line.startsWith("X:"))
                        return false;
 
@@ -53,14 +58,13 @@ public class AltosMag implements Cloneable {
                z = AltosLib.MISSING;
        }
 
-       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
                try {
                        AltosMag        mag = new AltosMag(link);
 
                        if (mag != null)
                                state.set_mag(mag);
                } catch (TimeoutException te) {
-               } catch (InterruptedException ie) {
                }
        }
 
index 8dc947dbab804d900ba9d399c8e022676dac0124..f825619016d515d952a46978ff8926caae272314 100644 (file)
@@ -44,14 +44,13 @@ public class AltosMma655x implements Cloneable {
                return n;
        }
 
-       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
                try {
                        AltosMma655x    mma655x = new AltosMma655x(link);
 
                        if (mma655x != null)
                                state.set_accel(mma655x.accel);
                } catch (TimeoutException te) {
-               } catch (InterruptedException ie) {
                }
        }
 
index b29fa9ae845d11ad4652448f4627587ae062027e..23d65ea9c07be5ca2f5ed9490af485df9d4555d7 100644 (file)
@@ -128,7 +128,7 @@ public class AltosMs5607 {
                return true;
        }
 
-       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
                try {
                        AltosMs5607     ms5607 = new AltosMs5607(link);
 
@@ -137,7 +137,6 @@ public class AltosMs5607 {
                                return;
                        }
                } catch (TimeoutException te) {
-               } catch (InterruptedException ie) {
                }
        }
 
index 88777cf3003ba9bdf9e7e870c063da07a24c358a..b010d56484e185cd158aa20b7689a51ec341491f 100644 (file)
@@ -27,9 +27,7 @@ public abstract class AltosProgrammer {
 
        abstract public void abort();
 
-       abstract public AltosRomconfig romconfig();
+       abstract public AltosRomconfig romconfig() throws InterruptedException;
 
        abstract public void set_romconfig(AltosRomconfig config);
-
-
 }
\ No newline at end of file
index 07952d7f76fc97ba61519a4a55ef79ce6a91183a..327a90bd645beef4f110228c026c8a9c6a62d58d 100644 (file)
@@ -130,7 +130,10 @@ public class AltosSelfFlash extends AltosProgrammer {
        public void close() {
                if (link != null) {
                        reboot();
-                       link.close();
+                       try {
+                               link.close();
+                       } catch (InterruptedException ie) {
+                       }
                        link = null;
                }
        }
@@ -140,7 +143,7 @@ public class AltosSelfFlash extends AltosProgrammer {
                close();
        }
 
-       private AltosHexfile get_rom() {
+       private AltosHexfile get_rom() throws InterruptedException {
                System.out.printf("get rom\n");
                try {
                        int base = AltosRomconfig.fetch_base(image);
@@ -152,15 +155,13 @@ public class AltosSelfFlash extends AltosProgrammer {
                } catch (AltosNoSymbol none) {
                        System.out.printf("no symbol %s\n", none.getMessage());
                        return null;
-               } catch (InterruptedException ie) {
-                       return null;
                } catch (IOException ie) {
                        return null;
                }
 
        }
 
-       public boolean check_rom_config() {
+       public boolean check_rom_config() throws InterruptedException {
                if (link == null) {
                        System.out.printf ("no link\n");
                        return true;
@@ -177,7 +178,7 @@ public class AltosSelfFlash extends AltosProgrammer {
                rom_config = romconfig;
        }
 
-       public AltosRomconfig romconfig() {
+       public AltosRomconfig romconfig() throws InterruptedException {
                System.out.printf("fetch romconfig\n");
                if (!check_rom_config())
                        return null;
index cbc65143fa9b51a4df9be57124efcbdd474fd31c..5f9eed55238fe2d3f68fdcf4a44f76f16d8d27dd 100644 (file)
@@ -25,7 +25,7 @@ public class AltosSensorEMini {
        public int      main;
        public int      batt;
 
-       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
                try {
                        AltosSensorEMini        sensor_emini = new AltosSensorEMini(link);
 
@@ -36,7 +36,6 @@ public class AltosSensorEMini {
                        state.set_main_voltage(AltosConvert.easy_mini_voltage(sensor_emini.main));
                        
                } catch (TimeoutException te) {
-               } catch (InterruptedException ie) {
                }
        }
 
index 3afb8a642612509928876bfff311aeb581e54ccf..e715242a268219556679bab842339d7b8272002c 100644 (file)
@@ -88,7 +88,7 @@ class AltosSensorMega {
                }
        }
 
-       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
                try {
                        AltosSensorMega sensor_mega = new AltosSensorMega(link);
 
@@ -102,7 +102,6 @@ class AltosSensorMega {
                        state.set_ignitor_voltage(ignitor_voltage);
 
                } catch (TimeoutException te) {
-               } catch (InterruptedException ie) {
                }
        }
 }
index 4a51d492db4188f9d69861f600a34de49c1abb15..c30eaebd9a15ce60632d37162f47330fadb883d5 100644 (file)
@@ -52,14 +52,13 @@ class AltosSensorMetrum {
                }
        }
 
-       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
                try {
                        AltosSensorMetrum       sensor_metrum = new AltosSensorMetrum(link);
                        state.set_battery_voltage(AltosConvert.mega_battery_voltage(sensor_metrum.v_batt));
                        state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sensor_metrum.sense_a));
                        state.set_main_voltage(AltosConvert.mega_pyro_voltage(sensor_metrum.sense_m));
                } catch (TimeoutException te) {
-               } catch (InterruptedException ie) {
                }
        }
 }
index 2696a3080a252c68f10f43e1b0d49c75f82f5e20..f867de4b8efa5dc0eb0f8b410cdbd1732d382568 100644 (file)
@@ -28,7 +28,7 @@ public class AltosSensorTM {
        public int      drogue;
        public int      main;
 
-       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
                try {
                        AltosSensorTM   sensor_tm = new AltosSensorTM(link);
 
@@ -42,7 +42,6 @@ public class AltosSensorTM {
                        state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(sensor_tm.main));
                        
                } catch (TimeoutException te) {
-               } catch (InterruptedException ie) {
                }
        }
 
index be071e5d1ea36e0e7a9c2b433d5e6a826ea11dac..ee03091065881debdce275e1f02788dc01854193 100644 (file)
@@ -25,7 +25,7 @@ public class AltosSensorTMini {
        public int      main;
        public int      batt;
 
-       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
                try {
                        AltosSensorTMini        sensor_tmini = new AltosSensorTMini(link);
 
@@ -36,7 +36,6 @@ public class AltosSensorTMini {
                        state.set_main_voltage(AltosConvert.easy_mini_voltage(sensor_tmini.main));
                        
                } catch (TimeoutException te) {
-               } catch (InterruptedException ie) {
                }
        }
 
index ec4f7609a1e3f1056e06abc80739061877fe18bb..97a5dfe2464186f39ca7e25880886d32dca65cea 100644 (file)
@@ -18,5 +18,5 @@
 package org.altusmetrum.altoslib_2;
 
 public interface AltosStateUpdate {
-       public void     update_state(AltosState state);
+       public void     update_state(AltosState state) throws InterruptedException;
 }
\ No newline at end of file
index aea978445578e536b3daf3a5b1ffc73ffaf3675d..405c555b35b460c27448ca73fae8bb23a12b6c20 100644 (file)
@@ -54,7 +54,10 @@ public class AltosTelemetryReader extends AltosFlightReader {
        public void close(boolean interrupted) {
                link.remove_monitor(telem);
                log.close();
-               link.close();
+               try {
+                       link.close();
+               } catch (InterruptedException ie) {
+               }
        }
 
        public void set_frequency(double in_frequency) throws InterruptedException, TimeoutException {
@@ -83,7 +86,7 @@ public class AltosTelemetryReader extends AltosFlightReader {
                        else
                                return false;
                } catch (InterruptedException ie) {
-                       return true;
+                       return false;
                } catch (TimeoutException te) {
                        return true;
                }
@@ -114,7 +117,7 @@ public class AltosTelemetryReader extends AltosFlightReader {
                return link.has_monitor_battery();
        }
 
-       public double monitor_battery() {
+       public double monitor_battery() throws InterruptedException {
                return link.monitor_battery();
        }
 
@@ -130,12 +133,8 @@ public class AltosTelemetryReader extends AltosFlightReader {
                        telemetry = AltosPreferences.telemetry(link.serial);
                        set_telemetry(telemetry);
                        link.add_monitor(telem);
-               } catch (TimeoutException e) {
-                       close(true);
-                       throw(e);
-               } catch (InterruptedException e) {
+               } finally {
                        close(true);
-                       throw(e);
                }
        }
 }
index 4c9b7a6c405f5f827968dd95715b3a71ae50a1f3..1015f7c323774db278413bb61364c831c1f90f00 100644 (file)
@@ -85,7 +85,7 @@ public class AltosBTManage extends AltosUIDialog implements ActionListener, Iter
                        return devices.iterator();
                }
 
-               public java.util.List<AltosBTDevice> selected_list() {
+               public java.util.List<AltosBTDevice> selected_list() throws InterruptedException {
                        java.util.LinkedList<AltosBTDevice> l = new java.util.LinkedList<AltosBTDevice>();
                        Object[] a = getSelectedValues();
                        for (int i = 0; i < a.length; i++)
@@ -117,16 +117,22 @@ public class AltosBTManage extends AltosUIDialog implements ActionListener, Iter
        }
 
        public void add_known() {
-               for (AltosBTDevice device : visible_devices.selected_list()) {
-                       known_devices.add(device);
-                       visible_devices.remove(device);
+               try {
+                       for (AltosBTDevice device : visible_devices.selected_list()) {
+                               known_devices.add(device);
+                               visible_devices.remove(device);
+                       }
+               } catch (InterruptedException ie) {
                }
        }
 
        public void remove_known() {
-               for (AltosBTDevice device : known_devices.selected_list()) {
-                       known_devices.remove(device);
-                       visible_devices.add(device);
+               try {
+                       for (AltosBTDevice device : known_devices.selected_list()) {
+                               known_devices.remove(device);
+                               visible_devices.add(device);
+                       }
+               } catch (InterruptedException ie) {
                }
        }
 
index a6e6094fc1acbc21fb23dc5ca3de8e60ff612843..206cbee3e57bf2fd718d124f09da374ad2b167fd 100644 (file)
@@ -161,9 +161,9 @@ public class AltosConfig implements ActionListener {
                        } finally {
                                try {
                                        stop_serial();
+                                       serial_line.close();
                                } catch (InterruptedException ie) {
                                }
-                               serial_line.close();
                        }
                }
 
index e305d458a171fa388aa0ee2c1cfcfc286f1c9f63..296ad8ef9d761997aebf142704e1d4c6b5adde0a 100644 (file)
@@ -365,7 +365,7 @@ public class AltosFlashUI
 
        flash_task      flasher;
 
-       private boolean open_device() {
+       private boolean open_device() throws InterruptedException {
                try {
                        link = new AltosSerial(device);
                        if (is_pair_programmed())
@@ -408,8 +408,12 @@ public class AltosFlashUI
                        return;
                if (!select_source_file())
                        return;
-               if (!open_device())
+               try {
+                       if (!open_device())
+                               return;
+               } catch (InterruptedException ie) {
                        return;
+               }
                build_dialog();
                flash_task      f = new flash_task(this);
        }
index f4e16243cd4b05e1cbe66c8623a8dd7f1e5d05b2..6da920e29cb89e30f90338cc7e8fef9f74c7ca4a 100644 (file)
@@ -23,6 +23,7 @@ import javax.swing.*;
 import javax.swing.event.*;
 import java.io.*;
 import java.util.concurrent.*;
+import java.util.Arrays;
 import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
@@ -38,7 +39,10 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl
 
        void stop_display() {
                if (thread != null) {
-                       thread.abort();
+                       try {
+                               thread.abort();
+                       } catch (InterruptedException ie) {
+                       }
                }
                thread = null;
        }
@@ -191,7 +195,13 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl
                addWindowListener(new WindowAdapter() {
                                @Override
                                public void windowClosing(WindowEvent e) {
-                                       disconnect();
+                                       System.out.printf("Closing idle monitor window\n");
+                                       try {
+                                               disconnect();
+                                       } catch (Exception ex) {
+                                               System.out.println(Arrays.toString(ex.getStackTrace()));
+                                       }
+                                       System.out.printf("hiding\n");
                                        setVisible(false);
                                        dispose();
                                        AltosUIPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
index b85a7fa1d4bf3e19984290d9cab4a0180a40006f..5e9322e598a5a143c8fda318d2635613dbcc76ac 100644 (file)
@@ -146,7 +146,7 @@ public class AltosSerial extends AltosLink  {
                        try {
                                input_thread.interrupt();
                                input_thread.join();
-                       } catch (InterruptedException e) {
+                       } catch (InterruptedException ie) {
                        }
                        input_thread = null;
                }
@@ -156,18 +156,16 @@ public class AltosSerial extends AltosLink  {
 
        private void putc(char c) {
                if (altos != null)
-                       if (libaltos.altos_putchar(altos, c) != 0) {
+                       if (libaltos.altos_putchar(altos, c) != 0)
                                close_serial();
-                       }
        }
 
        public void putchar(byte c) {
                if (altos != null) {
                        if (debug)
                                System.out.printf(" %02x", (int) c & 0xff);
-                       if (libaltos.altos_putchar(altos, (char) c) != 0) {
+                       if (libaltos.altos_putchar(altos, (char) c) != 0)
                                close_serial();
-                       }
                }
        }