High level Bluetooth Low Energy API and radio abstraction layer

Dependents:   BLE_ANCS_SDAPI BLE_temperature BLE_HeartRate BLE_ANCS_SDAPI_IRC ... more

Overview

The BLE_API is a high level abstraction for using Bluetooth Low Energy on multiple platforms. For details and examples using the BLE_API please see the BLE_API Summary Page. Or click on the API Documentation tab above.

Supported Services

Supported services can be found in the BLE_API/services folder.

Files at this revision

API Documentation at this revision

Comitter:
rgrover1
Date:
Thu Nov 26 12:52:04 2015 +0000
Parent:
918:2b12b53101ea
Child:
920:d18cff0c4b09
Commit message:
Synchronized with git rev dfc03ce0
Author: Vincent Coubard
Convert Gap::timeout callback to a callback chain. Add 'boolean'
conversion and function operator syntax to
CallChainOfFunctionPointerWithContext

Changed in this revision

ble/CallChainOfFunctionPointersWithContext.h Show annotated file Show diff for this revision Revisions of this file
ble/FunctionPointerWithContext.h Show annotated file Show diff for this revision Revisions of this file
ble/Gap.h Show annotated file Show diff for this revision Revisions of this file
--- a/ble/CallChainOfFunctionPointersWithContext.h	Thu Nov 26 12:52:04 2015 +0000
+++ b/ble/CallChainOfFunctionPointersWithContext.h	Thu Nov 26 12:52:04 2015 +0000
@@ -97,6 +97,14 @@
         return common_add(new FunctionPointerWithContext<ContextType>(tptr, mptr));
     }
 
+    /** Add a function at the front of the chain.
+     *
+     *  @param func The FunctionPointerWithContext to add.
+     */
+    void add(const FunctionPointerWithContext<ContextType>& func) {
+        common_add(new FunctionPointerWithContext<ContextType>(func));
+    }
+
     /** 
      * Detach a function pointer from a callchain
      * 
@@ -153,6 +161,29 @@
         }
     }
 
+    /**
+     * @brief same as above but const 
+     */
+    void call(ContextType context) const {
+        if (chainHead) {
+            chainHead->call(context);
+        }
+    }
+
+    /**
+     * @brief same as above but with function call operator
+     */
+    void operator()(ContextType context) const {
+        call(context);
+    }
+
+    typedef void (CallChainOfFunctionPointersWithContext::*bool_type)() const;
+    void True() const {}
+
+    operator bool_type() const {
+        return chainHead == NULL ? 0 : &CallChainOfFunctionPointersWithContext::True;
+    }
+
 private:
     pFunctionPointerWithContext_t common_add(pFunctionPointerWithContext_t pf) {
         if (chainHead == NULL) {
--- a/ble/FunctionPointerWithContext.h	Thu Nov 26 12:52:04 2015 +0000
+++ b/ble/FunctionPointerWithContext.h	Thu Nov 26 12:52:04 2015 +0000
@@ -94,6 +94,13 @@
         }
     }
 
+    /**
+     * @brief Same as above
+     */
+    void operator()(ContextType context) const {
+        call(context);
+    }
+
     /** Same as above, workaround for mbed os FunctionPointer implementation. */
     void call(ContextType context) {
         _caller(this, context);
--- a/ble/Gap.h	Thu Nov 26 12:52:04 2015 +0000
+++ b/ble/Gap.h	Thu Nov 26 12:52:04 2015 +0000
@@ -140,8 +140,9 @@
         return (durationInMillis * 1000) / UNIT_1_25_MS;
     }
 
+    typedef FunctionPointerWithContext<TimeoutSource_t> TimeoutEventCallback_t;
+    typedef CallChainOfFunctionPointersWithContext<TimeoutSource_t> TimeoutEventCallbackChain_t;
 
-    typedef void (*TimeoutEventCallback_t)(TimeoutSource_t source);
     typedef void (*ConnectionEventCallback_t)(const ConnectionCallbackParams_t *params);
     typedef void (*DisconnectionEventCallback_t)(const DisconnectionCallbackParams_t *params);
     typedef FunctionPointerWithContext<bool> RadioNotificationEventCallback_t;
@@ -893,7 +894,13 @@
      * Set up a callback for timeout events. Refer to TimeoutSource_t for
      * possible event types.
      */
-    void onTimeout(TimeoutEventCallback_t callback) {timeoutCallback = callback;}
+    void onTimeout(TimeoutEventCallback_t callback) {
+        timeoutCallbackChain.add(callback);
+    }
+
+    TimeoutEventCallbackChain_t& onTimeout() {
+        return timeoutCallbackChain;
+    }
 
     /**
      * Append to a chain of callbacks to be invoked upon GAP connection.
@@ -956,7 +963,7 @@
         _scanResponse(),
         state(),
         scanningActive(false),
-        timeoutCallback(NULL),
+        timeoutCallbackChain(),
         radioNotificationCallback(),
         onAdvertisementReport(),
         connectionCallChain(),
@@ -1002,8 +1009,8 @@
     }
 
     void processTimeoutEvent(TimeoutSource_t source) {
-        if (timeoutCallback) {
-            timeoutCallback(source);
+        if (timeoutCallbackChain) {
+            timeoutCallbackChain(source);
         }
     }
 
@@ -1017,7 +1024,7 @@
     bool                             scanningActive;
 
 protected:
-    TimeoutEventCallback_t           timeoutCallback;
+    TimeoutEventCallbackChain_t           timeoutCallbackChain;
     RadioNotificationEventCallback_t radioNotificationCallback;
     AdvertisementReportCallback_t    onAdvertisementReport;
     CallChainOfFunctionPointersWithContext<const ConnectionCallbackParams_t*>    connectionCallChain;