More ALtosUI changes
authorKeith Packard <keithp@keithp.com>
Thu, 22 Apr 2010 23:25:35 +0000 (16:25 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 22 Apr 2010 23:25:38 +0000 (16:25 -0700)
ao-tools/altosui/AltosSerial.java
ao-tools/altosui/AltosUI.java
ao-tools/altosui/Makefile

index e4cedde22b6d6b9c0deedc6c2a506a94f32d0516..03ab28c55376ff635c4c7b964304f0ab7cd1b269 100644 (file)
@@ -36,7 +36,7 @@ import altosui.AltosSerialMonitor;
  */
 class AltosSerialReader implements Runnable {
        InputStream     serial_in;
-       LinkedBlockingQueue<String> monitor_queue;
+       LinkedList<LinkedBlockingQueue<String>> monitors;
        LinkedBlockingQueue<String> reply_queue;
        Thread input_thread;
        String line;
@@ -56,9 +56,12 @@ class AltosSerialReader implements Runnable {
                                synchronized(this) {
                                        if (c == '\n') {
                                                if (line != "") {
-                                                       if (line.startsWith("VERSION"))
-                                                               monitor_queue.put(line);
-                                                       else
+                                                       if (line.startsWith("VERSION")) {
+                                                               for (int e = 0; e < monitors.size(); e++) {
+                                                                       LinkedBlockingQueue<String> q = monitors.get(e);
+                                                                       q.put(line);
+                                                               }
+                                                       } else
                                                                reply_queue.put(line);
                                                        line = "";
                                                }
@@ -72,16 +75,18 @@ class AltosSerialReader implements Runnable {
                }
        }
 
-       public String get_telem() throws InterruptedException {
-               String s = monitor_queue.take();
-               System.out.println(s);
-               return s;
-       }
-
        public String get_reply() throws InterruptedException {
                return reply_queue.take();
        }
 
+       public void add_monitor(LinkedBlockingQueue<String> q) {
+               monitors.add(q);
+       }
+
+       public void remove_monitor(LinkedBlockingQueue<String> q) {
+               monitors.remove(q);
+       }
+
        public void flush () {
                synchronized(this) {
                        if (!"VERSION".startsWith(line) && !line.startsWith("VERSION"))
@@ -132,7 +137,7 @@ class AltosSerialReader implements Runnable {
                serial_in = null;
                input_thread = null;
                line = "";
-               monitor_queue = new LinkedBlockingQueue<String> ();
+               monitors = new LinkedList<LinkedBlockingQueue<String>> ();
                reply_queue = new LinkedBlockingQueue<String> ();
        }
 
@@ -142,10 +147,6 @@ public class AltosSerial {
        OutputStream serial_out = null;
        AltosSerialReader reader = null;
 
-       public String get_telem() throws InterruptedException {
-               return reader.get_telem();
-       }
-
        CommPort comm_port = null;
 
        public void close() {
@@ -178,6 +179,14 @@ public class AltosSerial {
                reader = new AltosSerialReader();
        }
 
+       public void add_monitor(LinkedBlockingQueue<String> q) {
+               reader.add_monitor(q);
+       }
+
+       public void remove_monitor(LinkedBlockingQueue<String> q) {
+               reader.remove_monitor(q);
+       }
+
        public AltosSerial() {
                init();
        }
index 7f008f3aadb7930e869a9916c3d56e2186fd88e5..2952fcc08c0021f4bdc508ac3cd8c72c57de9da6 100644 (file)
@@ -26,6 +26,7 @@ import java.io.*;
 import java.util.*;
 import java.text.*;
 import java.util.prefs.*;
+import java.util.concurrent.LinkedBlockingQueue;
 import gnu.io.*;
 
 import altosui.AltosSerial;
@@ -391,14 +392,6 @@ public class AltosUI extends JFrame {
                return true;
        }
 
-       private void PickSerialDevice() {
-               java.util.Enumeration<CommPortIdentifier> port_list = CommPortIdentifier.getPortIdentifiers();
-               while (port_list.hasMoreElements()) {
-                       CommPortIdentifier identifier = port_list.nextElement();
-                       System.out.println("Serial port " + identifier.getName());
-               }
-       }
-
        class DisplayThread extends Thread {
                String read() throws InterruptedException { return null; }
 
@@ -433,21 +426,22 @@ public class AltosUI extends JFrame {
 
        class DeviceThread extends DisplayThread {
                AltosSerial     serial;
+               LinkedBlockingQueue<String> telem;
 
                String read() throws InterruptedException {
-                       System.out.println("Waiting for telemetry");
-                       String s = serial.get_telem();
-                       System.out.println("Got telemetry " + s);
-                       return s;
+                       return telem.take();
                }
 
                void close() {
                        serial.close();
+                       serial.remove_monitor(telem);
                        System.out.println("DisplayThread done");
                }
 
                public DeviceThread(AltosSerial s) {
                        serial = s;
+                       telem = new LinkedBlockingQueue<String>();
+                       serial.add_monitor(telem);
                }
        }
 
index fbe0a5eb41cb7ab2beafbcec03c3e2b2348e20f9..b9f025dab5359b4ecf00a3b203a9b9567719e66c 100644 (file)
@@ -3,9 +3,12 @@
 CLASSPATH=..:/usr/share/java/*
 CLASSFILES=\
        AltosConvert.class \
+       AltosFile.class \
        AltosGPS.class \
        AltosGreatCircle.class \
+       AltosLog.class \
        AltosParse.class \
+       AltosPreferences.class \
        AltosSerialMonitor.class \
        AltosSerial.class \
        AltosState.class \