X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosui%2FAltosSerial.java;h=f9f9e6e425232436d9e8ce4fe6788496b5dc4cb4;hb=dbe915795c66995805b5f37e6eb698cf2c143e61;hp=b19143e58b7080070457d606a93e8798deaf9a71;hpb=3fbefb3eea981d34a09496cf8abf0119de2e35bf;p=fw%2Faltos diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index b19143e5..f9f9e6e4 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -47,6 +47,13 @@ public class AltosSerial implements Runnable { byte[] line_bytes; int line_count; boolean monitor_mode; + static boolean debug; + boolean remote; + LinkedList pending_output = new LinkedList(); + + static void set_debug(boolean new_debug) { + debug = new_debug; + } public void run () { int c; @@ -78,13 +85,14 @@ public class AltosSerial implements Runnable { for (int i = 0; i < line_count; i++) line = line + line_bytes[i]; } + if (debug) + System.out.printf("\t\t\t\t\t%s\n", line); if (line.startsWith("VERSION") || line.startsWith("CRC")) { for (int e = 0; e < monitors.size(); e++) { LinkedBlockingQueue q = monitors.get(e); q.put(new AltosLine (line)); } } else { -// System.out.printf("GOT: %s\n", line); reply_queue.put(new AltosLine (line)); } line_count = 0; @@ -108,16 +116,24 @@ public class AltosSerial implements Runnable { } public void flush_output() { - if (altos != null) + if (altos != null) { + for (String s : pending_output) + System.out.print(s); + pending_output.clear(); libaltos.altos_flush(altos); + } } public void flush_input() { flush_output(); boolean got_some; + + int timeout = 100; + if (remote) + timeout = 300; do { try { - Thread.sleep(100); + Thread.sleep(timeout); } catch (InterruptedException ie) { } got_some = !reply_queue.isEmpty(); @@ -174,15 +190,18 @@ public class AltosSerial implements Runnable { synchronized (devices_opened) { devices_opened.remove(device.getPath()); } + if (debug) + System.out.printf("Closing %s\n", device.getPath()); } - public void putc(char c) { + private void putc(char c) { if (altos != null) libaltos.altos_putchar(altos, c); } public void print(String data) { -// System.out.printf("\"%s\" ", data); + if (debug) + pending_output.add(data); for (int i = 0; i < data.length(); i++) putc(data.charAt(i)); } @@ -202,6 +221,8 @@ public class AltosSerial implements Runnable { close(); throw new FileNotFoundException(device.toShortString()); } + if (debug) + System.out.printf("Open %s\n", device.getPath()); input_thread = new Thread(this); input_thread.start(); print("~\nE 0\n"); @@ -242,6 +263,24 @@ public class AltosSerial implements Runnable { } } + public void start_remote() { + if (debug) + System.out.printf("start remote\n"); + set_radio(); + printf("p\nE 0\n"); + flush_input(); + remote = true; + } + + public void stop_remote() { + if (debug) + System.out.printf("stop remote\n"); + flush_input(); + printf ("~"); + flush_output(); + remote = false; + } + public AltosSerial(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { device = in_device; line = "";