X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FAltosDroidLink.java;h=a443b6e987e8fce060001c06d1ca84b70a62cde2;hp=badb2caa82fee51885339877ddc3549ec27e87df;hb=297eb795b24ec31f6599f48bc8c3769557a7ec6f;hpb=7bfa8841b65707d629b425b306ec4cc3acfc156c diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidLink.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidLink.java index badb2caa..a443b6e9 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidLink.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidLink.java @@ -3,7 +3,8 @@ * * 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. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -23,16 +24,11 @@ import java.io.OutputStream; import java.util.UUID; import android.os.Handler; -import android.util.Log; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_13.*; public abstract class AltosDroidLink extends AltosLink { - // Debugging - private static final String TAG = "AltosDroidLink"; - private static final boolean D = true; - Handler handler; Thread input_thread = null; @@ -70,7 +66,7 @@ public abstract class AltosDroidLink extends AltosLink { // Configure the newly connected device for telemetry print("~\nE 0\n"); set_monitor(false); - if (D) Log.d(TAG, "ConnectThread: connected"); + AltosDebug.debug("ConnectThread: connected"); /* Let TelemetryService know we're connected */ @@ -83,7 +79,7 @@ public abstract class AltosDroidLink extends AltosLink { public void closing() { synchronized(closed_lock) { - if (D) Log.d(TAG, "Marked closing true"); + AltosDebug.debug("Marked closing true"); closing = true; } } @@ -97,14 +93,14 @@ public abstract class AltosDroidLink extends AltosLink { abstract void close_device(); public void close() { - if (D) Log.d(TAG, "close(): begin"); + AltosDebug.debug("close(): begin"); closing(); flush_output(); synchronized (closed_lock) { - if (D) Log.d(TAG, "Marked closed true"); + AltosDebug.debug("Marked closed true"); closed = true; } @@ -113,11 +109,11 @@ public abstract class AltosDroidLink extends AltosLink { synchronized(this) { if (input_thread != null) { - if (D) Log.d(TAG, "close(): stopping input_thread"); + AltosDebug.debug("close(): stopping input_thread"); try { - if (D) Log.d(TAG, "close(): input_thread.interrupt()....."); + AltosDebug.debug("close(): input_thread.interrupt()....."); input_thread.interrupt(); - if (D) Log.d(TAG, "close(): input_thread.join()....."); + AltosDebug.debug("close(): input_thread.join()....."); input_thread.join(); } catch (Exception e) {} input_thread = null; @@ -143,7 +139,7 @@ public abstract class AltosDroidLink extends AltosLink { private void debug_input(byte b) { if (b == '\n') { - Log.d(TAG, " " + new String(debug_chars, 0, debug_off)); + AltosDebug.debug(" " + new String(debug_chars, 0, debug_off)); debug_off = 0; } else { if (debug_off < buffer_size) @@ -153,11 +149,11 @@ public abstract class AltosDroidLink extends AltosLink { private void disconnected() { if (closed()) { - if (D) Log.d(TAG, "disconnected after closed"); + AltosDebug.debug("disconnected after closed"); return; } - if (D) Log.d(TAG, "Sending disconnected message"); + AltosDebug.debug("Sending disconnected message"); handler.obtainMessage(TelemetryService.MSG_DISCONNECTED, this).sendToTarget(); } @@ -169,14 +165,14 @@ public abstract class AltosDroidLink extends AltosLink { while (buffer_off == buffer_len) { buffer_len = read(in_buffer, buffer_size); if (buffer_len < 0) { - Log.d(TAG, "ERROR returned from getchar()"); + AltosDebug.debug("ERROR returned from getchar()"); disconnected(); return ERROR; } buffer_off = 0; } - if (D) - debug_input(in_buffer[buffer_off]); +// if (AltosDebug.D) +// debug_input(in_buffer[buffer_off]); return in_buffer[buffer_off++]; } @@ -192,7 +188,7 @@ public abstract class AltosDroidLink extends AltosLink { int sent = write(out_buffer, out_buffer_off); if (sent <= 0) { - Log.d(TAG, "flush_output() failed"); + AltosDebug.debug("flush_output() failed"); out_buffer_off = 0; break; } @@ -212,10 +208,9 @@ public abstract class AltosDroidLink extends AltosLink { public void print(String data) { byte[] bytes = data.getBytes(); - if (D) Log.d(TAG, "print(): begin"); +// AltosDebug.debug(data.replace('\n', '\\')); for (byte b : bytes) putchar(b); - if (D) Log.d(TAG, "print(): Wrote bytes: '" + data.replace('\n', '\\') + "'"); } public AltosDroidLink(Handler handler) {