altosui: Use timeouts to recover from broken packet links.
[fw/altos] / ao-tools / altosui / AltosSerial.java
index 99a92fdba5153c69aa8569de3a21012220172a43..0d32a5ae851807e0940a634acf7ccfef335030cd 100644 (file)
@@ -132,6 +132,14 @@ public class AltosSerial implements Runnable {
                return line.line;
        }
 
+       public String get_reply(int timeout) throws InterruptedException {
+               flush_output();
+               AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS);
+               if (line == null)
+                       return null;
+               return line.line;
+       }
+
        public void add_monitor(LinkedBlockingQueue<AltosLine> q) {
                set_monitor(true);
                monitors.add(q);
@@ -185,10 +193,9 @@ public class AltosSerial implements Runnable {
                                throw new AltosSerialInUseException(device);
                        devices_opened.add(device.getPath());
                }
-               close();
                altos = libaltos.altos_open(device);
                if (altos == null)
-                       throw new FileNotFoundException(device.getPath());
+                       throw new FileNotFoundException(device.toString());
                input_thread = new Thread(this);
                input_thread.start();
                print("~\nE 0\n");