From e26306c9350ef1d107d4257ef1c09d15165c9154 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 18 Dec 2013 01:14:11 -0800 Subject: [PATCH] altoslib: Pass InterruptedException up the stack instead of hiding it 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 --- altoslib/AltosDebug.java | 23 +++++++-------- altoslib/AltosFlash.java | 4 +-- altoslib/AltosFlightReader.java | 4 +-- altoslib/AltosGPS.java | 3 +- altoslib/AltosIMU.java | 3 +- altoslib/AltosIdleFetch.java | 3 +- altoslib/AltosIdleMonitor.java | 18 +++++++----- altoslib/AltosIgnite.java | 15 +++------- altoslib/AltosLink.java | 47 ++++++++++++++---------------- altoslib/AltosLog.java | 11 +++---- altoslib/AltosMag.java | 8 +++-- altoslib/AltosMma655x.java | 3 +- altoslib/AltosMs5607.java | 3 +- altoslib/AltosProgrammer.java | 4 +-- altoslib/AltosSelfFlash.java | 13 +++++---- altoslib/AltosSensorEMini.java | 3 +- altoslib/AltosSensorMega.java | 3 +- altoslib/AltosSensorMetrum.java | 3 +- altoslib/AltosSensorTM.java | 3 +- altoslib/AltosSensorTMini.java | 3 +- altoslib/AltosStateUpdate.java | 2 +- altoslib/AltosTelemetryReader.java | 15 +++++----- altosui/AltosBTManage.java | 20 ++++++++----- altosui/AltosConfig.java | 2 +- altosui/AltosFlashUI.java | 8 +++-- altosui/AltosIdleMonitorUI.java | 14 +++++++-- altosui/AltosSerial.java | 8 ++--- 27 files changed, 123 insertions(+), 123 deletions(-) diff --git a/altoslib/AltosDebug.java b/altoslib/AltosDebug.java index 8faab03b..fb11d39a 100644 --- a/altoslib/AltosDebug.java +++ b/altoslib/AltosDebug.java @@ -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(); } diff --git a/altoslib/AltosFlash.java b/altoslib/AltosFlash.java index 0906f2ef..0977070e 100644 --- a/altoslib/AltosFlash.java +++ b/altoslib/AltosFlash.java @@ -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; diff --git a/altoslib/AltosFlightReader.java b/altoslib/AltosFlightReader.java index 4a722e42..b251e7cc 100644 --- a/altoslib/AltosFlightReader.java +++ b/altoslib/AltosFlightReader.java @@ -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; } } diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index 1d5b0755..f5162225 100644 --- a/altoslib/AltosGPS.java +++ b/altoslib/AltosGPS.java @@ -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); } diff --git a/altoslib/AltosIMU.java b/altoslib/AltosIMU.java index c231dda7..6d88ccae 100644 --- a/altoslib/AltosIMU.java +++ b/altoslib/AltosIMU.java @@ -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) { } } diff --git a/altoslib/AltosIdleFetch.java b/altoslib/AltosIdleFetch.java index 64c421f4..4adc6c41 100644 --- a/altoslib/AltosIdleFetch.java +++ b/altoslib/AltosIdleFetch.java @@ -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) { } diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index d858845a..c816c202 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -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) diff --git a/altoslib/AltosIgnite.java b/altoslib/AltosIgnite.java index 42169989..fc9599b6 100644 --- a/altoslib/AltosIgnite.java +++ b/altoslib/AltosIgnite.java @@ -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; } diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index ba557a72..ee1f9785 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -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) { } } diff --git a/altoslib/AltosLog.java b/altoslib/AltosLog.java index 015d9f65..d4fbee97 100644 --- a/altoslib/AltosLog.java +++ b/altoslib/AltosLog.java @@ -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; diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index 56add8f3..89e72bd6 100644 --- a/altoslib/AltosMag.java +++ b/altoslib/AltosMag.java @@ -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) { } } diff --git a/altoslib/AltosMma655x.java b/altoslib/AltosMma655x.java index 8dc947db..f8256190 100644 --- a/altoslib/AltosMma655x.java +++ b/altoslib/AltosMma655x.java @@ -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) { } } diff --git a/altoslib/AltosMs5607.java b/altoslib/AltosMs5607.java index b29fa9ae..23d65ea9 100644 --- a/altoslib/AltosMs5607.java +++ b/altoslib/AltosMs5607.java @@ -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) { } } diff --git a/altoslib/AltosProgrammer.java b/altoslib/AltosProgrammer.java index 88777cf3..b010d564 100644 --- a/altoslib/AltosProgrammer.java +++ b/altoslib/AltosProgrammer.java @@ -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 diff --git a/altoslib/AltosSelfFlash.java b/altoslib/AltosSelfFlash.java index 07952d7f..327a90bd 100644 --- a/altoslib/AltosSelfFlash.java +++ b/altoslib/AltosSelfFlash.java @@ -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; diff --git a/altoslib/AltosSensorEMini.java b/altoslib/AltosSensorEMini.java index cbc65143..5f9eed55 100644 --- a/altoslib/AltosSensorEMini.java +++ b/altoslib/AltosSensorEMini.java @@ -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) { } } diff --git a/altoslib/AltosSensorMega.java b/altoslib/AltosSensorMega.java index 3afb8a64..e715242a 100644 --- a/altoslib/AltosSensorMega.java +++ b/altoslib/AltosSensorMega.java @@ -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) { } } } diff --git a/altoslib/AltosSensorMetrum.java b/altoslib/AltosSensorMetrum.java index 4a51d492..c30eaebd 100644 --- a/altoslib/AltosSensorMetrum.java +++ b/altoslib/AltosSensorMetrum.java @@ -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) { } } } diff --git a/altoslib/AltosSensorTM.java b/altoslib/AltosSensorTM.java index 2696a308..f867de4b 100644 --- a/altoslib/AltosSensorTM.java +++ b/altoslib/AltosSensorTM.java @@ -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) { } } diff --git a/altoslib/AltosSensorTMini.java b/altoslib/AltosSensorTMini.java index be071e5d..ee030910 100644 --- a/altoslib/AltosSensorTMini.java +++ b/altoslib/AltosSensorTMini.java @@ -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) { } } diff --git a/altoslib/AltosStateUpdate.java b/altoslib/AltosStateUpdate.java index ec4f7609..97a5dfe2 100644 --- a/altoslib/AltosStateUpdate.java +++ b/altoslib/AltosStateUpdate.java @@ -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 diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java index aea97844..405c555b 100644 --- a/altoslib/AltosTelemetryReader.java +++ b/altoslib/AltosTelemetryReader.java @@ -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); } } } diff --git a/altosui/AltosBTManage.java b/altosui/AltosBTManage.java index 4c9b7a6c..1015f7c3 100644 --- a/altosui/AltosBTManage.java +++ b/altosui/AltosBTManage.java @@ -85,7 +85,7 @@ public class AltosBTManage extends AltosUIDialog implements ActionListener, Iter return devices.iterator(); } - public java.util.List selected_list() { + public java.util.List selected_list() throws InterruptedException { java.util.LinkedList l = new java.util.LinkedList(); 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) { } } diff --git a/altosui/AltosConfig.java b/altosui/AltosConfig.java index a6e6094f..206cbee3 100644 --- a/altosui/AltosConfig.java +++ b/altosui/AltosConfig.java @@ -161,9 +161,9 @@ public class AltosConfig implements ActionListener { } finally { try { stop_serial(); + serial_line.close(); } catch (InterruptedException ie) { } - serial_line.close(); } } diff --git a/altosui/AltosFlashUI.java b/altosui/AltosFlashUI.java index e305d458..296ad8ef 100644 --- a/altosui/AltosFlashUI.java +++ b/altosui/AltosFlashUI.java @@ -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); } diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index f4e16243..6da920e2 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -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); diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index b85a7fa1..5e9322e5 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -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(); - } } } -- 2.30.2