X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosLink.java;h=6d510563c5d32622bfbc3cfb854da885c21b4f27;hb=7c6231ecef2e4f978a0de452a17a2a24e6e68827;hp=d59e73ba6eca2a690da98f0d46e9db7e6c870919;hpb=52196975c447851f14619213c1de5101d334eebc;p=fw%2Faltos diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index d59e73ba..6d510563 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -17,13 +17,11 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.io.*; import java.util.concurrent.*; import java.util.*; -import java.text.*; -public abstract class AltosLink { +public abstract class AltosLink implements Runnable { public final static int ERROR = -1; public final static int TIMEOUT = -2; @@ -101,15 +99,23 @@ public abstract class AltosLink { try { for (;;) { c = getchar(); - if (Thread.interrupted()) + if (Thread.interrupted()) { + if (debug) + System.out.printf("INTERRUPTED\n"); break; + } if (c == ERROR) { + if (debug) + System.out.printf("ERROR\n"); add_telem (new AltosLine()); add_reply (new AltosLine()); break; } - if (c == TIMEOUT) + if (c == TIMEOUT) { + if (debug) + System.out.printf("TIMEOUT\n"); continue; + } if (c == '\r') continue; synchronized(this) { @@ -180,6 +186,14 @@ public abstract class AltosLink { reply_queue.put (line); } + public void abort_reply() { + try { + add_telem (new AltosLine()); + add_reply (new AltosLine()); + } catch (InterruptedException e) { + } + } + public void add_string(String line) throws InterruptedException { if (line.startsWith("TELEM") || line.startsWith("VERSION") || line.startsWith("CRC")) { add_telem(new AltosLine(line));