import android.app.Service;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.IBinder;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.os.IBinder;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
// Unique Identification Number for the Notification.
// We use it on Notification start, and to cancel it.
private int NOTIFICATION = R.string.telemetry_service_label;
//private NotificationManager mNM;
ArrayList<Messenger> mClients = new ArrayList<Messenger>(); // Keeps track of all current registered clients.
// Unique Identification Number for the Notification.
// We use it on Notification start, and to cancel it.
private int NOTIFICATION = R.string.telemetry_service_label;
//private NotificationManager mNM;
ArrayList<Messenger> mClients = new ArrayList<Messenger>(); // Keeps track of all current registered clients.
private AltosBluetooth mAltosBluetooth = null;
private int state = STATE_NONE;
LinkedBlockingQueue<AltosLine> telem;
private AltosBluetooth mAltosBluetooth = null;
private int state = STATE_NONE;
LinkedBlockingQueue<AltosLine> telem;
+ try {
+ msg.replyTo.send(Message.obtain(null, AltosDroid.MSG_STATE_CHANGE, s.state, -1));
+ } catch (RemoteException e) {
+ s.mClients.remove(msg.replyTo);
+ }
if (D) Log.d(TAG, "Client bound to service");
break;
case MSG_UNREGISTER_CLIENT:
if (D) Log.d(TAG, "Client bound to service");
break;
case MSG_UNREGISTER_CLIENT:
- private void startAltosBluetooth(BluetoothDevice d) {
- mAltosBluetooth = new AltosBluetooth(d);
- mAltosBluetooth.add_monitor(telem);
+ private void startAltosBluetooth() {
+ if (mAltosBluetooth == null) {
+ if (D) Log.i(TAG, "Connecting to " + device.getName());
+ mAltosBluetooth = new AltosBluetooth(device, mHandler);