Skip to content

Commit 4280720

Browse files
committed
samples: bluetooth: Update cs ras sample to trigger procedures one by one
This means procedures will be triggered more often by default and makes it easier to manage different ranging counters. Signed-off-by: Sean Madigan <[email protected]>
1 parent 619d8c1 commit 4280720

File tree

1 file changed

+16
-19
lines changed
  • samples/bluetooth/channel_sounding_ras_initiator/src

1 file changed

+16
-19
lines changed

samples/bluetooth/channel_sounding_ras_initiator/src/main.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,11 @@ NET_BUF_SIMPLE_DEFINE_STATIC(latest_peer_steps, BT_RAS_PROCEDURE_MEM);
5151
static int32_t most_recent_peer_ranging_counter = PROCEDURE_COUNTER_NONE;
5252
static int32_t most_recent_local_ranging_counter = PROCEDURE_COUNTER_NONE;
5353
static int32_t dropped_ranging_counter = PROCEDURE_COUNTER_NONE;
54-
static bool distance_estimation_in_progress;
5554

5655
static void subevent_result_cb(struct bt_conn *conn, struct bt_conn_le_cs_subevent_result *result)
5756
{
5857
LOG_INF("Subevent result callback %d", result->header.procedure_counter);
5958

60-
if (distance_estimation_in_progress) {
61-
LOG_WRN("New procedure data received whilst estimating previous distance, drop "
62-
"this procedure.");
63-
dropped_ranging_counter = result->header.procedure_counter;
64-
return;
65-
}
66-
6759
if (result->header.subevent_done_status == BT_CONN_LE_CS_SUBEVENT_ABORTED) {
6860
/* If this subevent was aborted, drop the entire procedure for now. */
6961
LOG_WRN("Subevent aborted");
@@ -97,7 +89,6 @@ static void subevent_result_cb(struct bt_conn *conn, struct bt_conn_le_cs_subeve
9789

9890
if (result->header.procedure_done_status == BT_CONN_LE_CS_PROCEDURE_COMPLETE) {
9991
most_recent_local_ranging_counter = result->header.procedure_counter;
100-
distance_estimation_in_progress = true;
10192
k_sem_give(&sem_procedure_done);
10293
} else if (result->header.procedure_done_status == BT_CONN_LE_CS_PROCEDURE_ABORTED) {
10394
LOG_WRN("Procedure aborted");
@@ -466,7 +457,7 @@ int main(void)
466457
.max_procedure_len = 100,
467458
.min_procedure_interval = 100,
468459
.max_procedure_interval = 100,
469-
.max_procedure_count = 0,
460+
.max_procedure_count = 1,
470461
.min_subevent_len = 60000,
471462
.max_subevent_len = 60000,
472463
.tone_antenna_config_selection = BT_LE_CS_TONE_ANTENNA_CONFIGURATION_INDEX_ONE,
@@ -488,15 +479,22 @@ int main(void)
488479
.enable = 1,
489480
};
490481

491-
err = bt_le_cs_procedure_enable(connection, &params);
492-
if (err) {
493-
LOG_ERR("Failed to enable CS procedures (err %d)", err);
494-
return 0;
495-
}
496-
497482
while (true) {
498-
k_sem_take(&sem_procedure_done, K_FOREVER);
499-
distance_estimation_in_progress = true;
483+
err = bt_le_cs_procedure_enable(connection, &params);
484+
if (err) {
485+
LOG_ERR("Failed to enable CS procedures (err %d)", err);
486+
return 0;
487+
}
488+
489+
err = k_sem_take(&sem_procedure_done, K_SECONDS(1));
490+
if (err) {
491+
LOG_WRN("Timeout waiting for local procedure done (err %d)", err);
492+
493+
/* Check if remote has rd ready to align counters. */
494+
k_sem_take(&sem_rd_ready, K_SECONDS(1));
495+
496+
goto retry;
497+
}
500498

501499
err = k_sem_take(&sem_rd_ready, K_SECONDS(1));
502500
if (err) {
@@ -531,7 +529,6 @@ int main(void)
531529
retry:
532530
net_buf_simple_reset(&latest_local_steps);
533531
net_buf_simple_reset(&latest_peer_steps);
534-
distance_estimation_in_progress = false;
535532
}
536533

537534
return 0;

0 commit comments

Comments
 (0)