+ // Handler of incoming messages from clients.
+ static class IncomingHandler extends Handler {
+ private final WeakReference<TelemetryService> service;
+ IncomingHandler(TelemetryService s) { service = new WeakReference<TelemetryService>(s); }
+
+ @Override
+ public void handleMessage(Message msg) {
+ TelemetryService s = service.get();
+ switch (msg.what) {
+ case MSG_REGISTER_CLIENT:
+ s.mClients.add(msg.replyTo);
+ if (D) Log.d(TAG, "Client bound to service");
+ break;
+ case MSG_UNREGISTER_CLIENT:
+ s.mClients.remove(msg.replyTo);
+ if (D) Log.d(TAG, "Client unbound from service");
+ break;
+ case MSG_CONNECT_TELEBT:
+ if (D) Log.d(TAG, "Connect command received");
+ s.startAltosBluetooth((BluetoothDevice) msg.obj);
+ break;
+ default:
+ super.handleMessage(msg);
+ }
+ }
+ }
+
+ private void stopAltosBluetooth() {
+ if (mAltosBluetooth != null) {
+ mAltosBluetooth.close();
+ mAltosBluetooth = null;
+ }
+ telem.clear();
+ }
+
+ private void startAltosBluetooth(BluetoothDevice d) {
+ mAltosBluetooth = new AltosBluetooth(d);
+ mAltosBluetooth.add_monitor(telem);
+ }
+