Skip to content

Commit 9c4d837

Browse files
eriksandgrenhermabe
authored andcommitted
bluetooth: cs_de: Set tone quality ok for unused channels
This fixes an issue where the quality on the unused channels counted towards the number of channels with bad quality. Signed-off-by: Erik Sandgren <[email protected]>
1 parent 0b0b54f commit 9c4d837

File tree

3 files changed

+15
-13
lines changed
  • include/bluetooth
  • samples/bluetooth/channel_sounding_ras_initiator/src
  • subsys/bluetooth/cs_de

3 files changed

+15
-13
lines changed

include/bluetooth/cs_de.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ typedef struct {
9595
* @brief Partially populate the report.
9696
* This populates the report but does not set the distance estimates and the quality.
9797
* @param[in] local_steps Buffer to the local step data to parse.
98-
* @param[in] peer_steps Buffer to the peer ranging data to parse.
99-
* @param[in] role Role of the local controller.
98+
* @param[in] peer_steps Buffer to the peer ranging data to parse.
99+
* @param[in] config CS config of the local controller.
100100
* @param[out] p_report Report populated with the raw data from the last ranging.
101101
*/
102102
void cs_de_populate_report(struct net_buf_simple *local_steps, struct net_buf_simple *peer_steps,
103-
enum bt_conn_le_cs_role role, cs_de_report_t *p_report);
103+
struct bt_conn_le_cs_config *config, cs_de_report_t *p_report);
104104

105105
/* Takes partially populated report and calculates distance estimates and quality. */
106106
cs_de_quality_t cs_de_calc(cs_de_report_t *p_report);

samples/bluetooth/channel_sounding_ras_initiator/src/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static uint32_t ras_feature_bits;
6060
static uint8_t buffer_index;
6161
static uint8_t buffer_num_valid;
6262
static cs_de_dist_estimates_t distance_estimate_buffer[MAX_AP][DE_SLIDING_WINDOW_SIZE];
63+
static struct bt_conn_le_cs_config cs_config;
6364

6465
static void store_distance_estimates(cs_de_report_t *p_report)
6566
{
@@ -180,8 +181,7 @@ static void ranging_data_cb(struct bt_conn *conn, uint16_t ranging_counter, int
180181
/* This struct is static to avoid putting it on the stack (it's very large) */
181182
static cs_de_report_t cs_de_report;
182183

183-
cs_de_populate_report(&latest_local_steps, &latest_peer_steps, BT_CONN_LE_CS_ROLE_INITIATOR,
184-
&cs_de_report);
184+
cs_de_populate_report(&latest_local_steps, &latest_peer_steps, &cs_config, &cs_de_report);
185185

186186
net_buf_simple_reset(&latest_local_steps);
187187

@@ -401,6 +401,7 @@ static void config_create_cb(struct bt_conn *conn,
401401
ARG_UNUSED(conn);
402402

403403
if (status == BT_HCI_ERR_SUCCESS) {
404+
cs_config = *config;
404405
LOG_INF("CS config creation complete. ID: %d", config->id);
405406
k_sem_give(&sem_config_created);
406407
} else {

subsys/bluetooth/cs_de/cs_de.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ static void calculate_dist_rtt(cs_de_report_t *p_report)
279279
}
280280
}
281281

282-
static bool m_is_tone_quality_bad(cs_de_tone_quality_t *p_tone_qi)
282+
static bool m_is_tone_quality_bad(cs_de_tone_quality_t *p_tone_qi, uint8_t channel_map[10])
283283
{
284284
uint8_t bad_tones_count = 0;
285-
286285
for (uint8_t i = 0; i < NUM_CHANNELS; ++i) {
287-
if (p_tone_qi[i] == CS_DE_TONE_QUALITY_BAD) {
286+
if (BT_LE_CS_CHANNEL_BIT_GET(channel_map, i + CHANNEL_INDEX_OFFSET) &&
287+
p_tone_qi[i] == CS_DE_TONE_QUALITY_BAD) {
288288
bad_tones_count += 1;
289289
}
290290
}
@@ -422,25 +422,26 @@ static bool process_step_data(struct bt_le_cs_subevent_step *local_step,
422422
}
423423

424424
void cs_de_populate_report(struct net_buf_simple *local_steps, struct net_buf_simple *peer_steps,
425-
enum bt_conn_le_cs_role role, cs_de_report_t *p_report)
425+
struct bt_conn_le_cs_config *config, cs_de_report_t *p_report)
426426
{
427427
memset(p_report, 0x0, sizeof(*p_report));
428428
memset(m_n_iqs, 0, sizeof(m_n_iqs));
429429
memset(m_tone_quality_indicators, CS_DE_TONE_QUALITY_BAD,
430430
sizeof(m_tone_quality_indicators));
431431

432-
p_report->role = role;
432+
p_report->role = config->role;
433433

434-
bt_ras_rreq_rd_subevent_data_parse(peer_steps, local_steps, role, process_ranging_header,
435-
NULL, process_step_data, p_report);
434+
bt_ras_rreq_rd_subevent_data_parse(peer_steps, local_steps, config->role,
435+
process_ranging_header, NULL, process_step_data,
436+
p_report);
436437

437438
for (uint8_t ap = 0; ap < p_report->n_ap; ap++) {
438439
p_report->distance_estimates[ap].ifft = NAN;
439440
p_report->distance_estimates[ap].phase_slope = NAN;
440441
p_report->distance_estimates[ap].rtt = NAN;
441442
p_report->distance_estimates[ap].best = NAN;
442443

443-
if (m_is_tone_quality_bad(&m_tone_quality_indicators[ap][0])) {
444+
if (m_is_tone_quality_bad(&m_tone_quality_indicators[ap][0], config->channel_map)) {
444445
p_report->tone_quality[ap] = CS_DE_TONE_QUALITY_BAD;
445446
} else {
446447
p_report->tone_quality[ap] = CS_DE_TONE_QUALITY_OK;

0 commit comments

Comments
 (0)