You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/07/17 18:36:13 UTC

[5/9] incubator-mynewt-core git commit: ble apps - Account for GAP conn-desc change.

ble apps - Account for GAP conn-desc change.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/6e78b30e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6e78b30e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6e78b30e

Branch: refs/heads/develop
Commit: 6e78b30ea762a354de4376b00dbcbb1769847e68
Parents: 3f735f6
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jul 15 17:26:28 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Sat Jul 16 10:36:08 2016 -0700

----------------------------------------------------------------------
 apps/blecent/src/main.c | 32 ++++++++++++++++++--------------
 apps/blecent/src/misc.c |  2 +-
 apps/bleprph/src/main.c | 17 ++++++++++++++---
 apps/bletiny/src/main.c | 16 ++++++++++++----
 4 files changed, 45 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e78b30e/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index a86f11a..f41a313 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -372,6 +372,7 @@ blecent_connect_if_interesting(const struct ble_gap_disc_desc *disc)
 static int
 blecent_gap_event(struct ble_gap_event *event, void *arg)
 {
+    struct ble_gap_conn_desc desc;
     int rc;
 
     switch (event->type) {
@@ -385,32 +386,34 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
 
     case BLE_GAP_EVENT_CONNECT:
         /* A new connection was established or a connection attempt failed. */
-        BLECENT_LOG(INFO, "connection %s; status=%d ",
-                    event->connect.status == 0 ? "established" : "failed",
-                    event->connect.status);
-        print_conn_desc(&event->connect.conn);
-        BLECENT_LOG(INFO, "\n");
-
-        if (event->connect.status != 0) {
-            /* Connection attempt failed; resume scanning. */
-            blecent_scan();
-        } else {
+        if (event->connect.status == 0) {
             /* Connection successfully established. */
+            BLECENT_LOG(INFO, "Connection established ");
+
+            rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
+            assert(rc == 0);
+            print_conn_desc(&desc);
+            BLECENT_LOG(INFO, "\n");
 
             /* Remember peer. */
-            rc = peer_add(event->connect.conn.conn_handle);
+            rc = peer_add(event->connect.conn_handle);
             if (rc != 0) {
                 BLECENT_LOG(ERROR, "Failed to add peer; rc=%d\n", rc);
                 return 0;
             }
 
             /* Perform service discovery. */
-            rc = peer_disc_all(event->connect.conn.conn_handle,
+            rc = peer_disc_all(event->connect.conn_handle,
                                blecent_on_disc_complete, NULL);
             if (rc != 0) {
                 BLECENT_LOG(ERROR, "Failed to discover services; rc=%d\n", rc);
                 return 0;
             }
+        } else {
+            /* Connection attempt failed; resume scanning. */
+            BLECENT_LOG(ERROR, "Error: Connection failed; status=%d\n",
+                        event->connect.status);
+            blecent_scan();
         }
 
         return 0;
@@ -432,8 +435,9 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
         /* Encryption has been enabled or disabled for this connection. */
         BLECENT_LOG(INFO, "encryption change event; status=%d ",
                     event->enc_change.status);
-        print_conn_desc(&event->enc_change.conn);
-        BLECENT_LOG(INFO, "\n");
+        rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc);
+        assert(rc == 0);
+        print_conn_desc(&desc);
         return 0;
 
     default:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e78b30e/apps/blecent/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/misc.c b/apps/blecent/src/misc.c
index 8371b14..ea3f055 100644
--- a/apps/blecent/src/misc.c
+++ b/apps/blecent/src/misc.c
@@ -88,7 +88,7 @@ print_conn_desc(const struct ble_gap_conn_desc *desc)
     BLECENT_LOG(DEBUG, "peer_id_addr_type=%d peer_id_addr=%s ",
                 desc->peer_id_addr_type, addr_str(desc->peer_id_addr));
     BLECENT_LOG(DEBUG, "conn_itvl=%d conn_latency=%d supervision_timeout=%d "
-                "encrypted=%d authenticated=%d bonded=%d\n",
+                "encrypted=%d authenticated=%d bonded=%d",
                 desc->conn_itvl, desc->conn_latency,
                 desc->supervision_timeout,
                 desc->sec_state.encrypted,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e78b30e/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 22ad0e3..097df82 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -192,13 +192,20 @@ bleprph_advertise(void)
 static int
 bleprph_gap_event(struct ble_gap_event *event, void *arg)
 {
+    struct ble_gap_conn_desc desc;
+    int rc;
+
     switch (event->type) {
     case BLE_GAP_EVENT_CONNECT:
         /* A new connection was established or a connection attempt failed. */
         BLEPRPH_LOG(INFO, "connection %s; status=%d ",
                        event->connect.status == 0 ? "established" : "failed",
                        event->connect.status);
-        bleprph_print_conn_desc(&event->connect.conn);
+        if (event->connect.status == 0) {
+            rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
+            assert(rc == 0);
+            bleprph_print_conn_desc(&desc);
+        }
         BLEPRPH_LOG(INFO, "\n");
 
         if (event->connect.status != 0) {
@@ -220,7 +227,9 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
         /* The central has updated the connection parameters. */
         BLEPRPH_LOG(INFO, "connection updated; status=%d ",
                     event->conn_update.status);
-        bleprph_print_conn_desc(&event->conn_update.conn);
+        rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
+        assert(rc == 0);
+        bleprph_print_conn_desc(&desc);
         BLEPRPH_LOG(INFO, "\n");
         return 0;
 
@@ -228,7 +237,9 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
         /* Encryption has been enabled or disabled for this connection. */
         BLEPRPH_LOG(INFO, "encryption change event; status=%d ",
                     event->enc_change.status);
-        bleprph_print_conn_desc(&event->enc_change.conn);
+        rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
+        assert(rc == 0);
+        bleprph_print_conn_desc(&desc);
         BLEPRPH_LOG(INFO, "\n");
         return 0;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e78b30e/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index c7bd762..2350570 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -915,17 +915,21 @@ bletiny_on_write_reliable(uint16_t conn_handle,
 static int
 bletiny_gap_event(struct ble_gap_event *event, void *arg)
 {
+    struct ble_gap_conn_desc desc;
     int conn_idx;
+    int rc;
 
     switch (event->type) {
     case BLE_GAP_EVENT_CONNECT:
         console_printf("connection %s; status=%d ",
                        event->connect.status == 0 ? "established" : "failed",
                        event->connect.status);
-        print_conn_desc(&event->connect.conn);
 
         if (event->connect.status == 0) {
-            bletiny_conn_add(&event->connect.conn);
+            rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
+            assert(rc == 0);
+            print_conn_desc(&desc);
+            bletiny_conn_add(&desc);
         }
         return 0;
 
@@ -967,7 +971,9 @@ bletiny_gap_event(struct ble_gap_event *event, void *arg)
     case BLE_GAP_EVENT_CONN_UPDATE:
         console_printf("connection updated; status=%d ",
                        event->conn_update.status);
-        print_conn_desc(&event->conn_update.conn);
+        rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc);
+        assert(rc == 0);
+        print_conn_desc(&desc);
         return 0;
 
     case BLE_GAP_EVENT_CONN_UPDATE_REQ:
@@ -989,7 +995,9 @@ bletiny_gap_event(struct ble_gap_event *event, void *arg)
     case BLE_GAP_EVENT_ENC_CHANGE:
         console_printf("encryption change event; status=%d ",
                        event->enc_change.status);
-        print_conn_desc(&event->enc_change.conn);
+        rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc);
+        assert(rc == 0);
+        print_conn_desc(&desc);
         return 0;
 
     case BLE_GAP_EVENT_NOTIFY_RX: