redefine AdvertisementReportCallback_t in terms of AdvertisementCallbackParams_t.
This allows us to make use of FunctionPointerWithContext.
This commit is contained in:
parent
9263436522
commit
aebfbce3f5
2 changed files with 21 additions and 12 deletions
|
@ -269,7 +269,7 @@ public:
|
|||
* every advertisement report. Can be passed in as NULL, in which case
|
||||
* scanning may not be enabled at all.
|
||||
*/
|
||||
ble_error_t startScan(Gap::AdvertisementReportCallback_t callback);
|
||||
ble_error_t startScan(void (*callback)(const Gap::AdvertisementCallbackParams_t *params));
|
||||
|
||||
/**
|
||||
* Stop scanning. The current scanning parameters remain in effect.
|
||||
|
@ -783,7 +783,7 @@ BLEDevice::setActiveScan(bool activeScanning) {
|
|||
}
|
||||
|
||||
inline ble_error_t
|
||||
BLEDevice::startScan(Gap::AdvertisementReportCallback_t callback) {
|
||||
BLEDevice::startScan(void (*callback)(const Gap::AdvertisementCallbackParams_t *params)) {
|
||||
return transport->getGap().startScan(scanningParams, callback);
|
||||
}
|
||||
|
||||
|
|
29
public/Gap.h
29
public/Gap.h
|
@ -21,6 +21,7 @@
|
|||
#include "GapAdvertisingParams.h"
|
||||
#include "GapEvents.h"
|
||||
#include "CallChain.h"
|
||||
#include "FunctionPointerWithContext.h"
|
||||
|
||||
using namespace mbed;
|
||||
|
||||
|
@ -152,12 +153,15 @@ public:
|
|||
typedef void (*LinkSecuredCallback_t)(Handle_t handle, SecurityMode_t securityMode);
|
||||
typedef void (*PasskeyDisplayCallback_t)(Handle_t handle, const Passkey_t passkey);
|
||||
|
||||
typedef void (*AdvertisementReportCallback_t)(const address_t peerAddr,
|
||||
int8_t rssi,
|
||||
bool isScanResponse,
|
||||
AdvertisementType_t type,
|
||||
uint8_t advertisingDataLen,
|
||||
const uint8_t *advertisingData);
|
||||
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;
|
||||
|
||||
|
@ -168,7 +172,7 @@ private:
|
|||
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;
|
||||
virtual ble_error_t startScan(const GapScanningParams &scanningParams, AdvertisementReportCallback_t callback) = 0;
|
||||
virtual ble_error_t startScan(const GapScanningParams &scanningParams, void (*callback)(const AdvertisementCallbackParams_t *params)) = 0;
|
||||
virtual ble_error_t stopScan() = 0;
|
||||
virtual uint16_t getMinAdvertisingInterval(void) const = 0;
|
||||
virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const = 0;
|
||||
|
@ -322,9 +326,14 @@ public:
|
|||
AdvertisementType_t type,
|
||||
uint8_t advertisingDataLen,
|
||||
const uint8_t *advertisingData) {
|
||||
if (onAdvertisementReport) {
|
||||
onAdvertisementReport(peerAddr, rssi, isScanResponse, type, advertisingDataLen, advertisingData);
|
||||
}
|
||||
AdvertisementCallbackParams_t params;
|
||||
memcpy(params.peerAddr, peerAddr, ADDR_LEN);
|
||||
params.rssi = rssi;
|
||||
params.isScanResponse = isScanResponse;
|
||||
params.type = type;
|
||||
params.advertisingDataLen = advertisingDataLen;
|
||||
params.advertisingData = advertisingData;
|
||||
onAdvertisementReport.call(¶ms);
|
||||
}
|
||||
|
||||
void processEvent(GapEvents::gapEvent_e type) {
|
||||
|
|
Loading…
Reference in a new issue