From 9025c432b862a4881431727bde37aecde68143d3 Mon Sep 17 00:00:00 2001 From: Victor Chavez Date: Sat, 13 Apr 2024 17:53:52 +0200 Subject: [PATCH] Fix adv data types Updated test to check that adv data is sent correctly --- include/ble_utils/uuid.hpp | 2 +- samples/uptime/src/ble.cpp | 6 +++++- tests/renode/ble_central/src/discovery.cpp | 4 ++-- tests/renode/uptime_test.robot | 7 +++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/ble_utils/uuid.hpp b/include/ble_utils/uuid.hpp index 410af4d..25910e2 100644 --- a/include/ble_utils/uuid.hpp +++ b/include/ble_utils/uuid.hpp @@ -67,7 +67,7 @@ static constexpr bt_uuid_128 uuid128_init(uint32_t w32,uint16_t w1,uint16_t w2,u const uint8_t b15 = static_cast(w32 >> 24 & 0xFF); bt_uuid_128 uuid { - .uuid = BT_UUID_TYPE_128, + .uuid = {.type = BT_UUID_TYPE_128}, .val = {b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15} }; return uuid; diff --git a/samples/uptime/src/ble.cpp b/samples/uptime/src/ble.cpp index e0cdfc4..c82642b 100644 --- a/samples/uptime/src/ble.cpp +++ b/samples/uptime/src/ble.cpp @@ -89,17 +89,21 @@ bool register_svc_to_scan_rsp(const bt_uuid *uuid) { uint8_t data_len; const uint8_t * p_data; + uint8_t adv_type; switch(uuid->type){ case BT_UUID_TYPE_16: data_len = 2; + adv_type = BT_DATA_UUID16_SOME; p_data = (const uint8_t *)&((bt_uuid_16 *)uuid)->val; break; case BT_UUID_TYPE_32: data_len = 4; + adv_type = BT_DATA_UUID32_SOME; p_data = (const uint8_t *)&((bt_uuid_32 *)uuid)->val; break; case BT_UUID_TYPE_128: data_len = 16; + adv_type = BT_DATA_UUID128_SOME; p_data = (const uint8_t *)&((bt_uuid_128 *)uuid)->val[0]; break; default: @@ -108,7 +112,7 @@ bool register_svc_to_scan_rsp(const bt_uuid *uuid) if (sd_cnt < MAX_SD_SIZE) { bt_data data = {. - type = uuid->type, + type = adv_type, .data_len = data_len, .data = p_data }; diff --git a/tests/renode/ble_central/src/discovery.cpp b/tests/renode/ble_central/src/discovery.cpp index 7e1dad2..de41d98 100644 --- a/tests/renode/ble_central/src/discovery.cpp +++ b/tests/renode/ble_central/src/discovery.cpp @@ -193,9 +193,9 @@ static void device_found_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, //LOG_INF("[DEVICE]: %s, AD evt type %u, AD data len %u, RSSI %i", // dev, type, ad->len, rssi); - /* We're only interested in connectable events */ if (type == BT_GAP_ADV_TYPE_ADV_IND || - type == BT_GAP_ADV_TYPE_ADV_DIRECT_IND) { + type == BT_GAP_ADV_TYPE_ADV_DIRECT_IND || + type == BT_GAP_ADV_TYPE_SCAN_RSP) { bt_data_parse(ad, adv_data_cb, (void *)addr); } } diff --git a/tests/renode/uptime_test.robot b/tests/renode/uptime_test.robot index c958b60..b07c1f3 100644 --- a/tests/renode/uptime_test.robot +++ b/tests/renode/uptime_test.robot @@ -1,5 +1,7 @@ -*** Copyright (c) 2024, Victor Chavez *** -*** SPDX-License-Identifier: Apache-2.0 *** +*** Comments *** +Copyright (c) 2024, Victor Chavez +SPDX-License-Identifier: Apache-2.0 + *** Variables *** ${UART} sysbus.uart0 @@ -51,6 +53,7 @@ Uptime Demo Wait For Line On Uart Booting Zephyr testerId=${per_uart} Wait For Line On Uart Scanning successfully started testerId=${cen_uart} Wait For Line On Uart Bluetooth initialized testerId=${per_uart} + Wait For Line On Uart Matched Uptime adv. UUID testerId=${cen_uart} Wait For Line On Uart Connected testerId=${per_uart} Wait For Line On Uart Connected testerId=${cen_uart} Wait For Line On Uart Service found testerId=${cen_uart}