mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-21 20:50:55 +01:00
Add directed peer address parameter to advertising start.
Adds a parameter to NimBLEAdvertising::start to take the peer address for use with directed advertising.
This commit is contained in:
parent
d83cd94d5b
commit
0aa7e9510d
2 changed files with 19 additions and 5 deletions
|
@ -387,9 +387,10 @@ void NimBLEAdvertising::setScanResponseData(NimBLEAdvertisementData& advertiseme
|
|||
* @brief Start advertising.
|
||||
* @param [in] duration The duration, in milliseconds, to advertise, 0 == advertise forever.
|
||||
* @param [in] advCompleteCB A pointer to a callback to be invoked when advertising ends.
|
||||
* @param [in] dirAddr The address of a peer to directly advertise to.
|
||||
* @return True if advertising started successfully.
|
||||
*/
|
||||
bool NimBLEAdvertising::start(uint32_t duration, void (*advCompleteCB)(NimBLEAdvertising *pAdv)) {
|
||||
bool NimBLEAdvertising::start(uint32_t duration, void (*advCompleteCB)(NimBLEAdvertising *pAdv), NimBLEAddress* dirAddr) {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> Advertising start: customAdvData: %d, customScanResponseData: %d",
|
||||
m_customAdvData, m_customScanResponseData);
|
||||
|
||||
|
@ -620,15 +621,27 @@ bool NimBLEAdvertising::start(uint32_t duration, void (*advCompleteCB)(NimBLEAdv
|
|||
m_advDataSet = true;
|
||||
}
|
||||
|
||||
ble_addr_t peerAddr;
|
||||
if (dirAddr != nullptr) {
|
||||
memcpy(&peerAddr.val, dirAddr->getNative(), 6);
|
||||
peerAddr.type = dirAddr->getType();
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
rc = ble_gap_adv_start(NimBLEDevice::m_own_addr_type, NULL, duration,
|
||||
rc = ble_gap_adv_start(NimBLEDevice::m_own_addr_type,
|
||||
(dirAddr != nullptr) ? &peerAddr : NULL,
|
||||
duration,
|
||||
&m_advParams,
|
||||
(pServer != nullptr) ? NimBLEServer::handleGapEvent :
|
||||
NimBLEAdvertising::handleGapEvent,
|
||||
(void*)this);
|
||||
#else
|
||||
rc = ble_gap_adv_start(NimBLEDevice::m_own_addr_type, NULL, duration,
|
||||
&m_advParams, NimBLEAdvertising::handleGapEvent, this);
|
||||
rc = ble_gap_adv_start(NimBLEDevice::m_own_addr_type,
|
||||
(dirAddr != nullptr) ? &peerAddr : NULL,
|
||||
duration,
|
||||
&m_advParams,
|
||||
NimBLEAdvertising::handleGapEvent,
|
||||
(void*)this);
|
||||
#endif
|
||||
switch(rc) {
|
||||
case 0:
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
/**************************/
|
||||
|
||||
#include "NimBLEUUID.h"
|
||||
#include "NimBLEAddress.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -90,7 +91,7 @@ public:
|
|||
void addServiceUUID(const NimBLEUUID &serviceUUID);
|
||||
void addServiceUUID(const char* serviceUUID);
|
||||
void removeServiceUUID(const NimBLEUUID &serviceUUID);
|
||||
bool start(uint32_t duration = 0, void (*advCompleteCB)(NimBLEAdvertising *pAdv) = nullptr);
|
||||
bool start(uint32_t duration = 0, void (*advCompleteCB)(NimBLEAdvertising *pAdv) = nullptr, NimBLEAddress* dirAddr = nullptr);
|
||||
bool stop();
|
||||
void setAppearance(uint16_t appearance);
|
||||
void setName(const std::string &name);
|
||||
|
|
Loading…
Reference in a new issue