Receiving BLE events in multiple tasks

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
6 posts / 0 new
Last post
firebird
Offline
最后一次露面:1 month 6 hours ago
Joined:2019-07-12 09:48
Receiving BLE events in multiple tasks

Hi teams,

我有质疑在网格应用程序中进行分离的扫描,如下线程。

https://support.dialog-seminile.com/forums/post/dialog-smartbond-bluetooth-low-energy-%2%80%93-software/separate-scan-mesh-application.

but when I called ble_gap_scan_start() and get BLE events with ble_get_event() in separate task, console says another scan was already running, and not only BLE_EVT_GAP_ADV_REPORT/BLE_EVT_GAP_SCAN_COMPLETED, but other events also be received in the same task.

And eventually, MESH application did not work.

How can I separate BLE event handling among multiple tasks?

Device:
PM_DIALOG.
Offline
最后一次露面:22 hours 50 min ago
Staff
Joined:2018-02-08 11:03
嗨firebird。

嗨firebird。

I assume that you are working on ble_mesh project. Otherwise, please indicate where you are working on. Since you have modified it, can you please share what modifications we have done and which your requirement is? Have you added a custom task?

谢谢,PM_DIALOG.

firebird
Offline
最后一次露面:1 month 6 hours ago
Joined:2019-07-12 09:48
Hi,

Hi,

是的,我正在使用带有网格SDK 1.6.1的BLE_MESH示例。

I added the following task and started it after device has been provisioned.

Currently, this task just start another scan and check RSSI strength. I will add some codes for identifing specific devices later.

/ ** **************************************************************************************** * * @file scanner_task.c * *@Brief Main Task + BLE * *版权所有(C)2019 Infomark,Co.,Co.,Ltd。*此计算机程序包括Infomark,Co.,Ltd.保留所有权利的机密,专有信息*。* **************************************************************************************** * / #include  #include #include“osal.h”#include“ad_ble.h”#include“ble_common.h”#include“ble_gap.h”#include“ble_bufops.h”#include“ble_uuid.h”#include“sys_watchdog.h“静态void start_scan(void){ble_error_t状态;status = ble_gap_scan_start(gap_scan_passive,gap_scan_gen_disc_mode,ble_scan_interval_from_ms(30),ble_scan_window_from_ms(30),false,false);if(status!= ble_status_ok){printf(“错误:应用程序已经扫描\ r \ n”);printf(“扫描开始\ r \ n”);}静态void handle_evt_gap_adv_report(const ble_evt_gap_adv_report_t * evt){const uint8_t * p; uint8_t ad_len, ad_type; const char *dev_name = NULL; size_t dev_name_len = 0; printf("Device found: %s %s RSSI=%d\r\n", evt->address.addr_type == PUBLIC_ADDRESS ? "public " : "private", ble_address_to_string(&evt->address), (int8_t)evt->rssi); for (p = evt->data; p < evt->data + evt->length; p += ad_len) { ad_len = (*p++) - 1; /* ad_len is length of value only, without type */ ad_type = *p++; /* Device not found so we look for UUID */ if (ad_type == GAP_DATA_TYPE_UUID16_LIST || ad_type == GAP_DATA_TYPE_UUID16_LIST_INC) { size_t idx; for (idx = 0; idx < ad_len; idx += sizeof(uint16_t)) { printf("\tUUID16: %04X\r\n", get_u16(p + idx)); } } /* Look for name and store it to use later, if proper UUID is found */ if (ad_type == GAP_DATA_TYPE_SHORT_LOCAL_NAME || ad_type == GAP_DATA_TYPE_LOCAL_NAME) { dev_name = (const char*)p; dev_name_len = ad_len; printf("\tNAME: %.*s\r\n", dev_name_len, dev_name); } } } static void handle_evt_gap_scan_completed(const ble_evt_gap_scan_completed_t *evt) { printf("SCAN STOPPED\r\n"); start_scan(); } void scanner_main_task(void *pvParameters) { /* Just remove compiler warnings about the unused parameter */ (void)pvParameters; start_scan(); for (;;) { ble_evt_hdr_t *hdr; /* * Wait for a BLE event - this task will block * indefinitely until something is received. */ hdr = ble_get_event(true); if (!hdr) { continue; } switch (hdr->evt_code) { case BLE_EVT_GAP_ADV_REPORT: handle_evt_gap_adv_report((ble_evt_gap_adv_report_t *) hdr); break; case BLE_EVT_GAP_SCAN_COMPLETED: handle_evt_gap_scan_completed((ble_evt_gap_scan_completed_t *) hdr); break; default: printf("Event: %d\r\n", hdr->evt_code); ble_handle_event_default(hdr); break; } /* Free event buffer (it's not needed anymore) */ OS_FREE(hdr); } }

PM_DIALOG.
Offline
最后一次露面:22 hours 50 min ago
Staff
Joined:2018-02-08 11:03
嗨Firebird,

嗨Firebird,

Can you please run your code in debug mode? Does it get stuck anywhere?

谢谢,PM_DIALOG.

firebird
Offline
最后一次露面:1 month 6 hours ago
Joined:2019-07-12 09:48
此代码运行一段时间

此代码运行一段时间和随机卡。

Every time it stuck, the position is different, so can't figure out the cause.

And some events like BLE_EVT_GAP_ADV_COMPLETED, which is not intended to receive (related with MESH function) was received.

I want to know the followings:

1.这种方法是否正确?即,我可以在不影响彼此的情况下在多个任务中获得BLE事件吗?

2. If so, can you please review my code and advice what is wrong.

3.如果没有,回到最初的问题,如何I execute separate scan in MESH application?

firebird
Offline
最后一次露面:1 month 6 hours ago
Joined:2019-07-12 09:48
任何更新?

任何更新?