altosui: New AltosSerial.set_radio function sets channel/call
[fw/altos] / ao-tools / altosui / AltosEepromDownload.java
index 6dbbd3ebb8c3477e8b41250cb39ab529a501272e..02fc36f298cfc6922710aaace084a6fa091e1eb0 100644 (file)
@@ -26,19 +26,7 @@ import java.io.*;
 import java.util.*;
 import java.text.*;
 import java.util.prefs.*;
-import java.util.concurrent.LinkedBlockingQueue;
-
-import altosui.Altos;
-import altosui.AltosSerial;
-import altosui.AltosSerialMonitor;
-import altosui.AltosRecord;
-import altosui.AltosTelemetry;
-import altosui.AltosState;
-import altosui.AltosDeviceDialog;
-import altosui.AltosPreferences;
-import altosui.AltosLog;
-import altosui.AltosVoice;
-import altosui.AltosEepromMonitor;
+import java.util.concurrent.*;
 
 import libaltosJNI.*;
 
@@ -90,7 +78,7 @@ public class AltosEepromDownload implements Runnable {
        Thread                  eeprom_thread;
        AltosEepromMonitor      monitor;
 
-       void CaptureLog() throws IOException, InterruptedException {
+       void CaptureLog() throws IOException, InterruptedException, TimeoutException {
                int                     serial = 0;
                int                     block, state_block = 0;
                int                     addr;
@@ -109,8 +97,10 @@ public class AltosEepromDownload implements Runnable {
                /* Pull the serial number out of the version information */
 
                for (;;) {
-                       String  line = serial_line.get_reply();
+                       String  line = serial_line.get_reply(5000);
 
+                       if (line == null)
+                               throw new TimeoutException();
                        if (line.startsWith("serial-number")) {
                                try {
                                        serial = Integer.parseInt(line.substring(13).trim());
@@ -137,7 +127,9 @@ public class AltosEepromDownload implements Runnable {
                        any_valid = false;
                        monitor.set_value(state_names[state], state, block - state_block);
                        for (addr = 0; addr < 0x100;) {
-                               String  line = serial_line.get_reply();
+                               String  line = serial_line.get_reply(5000);
+                               if (line == null)
+                                       throw new TimeoutException();
                                int[] values = ParseHex(line);
 
                                if (values == null) {
@@ -224,8 +216,7 @@ public class AltosEepromDownload implements Runnable {
 
        public void run () {
                if (remote) {
-                       serial_line.set_channel(AltosPreferences.channel());
-                       serial_line.set_callsign(AltosPreferences.callsign());
+                       serial_line.set_radio();
                        serial_line.printf("p\nE 0\n");
                        serial_line.flush_input();
                }
@@ -240,10 +231,16 @@ public class AltosEepromDownload implements Runnable {
                        CaptureLog();
                } catch (IOException ee) {
                        JOptionPane.showMessageDialog(frame,
-                                                     device.getPath(),
+                                                     device.toShortString(),
                                                      ee.getLocalizedMessage(),
                                                      JOptionPane.ERROR_MESSAGE);
                } catch (InterruptedException ie) {
+               } catch (TimeoutException te) {
+                       JOptionPane.showMessageDialog(frame,
+                                                     String.format("Connection to \"%s\" failed",
+                                                                   device.toShortString()),
+                                                     "Connection Failed",
+                                                     JOptionPane.ERROR_MESSAGE);
                }
                if (remote)
                        serial_line.printf("~");
@@ -254,27 +251,32 @@ public class AltosEepromDownload implements Runnable {
 
        public AltosEepromDownload(JFrame given_frame) {
                frame = given_frame;
-               device = AltosDeviceDialog.show(frame, AltosDevice.Any);
+               device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
 
-               serial_line = new AltosSerial();
                remote = false;
 
                if (device != null) {
                        try {
-                               serial_line.open(device);
-                               if (!device.matchProduct(AltosDevice.TeleMetrum))
+                               serial_line = new AltosSerial(device);
+                               if (!device.matchProduct(AltosDevice.product_telemetrum))
                                        remote = true;
                                eeprom_thread = new Thread(this);
                                eeprom_thread.start();
                        } catch (FileNotFoundException ee) {
                                JOptionPane.showMessageDialog(frame,
                                                              String.format("Cannot open device \"%s\"",
-                                                                           device.getPath()),
+                                                                           device.toShortString()),
                                                              "Cannot open target device",
                                                              JOptionPane.ERROR_MESSAGE);
+                       } catch (AltosSerialInUseException si) {
+                               JOptionPane.showMessageDialog(frame,
+                                                             String.format("Device \"%s\" already in use",
+                                                                           device.toShortString()),
+                                                             "Device in use",
+                                                             JOptionPane.ERROR_MESSAGE);
                        } catch (IOException ee) {
                                JOptionPane.showMessageDialog(frame,
-                                                             device.getPath(),
+                                                             device.toShortString(),
                                                              ee.getLocalizedMessage(),
                                                              JOptionPane.ERROR_MESSAGE);
                        }