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 8faab03..fb11d39 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 0906f2e..0977070 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 4a722e4..b251e7c 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 1d5b075..f516222 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 c231dda..6d88cca 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 64c421f..4adc6c4 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 d858845..c816c20 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 4216998..fc9599b 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 ba557a7..ee1f978 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 015d9f6..d4fbee9 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 56add8f..89e72bd 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 8dc947d..f825619 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 b29fa9a..23d65ea 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 88777cf..b010d56 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 07952d7..327a90b 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 cbc6514..5f9eed5 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 3afb8a6..e715242 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 4a51d49..c30eaeb 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 2696a30..f867de4 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 be071e5..ee03091 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 ec4f760..97a5dfe 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 aea9784..405c555 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 4c9b7a6..1015f7c 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 a6e6094..206cbee 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 e305d45..296ad8e 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 f4e1624..6da920e 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 b85a7fa..5e9322e 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();
-                       }
                }
        }