altosui: flush replies from serial link when entering debug mode
authorKeith Packard <keithp@keithp.com>
Tue, 24 Aug 2010 23:43:38 +0000 (16:43 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 24 Aug 2010 23:43:38 +0000 (16:43 -0700)
We use replies in debug mode a lot and depend on them matching the
expected parameters. The case which caused trouble was using
TeleMetrum to reprogram TeleDongle -- sending the 'm 0' command (to
disable telemetry monitoring on TeleDongle) to the TeleMetrum caused
it to reply 'Syntax Error' which confused the subsequent flashing
operation. Flushing that reply gets things back in sync.

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

index df40410aae4ddd21dd16006b57bcff8278c36283..06c9a0bdb9808eadac132843ce3eab38c420b5ab 100644 (file)
@@ -98,6 +98,7 @@ public class AltosDebug extends AltosSerial {
        void ensure_debug_mode() {
                if (!debug_mode) {
                        printf("m 0\nD\n");
        void ensure_debug_mode() {
                if (!debug_mode) {
                        printf("m 0\nD\n");
+                       flush_reply();
                        debug_mode = true;
                }
        }
                        debug_mode = true;
                }
        }
index d02e25a965e7a9344b9ac0f6ab45b084a7953b40..3684f253ca6532f4ccf439d3e07f8266e97821e1 100644 (file)
@@ -66,8 +66,10 @@ public class AltosSerial implements Runnable {
                                                                        LinkedBlockingQueue<String> q = monitors.get(e);
                                                                        q.put(line);
                                                                }
                                                                        LinkedBlockingQueue<String> q = monitors.get(e);
                                                                        q.put(line);
                                                                }
-                                                       } else
+                                                       } else {
+//                                                             System.out.printf("GOT: %s\n", line);
                                                                reply_queue.put(line);
                                                                reply_queue.put(line);
+                                                       }
                                                        line = "";
                                                }
                                        } else {
                                                        line = "";
                                                }
                                        } else {
@@ -80,6 +82,11 @@ public class AltosSerial implements Runnable {
        }
 
        public void flush_reply() {
        }
 
        public void flush_reply() {
+               libaltos.altos_flush(altos);
+               try {
+                       Thread.sleep(100);
+               } catch (InterruptedException ie) {
+               }
                reply_queue.clear();
        }
 
                reply_queue.clear();
        }
 
@@ -132,6 +139,7 @@ public class AltosSerial implements Runnable {
        }
 
        public void print(String data) {
        }
 
        public void print(String data) {
+//             System.out.printf("\"%s\" ", data);
                for (int i = 0; i < data.length(); i++)
                        putc(data.charAt(i));
        }
                for (int i = 0; i < data.length(); i++)
                        putc(data.charAt(i));
        }