+ // This shouldn't be required - mConfigData should be null for any non-connected
+ // state, but to be safe and to reduce message size
+ AltosConfigData acd = (state == STATE_CONNECTED) ? mConfigData : null;
+
+ sendMessageToClients(Message.obtain(null, AltosDroid.MSG_STATE_CHANGE, state, -1, acd));
+ }
+
+ private void connected() {
+ try {
+ if (mAltosBluetooth == null)
+ throw new InterruptedException("no bluetooth");
+ mConfigData = mAltosBluetooth.config_data();
+ } catch (InterruptedException e) {
+ } catch (TimeoutException e) {
+ // If this timed out, then we really want to retry it, but
+ // probably safer to just retry the connection from scratch.
+ mHandler.obtainMessage(MSG_CONNECT_FAILED).sendToTarget();
+ return;
+ }
+
+ setState(STATE_CONNECTED);
+
+ mTelemetryReader = new TelemetryReader(mAltosBluetooth, mHandler);
+ mTelemetryReader.start();
+
+ mTelemetryLogger = new TelemetryLogger(this, mAltosBluetooth);
+ }
+
+
+ private void onTimerTick() {
+ if (D) Log.d(TAG, "Timer wakeup");
+ try {
+ if (mClients.size() <= 0 && state != STATE_CONNECTED) {
+ stopSelf();
+ }
+ } catch (Throwable t) {
+ Log.e(TAG, "Timer failed: ", t);
+ }