altosui: Move AltosConfigData.java to library
authorKeith Packard <keithp@keithp.com>
Tue, 3 Jan 2012 04:34:38 +0000 (20:34 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 3 Jun 2012 02:27:52 +0000 (19:27 -0700)
Create a new 'AltosLink' which exposes how to talk to the remote
device abstractly via 'get_reply' and 'printf' methods.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosSerial.java
altosui/altoslib/Makefile.am
altosui/altoslib/src/org/altusmetrum/AltosLib/AltosConfigData.java
altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLink.java [new file with mode: 0644]

index 74e945f3eff7d31d29ca6ff6af57b7615745ec5c..161f0e905995bab3bac4389432ca52034daa82c8 100644 (file)
@@ -41,7 +41,7 @@ import libaltosJNI.*;
  * threads.
  */
 
  * threads.
  */
 
-public class AltosSerial implements Runnable {
+public class AltosSerial implements Runnable, AltosLink {
 
        static java.util.List<String> devices_opened = Collections.synchronizedList(new LinkedList<String>());
 
 
        static java.util.List<String> devices_opened = Collections.synchronizedList(new LinkedList<String>());
 
index 967c8d06ec9c602e789f87eac187c834de509e11..cbf716b0daf1b69cba8f1af4248a70c3c4fa54e5 100644 (file)
@@ -11,12 +11,14 @@ AltosLibdir = $(datadir)/java
 
 AltosLib_JAVA = \
        $(SRC)/AltosLib.java \
 
 AltosLib_JAVA = \
        $(SRC)/AltosLib.java \
+       $(SRC)/AltosConfigData.java \
        $(SRC)/AltosConvert.java \
        $(SRC)/AltosCRCException.java \
        $(SRC)/AltosFrequency.java \
        $(SRC)/AltosGPS.java \
        $(SRC)/AltosGPSSat.java \
        $(SRC)/AltosLine.java \
        $(SRC)/AltosConvert.java \
        $(SRC)/AltosCRCException.java \
        $(SRC)/AltosFrequency.java \
        $(SRC)/AltosGPS.java \
        $(SRC)/AltosGPSSat.java \
        $(SRC)/AltosLine.java \
+       $(SRC)/AltosLink.java \
        $(SRC)/AltosParse.java \
        $(SRC)/AltosPreferences.java \
        $(SRC)/AltosRecordCompanion.java \
        $(SRC)/AltosParse.java \
        $(SRC)/AltosPreferences.java \
        $(SRC)/AltosRecordCompanion.java \
index ef34dd3ee06747ed6e2e0260e54bd670c2f816cb..0bc5d5a80a8b9ca1659ba3b8c18308b0d2c8c5c6 100644 (file)
 
 package altosui;
 
 
 package altosui;
 
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import javax.swing.filechooser.FileNameExtensionFilter;
-import javax.swing.table.*;
 import java.io.*;
 import java.util.*;
 import java.text.*;
 import java.io.*;
 import java.util.*;
 import java.text.*;
@@ -29,8 +24,6 @@ import java.util.prefs.*;
 import java.util.concurrent.*;
 import org.altusmetrum.AltosLib.*;
 
 import java.util.concurrent.*;
 import org.altusmetrum.AltosLib.*;
 
-import libaltosJNI.*;
-
 public class AltosConfigData implements Iterable<String> {
 
        /* Version information */
 public class AltosConfigData implements Iterable<String> {
 
        /* Version information */
@@ -138,14 +131,14 @@ public class AltosConfigData implements Iterable<String> {
                return 0;
        }
 
                return 0;
        }
 
-       public AltosConfigData(AltosSerial serial_line) throws InterruptedException, TimeoutException {
-               serial_line.printf("c s\np\nf\nl\nv\n");
+       public AltosConfigData(AltosLink link) throws InterruptedException, TimeoutException {
+               link.printf("c s\np\nf\nl\nv\n");
                lines = new LinkedList<String>();
                radio_setting = 0;
                radio_frequency = 0;
                stored_flight = 0;
                for (;;) {
                lines = new LinkedList<String>();
                radio_setting = 0;
                radio_frequency = 0;
                stored_flight = 0;
                for (;;) {
-                       String line = serial_line.get_reply();
+                       String line = link.get_reply();
                        if (line == null)
                                throw new TimeoutException();
                        if (line.contains("Syntax error"))
                        if (line == null)
                                throw new TimeoutException();
                        if (line.contains("Syntax error"))
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLink.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosLink.java
new file mode 100644 (file)
index 0000000..80f3d71
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.AltosLib;
+
+public interface AltosLink {
+       public void printf(String format, Object ... arguments) throws InterruptedException;
+
+       public String get_reply() throws InterruptedException;
+
+       public String get_reply(int timeout) throws InterruptedException;
+}