altosui: Simple timeouts don't work with query data
authorKeith Packard <keithp@keithp.com>
Wed, 3 Aug 2011 01:01:52 +0000 (18:01 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 3 Aug 2011 01:03:37 +0000 (18:03 -0700)
To get the query to come back, it's best to abort and retry the
command, other wise the command may have been lost to the previous
connection.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosConfigData.java
altosui/AltosSerial.java

index 6b80171a90101c45fe7d791963b96b91a861570e..1d50ade9aeaa0a2c3ec48327537b8a3c86fb20fd 100644 (file)
@@ -85,7 +85,7 @@ public class AltosConfigData implements Iterable<String> {
                serial_line.printf("c s\nv\n");
                lines = new LinkedList<String>();
                for (;;) {
-                       String line = serial_line.get_reply(5000);
+                       String line = serial_line.get_reply_no_dialog(5000);
                        if (line == null)
                                throw new TimeoutException();
                        if (line.contains("Syntax error"))
index 8f8f99d7f458088aaa62abf3eb66cff23fb3e7af..cb82a574ed4381d5c87862f2d9de23757dad5afb 100644 (file)
@@ -233,12 +233,14 @@ public class AltosSerial implements Runnable {
                abort = false;
                timeout_started = false;
                for (;;) {
+                       System.out.printf("timeout %d\n", timeout);
                        AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS);
                        if (line != null) {
                                stop_timeout_dialog();
                                --in_reply;
                                return line.line;
                        }
+                       System.out.printf("no line remote %b can_cancel %b\n", remote, can_cancel);
                        if (!remote || !can_cancel || check_timeout()) {
                                --in_reply;
                                return null;
@@ -246,6 +248,14 @@ public class AltosSerial implements Runnable {
                }
        }
 
+       public String get_reply_no_dialog(int timeout) throws InterruptedException, TimeoutException {
+               flush_output();
+               AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS);
+               if (line != null)
+                       return line.line;
+               return null;
+       }
+
        public void add_monitor(LinkedBlockingQueue<AltosLine> q) {
                set_monitor(true);
                monitors.add(q);