apps: Add periodic advertising instance to ext_advertiser sample

Add new instance that advertises 1650 bytes of periodic data.
This commit is contained in:
Szymon Janc
2021-07-27 15:53:41 +02:00
parent 3900772458
commit 28533d46f8
2 changed files with 86 additions and 3 deletions
+80
View File
@@ -411,6 +411,84 @@ start_non_connectable_ext(void)
console_printf("instance %u started (non-con non-scan)\n", instance);
}
static void start_periodic(void)
{
struct ble_gap_periodic_adv_params pparams;
struct ble_gap_ext_adv_params params;
struct ble_hs_adv_fields adv_fields;
struct os_mbuf *data;
uint8_t instance = 5;
ble_addr_t addr;
int rc;
/* For periodic we use nstance with non-connectable advertising */
memset (&params, 0, sizeof(params));
/* advertise using random addr */
params.own_addr_type = BLE_OWN_ADDR_RANDOM;
params.primary_phy = BLE_HCI_LE_PHY_1M;
params.secondary_phy = BLE_HCI_LE_PHY_1M;
params.tx_power = 127;
params.sid = 2;
/* configure instance 0 */
rc = ble_gap_ext_adv_configure(instance, &params, NULL, NULL, NULL);
assert (rc == 0);
/* set random (NRPA) address for instance */
rc = ble_hs_id_gen_rnd(1, &addr);
assert (rc == 0);
rc = ble_gap_ext_adv_set_addr(instance, &addr );
assert (rc == 0);
memset(&adv_fields, 0, sizeof(adv_fields));
adv_fields.name = (const uint8_t *)"nimble with periodic";
adv_fields.name_len = strlen((char *)adv_fields.name);
/* Default to legacy PDUs size, mbuf chain will be increased if needed
*/
data = os_msys_get_pkthdr(BLE_HCI_MAX_ADV_DATA_LEN, 0);
assert(data);
rc = ble_hs_adv_set_fields_mbuf(&adv_fields, data);
assert(rc == 0);
rc = ble_gap_ext_adv_set_data(instance, data);
assert(rc == 0);
/* configure periodic advertising */
memset(&pparams, 0, sizeof(pparams));
pparams.include_tx_power = 1;
pparams.itvl_min = 160;
pparams.itvl_max = 240;
rc = ble_gap_periodic_adv_configure(instance, &pparams);
assert(rc == 0);
/* get mbuf for periodic data */
data = os_msys_get_pkthdr(sizeof(ext_adv_pattern_1), 0);
assert(data);
/* fill mbuf with periodic data */
rc = os_mbuf_append(data, ext_adv_pattern_1, sizeof(ext_adv_pattern_1));
assert(rc == 0);
rc = ble_gap_periodic_adv_set_data(instance, data);
assert (rc == 0);
/* start periodic advertising */
rc = ble_gap_periodic_adv_start(instance);
assert (rc == 0);
/* start advertising */
rc = ble_gap_ext_adv_start(instance, 0, 0);
assert (rc == 0);
console_printf("instance %u started (periodic)\n", instance);
}
static void
on_sync(void)
{
@@ -435,6 +513,8 @@ on_sync(void)
start_legacy_duration(0, true);
start_ext_max_events(0, true);
start_periodic();
}
/*
+6 -3
View File
@@ -30,6 +30,9 @@ syscfg.vals:
# Enable Extended Advertising
BLE_EXT_ADV: 1
# Enable Periodic Advertising
BLE_PERIODIC_ADV: 1
# Max advertising data size
BLE_EXT_ADV_MAX_SIZE: 1650
@@ -37,12 +40,12 @@ syscfg.vals:
# to historical reasonds total number of advertising
# instances is BLE_MULTI_ADV_INSTANCES + 1 as instance
# 0 is always available
BLE_MULTI_ADV_INSTANCES: 4
BLE_MULTI_ADV_INSTANCES: 5
# Controller uses msys pool for storing advertising data and scan responses.
# Since we advertise a lot of data (~4k in total) at the same time we need
# Since we advertise a lot of data (~6k in total) at the same time we need
# to increase block count.
MSYS_1_BLOCK_COUNT: 24
MSYS_1_BLOCK_COUNT: 32
# Whether to save data to sys/config, or just keep it in RAM.
BLE_STORE_CONFIG_PERSIST: 0