接收多个任务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事件,控制台说,另一个扫描已经运行,不仅BLE_EVT_GAP_ADV_REPORT / BLE_EVT_GAP_SCAN_COMPLETED,但是其他事件也以同样的任务接收。

最终,MESH应用程序没有工作。

我怎么能分开BLE事件多任务处理之中?

设备:
PM_Dialog
离线
最后看到:4小时5分钟前
员工
加入时间:2018年2月8日11:03
嗨,火鸟。

嗨,火鸟。

我假设你是在ble_mesh项目。否则,请注明你在哪里工作。既然你已经修改了它,你可以请我们的份额做了什么修改和您的要求是什么?您已经添加了自定义任务?

谢谢,PM_Dialog

火鸟
离线
最后看到:1个月1个星期前
加入时间:2019-07-12 09:48
嗨,

嗨,

是的,我用的网眼SDK 1.6.1 ble_mesh例子。

我增加了以下任务,并开始其设备已设置之后。

目前,这项工作刚刚开始另一扫描和检查RSSI强度。我将添加一些代码后identifing特定的设备。

/ ** **************************************************************************************** * * @file scanner_task.c * * @brief Main task + BLE * * Copyright (C) 2019 INFOMARK, Co., Ltd. * This computer program includes Confidential, Proprietary Information * of INFOMARK, Co., Ltd. All Rights Reserved. * **************************************************************************************** */ #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" static void start_scan(void) { ble_error_t status; 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小时5分钟前
员工
加入时间:2018年2月8日11:03
嗨火鸟,

嗨火鸟,

能否请您以调试模式运行你的代码?它是否会卡住地方?

谢谢,PM_Dialog

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

此代码运行了一段时间,随机卡死。

每次它卡住了,位置是不同的,所以不能找出原因。

而像BLE_EVT_GAP_ADV_COMPLETED,这是不打算接收(网眼功能有关的)一些事件被接收。

我想知道以下内容:

1.这是方法正确吗?即我才能多任务BLE事件,而不互相影响?

2.如果是的话,可以请你检查我的代码和建议什么是错的。

3.如果没有,回到原来的问题,我怎么能在MESH应用程序中执行单独的扫描?

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

任何更新吗?