High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Revision:
659:5fc41956cbd0
Parent:
598:5e2bbddc8701
Child:
661:f1c5136ca57c
--- a/public/Gap.h	Fri Jun 19 15:52:59 2015 +0100
+++ b/public/Gap.h	Fri Jun 19 15:53:00 2015 +0100
@@ -17,16 +17,15 @@
 #ifndef __GAP_H__
 #define __GAP_H__
 
+#include "GapAdvertisingData.h"
+#include "GapAdvertisingParams.h"
 #include "GapEvents.h"
 #include "CallChain.h"
 #include "FunctionPointerWithContext.h"
 
 using namespace mbed;
 
-/* Forward declarations for classes which will only be used for pointers or references in the following. */
-class GapAdvertisingParams;
-class GapScanningParams;
-class GapAdvertisingData;
+class GapScanningParams; /* forward declaration */
 
 class Gap {
 public:
@@ -77,49 +76,6 @@
         uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/
     } ConnectionParams_t;
 
-    enum Role_t {
-        PERIPHERAL  = 0x1, /**< Peripheral Role. */
-        CENTRAL     = 0x2, /**< Central Role.    */
-    };
-
-    struct AdvertisementCallbackParams_t {
-        Address_t            peerAddr;
-        int8_t               rssi;
-        bool                 isScanResponse;
-        AdvertisementType_t  type;
-        uint8_t              advertisingDataLen;
-        const uint8_t       *advertisingData;
-    };
-    typedef FunctionPointerWithContext<const AdvertisementCallbackParams_t *> AdvertisementReportCallback_t;
-
-    struct ConnectionCallbackParams_t {
-        Handle_t      handle;
-        Role_t        role;
-        AddressType_t peerAddrType;
-        Address_t     peerAddr;
-        AddressType_t ownAddrType;
-        Address_t     ownAddr;
-        const ConnectionParams_t *connectionParams;
-
-        ConnectionCallbackParams_t(Handle_t       handleIn,
-                                   Role_t         roleIn,
-                                   AddressType_t  peerAddrTypeIn,
-                                   const uint8_t *peerAddrIn,
-                                   AddressType_t  ownAddrTypeIn,
-                                   const uint8_t *ownAddrIn,
-                                   const ConnectionParams_t *connectionParamsIn) :
-            handle(handleIn),
-            role(roleIn),
-            peerAddrType(peerAddrTypeIn),
-            peerAddr(),
-            ownAddrType(ownAddrTypeIn),
-            ownAddr(),
-            connectionParams(connectionParamsIn) {
-            memcpy(peerAddr, peerAddrIn, ADDR_LEN);
-            memcpy(ownAddr, ownAddrIn, ADDR_LEN);
-        }
-    };
-
     enum SecurityMode_t {
         SECURITY_MODE_NO_ACCESS,
         SECURITY_MODE_ENCRYPTION_OPEN_LINK, /**< require no protection, open link. */
@@ -185,7 +141,10 @@
     }
 
     typedef void (*EventCallback_t)(void);
-    typedef void (*ConnectionEventCallback_t)(const ConnectionCallbackParams_t *params);
+    typedef void (*ConnectionEventCallback_t)(Handle_t,
+                                              AddressType_t peerAddrType, const Address_t peerAddr,
+                                              AddressType_t ownAddrType,  const Address_t ownAddr,
+                                              const ConnectionParams_t *);
     typedef void (*HandleSpecificEvent_t)(Handle_t handle);
     typedef void (*DisconnectionEventCallback_t)(Handle_t, DisconnectionReason_t);
     typedef void (*RadioNotificationEventCallback_t) (bool radio_active); /* gets passed true for ACTIVE; false for INACTIVE. */
@@ -194,12 +153,20 @@
     typedef void (*LinkSecuredCallback_t)(Handle_t handle, SecurityMode_t securityMode);
     typedef void (*PasskeyDisplayCallback_t)(Handle_t handle, const Passkey_t passkey);
 
-    friend class BLEDevice;
+    struct AdvertisementCallbackParams_t {
+        Address_t            peerAddr;
+        int8_t               rssi;
+        bool                 isScanResponse;
+        AdvertisementType_t  type;
+        uint8_t              advertisingDataLen;
+        const uint8_t       *advertisingData;
+    };
+    typedef FunctionPointerWithContext<const AdvertisementCallbackParams_t *> AdvertisementReportCallback_t;
 
-private:
+public:
     /* These functions must be defined in the sub-class */
-    virtual ble_error_t setAddress(AddressType_t type,  const Address_t address)                  = 0;
-    virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address)                        = 0;
+    virtual ble_error_t setAddress(AddressType_t type,   const Address_t address)                    = 0;
+    virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address)                          = 0;
     virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &) = 0;
     virtual ble_error_t startAdvertising(const GapAdvertisingParams &)                             = 0;
     virtual ble_error_t stopAdvertising(void)                                                      = 0;
@@ -207,10 +174,6 @@
     virtual uint16_t    getMinAdvertisingInterval(void) const                                      = 0;
     virtual uint16_t    getMinNonConnectableAdvertisingInterval(void) const                        = 0;
     virtual uint16_t    getMaxAdvertisingInterval(void) const                                      = 0;
-    virtual ble_error_t connect(const Address_t           peerAddr,
-                                Gap::AddressType_t        peerAddrType,
-                                const ConnectionParams_t *connectionParams,
-                                const GapScanningParams  *scanParams) = 0;
     virtual ble_error_t disconnect(DisconnectionReason_t reason)                                   = 0;
     virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params)                   = 0;
     virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params)             = 0;
@@ -247,7 +210,7 @@
         return err;
     }
 
-protected:
+public:
     virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) = 0;
 
     /* Event callback handlers */
@@ -311,7 +274,7 @@
     template<typename T>
     void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) {disconnectionCallChain.add(tptr, mptr);}
 
-private:
+public:
     GapState_t getState(void) const {
         return state;
     }
@@ -334,17 +297,10 @@
     }
 
 public:
-    void processConnectionEvent(Handle_t                  handle,
-                                Role_t                    role,
-                                AddressType_t             peerAddrType,
-                                const Address_t           peerAddr,
-                                AddressType_t             ownAddrType,
-                                const Address_t           ownAddr,
-                                const ConnectionParams_t *connectionParams) {
+    void processConnectionEvent(Handle_t handle, AddressType_t peerAddrType, const Address_t peerAddr, AddressType_t ownAddrType, const Address_t ownAddr, const ConnectionParams_t *params) {
         state.connected = 1;
         if (onConnection) {
-            ConnectionCallbackParams_t callbackParams(handle, role, peerAddrType, peerAddr, ownAddrType, ownAddr, connectionParams);
-            onConnection(&callbackParams);
+            onConnection(handle, peerAddrType, peerAddr, ownAddrType, ownAddr, params);
         }
     }