altosdroid: Add Connected/Connect_failed messages
authorMike Beattie <mike@ethernal.org>
Mon, 27 Aug 2012 07:41:29 +0000 (19:41 +1200)
committerMike Beattie <mike@ethernal.org>
Mon, 27 Aug 2012 07:41:29 +0000 (19:41 +1200)
Signed-off-by: Mike Beattie <mike@ethernal.org>
altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java

index bb188d80ca2a1d95186e9150a3ba3cabdbdf163f..19b2a2a54638db55acc43bf642b0ba86d49ff5f1 100644 (file)
@@ -103,6 +103,7 @@ public class AltosBluetooth extends AltosLink {
                                        input = null;
                                        output = null;
                                        AltosBluetooth.this.notifyAll();
+                                       handler.obtainMessage(TelemetryService.MSG_CONNECT_FAILED).sendToTarget();
                                        if (D) Log.e(TAG, "ConnectThread: Failed to establish connection");
                                        return;
                                }
@@ -147,6 +148,7 @@ public class AltosBluetooth extends AltosLink {
 
        private void connection_failed() {
                if (D) Log.e(TAG, "Bluetooth Socket IO failed!");
+               handler.obtainMessage(TelemetryService.MSG_DISCONNECTED).sendToTarget();
        }
 
        public void print(String data) {
index e9254badc235994e81b905158a8a4b6a0a3d3b2a..ecafc74a0fd6b13c0898dac920e790047f0dd8c9 100644 (file)
@@ -47,6 +47,8 @@ public class TelemetryService extends Service {
        static final int MSG_UNREGISTER_CLIENT = 2;
        static final int MSG_CONNECT           = 3;
        static final int MSG_CONNECTED         = 4;
+       static final int MSG_CONNECT_FAILED    = 5;
+       static final int MSG_DISCONNECTED      = 6;
 
        public static final int STATE_NONE       = 0;
        public static final int STATE_READY      = 1;
@@ -101,6 +103,14 @@ public class TelemetryService extends Service {
                                s.setState(STATE_CONNECTED);
                                s.mAltosBluetooth.add_monitor(s.telem);
                                break;
+                       case MSG_CONNECT_FAILED:
+                               if (D) Log.d(TAG, "Connection failed... retrying");
+                               s.startAltosBluetooth();
+                               break;
+                       case MSG_DISCONNECTED:
+                               if (D) Log.d(TAG, "Disconnected from " + s.device.getName());
+                               s.stopAltosBluetooth();
+                               break;
                        default:
                                super.handleMessage(msg);
                        }