From 720bdd126eec75c422c1b2fd6817ec1d3be23914 Mon Sep 17 00:00:00 2001 From: Olivier Lesage Date: Fri, 15 Aug 2025 12:44:09 +0200 Subject: [PATCH 1/3] samples: handle failure to connect in RAS samples Handle errors while connecting more gracefully. Signed-off-by: Olivier Lesage --- .../channel_sounding_ras_initiator/src/main.c | 10 +++++----- .../channel_sounding_ras_reflector/src/main.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/bluetooth/channel_sounding_ras_initiator/src/main.c b/samples/bluetooth/channel_sounding_ras_initiator/src/main.c index f38089260e24..aa4177f4e75e 100644 --- a/samples/bluetooth/channel_sounding_ras_initiator/src/main.c +++ b/samples/bluetooth/channel_sounding_ras_initiator/src/main.c @@ -347,13 +347,13 @@ static void connected_cb(struct bt_conn *conn, uint8_t err) if (err) { bt_conn_unref(conn); connection = NULL; - } - - connection = bt_conn_ref(conn); + } else { + connection = bt_conn_ref(conn); - k_sem_give(&sem_connected); + k_sem_give(&sem_connected); - dk_set_led_on(CON_STATUS_LED); + dk_set_led_on(CON_STATUS_LED); + } } static void disconnected_cb(struct bt_conn *conn, uint8_t reason) diff --git a/samples/bluetooth/channel_sounding_ras_reflector/src/main.c b/samples/bluetooth/channel_sounding_ras_reflector/src/main.c index 3f74945a1dd0..87906c4933a4 100644 --- a/samples/bluetooth/channel_sounding_ras_reflector/src/main.c +++ b/samples/bluetooth/channel_sounding_ras_reflector/src/main.c @@ -44,13 +44,13 @@ static void connected_cb(struct bt_conn *conn, uint8_t err) if (err) { bt_conn_unref(conn); connection = NULL; - } - - connection = bt_conn_ref(conn); + } else { + connection = bt_conn_ref(conn); - k_sem_give(&sem_connected); + k_sem_give(&sem_connected); - dk_set_led_on(CON_STATUS_LED); + dk_set_led_on(CON_STATUS_LED); + } } static void disconnected_cb(struct bt_conn *conn, uint8_t reason) From 34803fc2e949b4aed69e4c332b655c11c0cb401e Mon Sep 17 00:00:00 2001 From: Olivier Lesage Date: Mon, 18 Aug 2025 09:56:48 +0200 Subject: [PATCH 2/3] samples: clarify printout for distance estimates There was some confusion about what these printouts are. It's the latest measurements, so event if no new measurements have been made, the sample will continue printing out the old estimates. Signed-off-by: Olivier Lesage --- samples/bluetooth/channel_sounding_ras_initiator/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/bluetooth/channel_sounding_ras_initiator/src/main.c b/samples/bluetooth/channel_sounding_ras_initiator/src/main.c index aa4177f4e75e..4940bad88dee 100644 --- a/samples/bluetooth/channel_sounding_ras_initiator/src/main.c +++ b/samples/bluetooth/channel_sounding_ras_initiator/src/main.c @@ -710,8 +710,8 @@ int main(void) for (uint8_t ap = 0; ap < MAX_AP; ap++) { cs_de_dist_estimates_t distance_on_ap = get_distance(ap); - LOG_INF("Distance estimates on antenna path %u: ifft: %f, " - "phase_slope: %f, rtt: %f", + LOG_INF("Latest distance estimates on antenna path %u: ifft: %f, " + "phase_slope: %f, rtt: %f meters", ap, (double)distance_on_ap.ifft, (double)distance_on_ap.phase_slope, (double)distance_on_ap.rtt); From 1289b5ca6b647d29d82bb190624cc4c21a072e13 Mon Sep 17 00:00:00 2001 From: Olivier Lesage Date: Fri, 15 Aug 2025 12:47:21 +0200 Subject: [PATCH 3/3] samples: improve handling for the case where all subevents are aborted In case every subevent in the CS procedure was aborted, it would happen that the sample would try to parse the local steps anyway. An error message was printed in this case as there were no local steps to parse. Signed-off-by: Olivier Lesage --- .../channel_sounding_ras_initiator/src/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/samples/bluetooth/channel_sounding_ras_initiator/src/main.c b/samples/bluetooth/channel_sounding_ras_initiator/src/main.c index 4940bad88dee..6c6fdcd024d0 100644 --- a/samples/bluetooth/channel_sounding_ras_initiator/src/main.c +++ b/samples/bluetooth/channel_sounding_ras_initiator/src/main.c @@ -165,6 +165,18 @@ static void ranging_data_cb(struct bt_conn *conn, uint16_t ranging_counter, int LOG_DBG("Ranging data received for ranging counter %d", ranging_counter); + if (latest_local_steps.len == 0) { + LOG_WRN("All subevents in ranging counter %u were aborted", + most_recent_local_ranging_counter); + net_buf_simple_reset(&latest_local_steps); + k_sem_give(&sem_local_steps); + + if (!(ras_feature_bits & RAS_FEAT_REALTIME_RD)) { + net_buf_simple_reset(&latest_peer_steps); + } + return; + } + /* This struct is static to avoid putting it on the stack (it's very large) */ static cs_de_report_t cs_de_report;