+ // Configure the newly connected device for telemetry
+ print("~\nE 0\n");
+ set_monitor(false);
+ if (D) Log.d(TAG, "ConnectThread: connected");
+
+ /* Let TelemetryService know we're connected
+ */
+ handler.obtainMessage(TelemetryService.MSG_CONNECTED, this).sendToTarget();
+
+ /* Notify other waiting threads that we're connected now
+ */
+ notifyAll();
+ }
+ }
+ } catch (IOException io) {
+ connect_failed();
+ }
+ }
+
+ private void connect_failed() {
+ if (closed()) {
+ if (D) Log.d(TAG, "connect_failed after closed");
+ return;
+ }
+
+ close_socket();
+ input = null;
+ output = null;
+ handler.obtainMessage(TelemetryService.MSG_CONNECT_FAILED, this).sendToTarget();
+ if (D) Log.e(TAG, "ConnectThread: Failed to establish connection");
+ }
+
+ private void disconnected() {
+ if (closed()) {
+ if (D) Log.d(TAG, "disconnected after closed");
+ return;
+ }
+
+ if (D) Log.d(TAG, "Sending disconnected message");
+ handler.obtainMessage(TelemetryService.MSG_DISCONNECTED, this).sendToTarget();
+ }
+
+ private void close_socket() {
+ BluetoothSocket tmp_socket;
+
+ synchronized(this) {
+ tmp_socket = socket;
+ socket = null;
+ }
+
+ if (tmp_socket != null) {