Skip to content

Commit

Permalink
Merge pull request #788 from UUSim/master
Browse files Browse the repository at this point in the history
Added support for directed BLE advertisements.
  • Loading branch information
hathach committed Nov 30, 2023
2 parents ddaa71b + f96d9ce commit e1f1884
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*.obj

# Visual Studio Code
**/.vscode/
.vscode/
.idea/
.pio/
.piopm

# Executables
*.out
Expand All @@ -13,12 +16,11 @@
/tools/.idea/
/tools/midi_tests/node_modules

.idea/
.DS_Store
*.swp
/Output

# Ignore local overrides of platform.txt and boards.txt,
/boards.local.txt
/platform.local.txt
/libraries/**/build/

25 changes: 19 additions & 6 deletions libraries/Bluefruit52Lib/src/BLEAdvertising.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ void BLEAdvertising::setStopCallback(stop_callback_t fp)
_stop_cb = fp;
}

void BLEAdvertising::setPeerAddress(const ble_gap_addr_t& peer_addr) {
_peer_addr = peer_addr;
}

bool BLEAdvertising::isRunning(void)
{
return _runnning;
Expand All @@ -338,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)
Expand All @@ -354,9 +357,20 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
// , .set_id, .scan_req_notification
};

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() }
};
Expand Down Expand Up @@ -464,5 +478,4 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)

default: break;
}
}

}
4 changes: 4 additions & 0 deletions libraries/Bluefruit52Lib/src/BLEAdvertising.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ class BLEAdvertising : public BLEAdvertisingData
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);

bool isRunning(void);

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

uint32_t _conn_mask;

Expand Down

0 comments on commit e1f1884

Please sign in to comment.