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:51:59 2015 +0000
Parent:
883:a097e1be76f4
Child:
885:1164aa1735ca
Commit message:
Synchronized with git rev 9c001d27
Author: Rohit Grover
Merge branch 'develop'

Changed in this revision

ble/BLE.h Show annotated file Show diff for this revision Revisions of this file
ble/BLEInstanceBase.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/services/EddystoneConfigService.h Show annotated file Show diff for this revision Revisions of this file
ble/services/EddystoneService.h Show annotated file Show diff for this revision Revisions of this file
module.json Show annotated file Show diff for this revision Revisions of this file
source/BLE.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ble/BLE.h	Tue Nov 03 13:21:03 2015 +0000
+++ b/ble/BLE.h	Thu Nov 26 12:51:59 2015 +0000
@@ -22,8 +22,6 @@
 #include "GattServer.h"
 #include "GattClient.h"
 
-#include "ble/FunctionPointerWithContext.h"
-
 #ifdef YOTTA_CFG_MBED_OS
 #include "mbed-drivers/mbed_error.h"
 #else
@@ -43,28 +41,16 @@
     typedef unsigned InstanceID_t; /** The type returned by BLE::getInstanceID(). */
 
     /**
-     * The context provided to init-completion-callbacks (see init() below).
-     *
+     * The function signature for callbacks for initialization completion.
      * @param  ble
      *             A reference to the BLE instance being initialized.
      * @param  error
      *             This captures the result of initialization. It is set to
      *             BLE_ERROR_NONE if initialization completed successfully. Else
      *             the error value is implementation specific.
+     *
      */
-    struct InitializationCompleteCallbackContext {
-        BLE&        ble;   /* Reference to the BLE object which has been initialized */
-        ble_error_t error; /* Error status of the initialization. It is set to BLE_ERROR_NONE initialization completed successfully. */
-    };
-
-    /**
-     * The signature for function-pointer like callbacks for initialization-completion.
-     *
-     * @note There are two versions of init(). In addition to the simple
-     *     function-pointer, init() can also take a <Object, member> tuple as its
-     *     callback target. In case of the latter, the following declaration doesn't apply.
-     */
-    typedef void (*InitializationCompleteCallback_t)(InitializationCompleteCallbackContext *context);
+    typedef void (*InitializationCompleteCallback_t)(BLE &ble, ble_error_t error);
 
     /**
      * Initialize the BLE controller. This should be called before using
@@ -77,7 +63,7 @@
      * context where ordering is compiler specific and can't be guaranteed--it
      * is safe to call BLE::init() from within main().
      *
-     * @param  initCompleteCallback
+     * @param  callback
      *           A callback for when initialization completes for a BLE
      *           instance. This is an optional parameter, if no callback is
      *           setup the application can still determine the status of
@@ -86,36 +72,17 @@
      * @return  BLE_ERROR_NONE if the initialization procedure was started
      *     successfully.
      *
-     * @note If init() returns BLE_ERROR_NONE, the underlying stack must invoke
-     *     the initialization completion callback at some point.
-     *
-     * @note In some cases, initialization is instantaneous (or blocking); if
-     *     so, it is acceptable for the stack-specific implementation of init()
-     *     to invoke the completion callback directly--i.e. within its own
-     *     context.
+     * @note The underlying stack must invoke the initialization completion
+     *     callback in response to init(). In some cases, initialization is
+     *     instantaneous (or blocking); if so, it is acceptable for the stack-
+     *     specific implementation of init() to invoke the completion callback
+     *     directly--i.e. within its own context.
      *
      * @note Nearly all BLE APIs would return
      *     BLE_ERROR_INITIALIZATION_INCOMPLETE if used on an instance before the
      *     corresponding transport is initialized.
-     *
-     * @note There are two versions of init(). In addition to the simple
-     *     function-pointer, init() can also take an <Object, member> tuple as its
-     *     callback target.
      */
-    ble_error_t init(InitializationCompleteCallback_t initCompleteCallback = NULL) {
-        FunctionPointerWithContext<InitializationCompleteCallbackContext *> callback(initCompleteCallback);
-        return initImplementation(callback);
-    }
-
-    /**
-     * An alternate declaration for init(). This one takes an <Object, member> tuple as its
-     * callback target.
-     */
-    template<typename T>
-    ble_error_t init(T *object, void (T::*initCompleteCallback)(InitializationCompleteCallbackContext *context)) {
-        FunctionPointerWithContext<InitializationCompleteCallbackContext *> callback(object, initCompleteCallback);
-        return initImplementation(callback);
-    }
+    ble_error_t init(InitializationCompleteCallback_t callback = NULL);
 
     /**
      * @return true if initialization has completed for the underlying BLE
@@ -1421,15 +1388,6 @@
     }
 
 private:
-    /**
-     * Implementation of init() [internal to BLE_API].
-     *
-     * The implementation is separated into a private method because it isn't
-     * suitable to be included in the header.
-     */
-    ble_error_t initImplementation(FunctionPointerWithContext<InitializationCompleteCallbackContext *> callback);
-
-private:
     BLE(const BLE&);
     BLE &operator=(const BLE &);
 
--- a/ble/BLEInstanceBase.h	Tue Nov 03 13:21:03 2015 +0000
+++ b/ble/BLEInstanceBase.h	Thu Nov 26 12:51:59 2015 +0000
@@ -32,8 +32,7 @@
 class BLEInstanceBase
 {
 public:
-    virtual ble_error_t            init(BLE::InstanceID_t instanceID,
-                                        FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> initCallback) = 0;
+    virtual ble_error_t            init(BLE::InstanceID_t instanceID, BLE::InitializationCompleteCallback_t) = 0;
     virtual bool                   hasInitialized(void) const = 0;
     virtual ble_error_t            shutdown(void)             = 0;
     virtual const char *           getVersion(void)           = 0;
--- a/ble/FunctionPointerWithContext.h	Tue Nov 03 13:21:03 2015 +0000
+++ b/ble/FunctionPointerWithContext.h	Thu Nov 26 12:51:59 2015 +0000
@@ -19,6 +19,8 @@
 
 #include <string.h>
 
+
+
 /** A class for storing and calling a pointer to a static or member void function
  *  which takes a context.
  */
@@ -105,10 +107,10 @@
     template<typename T>
     static void membercaller(pFunctionPointerWithContext_t self, ContextType context) {
         if (self->_memberFunctionAndPointer._object) {
-            T *o = static_cast<T *>(self->_memberFunctionAndPointer._object);
+            T *o = static_cast<T *>(self->_memberFunctionAndPointer._object);        
             void (T::*m)(ContextType);
             memcpy((char*) &m, self->_memberFunctionAndPointer._memberFunction, sizeof(m));
-            (o->*m)(context);
+            (o->*m)(context);            
         }
     }
 
@@ -120,9 +122,9 @@
 
     struct MemberFunctionAndPtr {
         /*
-         * forward declaration of a class and a member function to this class.
-         * Because the compiler doesn't know anything about the forwarded member
-         * function, it will always use the biggest size and the biggest alignment
+         * forward declaration of a class and a member function to this class. 
+         * Because the compiler doesn't know anything about the forwarded member 
+         * function, it will always use the biggest size and the biggest alignment 
          * that a member function can take for objects of type UndefinedMemberFunction.
          */
         class UndefinedClass;
@@ -131,17 +133,17 @@
         void* _object;
         union {
             char _memberFunction[sizeof(UndefinedMemberFunction)];
-            UndefinedMemberFunction _alignment;
+            UndefinedMemberFunction _alignment;            
         };
     };
 
     union {
         pvoidfcontext_t _function;                      /**< static function pointer - NULL if none attached */
-        /**
-         * object this pointer and pointer to member -
-         * _memberFunctionAndPointer._object will be NULL if none attached
-         */
-        MemberFunctionAndPtr _memberFunctionAndPointer;
+        /** 
+         * object this pointer and pointer to member - 
+         * _memberFunctionAndPointer._object will be NULL if none attached 
+         */        
+        MemberFunctionAndPtr _memberFunctionAndPointer;      
     };
 
     void (*_caller)(FunctionPointerWithContext*, ContextType);
--- a/ble/services/EddystoneConfigService.h	Tue Nov 03 13:21:03 2015 +0000
+++ b/ble/services/EddystoneConfigService.h	Thu Nov 26 12:51:59 2015 +0000
@@ -215,7 +215,7 @@
         DBG("Setting Default TLM Data, version = %d, advPeriodInMind= %f", tlmVersionIn, advPeriodInSec);
         defaultTlmVersion   = tlmVersionIn;
         TlmBatteryVoltage   = 0;
-        TlmBeaconTemp       = 0x8000;
+        TlmBeaconTemp       = 0;
         TlmPduCount         = 0;
         TlmTimeSinceBoot    = 0;
         defaultTlmAdvPeriod = advPeriodInSec;
@@ -389,7 +389,7 @@
         params.flags = 0x10;
         memcpy(params.advPowerLevels, defaultAdvPowerLevels, sizeof(PowerLevels_t));
         params.txPowerMode  = TX_POWER_MODE_LOW;
-        params.beaconPeriod = (uint16_t) defaultUriAdvPeriod * 1000;
+        params.beaconPeriod = 1000;
 
         // TLM Frame
         params.tlmVersion      = defaultTlmVersion;
--- a/ble/services/EddystoneService.h	Tue Nov 03 13:21:03 2015 +0000
+++ b/ble/services/EddystoneService.h	Thu Nov 26 12:51:59 2015 +0000
@@ -101,9 +101,9 @@
     void setUIDFrameData(int8_t           power,
                          UIDNamespaceID_t namespaceID,
                          UIDInstanceID_t  instanceID,
-                         float            uidAdvPeriodIn,
+                         uint32_t         uidAdvPeriodIn,
                          uint16_t         RFU = 0x0000) {
-        if (0.0f == uidAdvPeriodIn) {
+        if (0 == uidAdvPeriodIn) {
             uidIsSet = false;
             return;
         }
@@ -170,8 +170,8 @@
      *  @param[in] urlAdvPeriodIn How long to advertise the URL frame (measured in # of adv periods)
      *  @return false on success, true on failure.
      */
-    bool setURLFrameData(int8_t power, const char *urlIn, float urlAdvPeriodIn) {
-        if (0.0f == urlAdvPeriodIn) {
+    bool setURLFrameData(int8_t power, const char *urlIn, uint32_t urlAdvPeriodIn) {
+        if (0 == urlAdvPeriodIn) {
             urlIsSet = false;
             return false;
         }
@@ -193,8 +193,8 @@
      *  @param[in] urlAdvPeriodIn     How long to advertise the URL frame (measured in # of adv periods)
      *  @return false on success, true on failure.
      */
-    bool setURLFrameEncodedData(int8_t power, const char *encodedUrlIn, uint8_t encodedUrlInLength, float urlAdvPeriodIn) {
-        if (0.0f == urlAdvPeriodIn) {
+    bool setURLFrameEncodedData(int8_t power, const char *encodedUrlIn, uint8_t encodedUrlInLength, uint32_t urlAdvPeriodIn) {
+        if (0 == urlAdvPeriodIn) {
             urlIsSet = false;
             return false;
         }
@@ -235,12 +235,12 @@
     *
     */
     void setTLMFrameData(uint8_t  version        = 0,
-                         float    advPeriod      = 60.0f,
+                         uint32_t advPeriod      = 60,
                          uint16_t batteryVoltage = 0,
-                         uint16_t beaconTemp     = 0x8000,
+                         uint16_t beaconTemp     = 0,
                          uint32_t pduCount       = 0,
                          uint32_t timeSinceBoot  = 0) {
-        if (0.0f == advPeriod) {
+        if (0 == advPeriod) {
             tlmIsSet = false;
             return;
         }
@@ -507,7 +507,7 @@
         // Initialize Frame transition, start with URL to pass eddystone validator app on first try
         if (urlIsSet) {
             frameIndex = url;
-            urlTicker.attach(this, &EddystoneService::urlCallback, (float) advPeriodus / 1000.0f);
+            urlTicker.attach(this, &EddystoneService::urlCallback, urlAdvPeriod);
             DBG("attached urlCallback every %d seconds", urlAdvPeriod);
         }
         if (uidIsSet) {
@@ -552,7 +552,7 @@
     UriData_t           defaultUriData;
     int8_t              defaultUrlPower;
     bool                urlIsSet;       // flag that enables / disable URI Frames
-    float               urlAdvPeriod;   // how long the url frame will be advertised for
+    uint32_t            urlAdvPeriod;   // how long the url frame will be advertised for
     Ticker              urlTicker;
 
     // UID Frame Variables
@@ -561,7 +561,7 @@
     int8_t              defaultUidPower;
     uint16_t            uidRFU;
     bool                uidIsSet;       // flag that enables / disable UID Frames
-    float               uidAdvPeriod;   // how long the uid frame will be advertised for
+    uint32_t            uidAdvPeriod;   // how long the uid frame will be advertised for
     Ticker              uidTicker;
 
     // TLM Frame Variables
@@ -571,7 +571,7 @@
     volatile uint32_t   TlmPduCount;
     volatile uint32_t   TlmTimeSinceBoot;
     bool                tlmIsSet;          // flag that enables / disables TLM frames
-    float               TlmAdvPeriod;      // number of minutes between adv frames
+    uint32_t            TlmAdvPeriod;      // number of minutes between adv frames
     Ticker              tlmTicker;
 
 public:
--- a/module.json	Tue Nov 03 13:21:03 2015 +0000
+++ b/module.json	Thu Nov 26 12:51:59 2015 +0000
@@ -1,6 +1,6 @@
 {
   "name": "ble",
-  "version": "2.0.3",
+  "version": "2.0.0",
   "description": "The BLE module offers a high level abstraction for using Bluetooth Low Energy on multiple platforms.",
   "keywords": [
     "Bluetooth",
--- a/source/BLE.cpp	Tue Nov 03 13:21:03 2015 +0000
+++ b/source/BLE.cpp	Thu Nov 26 12:51:59 2015 +0000
@@ -22,7 +22,7 @@
 #endif
 
 ble_error_t
-BLE::initImplementation(FunctionPointerWithContext<InitializationCompleteCallbackContext *> callback)
+BLE::init(BLE::InitializationCompleteCallback_t callback)
 {
     ble_error_t err = transport->init(instanceID, callback);
     if (err != BLE_ERROR_NONE) {