From 5b976a6651f4eb05d30afc08b9e1f27c7e52ae00 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Sep 2013 11:33:48 -0700 Subject: altoslib: Finish AltosState changes. Update version number. Removes all of the AltosRecord bits, changes the monitor idle bits to have per-object state updaters. Signed-off-by: Keith Packard --- altoslib/AltosIdleMonitor.java | 115 ++++++++++++----------------------------- 1 file changed, 32 insertions(+), 83 deletions(-) (limited to 'altoslib/AltosIdleMonitor.java') diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index b3ce5b20..d858845a 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; import java.io.*; import java.util.concurrent.*; @@ -24,11 +24,13 @@ import java.util.concurrent.*; public class AltosIdleMonitor extends Thread { AltosLink link; AltosIdleMonitorListener listener; - AltosState state; + + AltosIdleFetch fetch; + boolean remote; double frequency; String callsign; - AltosState previous_state; + AltosListenerState listener_state; AltosConfigData config_data; AltosGPS gps; @@ -47,86 +49,35 @@ public class AltosIdleMonitor extends Thread { return rssi; } - boolean has_sensor_tm(AltosConfigData config_data) { - return config_data.product.startsWith("TeleMetrum") || config_data.product.startsWith("TeleMini"); - } - - boolean has_sensor_mm(AltosConfigData config_data) { - return config_data.product.startsWith("TeleMega"); - } - - boolean has_gps(AltosConfigData config_data) { - return config_data.product.startsWith("TeleMetrum") || config_data.product.startsWith("TeleMega"); + void start_link() throws InterruptedException, TimeoutException { + if (remote) { + link.set_radio_frequency(frequency); + link.set_callsign(callsign); + link.start_remote(); + } else + link.flush_input(); } - AltosRecord sensor_mm(AltosConfigData config_data) throws InterruptedException, TimeoutException { - AltosRecordMM record_mm = new AltosRecordMM(); - AltosSensorMM sensor = new AltosSensorMM(link); - AltosMs5607 ms5607 = new AltosMs5607Query(link); - AltosIMU imu = new AltosIMUQuery(link); - - record_mm.accel_plus_g = config_data.accel_cal_plus; - record_mm.accel_minus_g = config_data.accel_cal_minus; - - record_mm.ground_accel = sensor.accel; - record_mm.accel = sensor.accel; - record_mm.ground_pres = ms5607.pa; - record_mm.pres = ms5607.pa; - record_mm.temp = ms5607.cc; - - record_mm.v_batt = sensor.v_batt; - record_mm.v_pyro = sensor.v_pyro; - record_mm.sense = sensor.sense; - - record_mm.imu = imu; - - return record_mm; + void stop_link() throws InterruptedException, TimeoutException { + if (remote) + link.stop_remote(); } - void update_state() throws InterruptedException, TimeoutException { - AltosRecord record = null; + void update_state(AltosState state) throws InterruptedException, TimeoutException { + boolean worked = false; try { - if (remote) { - link.set_radio_frequency(frequency); - link.set_callsign(callsign); - link.start_remote(); - } else - link.flush_input(); - config_data = new AltosConfigData(link); - - if (has_sensor_tm(config_data)) - record = new AltosSensorTM(link, config_data); - else if (has_sensor_mm(config_data)) - record = sensor_mm(config_data); - else - record = new AltosRecordNone(); - - if (has_gps(config_data)) - gps = new AltosGPSQuery(link, config_data); - - record.version = 0; - record.callsign = config_data.callsign; - record.serial = config_data.serial; - record.flight = config_data.log_available() > 0 ? 255 : 0; - record.status = 0; - record.state = AltosLib.ao_flight_idle; - record.gps = gps; - record.gps_sequence++; - state = new AltosState (record, state); + start_link(); + fetch.update_state(state); + worked = true; } finally { - if (remote) { - link.stop_remote(); - if (record != null) { - record.rssi = link.rssi(); - listener_state.battery = link.monitor_battery(); - } - } else { - if (record != null) - record.rssi = 0; + stop_link(); + if (worked) { + if (remote) + state.set_rssi(link.rssi(), 0); + listener_state.battery = link.monitor_battery(); } } - } public void set_frequency(double in_frequency) { @@ -139,10 +90,6 @@ public class AltosIdleMonitor extends Thread { link.abort_reply(); } - public void post_state() { - listener.update(state, listener_state); - } - public void abort() { if (isAlive()) { interrupt(); @@ -155,18 +102,20 @@ public class AltosIdleMonitor extends Thread { } public void run() { + AltosState state = new AltosState(); try { - for (;;) { + while (!link.has_error) { try { - update_state(); - post_state(); + link.config_data(); + update_state(state); + listener.update(state, listener_state); } catch (TimeoutException te) { } Thread.sleep(1000); } } catch (InterruptedException ie) { - link.close(); } + link.close(); } public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote) @@ -174,7 +123,7 @@ public class AltosIdleMonitor extends Thread { listener = in_listener; link = in_link; remote = in_remote; - state = null; listener_state = new AltosListenerState(); + fetch = new AltosIdleFetch(link); } } -- cgit v1.2.3 From e26306c9350ef1d107d4257ef1c09d15165c9154 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 18 Dec 2013 01:14:11 -0800 Subject: 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(-) (limited to 'altoslib/AltosIdleMonitor.java') 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(); - } } } -- cgit v1.2.3 From c1bfe09b6d3eb28d0c7cfe07a248843cf81bcd25 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 18 Dec 2013 13:36:04 -0800 Subject: altosui: Remove some debug printfs Signed-off-by: Keith Packard --- altoslib/AltosIdleMonitor.java | 3 --- altoslib/AltosMs5607.java | 8 -------- altosui/AltosIdleMonitorUI.java | 2 -- 3 files changed, 13 deletions(-) (limited to 'altoslib/AltosIdleMonitor.java') diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index c816c202..d9d71143 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -91,14 +91,11 @@ public class AltosIdleMonitor extends Thread { } 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(); Thread.sleep(100); } - System.out.printf("Appears to be dead now\n"); join(); } diff --git a/altoslib/AltosMs5607.java b/altoslib/AltosMs5607.java index 23d65ea9..2319d5b8 100644 --- a/altoslib/AltosMs5607.java +++ b/altoslib/AltosMs5607.java @@ -85,12 +85,10 @@ public class AltosMs5607 { } public boolean parse_line(String line) { - System.out.printf ("parse %s\n", line); String[] items = line.split("\\s+"); if (line.startsWith("Pressure:")) { if (items.length >= 2) { raw_pres = Integer.parseInt(items[1]); - System.out.printf ("raw_pres %d\n", raw_pres); } } else if (line.startsWith("Temperature:")) { if (items.length >= 2) @@ -99,10 +97,8 @@ public class AltosMs5607 { if (items.length >= 3) reserved = Integer.parseInt(items[2]); } else if (line.startsWith("ms5607 sens:")) { - System.out.printf ("found sens length %d\n", items.length); if (items.length >= 3) { sens = Integer.parseInt(items[2]); - System.out.printf ("sens %d\n", sens); } } else if (line.startsWith("ms5607 off:")) { if (items.length >= 3) @@ -156,13 +152,9 @@ public class AltosMs5607 { throw new TimeoutException(); } if (!parse_line(line)) { - System.out.printf ("stop parsing at %s\n", line); break; } } - System.out.printf ("sens %d off %d tcs %d tco %d tref %d tempsens %d crc %d pres %d temp %d\n", - sens, off, tcs, tco, tref, tempsens, crc, raw_pres, raw_temp); convert(); - System.out.printf ("pa %d cc %d\n", pa, cc); } } diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index 6da920e2..6a79604e 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -195,13 +195,11 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { - 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); -- cgit v1.2.3