Skip to content

Commit 28533d4

Browse files
committed
apps: Add periodic advertising instance to ext_advertiser sample
Add new instance that advertises 1650 bytes of periodic data.
1 parent 3900772 commit 28533d4

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

apps/ext_advertiser/src/main.c

+80
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,84 @@ start_non_connectable_ext(void)
411411
console_printf("instance %u started (non-con non-scan)\n", instance);
412412
}
413413

414+
static void start_periodic(void)
415+
{
416+
struct ble_gap_periodic_adv_params pparams;
417+
struct ble_gap_ext_adv_params params;
418+
struct ble_hs_adv_fields adv_fields;
419+
struct os_mbuf *data;
420+
uint8_t instance = 5;
421+
ble_addr_t addr;
422+
int rc;
423+
424+
/* For periodic we use nstance with non-connectable advertising */
425+
memset (&params, 0, sizeof(params));
426+
427+
/* advertise using random addr */
428+
params.own_addr_type = BLE_OWN_ADDR_RANDOM;
429+
430+
params.primary_phy = BLE_HCI_LE_PHY_1M;
431+
params.secondary_phy = BLE_HCI_LE_PHY_1M;
432+
params.tx_power = 127;
433+
params.sid = 2;
434+
435+
/* configure instance 0 */
436+
rc = ble_gap_ext_adv_configure(instance, &params, NULL, NULL, NULL);
437+
assert (rc == 0);
438+
439+
/* set random (NRPA) address for instance */
440+
rc = ble_hs_id_gen_rnd(1, &addr);
441+
assert (rc == 0);
442+
443+
rc = ble_gap_ext_adv_set_addr(instance, &addr );
444+
assert (rc == 0);
445+
446+
memset(&adv_fields, 0, sizeof(adv_fields));
447+
adv_fields.name = (const uint8_t *)"nimble with periodic";
448+
adv_fields.name_len = strlen((char *)adv_fields.name);
449+
450+
/* Default to legacy PDUs size, mbuf chain will be increased if needed
451+
*/
452+
data = os_msys_get_pkthdr(BLE_HCI_MAX_ADV_DATA_LEN, 0);
453+
assert(data);
454+
455+
rc = ble_hs_adv_set_fields_mbuf(&adv_fields, data);
456+
assert(rc == 0);
457+
458+
rc = ble_gap_ext_adv_set_data(instance, data);
459+
assert(rc == 0);
460+
461+
/* configure periodic advertising */
462+
memset(&pparams, 0, sizeof(pparams));
463+
pparams.include_tx_power = 1;
464+
pparams.itvl_min = 160;
465+
pparams.itvl_max = 240;
466+
467+
rc = ble_gap_periodic_adv_configure(instance, &pparams);
468+
assert(rc == 0);
469+
470+
/* get mbuf for periodic data */
471+
data = os_msys_get_pkthdr(sizeof(ext_adv_pattern_1), 0);
472+
assert(data);
473+
474+
/* fill mbuf with periodic data */
475+
rc = os_mbuf_append(data, ext_adv_pattern_1, sizeof(ext_adv_pattern_1));
476+
assert(rc == 0);
477+
478+
rc = ble_gap_periodic_adv_set_data(instance, data);
479+
assert (rc == 0);
480+
481+
/* start periodic advertising */
482+
rc = ble_gap_periodic_adv_start(instance);
483+
assert (rc == 0);
484+
485+
/* start advertising */
486+
rc = ble_gap_ext_adv_start(instance, 0, 0);
487+
assert (rc == 0);
488+
489+
console_printf("instance %u started (periodic)\n", instance);
490+
}
491+
414492
static void
415493
on_sync(void)
416494
{
@@ -435,6 +513,8 @@ on_sync(void)
435513
start_legacy_duration(0, true);
436514

437515
start_ext_max_events(0, true);
516+
517+
start_periodic();
438518
}
439519

440520
/*

apps/ext_advertiser/syscfg.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,22 @@ syscfg.vals:
3030
# Enable Extended Advertising
3131
BLE_EXT_ADV: 1
3232

33+
# Enable Periodic Advertising
34+
BLE_PERIODIC_ADV: 1
35+
3336
# Max advertising data size
3437
BLE_EXT_ADV_MAX_SIZE: 1650
3538

3639
# Number of multi-advertising instances. Note that due
3740
# to historical reasonds total number of advertising
3841
# instances is BLE_MULTI_ADV_INSTANCES + 1 as instance
3942
# 0 is always available
40-
BLE_MULTI_ADV_INSTANCES: 4
43+
BLE_MULTI_ADV_INSTANCES: 5
4144

4245
# Controller uses msys pool for storing advertising data and scan responses.
43-
# Since we advertise a lot of data (~4k in total) at the same time we need
46+
# Since we advertise a lot of data (~6k in total) at the same time we need
4447
# to increase block count.
45-
MSYS_1_BLOCK_COUNT: 24
48+
MSYS_1_BLOCK_COUNT: 32
4649

4750
# Whether to save data to sys/config, or just keep it in RAM.
4851
BLE_STORE_CONFIG_PERSIST: 0

0 commit comments

Comments
 (0)