使用 Nordic Scan 模块:允许在 Seeed Studio Xiao BLE 板上过滤短名称

问题描述 投票:0回答:1

我正在尝试使用扫描模块进行过滤扫描。现在我正在尝试实现一个短名称过滤器。

我在环境中使用 VS 代码的 nrf Connect 扩展,并使用 include 导入北欧蓝牙 LE 扫描库以供使用。

我使用 Windows 并使用 Seeed Studio XIAO nRF52840 板进行开发。

问题解释:

据我所知,到目前为止,要启用过滤扫描,我需要:

Add the filter to the scanning parameters through bt_scan_filter_add
    The structure for the filter should be found from the source code
Enable the filters which would need you to specify the filter modes that you want to include bt_scan_filter_enable
Set the callback functions through bt_scan_cb_register. the scan_filter_match callback will define how the filter matches are delt with
Start the scanning with bt_scan_start

鉴于这种高级理解,我编写了以下代码:


//--------------SCAN TESTING START---------------------//



        // int err = 0; 

        const struct bt_scan_init_param bt_scan_init_opts = {

                        .scan_param = NULL, //default config 

                        .connect_if_match = true,

                        .conn_param = NULL, //default config

        };

        

        bt_scan_init(&bt_scan_init_opts); 



        bt_scan_filter_remove_all();

        bt_scan_filter_disable(); 



        //double check if the definitin of the short name filter is correct

        struct bt_scan_short_name ble_shrt_name;

        ble_shrt_name.name = "shrtname";

        ble_shrt_name.min_len = 8;



        err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_SHORT_NAME, &ble_shrt_name);

        if (err < 0) {

                LOG_ERR("Error setting the short name filter (err: %d)\n", err);

                // return err; 

        }



        uint8_t filter_modes = BT_SCAN_SHORT_NAME_FILTER | BT_SCAN_UUID_FILTER;

        err = bt_scan_filter_enable(filter_modes, true); //Want all filters to be matched when looking for a new device

        if (err < 0) {

                LOG_ERR("Error establishing scan filters (err: %d)\n", err);

                // return err; 

        }




        bt_scan_cb_register(scan_filter_match); 

        bt_scan_cb_register(scan_filter_no_match); 

        bt_scan_cb_register(scan_connecting); 

        bt_scan_cb_register(scan_connecting_error); 



        err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);

        if (err < 0) {

                LOG_ERR("Error starting the bt scan (err: %d)\n", err);

        }



        //--------------SCAN TESTING END---------------------//

当我尝试将短名称过滤器添加到扫描系统时,我收到 ENOMEM (-12) 无法分配内存。

据我了解,这是因为需要的内存多于 MCU 可用的内存。但是,我通过配置文件设置以下参数来增加 MCU 可用的内存:

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_LOG_BUFFER_SIZE=4096

在这里浏览一些关于类似问题的其他帖子:如何通过短名称进行 bt_scan_filter_add ?

最后指出:“编辑:这仍然需要您通过

guiconfig
menuconfig
BT_SCAN_SHORT_NAME_CNT
中设置短名称过滤器的数量。”

我认为 guiconfig 和 menuconfig 也与 VS Code 的 NRF Connect 扩展中使用的 proj.config 文件相同。但是,当我设置此配置标志时,我收到一个错误

ignoring malformed line 'BT_SCAN_SHORT_NAME_CNT=1'

通过谷歌搜索 zephyr 配置,似乎该标志不可用。

任何人都可以指导我可能出现的错误吗?

非常感谢任何指导。

谢谢大家。

c bluetooth bluetooth-lowenergy nordic-semi
1个回答
0
投票

我相信这已在 您在 DevZone 上的问题得到解答 总之,prj.conf 中的“BT_SCAN_SHORT_NAME_CNT=1”应该是:“CONFIG_BT_SCAN_SHORT_NAME_CNT=1”。

© www.soinside.com 2019 - 2024. All rights reserved.