This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to reduce the time to reduce the time to establish Periodic sync in direction finding ?

Hi, I am Marcous. 

Currently I am doing multiple beacons (transmitters) in direction finding demos. Since I found that there is no way to simultaneously receive the CTE containing IQ values. I just map the order of transmitters and receive IQ values from different beacons at different slots, for example: [tx0, tx0, tx0, tx0, tx1, tx1, tx1, tx1, tx2, tx2, tx2, tx0, tx0, .....] . This actually works well and enables me to receive iq values to determine direction of multiple beacons. And my question is: how can I reduce the time to create sync? 

When I print the log information in the windows, I found that it takes about over 300 ms to create the sync between rx and tx .

In the tx side, I change the gap between each broadcasting with CTE to 0x0021(41ms). However, the total time(found periodic advertising + establish periodic sync) to switch between beacons is much longer than one CTE interval, which means that if move the antenna array in the rx side, I can not calculate the instant directions of each beacons. How can I reduce this time? Thanks a lot!!!

Parents
  • Hi, Elfving.

    It is already sometime after 20th. Hopefully we will deal with this problem soon!

  • Yes, hopefully we will!

    I've had a talk with the expert about your case, and what you have done should in theory be working. He is planning on taking a closer look.

    Thank you for your patience. I'll get back to you when I have more information.

    Best regards,

    Elfving

  • Hi, Elfving.

    Providing more debug details:

    In the scan.c -> bt_le_per_adv_sync_create -> get_pending_per_adv_sync function, I added some printk cmd to just show the error message. 

    Noting that I add one more bt_le_per_adv_sync_create to create_sync function in main. And the log information is like this:

    I have set the parameter CONFIG_BT_PER_ADV_SYNC_MAX to 3. And the code goes well in the first bt_le_per_adv_sync_create, and does not enter the if judgement. However, in the second bt_le_per_adv_sync_create, it goes wrong with per_adv_sync_pool[0].flag = 536873404 and SYNC_SYNCING = 2

  • Hey again Zltong!

    Once again, I am sorry it has taken this long. Our direction finding expertise has been very busy lately.

    I will take more of a look at it myself. Any more updates on how far you have gotten in the debugging on your side? 

    Marcous said:
    Hence I tried to get and record two per_addr(which is per_addr and per_addr1 )

    Would you mind showing me how you've modified the scan_recv function? I'll see if I can recreate your issue.

    Best regards,

    Elfving

  • I tried

    static void scan_recv(const struct bt_le_scan_recv_info *info,
    		      struct net_buf_simple *buf)
    {
    	char le_addr[BT_ADDR_LE_STR_LEN];
    	char name[PEER_NAME_LEN_MAX];
    
    	(void)memset(name, 0, sizeof(name));
    
    	bt_data_parse(buf, data_cb, name);
    
    	bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr));
    
    	printk("[DEVICE]: %s, AD evt type %u, Tx Pwr: %i, RSSI %i %s C:%u S:%u "
    	       "D:%u SR:%u E:%u Prim: %s, Secn: %s, Interval: 0x%04x (%u ms), "
    	       "SID: %u\n",
    	       le_addr, info->adv_type, info->tx_power, info->rssi, name,
    	       (info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) != 0,
    	       (info->adv_props & BT_GAP_ADV_PROP_SCANNABLE) != 0,
    	       (info->adv_props & BT_GAP_ADV_PROP_DIRECTED) != 0,
    	       (info->adv_props & BT_GAP_ADV_PROP_SCAN_RESPONSE) != 0,
    	       (info->adv_props & BT_GAP_ADV_PROP_EXT_ADV) != 0,
    	       phy2str(info->primary_phy), phy2str(info->secondary_phy),
    	       info->interval, adv_interval_to_ms(info->interval), info->sid);
    
    	if (!per_adv_found && info->interval && device_number == 0) {
    		bt_addr_le_copy(&per_addr, info->addr);
    		printk("1 [DEVICE]: %s\n", le_addr);
                    per_sid = info->sid;
    		device_number++;
    		return;
    	}
    	//if (!per_adv_found && info->interval) {
    	if (!per_adv_found && info->interval && device_number == 1) {
    		per_adv_found = true;
    		per_sid1 = info->sid;
    		strcpy(name_all, name);
    		bt_addr_le_copy(&per_addr1, info->addr);
    		printk("2 [DEVICE]: %s\n", le_addr);
    		device_number = 0;
    		k_sem_give(&sem_per_adv);
    	}
    }

    This is what I do with the scan_rec function, where I added one more global variable 

    static bt_addr_le_t per_addr1 together with per_addr to record the address of two broadcasting devices with cte extensions. 
    After that, in create_sync function 
    static void create_sync(void)
    {
    	struct bt_le_per_adv_sync_param sync_create_param;
    	struct bt_le_per_adv_sync_param sync_create_param1;
    	int err;
    	int err1;
    	printk("Creating Periodic Advertising Sync...");
    	bt_addr_le_copy(&sync_create_param1.addr, &per_addr1);
    	bt_addr_le_copy(&sync_create_param.addr, &per_addr);
    
    	sync_create_param.options = 0;
    	sync_create_param.sid = per_sid;
    	sync_create_param.skip = 0;
    	sync_create_param.timeout = 0xa;
    
    	sync_create_param1.options = 0;
    	sync_create_param1.sid = per_sid1;
    	sync_create_param1.skip = 0;
    	sync_create_param1.timeout = 0xa;
    
    	err1 = bt_le_per_adv_sync_create(&sync_create_param1, &sync1);
            for(int j=1;j<10000;++j)
            j=j;
    	err = bt_le_per_adv_sync_create(&sync_create_param, &sync);
    	if (err) {
    		printk("err failed (err %d)\n", err);
    		return;
    	}
    	if (err1) {
    		printk("err1 failed (err1 %d)\n", err1);
                    return;
    	}
    	printk("success.\n");
    }
    I tried to create 2 synchronizations with such two devices using the per_addr and per_addr1. My question is: it will always get error messages in the second times to do 
    bt_le_per_adv_sync_create function. 
  • From my understanding, scan_recv function only provides the per_addr information of the beacons. Though this information is random, it is fixed since the locator first detect the beacons. Besides, in create_sync function, I see that the only variable to consider is just per_addr. So I supposed that we can just record two Bluetooth devices' addresses and then create synchronization with them one by one. 

    I actually see a variable something like xxx_pool[BT_PER_ADV_SYNC_MAX] in a C header file. I think you officially support synchronous connections with multiple beacons but just failed. 

Reply
  • From my understanding, scan_recv function only provides the per_addr information of the beacons. Though this information is random, it is fixed since the locator first detect the beacons. Besides, in create_sync function, I see that the only variable to consider is just per_addr. So I supposed that we can just record two Bluetooth devices' addresses and then create synchronization with them one by one. 

    I actually see a variable something like xxx_pool[BT_PER_ADV_SYNC_MAX] in a C header file. I think you officially support synchronous connections with multiple beacons but just failed. 

Children
  • Hey Zltong!

    I believe I am seeing the same error as you.

    So it seems that you also saw that adding a bit of a time delay between creating the two syncs would make a difference? If I replaced your for loop with a k_msleep(1000); With that I can sometimes lose the error. 

    But a better solution would be to use the semaphore:

    printk("starting sync creation usually resulting in err EBUSY...\n");
    err = k_sem_take(&sem_per_sync, TIMEOUT_SYNC_CREATE);
    if (err) {
            printk("failed semaphore with err: (err %d)\n", err);
            return;
    }
    err1 = bt_le_per_adv_sync_create(&sync_create_param1, &sync1); 
    k_sem_give(&sem_per_sync);
    printk("sync creation done!\n"); 

    Does this work for you?

    Best regards,

    Elfving

  • Hi Elfving,

    I tried to tinker with the code as you wrote and eventually I can implement the multi synchronization + multiple cte ! Thanks a lot! I will continue to work on my project in this demo.  And I may come back to you with further questions, since my project may require multi-sync with about over ten beacons. I am afraid that I will counter more bugs during the process. 

    Anyway, this is a big jump! Thanks !

    Best regards,

    Zitong

Related