X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosSerial.java;h=9b2180baf6fea2a2ee1f4db343f9ae0155cbe350;hp=78d862d03645ccd7eae99eb1acfd1bbc17d19682;hb=02e657e45e217dc483a81f28020cfe65a826e9be;hpb=670034eef48d63cdaec8d271fa93da984ffe2ea9 diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index 78d862d0..9b2180ba 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -25,8 +25,8 @@ import java.io.*; import java.util.*; import java.awt.*; import javax.swing.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_4.*; +import org.altusmetrum.altosuilib_2.*; import libaltosJNI.*; @@ -57,11 +57,8 @@ public class AltosSerial extends AltosLink { public void flush_output() { super.flush_output(); if (altos != null) { - if (libaltos.altos_flush(altos) != 0) { - libaltos.altos_close(altos); - altos = null; - abort_reply(); - } + if (libaltos.altos_flush(altos) != 0) + close_serial(); } } @@ -72,7 +69,7 @@ public class AltosSerial extends AltosLink { Object[] options = { "Cancel" }; JOptionPane pane = new JOptionPane(); - pane.setMessage(String.format("Connecting to %s, %7.3f MHz", device.toShortString(), frequency)); + pane.setMessage(String.format("Connecting to %s, %7.3f MHz as %s", device.toShortString(), frequency, callsign)); pane.setOptions(options); pane.setInitialValue(null); @@ -122,6 +119,17 @@ public class AltosSerial extends AltosLink { SwingUtilities.invokeLater(r); } + private void close_serial() { + synchronized (devices_opened) { + devices_opened.remove(device.getPath()); + } + if (altos != null) { + libaltos.altos_free(altos); + altos = null; + } + abort_reply(); + } + public void close() { if (remote) { try { @@ -132,35 +140,33 @@ public class AltosSerial extends AltosLink { if (in_reply != 0) System.out.printf("Uh-oh. Closing active serial device\n"); - if (altos != null) { - libaltos.altos_close(altos); - } + close_serial(); + if (input_thread != null) { try { input_thread.interrupt(); input_thread.join(); - } catch (InterruptedException e) { + } catch (InterruptedException ie) { } input_thread = null; } - if (altos != null) { - libaltos.altos_free(altos); - altos = null; - } - synchronized (devices_opened) { - devices_opened.remove(device.getPath()); - } if (debug) System.out.printf("Closing %s\n", device.getPath()); } private void putc(char c) { if (altos != null) - if (libaltos.altos_putchar(altos, c) != 0) { - libaltos.altos_close(altos); - altos = null; - abort_reply(); - } + if (libaltos.altos_putchar(altos, c) != 0) + close_serial(); + } + + public void putchar(byte c) { + if (altos != null) { + if (debug) + System.out.printf(" %02x", (int) c & 0xff); + if (libaltos.altos_putchar(altos, (char) c) != 0) + close_serial(); + } } public void print(String data) {