-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: bluetooth: Add Channel Sounding Reflector with RRSP sample
This sample can be used to set up a Channel Sounding Reflector with the GATT Ranging Responder service. A Channel Sounding Initiator with Ranging Requestor can connect to this sample to receive CS Ranging Data and perform distance estimation. Signed-off-by: Aleksandar Stanoev <[email protected]>
- Loading branch information
1 parent
4239811
commit b5d96ff
Showing
7 changed files
with
280 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
samples/bluetooth/channel_sounding_ras_reflector/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(channel_sounding_ras_reflector) | ||
|
||
# NORDIC SDK APP START | ||
target_sources(app PRIVATE | ||
src/main.c | ||
) | ||
# NORDIC SDK APP END |
81 changes: 81 additions & 0 deletions
81
samples/bluetooth/channel_sounding_ras_reflector/README.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
.. _channel_sounding_ras_reflector: | ||
|
||
Bluetooth: Channel Sounding Reflector with Ranging Responder | ||
############################################################ | ||
|
||
.. contents:: | ||
:local: | ||
:depth: 2 | ||
|
||
This sample demonstrates how to use the ranging service to provide ranging data to a client. | ||
|
||
Requirements | ||
************ | ||
|
||
The sample supports the following development kits: | ||
|
||
.. table-from-sample-yaml:: | ||
|
||
The sample also requires a device running a Channel Sounding Initiator with Ranging Requestor to connect to. | ||
|
||
Overview | ||
******** | ||
|
||
The sample demonstrates a basic Bluetooth® Low Energy Peripheral role functionality that exposes the GATT Ranging Responder Service and configures the Channel Sounding reflector role. | ||
When Channel Sounding Ranging Data is generated by the controller, it will be automatically stored by the Ranging Service, and can be queried at any time by the Ranging Requestor. | ||
The Channel Sounding Ranging Data can then be used by the peer device to perform distance estimation. | ||
|
||
User interface | ||
************** | ||
|
||
The sample does not require user input and will advertise using the GATT Ranging Service UUID. | ||
The first LED on the development kit will be lit when a connection has been established. | ||
|
||
Building and running | ||
******************** | ||
.. |sample path| replace:: :file:`samples/bluetooth/channel_sounding_ras_reflector` | ||
|
||
.. include:: /includes/build_and_run.txt | ||
|
||
Testing | ||
======= | ||
|
||
After programming the sample to your development kit, you can test it by connecting to another development kit with a Channel Sounding Initiator role with Ranging Requestor. | ||
|
||
1. |connect_terminal_specific| | ||
#. Reset the kit. | ||
#. Program the other kit with the Channel Sounding Initiator with Ranging Requestor sample. | ||
#. Wait until the advertiser is detected by the Central. | ||
In the terminal window, check for information similar to the following:: | ||
|
||
I: Connected to xx.xx.xx.xx.xx.xx (random) (err 0x00) | ||
I: CS capability exchange completed. | ||
I: CS config creation complete. ID: 0 | ||
I: CS security enabled. | ||
I: CS procedures enabled. | ||
|
||
Dependencies | ||
************ | ||
|
||
This sample uses the following |NCS| libraries: | ||
|
||
* :ref:`dk_buttons_and_leds_readme` | ||
* :file:`include/bluetooth/services/ras.h` | ||
|
||
This sample uses the following Zephyr libraries: | ||
|
||
* :ref:`zephyr:logging_api`: | ||
|
||
* :file:`include/logging/log.h` | ||
|
||
* :file:`include/zephyr/types.h` | ||
* :ref:`zephyr:kernel_api`: | ||
|
||
* :file:`include/kernel.h` | ||
|
||
* :ref:`zephyr:bluetooth_api`: | ||
|
||
* :file:`include/bluetooth/bluetooth.h` | ||
* :file:`include/bluetooth/conn.h` | ||
* :file:`include/bluetooth/uuid.h` | ||
* :file:`include/bluetooth/cs.h` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
CONFIG_NCS_SAMPLES_DEFAULTS=y | ||
CONFIG_DK_LIBRARY=y | ||
|
||
CONFIG_BT=y | ||
CONFIG_BT_PERIPHERAL=y | ||
CONFIG_BT_SMP=y | ||
CONFIG_BT_DEVICE_NAME="Nordic CS Reflector" | ||
CONFIG_BT_MAX_CONN=1 | ||
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n | ||
CONFIG_BT_BONDABLE=n | ||
|
||
# The Ranging Profile recommends a MTU of at least 247 octets. | ||
CONFIG_BT_L2CAP_TX_MTU=498 | ||
CONFIG_BT_BUF_ACL_TX_SIZE=502 | ||
CONFIG_BT_BUF_ACL_RX_SIZE=502 | ||
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 | ||
CONFIG_BT_CTLR_PHY_2M=y | ||
|
||
CONFIG_BT_CHANNEL_SOUNDING=y | ||
CONFIG_BT_RAS=y | ||
CONFIG_BT_RAS_RRSP=y |
12 changes: 12 additions & 0 deletions
12
samples/bluetooth/channel_sounding_ras_reflector/sample.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
sample: | ||
description: Bluetooth Low Energy Channel Sounding Reflector with Ranging Service Responder | ||
name: Bluetooth LE Channel Sounding Reflector with RRSP | ||
tests: | ||
sample.bluetooth.channel_sounding_ras_reflector: | ||
sysbuild: true | ||
build_only: true | ||
integration_platforms: | ||
- nrf54l15dk/nrf54l15/cpuapp | ||
platform_allow: | ||
- nrf54l15dk/nrf54l15/cpuapp | ||
tags: bluetooth ci_build sysbuild |
141 changes: 141 additions & 0 deletions
141
samples/bluetooth/channel_sounding_ras_reflector/src/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
/** @file | ||
* @brief Channel Sounding Reflector with Ranging Responder sample | ||
*/ | ||
|
||
#include <zephyr/types.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/bluetooth/bluetooth.h> | ||
#include <zephyr/bluetooth/conn.h> | ||
#include <zephyr/bluetooth/uuid.h> | ||
#include <zephyr/bluetooth/cs.h> | ||
#include <bluetooth/services/ras.h> | ||
|
||
#include <dk_buttons_and_leds.h> | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(app_main, LOG_LEVEL_INF); | ||
|
||
#define CON_STATUS_LED DK_LED1 | ||
|
||
static K_SEM_DEFINE(sem_connected, 0, 1); | ||
|
||
static struct bt_conn *connection; | ||
|
||
static const struct bt_data ad[] = { | ||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), | ||
BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_RANGING_SERVICE_VAL)), | ||
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), | ||
}; | ||
|
||
static void connected_cb(struct bt_conn *conn, uint8_t err) | ||
{ | ||
char addr[BT_ADDR_LE_STR_LEN]; | ||
|
||
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); | ||
LOG_INF("Connected to %s (err 0x%02X)", addr, err); | ||
|
||
if (err) { | ||
bt_conn_unref(conn); | ||
connection = NULL; | ||
} | ||
|
||
connection = bt_conn_ref(conn); | ||
|
||
k_sem_give(&sem_connected); | ||
|
||
dk_set_led_on(CON_STATUS_LED); | ||
} | ||
|
||
static void disconnected_cb(struct bt_conn *conn, uint8_t reason) | ||
{ | ||
LOG_INF("Disconnected (reason 0x%02X)", reason); | ||
|
||
bt_conn_unref(conn); | ||
connection = NULL; | ||
|
||
dk_set_led_off(CON_STATUS_LED); | ||
} | ||
|
||
static void remote_capabilities_cb(struct bt_conn *conn, struct bt_conn_le_cs_capabilities *params) | ||
{ | ||
ARG_UNUSED(conn); | ||
ARG_UNUSED(params); | ||
LOG_INF("CS capability exchange completed."); | ||
} | ||
|
||
static void config_created_cb(struct bt_conn *conn, struct bt_conn_le_cs_config *config) | ||
{ | ||
ARG_UNUSED(conn); | ||
LOG_INF("CS config creation complete. ID: %d", config->id); | ||
} | ||
|
||
static void security_enabled_cb(struct bt_conn *conn) | ||
{ | ||
ARG_UNUSED(conn); | ||
LOG_INF("CS security enabled."); | ||
} | ||
|
||
static void procedure_enabled_cb(struct bt_conn *conn, | ||
struct bt_conn_le_cs_procedure_enable_complete *params) | ||
{ | ||
ARG_UNUSED(conn); | ||
if (params->state == 1) { | ||
LOG_INF("CS procedures enabled."); | ||
} else { | ||
LOG_INF("CS procedures disabled."); | ||
} | ||
} | ||
|
||
BT_CONN_CB_DEFINE(conn_cb) = { | ||
.connected = connected_cb, | ||
.disconnected = disconnected_cb, | ||
.le_cs_remote_capabilities_available = remote_capabilities_cb, | ||
.le_cs_config_created = config_created_cb, | ||
.le_cs_security_enabled = security_enabled_cb, | ||
.le_cs_procedure_enabled = procedure_enabled_cb, | ||
}; | ||
|
||
int main(void) | ||
{ | ||
int err; | ||
|
||
LOG_INF("Starting Channel Sounding Reflector Sample"); | ||
|
||
dk_leds_init(); | ||
|
||
err = bt_enable(NULL); | ||
if (err) { | ||
LOG_ERR("Bluetooth init failed (err %d)", err); | ||
return 0; | ||
} | ||
|
||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0); | ||
if (err) { | ||
LOG_ERR("Advertising failed to start (err %d)", err); | ||
return 0; | ||
} | ||
|
||
while (true) { | ||
k_sem_take(&sem_connected, K_FOREVER); | ||
|
||
const struct bt_le_cs_set_default_settings_param default_settings = { | ||
.enable_initiator_role = false, | ||
.enable_reflector_role = true, | ||
.cs_sync_antenna_selection = BT_LE_CS_ANTENNA_SELECTION_OPT_REPETITIVE, | ||
.max_tx_power = BT_HCI_OP_LE_CS_MAX_MAX_TX_POWER, | ||
}; | ||
|
||
err = bt_le_cs_set_default_settings(connection, &default_settings); | ||
if (err) { | ||
LOG_ERR("Failed to configure default CS settings (err %d)", err); | ||
} | ||
} | ||
|
||
return 0; | ||
} |