High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
Diff: public/Gap.h
- Revision:
- 514:1fa338281798
- Parent:
- 453:c8f73026ee16
- Child:
- 516:85b9261fbda7
--- a/public/Gap.h Fri Jun 19 15:52:05 2015 +0100 +++ b/public/Gap.h Fri Jun 19 15:52:05 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,22 @@ typedef void (*LinkSecuredCallback_t)(Handle_t handle, SecurityMode_t securityMode); typedef void (*PasskeyDisplayCallback_t)(Handle_t handle, const Passkey_t passkey); + 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; + friend class BLEDevice; private: /* 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 +176,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; @@ -334,17 +299,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); } }