Added support for directed BLE advertisements.
Can be used for example with advertising type BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED.
This commit is contained in:
1 parent
bf5047952f
commit
931b0ac1f7
2 files changed
+26
-2
No files matched your search
@@ -265,6 +265,7 @@ BLEAdvertising::BLEAdvertising(void)
|
||||
_stop_timeout = _left_timeout = 0;
|
||||
_stop_cb = NULL;
|
||||
_slow_cb = NULL;
|
||||
_directed = false; // Broadcast advertising is the default
|
||||
}
|
||||
|
||||
void BLEAdvertising::setFastTimeout(uint16_t sec)
|
||||
@@ -315,6 +316,17 @@ void BLEAdvertising::setStopCallback(stop_callback_t fp)
|
||||
_stop_cb = fp;
|
||||
}
|
||||
|
||||
void BLEAdvertising::setPeerAddress(const ble_gap_addr_t& peer_addr)
|
||||
{
|
||||
_directed = true;
|
||||
_peer_addr = peer_addr; // Copy address, used later in start function
|
||||
}
|
||||
|
||||
void BLEAdvertising::removePeerAddress()
|
||||
{
|
||||
_directed = false;
|
||||
}
|
||||
|
||||
bool BLEAdvertising::isRunning(void)
|
||||
{
|
||||
return _runnning;
|
||||
@@ -354,6 +366,11 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
|
||||
// , .set_id, .scan_req_notification
|
||||
};
|
||||
|
||||
if (_directed) {
|
||||
// Set target address when not using broadcasting
|
||||
adv_para.p_peer_addr = &_peer_addr;
|
||||
}
|
||||
|
||||
// gap_adv long-live is required by SD v6
|
||||
static ble_gap_adv_data_t gap_adv =
|
||||
{
|
||||
@@ -464,5 +481,4 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -134,6 +134,12 @@ public:
|
||||
bool setBeacon(BLEBeacon& beacon);
|
||||
bool setBeacon(EddyStoneUrl& eddy_url);
|
||||
|
||||
/// Advertise to a single peer instead of broadcasting
|
||||
void setPeerAddress(const ble_gap_addr_t& peer_addr);
|
||||
|
||||
/// Revert to broadcast advertising
|
||||
void removePeerAddress();
|
||||
|
||||
bool isRunning(void);
|
||||
|
||||
void restartOnDisconnect(bool enable);
|
||||
@@ -152,6 +158,8 @@ private:
|
||||
uint8_t _type;
|
||||
bool _start_if_disconnect;
|
||||
bool _runnning;
|
||||
ble_gap_addr_t _peer_addr; //! Target address for an ADV_DIRECT_IND advertisement
|
||||
bool _directed; //! Whether the advertisements are directed or broadcast
|
||||
|
||||
uint32_t _conn_mask;
|
||||
|
||||
|
||||
Reference in new issue
Block a user