You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2017/11/21 13:36:04 UTC

[GitHub] andrzej-kaczmarek closed pull request #668: nimble: Fix LLS and TPS

andrzej-kaczmarek closed pull request #668: nimble: Fix LLS and TPS
URL: https://github.com/apache/mynewt-core/pull/668
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/net/nimble/host/services/lls/include/services/lls/ble_svc_lls.h b/net/nimble/host/services/lls/include/services/lls/ble_svc_lls.h
index 049ab6fd6..7d1870e8a 100644
--- a/net/nimble/host/services/lls/include/services/lls/ble_svc_lls.h
+++ b/net/nimble/host/services/lls/include/services/lls/ble_svc_lls.h
@@ -40,9 +40,8 @@ uint8_t ble_svc_lls_alert_level_get(void);
 int ble_svc_lls_alert_level_set(uint8_t alert_level);
 void ble_svc_lls_on_gap_disconnect(int reason); 
 
-int ble_svc_lls_init(struct ble_hs_cfg *cfg, 
-                     uint8_t initial_alert_level,
-                     ble_svc_lls_event_fn *cb);
+void ble_svc_lls_set_cb(ble_svc_lls_event_fn *cb);
+void ble_svc_lls_init(void);
 
 #ifdef __cplusplus
 }
diff --git a/net/nimble/host/services/lls/pkg.yml b/net/nimble/host/services/lls/pkg.yml
index ae786dbca..0a228847c 100644
--- a/net/nimble/host/services/lls/pkg.yml
+++ b/net/nimble/host/services/lls/pkg.yml
@@ -25,7 +25,10 @@ pkg.keywords:
     - ble 
     - bluetooth
     - lls
-    - nimble 
+    - nimble
 
 pkg.deps:
     - net/nimble/host
+
+pkg.init:
+    ble_svc_lls_init: 300
diff --git a/net/nimble/host/services/lls/src/ble_svc_lls.c b/net/nimble/host/services/lls/src/ble_svc_lls.c
index 434814f34..a79fde63b 100644
--- a/net/nimble/host/services/lls/src/ble_svc_lls.c
+++ b/net/nimble/host/services/lls/src/ble_svc_lls.c
@@ -19,11 +19,13 @@
 
 #include <assert.h>
 #include <string.h>
+#include "sysinit/sysinit.h"
 #include "host/ble_hs.h"
 #include "services/lls/ble_svc_lls.h"
 
 /* Callback function */
-static ble_svc_lls_event_fn *cb_fn; 
+static ble_svc_lls_event_fn *ble_svc_lls_cb_fn;
+
 /* Alert level */
 static uint8_t ble_svc_lls_alert_level;
 
@@ -42,10 +44,10 @@ static const struct ble_gatt_svc_def ble_svc_lls_defs[] = {
     {
         /*** Service: Link Loss Service (LLS). */
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
-        .uuid = BLE_UUID16(BLE_SVC_LLS_UUID16),
+        .uuid = BLE_UUID16_DECLARE(BLE_SVC_LLS_UUID16),
         .characteristics = (struct ble_gatt_chr_def[]) { {
             /*** Characteristic: Alert Level. */
-            .uuid = BLE_UUID16(BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL),
+            .uuid = BLE_UUID16_DECLARE(BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL),
             .access_cb = ble_svc_lls_access,
             .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
         }, {
@@ -132,7 +134,7 @@ void
 ble_svc_lls_on_gap_disconnect(int reason)
 {
     if (reason == BLE_HS_HCI_ERR(BLE_ERR_CONN_SPVN_TMO)) {
-            cb_fn(ble_svc_lls_alert_level);
+            ble_svc_lls_cb_fn(ble_svc_lls_alert_level);
     } 
 }
 
@@ -165,37 +167,26 @@ ble_svc_lls_alert_level_set(uint8_t alert_level)
     return 0;
 }
 
+void
+ble_svc_lls_set_cb(ble_svc_lls_event_fn *cb)
+{
+    ble_svc_lls_cb_fn = cb;
+}
+
 /**
- * Initialize the LLS. The developer must specify the event function
- * callback for the LLS to function properly.
- *
- * @param initial_alert_level       The initial alert value to set
- * @param cb                        The callback function to call when 
- *                                      connection has been lost due to 
- *                                      link loss
+ * Initialize the IAS package.
  */
-int
-ble_svc_lls_init(struct ble_hs_cfg *cfg, uint8_t initial_alert_level,
-                 ble_svc_lls_event_fn *cb)
+void
+ble_svc_lls_init(void)
 {
     int rc;
-
-    if (!cb) {
-        return BLE_HS_EINVAL;
-    }
     
-    ble_svc_lls_alert_level = initial_alert_level;
-    cb_fn = cb;
+    /* Ensure this function only gets called by sysinit. */
+    SYSINIT_ASSERT_ACTIVE();
 
-    rc = ble_gatts_count_cfg(ble_svc_lls_defs, cfg);
-    if (rc != 0) {
-        return rc;
-    }
+    rc = ble_gatts_count_cfg(ble_svc_lls_defs);
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_gatts_add_svcs(ble_svc_lls_defs);
-    if (rc != 0) {
-        return rc;
-    }
-    
-    return 0;
+    SYSINIT_PANIC_ASSERT(rc == 0);
 }
diff --git a/net/nimble/host/services/tps/src/ble_svc_tps.c b/net/nimble/host/services/tps/src/ble_svc_tps.c
index fe71b7921..86eb139ed 100644
--- a/net/nimble/host/services/tps/src/ble_svc_tps.c
+++ b/net/nimble/host/services/tps/src/ble_svc_tps.c
@@ -41,10 +41,10 @@ static const struct ble_gatt_svc_def ble_svc_tps_defs[] = {
     {
         /*** Service: Tx Power Service. */
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
-        .uuid = BLE_UUID16(BLE_SVC_TPS_UUID16),
+        .uuid = BLE_UUID16_DECLARE(BLE_SVC_TPS_UUID16),
         .characteristics = (struct ble_gatt_chr_def[]) { {
             /*** Characteristic: Tx Power Level. */
-            .uuid = BLE_UUID16(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL),
+            .uuid = BLE_UUID16_DECLARE(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL),
             .access_cb = ble_svc_tps_access,
             .flags = BLE_GATT_CHR_F_READ,
         }, {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services