Bluetooth: samples: Use bt_gatt_find_by_uuid in peripheral sample

Demonstrate use of bt_gatt_find_by_uuid in peripheral sample. This
avoids the magical array index.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2021-06-22 13:52:18 +02:00 committed by Anas Nashif
commit 6eb7574076

View file

@ -326,6 +326,8 @@ static void hrs_notify(void)
void main(void) void main(void)
{ {
struct bt_gatt_attr *vnd_ind_attr;
char str[BT_UUID_STR_LEN];
int err; int err;
err = bt_enable(NULL); err = bt_enable(NULL);
@ -340,6 +342,11 @@ void main(void)
bt_conn_cb_register(&conn_callbacks); bt_conn_cb_register(&conn_callbacks);
bt_conn_auth_cb_register(&auth_cb_display); bt_conn_auth_cb_register(&auth_cb_display);
vnd_ind_attr = bt_gatt_find_by_uuid(vnd_svc.attrs, vnd_svc.attr_count,
&vnd_enc_uuid.uuid);
bt_uuid_to_str(&vnd_enc_uuid.uuid, str, sizeof(str));
printk("Indicate VND attr %p (UUID %s)\n", vnd_ind_attr, str);
/* Implement notification. At the moment there is no suitable way /* Implement notification. At the moment there is no suitable way
* of starting delayed work so we do it here * of starting delayed work so we do it here
*/ */
@ -356,12 +363,12 @@ void main(void)
bas_notify(); bas_notify();
/* Vendor indication simulation */ /* Vendor indication simulation */
if (simulate_vnd) { if (simulate_vnd && vnd_ind_attr) {
if (indicating) { if (indicating) {
continue; continue;
} }
ind_params.attr = &vnd_svc.attrs[2]; ind_params.attr = vnd_ind_attr;
ind_params.func = indicate_cb; ind_params.func = indicate_cb;
ind_params.destroy = indicate_destroy; ind_params.destroy = indicate_destroy;
ind_params.data = &indicating; ind_params.data = &indicating;