Skip to content

Commit bb4c441

Browse files
cvinayakdleach02
authored andcommitted
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 <[email protected]>
1 parent 7048b0f commit bb4c441

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ int broadcaster_multiple(void)
7777
};
7878
int err;
7979

80-
/* Initialize the Bluetooth Subsystem */
81-
err = bt_enable(NULL);
82-
if (err) {
83-
printk("Bluetooth init failed (err %d)\n", err);
84-
return err;
85-
}
86-
8780
for (int index = 0; index < CONFIG_BT_EXT_ADV_MAX_ADV_SET; index++) {
8881
/* Use advertising set instance index as SID */
8982
adv_param.sid = index;

samples/bluetooth/broadcaster_multiple/src/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@
55
*/
66

77
#include <zephyr/sys/printk.h>
8+
#include <zephyr/bluetooth/bluetooth.h>
89

910
int broadcaster_multiple(void);
1011

1112
int main(void)
1213
{
14+
int err;
15+
1316
printk("Starting Multiple Broadcaster Demo\n");
1417

18+
/* Initialize the Bluetooth Subsystem */
19+
err = bt_enable(NULL);
20+
if (err) {
21+
printk("Bluetooth init failed (err %d)\n", err);
22+
return 0;
23+
}
24+
1525
(void)broadcaster_multiple();
1626

1727
printk("Exiting %s thread.\n", __func__);

tests/bsim/bluetooth/host/adv/chain/src/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ static void test_adv_main(void)
5151
extern int broadcaster_multiple(void);
5252
int err;
5353

54+
err = bt_enable(NULL);
55+
if (err) {
56+
FAIL("Bluetooth init failed\n");
57+
58+
bs_trace_silent_exit(err);
59+
return;
60+
}
61+
5462
err = broadcaster_multiple();
5563
if (err) {
5664
FAIL("Adv tests failed\n");

0 commit comments

Comments
 (0)