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;
}
}
}
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);
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);
}
/*
* 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) {
}
}
- public void write_byte(byte b) throws IOException {
+ public void write_byte(byte b) throws IOException, InterruptedException {
byte[] bytes = { b };
write_bytes(bytes);
}
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();
}
close();
}
- public boolean check_rom_config() {
+ public boolean check_rom_config() throws InterruptedException {
if (debug == null)
return true;
if (rom_config == null)
rom_config = romconfig;
}
- public AltosRomconfig romconfig() {
+ public AltosRomconfig romconfig() throws InterruptedException {
if (!check_rom_config())
return null;
return rom_config;
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; }
}
}
}
- 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);
return;
}
} catch (TimeoutException te) {
- } catch (InterruptedException ie) {
}
state.set_gps(null, 0);
}
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) {
}
}
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);
}
}
state.set_received_time(System.currentTimeMillis());
- } catch (InterruptedException ie) {
} catch (TimeoutException te) {
}
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() {
}
} catch (InterruptedException ie) {
}
- link.close();
+ try {
+ link.close();
+ } catch (InterruptedException ie) {
+ }
}
public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote)
}
}
- public void fire(int igniter) {
+ public void fire(int igniter) throws InterruptedException {
if (link == null)
return;
try {
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;
}
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; }
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 {
try {
add_telem (new AltosLine());
add_reply (new AltosLine());
- } catch (InterruptedException e) {
+ } catch (InterruptedException ie) {
}
}
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;
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()) {
}
i++;
}
- } catch (InterruptedException ie) {
} catch (TimeoutException te) {
}
}
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;
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;
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) {
}
}
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) {
}
}
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);
return;
}
} catch (TimeoutException te) {
- } catch (InterruptedException ie) {
}
}
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
public void close() {
if (link != null) {
reboot();
- link.close();
+ try {
+ link.close();
+ } catch (InterruptedException ie) {
+ }
link = null;
}
}
close();
}
- private AltosHexfile get_rom() {
+ private AltosHexfile get_rom() throws InterruptedException {
System.out.printf("get rom\n");
try {
int base = AltosRomconfig.fetch_base(image);
} 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;
rom_config = romconfig;
}
- public AltosRomconfig romconfig() {
+ public AltosRomconfig romconfig() throws InterruptedException {
System.out.printf("fetch romconfig\n");
if (!check_rom_config())
return null;
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);
state.set_main_voltage(AltosConvert.easy_mini_voltage(sensor_emini.main));
} catch (TimeoutException te) {
- } catch (InterruptedException ie) {
}
}
}
}
- 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);
state.set_ignitor_voltage(ignitor_voltage);
} catch (TimeoutException te) {
- } catch (InterruptedException ie) {
}
}
}
}
}
- 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) {
}
}
}
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);
state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(sensor_tm.main));
} catch (TimeoutException te) {
- } catch (InterruptedException ie) {
}
}
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);
state.set_main_voltage(AltosConvert.easy_mini_voltage(sensor_tmini.main));
} catch (TimeoutException te) {
- } catch (InterruptedException ie) {
}
}
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
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 {
else
return false;
} catch (InterruptedException ie) {
- return true;
+ return false;
} catch (TimeoutException te) {
return true;
}
return link.has_monitor_battery();
}
- public double monitor_battery() {
+ public double monitor_battery() throws InterruptedException {
return link.monitor_battery();
}
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);
}
}
}
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++)
}
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) {
}
}
} finally {
try {
stop_serial();
+ serial_line.close();
} catch (InterruptedException ie) {
}
- serial_line.close();
}
}
flash_task flasher;
- private boolean open_device() {
+ private boolean open_device() throws InterruptedException {
try {
link = new AltosSerial(device);
if (is_pair_programmed())
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);
}
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.*;
void stop_display() {
if (thread != null) {
- thread.abort();
+ try {
+ thread.abort();
+ } catch (InterruptedException ie) {
+ }
}
thread = null;
}
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);
try {
input_thread.interrupt();
input_thread.join();
- } catch (InterruptedException e) {
+ } catch (InterruptedException ie) {
}
input_thread = null;
}
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();
- }
}
}