Skip to content

Commit e8204e9

Browse files
bluetooth: services: Add Channel Sounding Distance Estimation library
First draft of a mini-toolkit for processing CS results. Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
1 parent b4fcfd1 commit e8204e9

File tree

10 files changed

+522
-428
lines changed

10 files changed

+522
-428
lines changed

include/bluetooth/cs_de.h

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef DE_H__
8+
#define DE_H__
9+
10+
#include <zephyr/bluetooth/conn.h>
11+
#include <zephyr/net_buf.h>
12+
13+
/**
14+
* @brief Container of IQ values for local and remote measured tones
15+
*/
16+
typedef struct {
17+
/** In-phase measurements of tones on this device */
18+
float i_local[80];
19+
/** Quadrature-phase measurement of tones on this device */
20+
float q_local[80];
21+
/** In-phase measurements of tones from remote device */
22+
float i_remote[80];
23+
/** Quadrature-phase measurements of tones from remote device */
24+
float q_remote[80];
25+
} cs_de_iq_tones_t;
26+
27+
typedef enum {
28+
CS_DE_TONE_QUALITY_OK,
29+
CS_DE_TONE_QUALITY_BAD,
30+
} cs_de_tone_quality_t;
31+
32+
typedef struct {
33+
/** Quality indicator for tones on this device */
34+
cs_de_tone_quality_t qi_local[80];
35+
/** Quality indicator for tones on peer device */
36+
cs_de_tone_quality_t qi_remote[80];
37+
} cs_de_quality_indicators_t;
38+
39+
/**
40+
* @brief Container of distance estimate results for a number of different
41+
* methods, in meters.
42+
*/
43+
typedef struct {
44+
/** Distance estimate based on IFFT of spectrum */
45+
float ifft;
46+
/** Distance estimate based on average phase slope estimation */
47+
float phase_slope;
48+
/** Best effort distance estimate.
49+
*
50+
* This is a convenience value which is automatically set to the most
51+
* accurate of the estimation methods.
52+
*/
53+
float best;
54+
} cs_de_dist_estimates_t;
55+
56+
/**
57+
* @brief Quality of the procedure
58+
*/
59+
typedef enum {
60+
CS_DE_QUALITY_OK,
61+
CS_DE_QUALITY_DO_NOT_USE,
62+
} cs_de_quality_t;
63+
64+
/**
65+
* @brief Output data for distance estimation
66+
*/
67+
typedef struct {
68+
/** IQ values for local and remote measured tones.
69+
*/
70+
cs_de_iq_tones_t iq_tones[CONFIG_BT_RAS_MAX_ANTENNA_PATHS];
71+
72+
/** Quality indicators for the tones in iq_tones[0] */
73+
cs_de_quality_indicators_t tone_quality_indicators[CONFIG_BT_RAS_MAX_ANTENNA_PATHS];
74+
75+
/** Distance estimate results */
76+
cs_de_dist_estimates_t distance_estimates;
77+
78+
/** Quality indicator */
79+
cs_de_quality_t quality;
80+
} cs_de_report_t;
81+
82+
/**
83+
* @brief Partially populate the report.
84+
* This populates the report but does not set the distance estimates and the quality.
85+
* @param[in] local_steps Buffer to the local step data to parse.
86+
* @param[in] peer_steps Buffer to the peer ranging data to parse.
87+
* @param[in] role Role of the local controller.
88+
* @param[out] p_report Report populated with the raw data from the last ranging.
89+
*/
90+
void cs_de_populate_report(struct net_buf_simple *local_steps, struct net_buf_simple *peer_steps,
91+
enum bt_conn_le_cs_role role, cs_de_report_t *p_report);
92+
93+
/* Takes partially poulated report and calculates distance estimates and quality. */
94+
cs_de_quality_t cs_de_calc(cs_de_report_t *p_report);
95+
96+
#endif /* DE_H__ */

samples/bluetooth/channel_sounding_ras_initiator/prj.conf

+3
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ CONFIG_FPU=y
5353
CONFIG_FPU_SHARING=y
5454

5555
CONFIG_CBPRINTF_FP_SUPPORT=y
56+
57+
CONFIG_BT_CS_DE=y
58+
CONFIG_BT_CS_DE_1024_NFFT=y

0 commit comments

Comments
 (0)