@@ -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+
318322bool BLEAdvertising::isRunning (void )
319323{
320324 return _runnning;
@@ -338,8 +342,7 @@ void BLEAdvertising::restartOnDisconnect(bool enable)
338342bool 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+ }
0 commit comments