+ public String get_reply() throws InterruptedException {
+ return get_reply(5000);
+ }
+
+
+ public abstract boolean can_cancel_reply();
+ public abstract boolean show_reply_timeout();
+ public abstract void hide_reply_timeout();
+
+ public boolean reply_abort;
+ public int in_reply;
+ boolean cancel_enable = true;
+
+ public void set_cancel_enable(boolean e) {
+ cancel_enable = e;
+ }
+
+ boolean reply_timeout_shown = false;
+
+ private boolean check_reply_timeout() {
+ if (!cancel_enable)
+ return false;
+ if (!reply_timeout_shown)
+ reply_timeout_shown = show_reply_timeout();
+ return reply_abort;
+ }
+
+ private void cleanup_reply_timeout() {
+ if (reply_timeout_shown) {
+ reply_timeout_shown = false;
+ hide_reply_timeout();
+ }
+ }
+
+ private int len_read = 0;
+
+ private boolean match_bytes(byte[] bytes, int byte_count, String match) {
+ if (byte_count < match.length())
+ return false;
+ String line = new String(bytes, 0, byte_count, AltosLib.unicode_set);
+ if (line == null)
+ return false;
+ return line.indexOf(match) >= 0;
+ }
+
+ public void run () {
+ int c;
+ byte[] line_bytes = null;
+ int line_count = 0;
+
+ try {
+ for (;;) {
+ c = getchar();
+ if (Thread.interrupted()) {
+ break;
+ }
+ if (c == ERROR) {
+ if (debug)
+ System.out.printf("ERROR\n");
+ has_error = true;
+ add_telem (new AltosLine());
+ add_reply (new AltosLine());
+ break;
+ }
+ if (c == TIMEOUT) {
+ if (debug)
+ System.out.printf("TIMEOUT\n");
+ continue;
+ }
+ if (c == '\r' && len_read == 0)
+ continue;
+ synchronized(this) {
+ if (c == '\n' && len_read == 0) {
+ if (line_count != 0) {
+ add_bytes(line_bytes, line_count);
+ line_count = 0;
+ }
+ } else {
+ if (line_bytes == null) {
+ line_bytes = new byte[256];
+ } else if (line_count == line_bytes.length) {
+ byte[] new_line_bytes = new byte[line_count * 2];
+ System.arraycopy(line_bytes, 0, new_line_bytes, 0, line_count);
+ line_bytes = new_line_bytes;
+ }
+ line_bytes[line_count] = (byte) c;
+ line_count++;
+ if (len_read !=0 && line_count == len_read) {
+ add_binary(line_bytes, line_count);
+ line_count = 0;
+ len_read = 0;
+ }
+ if (match_string != null && match_bytes(line_bytes, line_count, match_string)) {
+ match_string = null;
+ add_bytes(line_bytes, line_count);
+ line_count = 0;
+ }
+ }
+ }
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+
+ public void set_match(String match) {
+ match_string = match;
+ }
+