-
Notifications
You must be signed in to change notification settings - Fork 7.8k
samples: Bluetooth: Broadcast multiple legacy and extended advertising #94304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c36dc91
7ddea29
ba81b32
7afe802
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -54,14 +54,18 @@ | |||||
*/ | ||||||
static uint8_t mfg_data[BT_MFG_DATA_LEN] = { 0xFF, 0xFF, }; | ||||||
|
||||||
static const struct bt_data ad[] = { | ||||||
static const struct bt_data ad_long[] = { | ||||||
BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)), | ||||||
#if CONFIG_BT_CTLR_ADV_DATA_LEN_MAX > 255 | ||||||
BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)), | ||||||
#endif | ||||||
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), | ||||||
}; | ||||||
|
||||||
static const struct bt_data ad_short[] = { | ||||||
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), | ||||||
}; | ||||||
|
||||||
static struct bt_le_ext_adv *adv[CONFIG_BT_EXT_ADV_MAX_ADV_SET]; | ||||||
|
||||||
int broadcaster_multiple(void) | ||||||
|
@@ -78,20 +82,56 @@ int broadcaster_multiple(void) | |||||
int err; | ||||||
|
||||||
for (int index = 0; index < CONFIG_BT_EXT_ADV_MAX_ADV_SET; index++) { | ||||||
const struct bt_data *ad; | ||||||
size_t ad_size; | ||||||
|
||||||
/* Use advertising set instance index as SID */ | ||||||
adv_param.sid = index; | ||||||
|
||||||
/* Use Coded PHY */ | ||||||
if ((index % 4) == 3) { | ||||||
adv_param.options = BT_LE_ADV_OPT_EXT_ADV; | ||||||
adv_param.options |= BT_LE_ADV_OPT_CODED; | ||||||
ad = ad_long; | ||||||
ad_size = ARRAY_SIZE(ad_long); | ||||||
/* Use 1M auxiliary PDU */ | ||||||
} else if ((index % 4) == 2) { | ||||||
adv_param.options = BT_LE_ADV_OPT_EXT_ADV; | ||||||
adv_param.options |= BT_LE_ADV_OPT_NO_2M; | ||||||
ad = ad_long; | ||||||
ad_size = ARRAY_SIZE(ad_long); | ||||||
/* Use 2M auxiliary PDU */ | ||||||
} else if ((index % 4) == 1) { | ||||||
adv_param.options = BT_LE_ADV_OPT_EXT_ADV; | ||||||
ad = ad_long; | ||||||
ad_size = ARRAY_SIZE(ad_long); | ||||||
/* Use 1M legacy PDU */ | ||||||
} else { | ||||||
adv_param.options = BT_LE_ADV_OPT_NONE; | ||||||
ad = ad_short; | ||||||
ad_size = ARRAY_SIZE(ad_short); | ||||||
} | ||||||
Comment on lines
+91
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider moving this into a Also consider storing this in an array like struct {
uint32_t options;
const struct bt_data *ad;
size_t ad_size
} adv_params[4]; So you can do things like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using an array is a better implementation, will update the PR. |
||||||
|
||||||
ext_adv_create_retry: | ||||||
/* Create a non-connectable advertising set */ | ||||||
err = bt_le_ext_adv_create(&adv_param, NULL, &adv[index]); | ||||||
if (err) { | ||||||
printk("Failed to create advertising set %d (err %d)\n", | ||||||
index, err); | ||||||
/* Failed creating Coded PHY advertising set? */ | ||||||
if (adv_param.options & BT_LE_ADV_OPT_CODED) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
printk("Failed to create advertising set %d with Coded PHY " | ||||||
"(err %d), retry without...\n", index, err); | ||||||
/* Retry with non-Coded PHY advertising set */ | ||||||
adv_param.options &= ~BT_LE_ADV_OPT_CODED; | ||||||
|
||||||
goto ext_adv_create_retry; | ||||||
} | ||||||
|
||||||
printk("Failed to create advertising set %d (err %d)\n", index, err); | ||||||
return err; | ||||||
} | ||||||
|
||||||
/* Set extended advertising data */ | ||||||
err = bt_le_ext_adv_set_data(adv[index], ad, ARRAY_SIZE(ad), | ||||||
NULL, 0); | ||||||
err = bt_le_ext_adv_set_data(adv[index], ad, ad_size, NULL, 0); | ||||||
if (err) { | ||||||
printk("Failed to set advertising data for set %d " | ||||||
"(err %d)\n", index, err); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the changes to this file also be applied to the other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two added where the Kconfig defaults already... but made sense to have it here to be similar to one used for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jhedberg Currently, the Controller specific is commented for this sample, do you agree that this be moved to a overlay and sample document/readme updated according to indicate the same, right?