Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vChavezB committed Apr 12, 2024
1 parent de82d89 commit e7aee88
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
3 changes: 1 addition & 2 deletions samples/uptime/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "ble.hpp"
#include <zephyr/kernel.h>
#include "uptime_service.hpp"
#include <zephyr/logging/log.h>
#include "uptime_service.hpp"
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);

uptime::Service uptime_service;
Expand All @@ -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;
Expand Down
26 changes: 21 additions & 5 deletions samples/uptime/src/uptime_service.cpp
Original file line number Diff line number Diff line change
@@ -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 ([email protected])
* @date 13.03.2023
*
* @brief
* BLE Service implementation
Expand All @@ -12,9 +11,11 @@
* - language: C++17
* - OS: Zephyr v3.2.x
********************************************************************/

#include <zephyr/logging/log.h>
#include "uptime_service.hpp"

LOG_MODULE_REGISTER(uptime_svc, CONFIG_LOG_DEFAULT_LEVEL);

namespace uptime
{

Expand Down Expand Up @@ -50,20 +51,35 @@ Notify::Notify():
{
}

void Notify::ccc_changed(CCCValue_e value)
{
int val = static_cast<int>(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<int>(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)
Expand Down
19 changes: 4 additions & 15 deletions samples/uptime/src/uptime_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <ble_utils/ble_utils.hpp>
#include <ble_utils/uuid.hpp>


namespace uptime
{

Expand Down Expand Up @@ -50,28 +51,16 @@ class Notify final: public ble_utils::gatt::CharacteristicNotify
public:
Notify();
private:
void ccc_changed(CCCValue_e value) override
{
int val = static_cast<int>(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
{
public:
Indicate();
private:
void ccc_changed(CCCValue_e value) override
{
int val = static_cast<int>(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();
};

}
Expand Down
13 changes: 4 additions & 9 deletions test/renode/uptime_central/src/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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<bt_addr_le_t*>(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) {
Expand Down Expand Up @@ -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 }};
Expand Down Expand Up @@ -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));

Expand Down
4 changes: 0 additions & 4 deletions test/renode/uptime_central/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
20 changes: 13 additions & 7 deletions test/renode/uptime_test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit e7aee88

Please sign in to comment.