auto use peerAddress if adv type is set to one of directed type
This commit is contained in:
parent
ea3dd125f0
commit
f96d9cef1e
3 changed files with 19 additions and 24 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -3,7 +3,10 @@
|
||||||
*.obj
|
*.obj
|
||||||
|
|
||||||
# Visual Studio Code
|
# Visual Studio Code
|
||||||
**/.vscode/
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
.pio/
|
||||||
|
.piopm
|
||||||
|
|
||||||
# Executables
|
# Executables
|
||||||
*.out
|
*.out
|
||||||
|
|
@ -13,7 +16,6 @@
|
||||||
/tools/.idea/
|
/tools/.idea/
|
||||||
/tools/midi_tests/node_modules
|
/tools/midi_tests/node_modules
|
||||||
|
|
||||||
.idea/
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.swp
|
*.swp
|
||||||
/Output
|
/Output
|
||||||
|
|
@ -21,4 +23,4 @@
|
||||||
# Ignore local overrides of platform.txt and boards.txt,
|
# Ignore local overrides of platform.txt and boards.txt,
|
||||||
/boards.local.txt
|
/boards.local.txt
|
||||||
/platform.local.txt
|
/platform.local.txt
|
||||||
/libraries/**/build/
|
|
||||||
|
|
|
||||||
|
|
@ -265,7 +265,6 @@ BLEAdvertising::BLEAdvertising(void)
|
||||||
_stop_timeout = _left_timeout = 0;
|
_stop_timeout = _left_timeout = 0;
|
||||||
_stop_cb = NULL;
|
_stop_cb = NULL;
|
||||||
_slow_cb = NULL;
|
_slow_cb = NULL;
|
||||||
_directed = false; // Broadcast advertising is the default
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BLEAdvertising::setFastTimeout(uint16_t sec)
|
void BLEAdvertising::setFastTimeout(uint16_t sec)
|
||||||
|
|
@ -316,15 +315,8 @@ void BLEAdvertising::setStopCallback(stop_callback_t fp)
|
||||||
_stop_cb = fp;
|
_stop_cb = fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BLEAdvertising::setPeerAddress(const ble_gap_addr_t& peer_addr)
|
void BLEAdvertising::setPeerAddress(const ble_gap_addr_t& peer_addr) {
|
||||||
{
|
_peer_addr = peer_addr;
|
||||||
_directed = true;
|
|
||||||
_peer_addr = peer_addr; // Copy address, used later in start function
|
|
||||||
}
|
|
||||||
|
|
||||||
void BLEAdvertising::removePeerAddress()
|
|
||||||
{
|
|
||||||
_directed = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BLEAdvertising::isRunning(void)
|
bool BLEAdvertising::isRunning(void)
|
||||||
|
|
@ -350,8 +342,7 @@ void BLEAdvertising::restartOnDisconnect(bool enable)
|
||||||
bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
|
bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
|
||||||
{
|
{
|
||||||
// ADV Params
|
// ADV Params
|
||||||
ble_gap_adv_params_t adv_para =
|
ble_gap_adv_params_t adv_para = {
|
||||||
{
|
|
||||||
.properties = { .type = _type, .anonymous = 0 },
|
.properties = { .type = _type, .anonymous = 0 },
|
||||||
.p_peer_addr = NULL , // Undirected advertisement
|
.p_peer_addr = NULL , // Undirected advertisement
|
||||||
.interval = interval , // advertising interval (in units of 0.625 ms)
|
.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
|
// , .set_id, .scan_req_notification
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_directed) {
|
switch(_type) {
|
||||||
// Set target address when not using broadcasting
|
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;
|
adv_para.p_peer_addr = &_peer_addr;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// gap_adv long-live is required by SD v6
|
// 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 },
|
.adv_data = { .p_data = _data, .len = _count },
|
||||||
.scan_rsp_data = { .p_data = Bluefruit.ScanResponse.getData(), .len = Bluefruit.ScanResponse.count() }
|
.scan_rsp_data = { .p_data = Bluefruit.ScanResponse.getData(), .len = Bluefruit.ScanResponse.count() }
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -134,12 +134,9 @@ public:
|
||||||
bool setBeacon(BLEBeacon& beacon);
|
bool setBeacon(BLEBeacon& beacon);
|
||||||
bool setBeacon(EddyStoneUrl& eddy_url);
|
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);
|
void setPeerAddress(const ble_gap_addr_t& peer_addr);
|
||||||
|
|
||||||
/// Revert to broadcast advertising
|
|
||||||
void removePeerAddress();
|
|
||||||
|
|
||||||
bool isRunning(void);
|
bool isRunning(void);
|
||||||
|
|
||||||
void restartOnDisconnect(bool enable);
|
void restartOnDisconnect(bool enable);
|
||||||
|
|
@ -159,7 +156,6 @@ private:
|
||||||
bool _start_if_disconnect;
|
bool _start_if_disconnect;
|
||||||
bool _runnning;
|
bool _runnning;
|
||||||
ble_gap_addr_t _peer_addr; //! Target address for an ADV_DIRECT_IND advertisement
|
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;
|
uint32_t _conn_mask;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue