- void get_data() throws InterruptedException, TimeoutException {
- try {
- start_serial();
- serial_line.printf("c s\nv\n");
- for (;;) {
- String line = serial_line.get_reply(5000);
- if (line == null)
- throw new TimeoutException();
- get_int(line, "serial-number", serial);
- get_int(line, "Main deploy:", main_deploy);
- get_int(line, "Apogee delay:", apogee_delay);
- get_int(line, "Radio channel:", radio_channel);
- get_int(line, "Radio cal:", radio_calibration);
- get_int(line, "Max flight log:", flight_log_max);
- get_string(line, "Callsign:", callsign);
- get_string(line,"software-version", version);
- get_string(line,"product", product);
-
- /* signals the end of the version info */
- if (line.startsWith("software-version"))
- break;
+ int pyro;
+
+ final static int serial_mode_read = 0;
+ final static int serial_mode_save = 1;
+ final static int serial_mode_reboot = 2;
+
+ class SerialData implements Runnable {
+ AltosConfig config;
+ int serial_mode;
+
+ void callback(String in_cmd) {
+ final String cmd = in_cmd;
+ Runnable r = new Runnable() {
+ public void run() {
+ if (cmd.equals("abort")) {
+ abort();
+ } else if (cmd.equals("all finished")) {
+ if (serial_line != null)
+ update_ui();
+ }
+ }
+ };
+ SwingUtilities.invokeLater(r);
+ }
+
+ void get_data() {
+ data = null;
+ try {
+ start_serial();
+ data = new AltosConfigData(config.serial_line);
+ } catch (InterruptedException ie) {
+ } catch (TimeoutException te) {
+ try {
+ stop_serial();
+ callback("abort");
+ } catch (InterruptedException ie) {
+ }
+ } finally {
+ try {
+ stop_serial();
+ } catch (InterruptedException ie) {
+ }
+ }
+ callback("all finished");
+ }
+
+ void save_data() {
+ try {
+ start_serial();
+ data.save(serial_line, remote);
+ if (remote)
+ AltosUIPreferences.set_frequency(device.getSerial(),
+ data.frequency());
+ } catch (InterruptedException ie) {
+ } catch (TimeoutException te) {
+ } finally {
+ try {
+ stop_serial();
+ } catch (InterruptedException ie) {
+ }
+ }
+ }
+
+ void reboot() {
+ try {
+ start_serial();
+ serial_line.printf("r eboot\n");
+ serial_line.flush_output();
+ } catch (InterruptedException ie) {
+ } catch (TimeoutException te) {
+ } finally {
+ try {
+ stop_serial();
+ serial_line.close();
+ } catch (InterruptedException ie) {
+ }