Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BLE_PowerBank_HeyFaradey
Fork of BLE_API by
Diff: public/Gap.h
- Revision:
- 527:493185cebc03
- Parent:
- 526:caa67c3187a0
- Child:
- 531:bdcd44b03974
diff -r caa67c3187a0 -r 493185cebc03 public/Gap.h
--- a/public/Gap.h Fri Jun 19 15:52:06 2015 +0100
+++ b/public/Gap.h Fri Jun 19 15:52:07 2015 +0100
@@ -17,15 +17,16 @@
#ifndef __GAP_H__
#define __GAP_H__
-#include "GapAdvertisingData.h"
-#include "GapAdvertisingParams.h"
#include "GapEvents.h"
#include "CallChain.h"
#include "FunctionPointerWithContext.h"
using namespace mbed;
-class GapScanningParams; /* forward declaration */
+/* Forward declarations for classes which will only be used for pointers or references in the following. */
+class GapAdvertisingParams;
+class GapScanningParams;
+class GapAdvertisingData;
class Gap {
public:
@@ -79,6 +80,49 @@
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. */
@@ -144,10 +188,7 @@
}
typedef void (*EventCallback_t)(void);
- 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 (*ConnectionEventCallback_t)(const ConnectionCallbackParams_t *params);
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. */
@@ -156,20 +197,10 @@
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;
-
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;
@@ -177,6 +208,10 @@
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;
@@ -303,10 +338,17 @@
}
public:
- void processConnectionEvent(Handle_t handle, AddressType_t peerAddrType, const Address_t peerAddr, AddressType_t ownAddrType, const Address_t ownAddr, const ConnectionParams_t *params) {
+ 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) {
state.connected = 1;
if (onConnection) {
- onConnection(handle, peerAddrType, peerAddr, ownAddrType, ownAddr, params);
+ ConnectionCallbackParams_t callbackParams(handle, role, peerAddrType, peerAddr, ownAddrType, ownAddr, connectionParams);
+ onConnection(&callbackParams);
}
}
