+ s.send_to_clients();
+ break;
+ case MSG_SETBAUD:
+ AltosDebug.debug("MSG_SETBAUD");
+ s.telemetry_state.telemetry_rate = (Integer) msg.obj;
+ if (s.telemetry_state.connect == TelemetryState.CONNECT_CONNECTED) {
+ s.altos_link.set_telemetry_rate(s.telemetry_state.telemetry_rate);
+ s.altos_link.save_telemetry_rate();
+ }
+ s.send_to_clients();
+ break;
+
+ /*
+ *Messages from AltosBluetooth
+ */
+ case MSG_CONNECTED:
+ AltosDebug.debug("MSG_CONNECTED");
+ bt = (AltosDroidLink) msg.obj;
+
+ if (bt != s.altos_link) {
+ AltosDebug.debug("Stale message");
+ break;
+ }
+ AltosDebug.debug("Connected to device");
+ try {
+ s.connected();
+ } catch (InterruptedException ie) {
+ }
+ break;
+ case MSG_CONNECT_FAILED:
+ AltosDebug.debug("MSG_CONNECT_FAILED");
+ bt = (AltosDroidLink) msg.obj;
+
+ if (bt != s.altos_link) {
+ AltosDebug.debug("Stale message");
+ break;
+ }
+ if (s.address != null) {
+ AltosDebug.debug("Connection failed... retrying");
+ s.start_altos_bluetooth(s.address, true);
+ } else {
+ s.disconnect(true);
+ }
+ break;
+ case MSG_DISCONNECTED:
+
+ /* This can be sent by either AltosDroidLink or TelemetryReader */
+ AltosDebug.debug("MSG_DISCONNECTED");
+ bt = (AltosDroidLink) msg.obj;
+
+ if (bt != s.altos_link) {
+ AltosDebug.debug("Stale message");
+ break;
+ }
+ if (s.address != null) {
+ AltosDebug.debug("Connection lost... retrying");
+ s.start_altos_bluetooth(s.address, true);
+ } else {
+ s.disconnect(true);
+ }
+ break;
+
+ /*
+ * Messages from TelemetryReader
+ */
+ case MSG_TELEMETRY:
+ AltosDebug.debug("MSG_TELEMETRY");
+ s.telemetry((AltosTelemetry) msg.obj);
+ break;
+ case MSG_CRC_ERROR:
+ // forward crc error messages
+ s.telemetry_state.crc_errors = (Integer) msg.obj;
+ AltosDebug.debug("MSG_CRC_ERROR");
+ s.send_to_clients();