- private void sendMessageToClients(Message m) {
- for (int i=mClients.size()-1; i>=0; i--) {
- try {
- mClients.get(i).send(m);
- } catch (RemoteException e) {
- mClients.remove(i);
- }
+ /* Construct the message to deliver to clients
+ */
+ private Message message() {
+ if (telemetry_state == null)
+ Log.d(TAG, "telemetry_state null!");
+ if (telemetry_state.state == null)
+ Log.d(TAG, "telemetry_state.state null!");
+ return Message.obtain(null, AltosDroid.MSG_STATE, telemetry_state);
+ }
+
+ /* A new friend has connected
+ */
+ private void add_client(Messenger client) {
+
+ clients.add(client);
+ if (D) Log.d(TAG, "Client bound to service");
+
+ /* On connect, send the current state to the new client
+ */
+ send_to_client(client, message());
+
+ /* If we've got an address from a previous session, then
+ * go ahead and try to reconnect to the device
+ */
+ if (address != null && telemetry_state.connect == TelemetryState.CONNECT_DISCONNECTED) {
+ if (D) Log.d(TAG, "Reconnecting now...");
+ start_altos_bluetooth(address, false);