import java.util.UUID;
import android.os.Handler;
-import android.util.Log;
import org.altusmetrum.altoslib_7.*;
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;
// 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
*/
public void closing() {
synchronized(closed_lock) {
- if (D) Log.d(TAG, "Marked closing true");
+ AltosDebug.debug("Marked closing true");
closing = true;
}
}
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;
}
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;
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)
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();
}
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)
+ if (AltosDebug.D)
debug_input(in_buffer[buffer_off]);
return in_buffer[buffer_off++];
}
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;
}
public void print(String data) {
byte[] bytes = data.getBytes();
- if (D) Log.d(TAG, "print(): begin");
+ AltosDebug.debug("print(): begin");
for (byte b : bytes)
putchar(b);
- if (D) Log.d(TAG, "print(): Wrote bytes: '" + data.replace('\n', '\\') + "'");
+ AltosDebug.debug("print(): Wrote bytes: '" + data.replace('\n', '\\') + "'");
}
public AltosDroidLink(Handler handler) {