接收多个任务中的BLE事件

了解更多常见问题教程

6个帖子/ 0个新帖子
最后发表
火鸟
离线
最后看到:1个月1周前
加入:2019-07-12 09:48
接收多个任务中的BLE事件

嗨,团队,

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

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

但当我调用ble_gap_scan_start()和ble_get_event()在单独的任务,控制台说另一个扫描已经运行,不仅BLE_EVT_GAP_ADV_REPORT/BLE_EVT_GAP_SCAN_COMPLETED,但其他事件也收到在同一任务。

最后,网格应用程序没有工作。

如何在多个任务中分离BLE事件处理?

设备:
PM_Dialog
离线
最后看到:4小时18分钟前
工作人员
加入:2018-02-08 11:03
嗨,火鸟。

嗨,火鸟。

我假设你正在ble_mesh项目中工作。否则,请注明您的工作地点。既然你已经修改了,你能告诉我我们做了哪些修改,你的要求是什么吗?您添加了自定义任务吗?

谢谢,PM_Dialog

火鸟
离线
最后看到:1个月1周前
加入:2019-07-12 09:48
你好,

你好,

是的,我使用ble_mesh示例与MESH SDK 1.6.1。

我添加了以下任务,并在设备配置后启动它。

目前,该任务只是启动另一个扫描并检查RSSI强度。稍后我会添加一些代码用于识别特定的设备。

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @file scanner_task.c * * @brief主要任务+祝福* *版权(C) 2019 INFOMARK有限公司有限公司*这个计算机程序包含机密,专有信息* INFOMARK,有限公司保留所有权利。* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / # include < stdint。h > # include < stdio。h > # include”安排。h ad_ble # include。h ble_common # include。h ble_gap # include。h ble_bufops # include。h ble_uuid # include。h sys_watchdog # include。/ / / / / / / / / / / / / / / / /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("ERROR: application already scanning\r\n"); } printf("SCAN STARTED\r\n"); } static 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
离线
最后看到:4小时18分钟前
工作人员
加入:2018-02-08 11:03
嗨火鸟,

嗨火鸟,

你能在调试模式下运行你的代码吗?它会在什么地方卡住吗?

谢谢,PM_Dialog

火鸟
离线
最后看到:1个月1周前
加入:2019-07-12 09:48
此代码运行一段时间

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

每次卡住,位置都不一样,所以找不到原因。

而一些事件,如BLE_EVT_GAP_ADV_COMPLETED,它不打算接收(与MESH函数相关)被接收。

我想知道以下几点:

1.这种方法正确吗?例如,我能在多个任务中获得BLE事件而不影响彼此吗?

2.如果是的话,你能检查一下我的代码并指出哪里出了问题吗?

3.如果不是,回到原来的问题,我如何执行单独的扫描网格应用程序?

火鸟
离线
最后看到:1个月1周前
加入:2019-07-12 09:48
任何更新吗?

任何更新吗?