2022-05-16 21:02:42 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022 Codecoup
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2024-05-20 19:40:04 +02:00
|
|
|
#include <zephyr/autoconf.h>
|
2022-05-16 21:02:42 +02:00
|
|
|
#include <zephyr/bluetooth/bluetooth.h>
|
|
|
|
#include <zephyr/bluetooth/hci.h>
|
|
|
|
#include <zephyr/bluetooth/conn.h>
|
|
|
|
#include <zephyr/bluetooth/uuid.h>
|
|
|
|
#include <zephyr/bluetooth/gatt.h>
|
|
|
|
#include <zephyr/bluetooth/services/ias.h>
|
2024-05-20 19:40:04 +02:00
|
|
|
#include <zephyr/sys/printk.h>
|
|
|
|
#include <zephyr/types.h>
|
2022-05-16 21:02:42 +02:00
|
|
|
|
2024-05-20 19:40:04 +02:00
|
|
|
#include "bstests.h"
|
2022-05-16 21:02:42 +02:00
|
|
|
#include "common.h"
|
|
|
|
|
2024-05-20 19:40:04 +02:00
|
|
|
#ifdef CONFIG_BT_IAS
|
2022-05-16 21:02:42 +02:00
|
|
|
extern enum bst_result_t bst_result;
|
|
|
|
|
|
|
|
CREATE_FLAG(g_high_alert_received);
|
|
|
|
CREATE_FLAG(g_mild_alert_received);
|
|
|
|
CREATE_FLAG(g_stop_alert_received);
|
|
|
|
|
|
|
|
static void high_alert_cb(void)
|
|
|
|
{
|
|
|
|
SET_FLAG(g_high_alert_received);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mild_alert_cb(void)
|
|
|
|
{
|
|
|
|
SET_FLAG(g_mild_alert_received);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void no_alert_cb(void)
|
|
|
|
{
|
|
|
|
SET_FLAG(g_stop_alert_received);
|
|
|
|
}
|
|
|
|
|
|
|
|
BT_IAS_CB_DEFINE(ias_callbacks) = {
|
|
|
|
.high_alert = high_alert_cb,
|
|
|
|
.mild_alert = mild_alert_cb,
|
|
|
|
.no_alert = no_alert_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_main(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = bt_enable(NULL);
|
|
|
|
if (err != 0) {
|
|
|
|
FAIL("Bluetooth init failed (err %d)\n", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-14 10:02:15 +02:00
|
|
|
err = bt_le_adv_start(BT_LE_ADV_CONN_FAST_1, ad, AD_SIZE, NULL, 0);
|
2022-05-16 21:02:42 +02:00
|
|
|
if (err) {
|
|
|
|
FAIL("Advertising failed to start (err %d)\n", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk("Advertising successfully started\n");
|
|
|
|
|
2023-03-08 14:48:13 +01:00
|
|
|
WAIT_FOR_FLAG(flag_connected);
|
2022-05-16 21:02:42 +02:00
|
|
|
|
|
|
|
WAIT_FOR_FLAG(g_high_alert_received);
|
|
|
|
printk("High alert received\n");
|
|
|
|
|
|
|
|
err = bt_ias_local_alert_stop();
|
2023-02-24 11:10:53 +01:00
|
|
|
if (err != 0) {
|
|
|
|
FAIL("Failed to locally stop alert: %d\n", err);
|
2022-05-16 21:02:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
WAIT_FOR_FLAG(g_stop_alert_received);
|
|
|
|
|
|
|
|
WAIT_FOR_FLAG(g_mild_alert_received);
|
|
|
|
printk("Mild alert received\n");
|
|
|
|
|
|
|
|
WAIT_FOR_FLAG(g_stop_alert_received);
|
|
|
|
printk("Stop alert received\n");
|
|
|
|
|
|
|
|
PASS("IAS test passed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct bst_test_instance test_ias[] = {
|
|
|
|
{
|
|
|
|
.test_id = "ias",
|
2024-05-27 14:33:05 +02:00
|
|
|
.test_pre_init_f = test_init,
|
2022-05-16 21:02:42 +02:00
|
|
|
.test_tick_f = test_tick,
|
|
|
|
.test_main_f = test_main,
|
|
|
|
|
|
|
|
},
|
|
|
|
BSTEST_END_MARKER
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bst_test_list *test_ias_install(struct bst_test_list *tests)
|
|
|
|
{
|
|
|
|
return bst_add_tests(tests, test_ias);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_BT_IAS */
|