+ // Handler of incoming messages from clients.
+ class IncomingHandler extends Handler {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_REGISTER_CLIENT:
+ mClients.add(msg.replyTo);
+ if (D) Log.d(TAG, "Client bound to service");
+ break;
+ case MSG_UNREGISTER_CLIENT:
+ 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");
+ TeleBT_stop();
+ TeleBT_start((BluetoothDevice) msg.obj);
+ break;
+ default:
+ super.handleMessage(msg);
+ }
+ }
+ }
+
+ private void TeleBT_stop() {
+ if (mAltosBluetooth != null) {
+ mAltosBluetooth.close();
+ mAltosBluetooth = null;
+ }
+ telem.clear();
+ }
+
+ private void TeleBT_start(BluetoothDevice d) {
+ mAltosBluetooth = new AltosBluetooth(d);
+ mAltosBluetooth.add_monitor(telem);
+ }
+