Skip to content

Commit e1f1884

Browse files
authored
Merge pull request #788 from UUSim/master
Added support for directed BLE advertisements.
2 parents ddaa71b + f96d9ce commit e1f1884

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
*.obj
44

55
# Visual Studio Code
6-
**/.vscode/
6+
.vscode/
7+
.idea/
8+
.pio/
9+
.piopm
710

811
# Executables
912
*.out
@@ -13,12 +16,11 @@
1316
/tools/.idea/
1417
/tools/midi_tests/node_modules
1518

16-
.idea/
1719
.DS_Store
1820
*.swp
1921
/Output
2022

2123
# Ignore local overrides of platform.txt and boards.txt,
2224
/boards.local.txt
2325
/platform.local.txt
24-
/libraries/**/build/
26+

libraries/Bluefruit52Lib/src/BLEAdvertising.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ void BLEAdvertising::setStopCallback(stop_callback_t fp)
315315
_stop_cb = fp;
316316
}
317317

318+
void BLEAdvertising::setPeerAddress(const ble_gap_addr_t& peer_addr) {
319+
_peer_addr = peer_addr;
320+
}
321+
318322
bool BLEAdvertising::isRunning(void)
319323
{
320324
return _runnning;
@@ -338,8 +342,7 @@ void BLEAdvertising::restartOnDisconnect(bool enable)
338342
bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
339343
{
340344
// ADV Params
341-
ble_gap_adv_params_t adv_para =
342-
{
345+
ble_gap_adv_params_t adv_para = {
343346
.properties = { .type = _type, .anonymous = 0 },
344347
.p_peer_addr = NULL , // Undirected advertisement
345348
.interval = interval , // advertising interval (in units of 0.625 ms)
@@ -354,9 +357,20 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
354357
// , .set_id, .scan_req_notification
355358
};
356359

360+
switch(_type) {
361+
case BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED_HIGH_DUTY_CYCLE:
362+
case BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED:
363+
case BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_DIRECTED:
364+
case BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_SCANNABLE_DIRECTED:
365+
case BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_DIRECTED:
366+
adv_para.p_peer_addr = &_peer_addr;
367+
break;
368+
369+
default: break;
370+
}
371+
357372
// gap_adv long-live is required by SD v6
358-
static ble_gap_adv_data_t gap_adv =
359-
{
373+
static ble_gap_adv_data_t gap_adv = {
360374
.adv_data = { .p_data = _data, .len = _count },
361375
.scan_rsp_data = { .p_data = Bluefruit.ScanResponse.getData(), .len = Bluefruit.ScanResponse.count() }
362376
};
@@ -464,5 +478,4 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)
464478

465479
default: break;
466480
}
467-
}
468-
481+
}

libraries/Bluefruit52Lib/src/BLEAdvertising.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class BLEAdvertising : public BLEAdvertisingData
134134
bool setBeacon(BLEBeacon& beacon);
135135
bool setBeacon(EddyStoneUrl& eddy_url);
136136

137+
// Advertise to a single peer instead of broadcasting
138+
void setPeerAddress(const ble_gap_addr_t& peer_addr);
139+
137140
bool isRunning(void);
138141

139142
void restartOnDisconnect(bool enable);
@@ -152,6 +155,7 @@ class BLEAdvertising : public BLEAdvertisingData
152155
uint8_t _type;
153156
bool _start_if_disconnect;
154157
bool _runnning;
158+
ble_gap_addr_t _peer_addr; //! Target address for an ADV_DIRECT_IND advertisement
155159

156160
uint32_t _conn_mask;
157161

0 commit comments

Comments
 (0)