+ try {
+ s.connected();
+ } catch (InterruptedException ie) {
+ }
+ break;
+ case MSG_CONNECT_FAILED:
+ if (D) Log.d(TAG, "Connection failed... retrying");
+ if (s.address != null)
+ s.startAltosBluetooth(s.address);
+ break;
+ case MSG_DISCONNECTED:
+ Log.d(TAG, "MSG_DISCONNECTED");
+ s.stopAltosBluetooth();
+ break;
+ case MSG_TELEMETRY:
+ // forward telemetry messages
+ s.telemetry_state.state = (AltosState) msg.obj;
+ if (s.telemetry_state.state != null) {
+ if (D) Log.d(TAG, "Save state");
+ AltosPreferences.set_state(0, s.telemetry_state.state, null);
+ }
+ if (D) Log.d(TAG, "MSG_TELEMETRY");
+ s.sendMessageToClients();
+ break;
+ case MSG_CRC_ERROR:
+ // forward crc error messages
+ s.telemetry_state.crc_errors = (Integer) msg.obj;
+ if (D) Log.d(TAG, "MSG_CRC_ERROR");
+ s.sendMessageToClients();
+ break;
+ case MSG_SETFREQUENCY:
+ if (D) Log.d(TAG, "MSG_SETFREQUENCY");
+ s.telemetry_state.frequency = (Double) msg.obj;
+ if (s.telemetry_state.connect == TelemetryState.CONNECT_CONNECTED) {
+ try {
+ s.mAltosBluetooth.set_radio_frequency(s.telemetry_state.frequency);
+ s.mAltosBluetooth.save_frequency();
+ } catch (InterruptedException e) {
+ } catch (TimeoutException e) {
+ }
+ }
+ s.sendMessageToClients();
+ break;
+ case MSG_SETBAUD:
+ if (D) Log.d(TAG, "MSG_SETBAUD");
+ s.telemetry_state.telemetry_rate = (Integer) msg.obj;
+ if (s.telemetry_state.connect == TelemetryState.CONNECT_CONNECTED) {
+ s.mAltosBluetooth.set_telemetry_rate(s.telemetry_state.telemetry_rate);
+ s.mAltosBluetooth.save_telemetry_rate();
+ }
+ s.sendMessageToClients();