From e7aee880e184536b2ce704b232276613157a2b38 Mon Sep 17 00:00:00 2001 From: Victor Chavez Date: Sat, 13 Apr 2024 01:47:50 +0200 Subject: [PATCH] updated tests --- samples/uptime/src/main.cpp | 3 +-- samples/uptime/src/uptime_service.cpp | 26 ++++++++++++++++---- samples/uptime/src/uptime_service.hpp | 19 +++----------- test/renode/uptime_central/src/discovery.cpp | 13 +++------- test/renode/uptime_central/src/main.cpp | 4 --- test/renode/uptime_test.robot | 20 +++++++++------ 6 files changed, 43 insertions(+), 42 deletions(-) diff --git a/samples/uptime/src/main.cpp b/samples/uptime/src/main.cpp index fba8c44..84fd0eb 100644 --- a/samples/uptime/src/main.cpp +++ b/samples/uptime/src/main.cpp @@ -14,8 +14,8 @@ #include "ble.hpp" #include -#include "uptime_service.hpp" #include +#include "uptime_service.hpp" LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL); uptime::Service uptime_service; @@ -29,7 +29,6 @@ int main(void) { const uint32_t uptime_ms = k_uptime_get_32(); uptime_service.update(uptime_ms/1000U); - LOG_INF("Uptime: %u", uptime_ms); k_sleep(K_MSEC(1000)); } return 0; diff --git a/samples/uptime/src/uptime_service.cpp b/samples/uptime/src/uptime_service.cpp index f76f3c5..293a83f 100644 --- a/samples/uptime/src/uptime_service.cpp +++ b/samples/uptime/src/uptime_service.cpp @@ -1,9 +1,8 @@ /*!***************************************************************** -* Copyright 2023, Victor Chavez +* Copyright 2023-2024, Victor Chavez * SPDX-License-Identifier: Apache-2.0 * @file uptime_service.cpp * @author Victor Chavez (chavez-bermudez@fh-aachen.de) -* @date 13.03.2023 * * @brief * BLE Service implementation @@ -12,9 +11,11 @@ * - language: C++17 * - OS: Zephyr v3.2.x ********************************************************************/ - +#include #include "uptime_service.hpp" +LOG_MODULE_REGISTER(uptime_svc, CONFIG_LOG_DEFAULT_LEVEL); + namespace uptime { @@ -50,20 +51,35 @@ Notify::Notify(): { } +void Notify::ccc_changed(CCCValue_e value) +{ + int val = static_cast(value); + LOG_INF("Characteristic Notify Uptime CCC changed %d\n",val); +} + Indicate::Indicate(): ble_utils::gatt::CharacteristicIndicate((const bt_uuid*)&uuid::char_indicate) { } +void Indicate::ccc_changed(CCCValue_e value) +{ + int val = static_cast(value); + LOG_INF("Characteristic Indicate Uptime CCC changed %d\n",val); +} +void Indicate::indicate_rsp() +{ + LOG_INF("Characteristic Indicate Uptime Completed\n"); +} + } // namespace characteristic Service::Service(): ble_utils::gatt::Service((const bt_uuid*)&uuid::svc_base) { register_char(&m_basic); - register_char(&m_indicate); - register_char(&m_notify); + register_char(&m_notify); } void Service::update(uint32_t uptime) diff --git a/samples/uptime/src/uptime_service.hpp b/samples/uptime/src/uptime_service.hpp index d8c84ff..acd084d 100644 --- a/samples/uptime/src/uptime_service.hpp +++ b/samples/uptime/src/uptime_service.hpp @@ -16,6 +16,7 @@ #include #include + namespace uptime { @@ -50,11 +51,7 @@ class Notify final: public ble_utils::gatt::CharacteristicNotify public: Notify(); private: - void ccc_changed(CCCValue_e value) override - { - int val = static_cast(value); - printk("Characteristic Notify Uptime CCC changed %d\n",val); - } + void ccc_changed(CCCValue_e value) override; }; class Indicate final: public ble_utils::gatt::CharacteristicIndicate @@ -62,16 +59,8 @@ class Indicate final: public ble_utils::gatt::CharacteristicIndicate public: Indicate(); private: - void ccc_changed(CCCValue_e value) override - { - int val = static_cast(value); - printk("Characteristic Indicate Uptime CCC changed %d\n",val); - } - void indicate_rsp() override - { - printk("Characteristic Indicate Uptime Completed\n"); - } - + void ccc_changed(CCCValue_e value) override; + void indicate_rsp(); }; } diff --git a/test/renode/uptime_central/src/discovery.cpp b/test/renode/uptime_central/src/discovery.cpp index 544902b..6752e87 100644 --- a/test/renode/uptime_central/src/discovery.cpp +++ b/test/renode/uptime_central/src/discovery.cpp @@ -57,13 +57,12 @@ static uint8_t uptime_notify_cb(bt_conn *conn, bt_gatt_subscribe_params *params, const void *data, uint16_t length) { - LOG_INF("Notification cb"); if (conn == NULL) { return BT_GATT_ITER_CONTINUE; } if (!data) { - LOG_INF("[UNSUBSCRIBED]"); + LOG_INF("Unsubscribed"); params->value_handle = 0U; return BT_GATT_ITER_CONTINUE; } @@ -117,7 +116,7 @@ static uint8_t service_discover_cb(bt_conn *conn, device_char_cnt = 0; discover_characteristics(conn, attr, device_char_cnt); } else if(char_found) { - LOG_INF("attr handle %u",attr->handle); + LOG_INF("Chrc %d/%d found",device_char_cnt+1,TOTAL_CHARACTERISTICS); if (bt_uuid_cmp(params->uuid, &uptime::uuid::char_notify.uuid) == 0) { // Subscribe to uptime notification @@ -129,15 +128,13 @@ static uint8_t service_discover_cb(bt_conn *conn, if (err != 0 && err != -EALREADY) { LOG_ERR("Subscribe failed (err %d)", err); } else { - LOG_INF("[SUBSCRIBED]"); + LOG_INF("Subscribed"); } return BT_GATT_ITER_STOP; } if (device_char_cnt == TOTAL_CHARACTERISTICS-1) { device_found = true; - LOG_INF("All Chars found"); } else if (device_char_cnt < TOTAL_CHARACTERISTICS) { - LOG_INF("Char found"); device_char_cnt++; discover_characteristics(conn, attr, device_char_cnt); } @@ -150,7 +147,6 @@ static uint8_t service_discover_cb(bt_conn *conn, static bool adv_data_cb(bt_data *data, void *user_data) { auto addr = static_cast(user_data); - int i; LOG_INF("Adv data type %u len %u", data->type, data->data_len); int err = bt_le_scan_stop(); if (err) { @@ -179,7 +175,7 @@ static bool adv_data_cb(bt_data *data, void *user_data) LOG_INF("AD malformed"); return true; } - for (i = 0; i < data->data_len; i += BT_UUID_SIZE_128) { + for (int i = 0; i < data->data_len; i += BT_UUID_SIZE_128) { int err; bt_uuid_128 adv_uuid ={ .uuid = { BT_UUID_TYPE_128 }}; @@ -255,7 +251,6 @@ static void find_main_service() static void connected(bt_conn *conn, uint8_t conn_err) { char addr[BT_ADDR_LE_STR_LEN]; - int err; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); diff --git a/test/renode/uptime_central/src/main.cpp b/test/renode/uptime_central/src/main.cpp index ad215d7..997f113 100644 --- a/test/renode/uptime_central/src/main.cpp +++ b/test/renode/uptime_central/src/main.cpp @@ -22,9 +22,5 @@ int main() LOG_ERR("Error starting scan,err %d",rc); return rc; } - while(1) { - LOG_INF("Sleeping"); - k_sleep(K_MSEC(10000)); - } return 0; } diff --git a/test/renode/uptime_test.robot b/test/renode/uptime_test.robot index 1f0ae76..6988786 100644 --- a/test/renode/uptime_test.robot +++ b/test/renode/uptime_test.robot @@ -45,10 +45,16 @@ Uptime Demo Start Emulation - Wait For Line On Uart Booting Zephyr testerId=${cen_uart} - 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 Connected testerId=${per_uart} - Wait For Line On Uart Connected testerId=${cen_uart} - Wait For Line On Uart All Chars Found testerId=${cen_uart} + Wait For Line On Uart Booting Zephyr testerId=${cen_uart} + 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 Connected testerId=${per_uart} + Wait For Line On Uart Characteristic Notify uptime CCC changed 1 testerId=${per_uart} + Wait For Line On Uart Connected testerId=${cen_uart} + Wait For Line On Uart Service found testerId=${cen_uart} + Wait For Line On Uart Chrc 3/3 found testerId=${cen_uart} + Wait For Line On Uart Subscribed testerId=${cen_uart} + Wait For Line On Uart Uptime value 1 testerId=${cen_uart} + Wait For Line On Uart Uptime value 2 testerId=${cen_uart} + Wait For Line On Uart Uptime value 3 testerId=${cen_uart} \ No newline at end of file