I am trying to connect to two reflectors and sound only from 1 device so far the connection and soundnig works well for first set of connection and after a disconnectio, the device which got connected the first will always suffer a problem with the stepmode, both the reflectoirs are running on same firmware and I tried changing the connection sequence to see if it was hardware problem, but the behaviour persists with the first connected device
I found the issue, and I can sound, but the device has problems like this.
W: Mismatch of local and peer step mode 1 != 2
E: empty step data
E: empty step data
I use a different Config ID for both of the devices.
Some logs are posted below
I: Filters matched. Address: F9:B1:53:59:F9:F5 (random) connectable: 1
New Device F9:B1:53:59:F9:F5 (random) connected, total connected: 1
I: Unfiltered scan started with NUS and RAS filters
I: Pairing completed: F9:B1:53:59:F9:F5 (random), bonded: 0
I: Security changed: F9:B1:53:59:F9:F5 (random) level 2
I: MTU exchange success (498)
I: Service discovery completed for NUS
I: Service discovery completed for RAS
I: Read RAS feature bits: 0x1
I: CS capability exchange completed.
I: CS config creation complete. ID: 0
I: CS security enabled. CS device count changed to 1
I: CS procedures enabled:
- config ID: 0
- antenna configuration index: 0
- TX power: 0 dbm
- subevent length: 28198 us
- subevents per event: 1
- subevent interval: 0
- event interval: 2
- procedure interval: 5
- procedure count: 0
- maximum procedure length: 1000
Data from Reflector 1
I: nan,3.761549,1.847759
I: Filters matched. Address: F3:75:57:CA:A5:3A (random) connectable: 1
New Device F3:75:57:CA:A5:3A (random) connected, total connected: 2
I: Pairing completed: F3:75:57:CA:A5:3A (random), bonded: 0
I: Security changed: F3:75:57:CA:A5:3A (random) level 2
I: MTU exchange success (498)
I: Service discovery completed for NUS
I: Service discovery completed for RAS
I: Read RAS feature bits: 0x1
I: CS capability exchange completed.
I: CS config creation complete. ID: 1
I: CS security enabled. CS device count changed to 2
I: 1.299335,2.228551,2.519953
I: Disabling the CS procedure
I: Enabling the CS procedure
I: Sounding to device 1
E: empty step data
I: CS procedures disabled.
I: CS procedures enabled:
- config ID: 1
- antenna configuration index: 0
- TX power: 0 dbm
- subevent length: 28198 us
- subevents per event: 1
- subevent interval: 0
- event interval: 2
- procedure interval: 5
- procedure count: 0
- maximum procedure length: 1000
I: 1.847552,2.685281,nan
I: Disabling the CS procedure
I: Enabling the CS procedure
I: Sounding to device 0
I: CS procedures disabled.
W: Mismatch of local and peer step mode 2 != 1
I: CS procedures enabled:
- config ID: 0
- antenna configuration index: 0
- TX power: 0 dbm
- subevent length: 28198 us
- subevents per event: 1
- subevent interval: 0
- event interval: 2
- procedure interval: 5
- procedure count: 0
- maximum procedure length: 1000
I: Ranging data dropped as peer ranging counter doesn't match local ranging data counter. (peer: 105, local: 104)
void switch_CS_device(void){
int err;
while (1) {
k_sleep(K_SECONDS(10));
if(cs_device_count > 1){
uint8_t old_device_index = node_index_val;
node_index_val = (node_index_val + 1) % 2;
struct bt_conn *new_conn = conn_contexts[node_index_val].conn;
struct bt_conn *old_conn = conn_contexts[old_device_index].conn;
// Disable old device with its config ID
struct bt_le_cs_procedure_enable_param disable_params = {
.config_id = old_device_index, // Use old device's config ID
.enable = BT_CONN_LE_CS_PROCEDURES_DISABLED,
};
err = bt_le_cs_procedure_enable(old_conn, &disable_params);
LOG_INF("Disabling the CS procedure");
if (err) {
LOG_ERR("Failed to disable CS procedures (err %d) for Device %d", err,node_index_val);
return;
}
most_recent_local_ranging_counter = PROCEDURE_COUNTER_NONE;
dropped_ranging_counter = PROCEDURE_COUNTER_NONE;
buffer_index = 0;
buffer_num_valid = 0;
// Reset step buffers
net_buf_simple_reset(&latest_local_steps);
net_buf_simple_reset(&latest_peer_steps);
// Clear distance estimate buffer
memset(distance_estimate_buffer, 0, sizeof(distance_estimate_buffer));
// Reset semaphores to clean state
k_sem_reset(&sem_local_steps);
k_sem_give(&sem_local_steps);
k_sem_take(&sem_cs_enable_disable,K_FOREVER);
LOG_INF("Waiting for complete CS shutdown...");
k_sleep(K_MSEC(500));
// Enable new device with its config ID
struct bt_le_cs_procedure_enable_param enable_params = {
.config_id = node_index_val, // Use new device's config ID
.enable = BT_CONN_LE_CS_PROCEDURES_ENABLED,
};
err = bt_le_cs_procedure_enable(new_conn, &enable_params);
LOG_INF("Enabling the CS procedure");
if (err) {
LOG_ERR("Failed to enable CS procedures (err %d) for Device %d", err,node_index_val);
return;
}
else{
LOG_INF("Sounding to device %d", node_index_val);
}
k_sem_take(&sem_cs_enable_disable,K_FOREVER);
}
}
}
void cs_init(struct bt_conn *conn){
int err;
const struct bt_le_cs_set_default_settings_param default_settings = {
.enable_initiator_role = true,
.enable_reflector_role = false,
.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(conn, &default_settings);
if (err) {
LOG_ERR("Failed to configure default CS settings (err %d)", err);
return;
}
err = bt_ras_rreq_read_features(conn, ras_features_read_cb);
if (err) {
LOG_ERR("Could not get RAS features from peer (err %d)", err);
return;
}
k_sem_take(&sem_ras_features, K_FOREVER);
const bool realtime_rd = ras_feature_bits & RAS_FEAT_REALTIME_RD;
if (realtime_rd) {
err = bt_ras_rreq_realtime_rd_subscribe(conn, &latest_peer_steps, ranging_data_cb);
if (err) {
LOG_ERR("RAS RREQ Real-time ranging data subscribe failed (err %d)", err);
return;
}
} else {
err = bt_ras_rreq_rd_overwritten_subscribe(conn, ranging_data_overwritten_cb);
if (err) {
LOG_ERR("RAS RREQ ranging data overwritten subscribe failed (err %d)", err);
return;
}
err = bt_ras_rreq_rd_ready_subscribe(conn, ranging_data_ready_cb);
if (err) {
LOG_ERR("RAS RREQ ranging data ready subscribe failed (err %d)", err);
return;
}
err = bt_ras_rreq_on_demand_rd_subscribe(conn);
if (err) {
LOG_ERR("RAS RREQ On-demand ranging data subscribe failed (err %d)", err);
return;
}
err = bt_ras_rreq_cp_subscribe(conn);
if (err) {
LOG_ERR("RAS RREQ CP subscribe failed (err %d)", err);
return;
}
}
err = bt_le_cs_read_remote_supported_capabilities(conn);
if (err) {
LOG_ERR("Failed to exchange CS capabilities (err %d)", err);
return;
}
k_sem_take(&sem_remote_capabilities_obtained, K_FOREVER);
struct bt_le_cs_create_config_params config_params = {
.id = cs_device_count,
.main_mode_type = BT_CONN_LE_CS_MAIN_MODE_2,
.sub_mode_type = BT_CONN_LE_CS_SUB_MODE_1,
.min_main_mode_steps = 2,
.max_main_mode_steps = 5,
.main_mode_repetition = 0,
.mode_0_steps = NUM_MODE_0_STEPS,
.role = BT_CONN_LE_CS_ROLE_INITIATOR,
.rtt_type = BT_CONN_LE_CS_RTT_TYPE_AA_ONLY,
.cs_sync_phy = BT_CONN_LE_CS_SYNC_1M_PHY,
.channel_map_repetition = 3,
.channel_selection_type = BT_CONN_LE_CS_CHSEL_TYPE_3B,
.ch3c_shape = BT_CONN_LE_CS_CH3C_SHAPE_HAT,
.ch3c_jump = 0, //2
};
bt_le_cs_set_valid_chmap_bits(config_params.channel_map);
err = bt_le_cs_create_config(conn, &config_params,
BT_LE_CS_CREATE_CONFIG_CONTEXT_LOCAL_AND_REMOTE);
if (err) {
LOG_ERR("Failed to create CS config (err %d)", err);
return;
}
k_sem_take(&sem_config_created, K_FOREVER);
err = bt_le_cs_security_enable(conn);
if (err) {
LOG_ERR("Failed to start CS Security (err %d)", err);
return;
}
k_sem_take(&sem_cs_security_enabled, K_FOREVER);
const struct bt_le_cs_set_procedure_parameters_param procedure_params = {
.config_id = cs_device_count-1,
.max_procedure_len = 1000,
.min_procedure_interval = realtime_rd ? 5 : 10,
.max_procedure_interval = realtime_rd ? 5 : 10,
.max_procedure_count = 0,
.min_subevent_len = 60000,
.max_subevent_len = 60000,
.tone_antenna_config_selection = BT_LE_CS_TONE_ANTENNA_CONFIGURATION_A1_B1,
.phy = BT_LE_CS_PROCEDURE_PHY_1M,
.tx_power_delta = 0x80,
.preferred_peer_antenna = BT_LE_CS_PROCEDURE_PREFERRED_PEER_ANTENNA_1,
.snr_control_initiator = BT_LE_CS_SNR_CONTROL_NOT_USED,
.snr_control_reflector = BT_LE_CS_SNR_CONTROL_NOT_USED,
};
err = bt_le_cs_set_procedure_parameters(conn, &procedure_params);
if (err) {
LOG_ERR("Failed to set procedure parameters (err %d)", err);
return;
}
if(!(cs_device_count > 1)){
struct bt_le_cs_procedure_enable_param params = {
.config_id = cs_device_count-1,
.enable = 1,
};
err = bt_le_cs_procedure_enable(conn, ¶ms);
if (err) {
LOG_ERR("Failed to enable CS procedures (err %d)", err);
return;
}
node_index_val = find_connID(conn);
}
}