You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2021/07/30 07:56:41 UTC

[mynewt-nimble] branch master updated: apps: Add periodic advertising instance to ext_advertiser sample

This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new 28533d4  apps: Add periodic advertising instance to ext_advertiser sample
28533d4 is described below

commit 28533d46f8f7c77b2a00b9a71909cd17ea36e996
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Tue Jul 27 15:53:41 2021 +0200

    apps: Add periodic advertising instance to ext_advertiser sample
    
    Add new instance that advertises 1650 bytes of periodic data.
---
 apps/ext_advertiser/src/main.c | 80 ++++++++++++++++++++++++++++++++++++++++++
 apps/ext_advertiser/syscfg.yml |  9 +++--
 2 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/apps/ext_advertiser/src/main.c b/apps/ext_advertiser/src/main.c
index 6bbc23d..86b7284 100644
--- a/apps/ext_advertiser/src/main.c
+++ b/apps/ext_advertiser/src/main.c
@@ -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();
 }
 
 /*
diff --git a/apps/ext_advertiser/syscfg.yml b/apps/ext_advertiser/syscfg.yml
index 5f5fb54..f157ab8 100644
--- a/apps/ext_advertiser/syscfg.yml
+++ b/apps/ext_advertiser/syscfg.yml
@@ -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