altosui: Make sure packet mode is turned off when the connection fails
authorKeith Packard <keithp@keithp.com>
Wed, 24 Nov 2010 18:55:18 +0000 (10:55 -0800)
committerKeith Packard <keithp@keithp.com>
Wed, 24 Nov 2010 18:55:18 +0000 (10:55 -0800)
When the packet connection times out, turn packet mode off when
closing the serial port.

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

index b1acd41072e35d138f00c2d47b027ec263165117..1c42870f8d7ff61519a2df97b9eb88404cfab6cd 100644 (file)
@@ -74,7 +74,7 @@ public class AltosConfig implements Runnable, ActionListener {
        string_ref      product;
        string_ref      callsign;
        AltosConfigUI   config_ui;
-
+       boolean         serial_started;
 
        boolean get_int(String line, String label, int_ref x) {
                if (line.startsWith(label)) {
@@ -108,6 +108,7 @@ public class AltosConfig implements Runnable, ActionListener {
        }
 
        void start_serial() throws InterruptedException {
+               serial_started = true;
                if (remote) {
                        serial_line.set_radio();
                        serial_line.printf("p\nE 0\n");
@@ -116,6 +117,9 @@ public class AltosConfig implements Runnable, ActionListener {
        }
 
        void stop_serial() throws InterruptedException {
+               if (!serial_started)
+                       return;
+               serial_started = false;
                if (remote) {
                        serial_line.printf("~");
                        serial_line.flush_output();
@@ -160,6 +164,10 @@ public class AltosConfig implements Runnable, ActionListener {
                                                            device.toShortString()),
                                              "Connection Failed",
                                              JOptionPane.ERROR_MESSAGE);
+               try {
+                       stop_serial();
+               } catch (InterruptedException ie) {
+               }
                serial_line.close();
                serial_line = null;
        }
index 75c0a17a9bb0fb8bfec7cdbf8ced2d4d050ce956..3cbd8a751e1e53af63fa54c4de70ffcc3b0bab80 100644 (file)
@@ -24,6 +24,7 @@ public class AltosIgnite {
        AltosDevice     device;
        AltosSerial     serial;
        boolean         remote;
+       boolean         serial_started;
        final static int        None = 0;
        final static int        Apogee = 1;
        final static int        Main = 2;
@@ -34,6 +35,7 @@ public class AltosIgnite {
        final static int        Open = 3;
 
        private void start_serial() throws InterruptedException {
+               serial_started = true;
                if (remote) {
                        serial.set_radio();
                        serial.printf("p\nE 0\n");
@@ -42,6 +44,9 @@ public class AltosIgnite {
        }
 
        private void stop_serial() throws InterruptedException {
+               if (!serial_started)
+                       return;
+               serial_started = false;
                if (serial == null)
                        return;
                if (remote) {
@@ -148,6 +153,10 @@ public class AltosIgnite {
        }
 
        public void close() {
+               try {
+                       stop_serial();
+               } catch (InterruptedException ie) {
+               }
                serial.close();
                serial = null;
        }