Reset the channel sounding parameters after a disconnection

Hi, I am trying to sound two reflectors from a single initiator, and since the CS works on a one-to-one ACL system, I wanted to know how I can reset the CS-related stuff in the code. I did try this without reboot, the data becomes stagnant after a reconnection or when I connect 2 reflectors (not sound, but just connect)  

The sample provided by Nordic does a soft reboot, so it works flawlessly. I am trying to take a different path of not connecting to both of my nodes at once and do a soft reboot every time I wanna switch the sounding, but I wanted to know if a manual reset was possible for the CS params and buffer, so that I can continue with sounding another device without doing a soft reboot.

Parents
  • Hello,

    This should be possible. You mention that you want one initiator and two reflectors. This will probably work, but if you are planning to have many reflectors, you may want to switch it around. You see, the main CPU usage is in the initiator, and the reflector is not doing any heavy lifting. This means that if you plan to have many stationary devices and one moving device, it may make sense to have the stationary devices being the initiators, all doing channel sounding towards the same reflector. This means that the moving device (reflector) can last longer on a smaller battery.

    without reboot, the data becomes stagnant after a reconnection

    What does it mean? do you get any channel sounding data from the second connection, or none at all?

    Best regards,

    Edvin

  • I have found my answer and also a mistake.

    bt_le_cs_procedure_enable() was returning an error because the connection would already be stale after the disconnection. Hence, I tried to run it just by resetting the buffers, but I soon faced this issue of 

    W: Could not locate mandatory
    On-demand ranging data characteristic E: RAS RREQ alloc init failed (err -22)
    Then I started looking into my device discovery and found a problem there. I use NUS and RAS as well, so I chained their discoveries. And I was not resetting some states to do this properly.
     
    Now I need to work on the multiple connections part. This whole RAS and NUS were running on the multilink_central code, so do you have any suggestions on the multiple connections and the sounding part?
  • Hi Edvin,
    I am actually doing my master's thesis on the implementation of this, so for the current scenario considered, it's going to be 2 moving devices with 1 stationary device.
    So I am using 1 central initiator (stationary) with 2 peripheral reflectors (moving). Does this make sense in terms of power consumption footprint?
    I implemented the part where I am currently sounding to 2 devices consecutively. At any given point in time, there is only 1 peripheral reflector connected to the central initiator. The problem arises as the switching (disconnection, connection, and CS parameters exchange) takes around 4-5 seconds. Is there any way I can get a better response time?
    I am looking into 2 directions of solutions for this:

    1) Find a way to make the CS params exchange faster (maybe store the params in flash)  - This reduces the time for CS param exchange

    2) Stay connected to 2 devices, but sound only to one device - This reduces the time taken for connection and disconnection

    Can I get some insights about these probable solution methods? I would also be glad to know if you have some other solution in mind.

    Thanks,
    Vinayaka KS

  • I would try to get the second scenario working. There is no point in keeping connecting and disconnecting all the time. Just stay connected to both, and do channel sounding measurements on one at the time. 

    When you have multiple devices, it is a good idea to have the central being the initiator (like you do), because it causes less timing issues. 

    You have a function:

    err = bt_le_cs_set_procedure_parameters(connection, &procedure_params);

    where the first parameter, "connection" points to the connection to the reflector. If you have two connections, you need to store two of these connection pointers, and then call bt_le_cs_set_procedure_parameters() on both of them.

    Best regards,

    Edvin

  • Thanks a lot, I will try implementing this now.

    Regards,

    Vinayaka KS

  • I am not able to enable the CS procedures for the 2nd device. Is this a problem with the memory?

    I: Disabling the CS procedure
    I: Free rreq 0x20002b18 for conn 0x200076d8
    I: CS procedures disabled.
    W: opcode 0x2094 status 0x07
    I: Enabling the CS procedure
    E: Failed to enable CS procedures (err -5) for Device1


    void switch_CS_device(void){
    	int err;
    	while (1) {
    		k_sleep(K_SECONDS(10));
    
    		if(cs_device_count > 1){
    			node_index_val = (node_index_val+1)%2; 
    
    			struct bt_le_cs_procedure_enable_param enable_params = {
    				.config_id = CS_CONFIG_ID,
    				.enable = BT_CONN_LE_CS_PROCEDURES_ENABLED,
    			};
    
    			struct bt_le_cs_procedure_enable_param disable_params = {
    				.config_id = CS_CONFIG_ID,
    				.enable = BT_CONN_LE_CS_PROCEDURES_DISABLED,
    			};
    
    			err = bt_le_cs_procedure_enable(conn_contexts[(node_index_val+1)%2].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;
    			}
    			k_sem_take(&sem_cs_enable_disable,K_FOREVER);
    
    			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);
    			bt_ras_rreq_free(conn_contexts[(node_index_val+1)%2].conn);
    			k_msleep(1000);
    
    			err = bt_le_cs_procedure_enable(conn_contexts[node_index_val].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);
    		}
    	}
    }

  • I don't have a multi-connection channel sounding sample at hand. Do you mind sending me what you already have, then perhaps I can have a look at it, and give it a go.

    I will not be able to look into it tomorrow, but hopefully during the beginning of next week.

    Best regards,

    Edvin

Reply Children
  • I have sent both the peripheral and central.

  • Hi Vinayaka, have you got any update on your attempts to do multi connection channel sounding ? I am also trying to do it but unfortunately, without success. 
    Regards, 
    Fhar

  • I found the issue, I was not setting one config 

    CONFIG_BT_CTLR_CHANNEL_SOUNDING=y

    And now 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

    This happens to the device that gets connected first, and happens every time I sound it. The 2nd device is able to get the data.

  • Ok, I did find an issue. You are restarting the the advertising directly in the .recycled callback.

    I saw that the channel_sounding_ras_reflector sample just rebooted in the disconnected_cb event. This is a quick (and dirty) way to just reset the state of the reflector. But of course, this is maybe not allwals desireable.

    Attached is a modified channel_sounding_ras_reflector sample (tested in NCS v3.2.1):

    cs_refl.zip

    Note that the recycled_cb() calls advertising_start(), but this doesn't directly call bt_le_adv_start(). This needs to be done through a work handler, like it is done in e.g. the NCS\nrf\samples\bluetooth\peripheral_uart sample. It is a bit more lines of code, but the idea is that you can't call BT API directly from the recycled callback, as it will block itself. Therefore you need to add these small pieces of code:

    // in main.c:
    
    static struct k_work adv_work;
    
    ...
    
    static void adv_work_handler(struct k_work *work)
    {
    	int err = bt_le_adv_start(BT_LE_ADV_CONN_FAST_2, ad, ARRAY_SIZE(ad), NULL, 0);
    	if (err) {
    		LOG_ERR("Advertising failed to start (err %d)", err);
    		return;
    	}
    }
    
    ...
    
    static void recycled_cb(void)
    {
    	LOG_INF("Connection object available from previous conn. Disconnect is complete!");
    	advertising_start();
    }
    
    BT_CONN_CB_DEFINE(conn_cb) = {
    	...
    	.recycled = recycled_cb,
    };
    
    ...
    
    int main(void)
    {
    ...
    	k_work_init(&adv_work, adv_work_handler);
    	advertising_start();
    ...
    }

    Try that, and let me know if it doesn't work.

    Best regards,

    Edvin

Related