From bb4c44153b3bbf7c55b3f3c41d8873626d140f4f Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 25 Oct 2024 10:27:41 +0200 Subject: [PATCH] samples: Bluetooth: broadcaster_multiple: Refactor for reuse Refactor the sample so that multiple advertising setup can be reused in other sample if required. Bluetooth enable can be in the sample that reuses the advertising setup. Signed-off-by: Vinayak Kariappa Chettimada --- .../broadcaster_multiple/src/broadcaster_multiple.c | 7 ------- samples/bluetooth/broadcaster_multiple/src/main.c | 10 ++++++++++ tests/bsim/bluetooth/host/adv/chain/src/main.c | 8 ++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c index f2e7127b406..63834fa3852 100644 --- a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c +++ b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c @@ -77,13 +77,6 @@ int broadcaster_multiple(void) }; int err; - /* Initialize the Bluetooth Subsystem */ - err = bt_enable(NULL); - if (err) { - printk("Bluetooth init failed (err %d)\n", err); - return err; - } - for (int index = 0; index < CONFIG_BT_EXT_ADV_MAX_ADV_SET; index++) { /* Use advertising set instance index as SID */ adv_param.sid = index; diff --git a/samples/bluetooth/broadcaster_multiple/src/main.c b/samples/bluetooth/broadcaster_multiple/src/main.c index f30db217e86..4da680e4d8b 100644 --- a/samples/bluetooth/broadcaster_multiple/src/main.c +++ b/samples/bluetooth/broadcaster_multiple/src/main.c @@ -5,13 +5,23 @@ */ #include +#include int broadcaster_multiple(void); int main(void) { + int err; + printk("Starting Multiple Broadcaster Demo\n"); + /* Initialize the Bluetooth Subsystem */ + err = bt_enable(NULL); + if (err) { + printk("Bluetooth init failed (err %d)\n", err); + return 0; + } + (void)broadcaster_multiple(); printk("Exiting %s thread.\n", __func__); diff --git a/tests/bsim/bluetooth/host/adv/chain/src/main.c b/tests/bsim/bluetooth/host/adv/chain/src/main.c index dd7a400cb62..ad718125318 100644 --- a/tests/bsim/bluetooth/host/adv/chain/src/main.c +++ b/tests/bsim/bluetooth/host/adv/chain/src/main.c @@ -51,6 +51,14 @@ static void test_adv_main(void) extern int broadcaster_multiple(void); int err; + err = bt_enable(NULL); + if (err) { + FAIL("Bluetooth init failed\n"); + + bs_trace_silent_exit(err); + return; + } + err = broadcaster_multiple(); if (err) { FAIL("Adv tests failed\n");