@@ -265,7 +265,6 @@ BLEAdvertising::BLEAdvertising(void)
265
265
_stop_timeout = _left_timeout = 0 ;
266
266
_stop_cb = NULL ;
267
267
_slow_cb = NULL ;
268
- _directed = false ; // Broadcast advertising is the default
269
268
}
270
269
271
270
void BLEAdvertising::setFastTimeout (uint16_t sec)
@@ -316,15 +315,8 @@ void BLEAdvertising::setStopCallback(stop_callback_t fp)
316
315
_stop_cb = fp;
317
316
}
318
317
319
- void BLEAdvertising::setPeerAddress (const ble_gap_addr_t & peer_addr)
320
- {
321
- _directed = true ;
322
- _peer_addr = peer_addr; // Copy address, used later in start function
323
- }
324
-
325
- void BLEAdvertising::removePeerAddress ()
326
- {
327
- _directed = false ;
318
+ void BLEAdvertising::setPeerAddress (const ble_gap_addr_t & peer_addr) {
319
+ _peer_addr = peer_addr;
328
320
}
329
321
330
322
bool BLEAdvertising::isRunning (void )
@@ -350,8 +342,7 @@ void BLEAdvertising::restartOnDisconnect(bool enable)
350
342
bool BLEAdvertising::_start (uint16_t interval, uint16_t timeout)
351
343
{
352
344
// ADV Params
353
- ble_gap_adv_params_t adv_para =
354
- {
345
+ ble_gap_adv_params_t adv_para = {
355
346
.properties = { .type = _type, .anonymous = 0 },
356
347
.p_peer_addr = NULL , // Undirected advertisement
357
348
.interval = interval , // advertising interval (in units of 0.625 ms)
@@ -366,14 +357,20 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
366
357
// , .set_id, .scan_req_notification
367
358
};
368
359
369
- if (_directed) {
370
- // Set target address when not using broadcasting
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:
371
366
adv_para.p_peer_addr = &_peer_addr;
367
+ break ;
368
+
369
+ default : break ;
372
370
}
373
371
374
372
// gap_adv long-live is required by SD v6
375
- static ble_gap_adv_data_t gap_adv =
376
- {
373
+ static ble_gap_adv_data_t gap_adv = {
377
374
.adv_data = { .p_data = _data, .len = _count },
378
375
.scan_rsp_data = { .p_data = Bluefruit.ScanResponse .getData (), .len = Bluefruit.ScanResponse .count () }
379
376
};
0 commit comments