auto use peerAddress if adv type is set to one of directed type

This commit is contained in:
hathach 2023-11-30 12:34:15 +07:00
parent ea3dd125f0
commit f96d9cef1e
3 changed files with 19 additions and 24 deletions

8
.gitignore vendored
View file

@ -3,7 +3,10 @@
*.obj
# Visual Studio Code
**/.vscode/
.vscode/
.idea/
.pio/
.piopm
# Executables
*.out
@ -13,7 +16,6 @@
/tools/.idea/
/tools/midi_tests/node_modules
.idea/
.DS_Store
*.swp
/Output
@ -21,4 +23,4 @@
# Ignore local overrides of platform.txt and boards.txt,
/boards.local.txt
/platform.local.txt
/libraries/**/build/

View file

@ -265,7 +265,6 @@ 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)
@ -316,15 +315,8 @@ 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;
void BLEAdvertising::setPeerAddress(const ble_gap_addr_t& peer_addr) {
_peer_addr = peer_addr;
}
bool BLEAdvertising::isRunning(void)
@ -350,8 +342,7 @@ void BLEAdvertising::restartOnDisconnect(bool enable)
bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
{
// ADV Params
ble_gap_adv_params_t adv_para =
{
ble_gap_adv_params_t adv_para = {
.properties = { .type = _type, .anonymous = 0 },
.p_peer_addr = NULL , // Undirected advertisement
.interval = interval , // advertising interval (in units of 0.625 ms)
@ -366,14 +357,20 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
// , .set_id, .scan_req_notification
};
if (_directed) {
// Set target address when not using broadcasting
switch(_type) {
case BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED_HIGH_DUTY_CYCLE:
case BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED:
case BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_DIRECTED:
case BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_SCANNABLE_DIRECTED:
case BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_DIRECTED:
adv_para.p_peer_addr = &_peer_addr;
break;
default: break;
}
// gap_adv long-live is required by SD v6
static ble_gap_adv_data_t gap_adv =
{
static ble_gap_adv_data_t gap_adv = {
.adv_data = { .p_data = _data, .len = _count },
.scan_rsp_data = { .p_data = Bluefruit.ScanResponse.getData(), .len = Bluefruit.ScanResponse.count() }
};

View file

@ -134,12 +134,9 @@ public:
bool setBeacon(BLEBeacon& beacon);
bool setBeacon(EddyStoneUrl& eddy_url);
/// Advertise to a single peer instead of broadcasting
// 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);
@ -159,7 +156,6 @@ private:
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;