+ s.device = (BluetoothDevice) msg.obj;
+ s.startAltosBluetooth();
+ break;
+ case MSG_CONNECTED:
+ if (D) Log.d(TAG, "Connected to device");
+ s.connected();
+ break;
+ case MSG_CONNECT_FAILED:
+ if (D) Log.d(TAG, "Connection failed... retrying");
+ s.startAltosBluetooth();
+ break;
+ case MSG_DISCONNECTED:
+ // Only do the following if we haven't been shutdown elsewhere..
+ if (s.device != null) {
+ if (D) Log.d(TAG, "Disconnected from " + s.device.getName());
+ s.stopAltosBluetooth();
+ }
+ break;
+ case MSG_TELEMETRY:
+ // forward telemetry messages
+ s.last_state = (AltosState) msg.obj;
+ s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_TELEMETRY, msg.obj));
+ break;
+ case MSG_CRC_ERROR:
+ // forward crc error messages
+ s.last_crc_errors = (Integer) msg.obj;
+ s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_CRC_ERROR, msg.obj));
+ break;
+ case MSG_SETFREQUENCY:
+ if (s.state == STATE_CONNECTED) {
+ try {
+ s.mAltosBluetooth.set_radio_frequency((Double) msg.obj);
+ } catch (InterruptedException e) {
+ } catch (TimeoutException e) {
+ }
+ }
+ break;
+ case MSG_SETBAUD:
+ if (s.state == STATE_CONNECTED) {
+ s.mAltosBluetooth.set_telemetry_rate((Integer) msg.obj);
+ }