627|1

74

帖子

0

TA的资源

一粒金砂(中级)

 

【NRF52840】学习记录——过滤 [复制链接]

【NRF52840】学习记录——扫描过滤

  • 扫描过滤初始化nrf_ble_scan_filter_set
/**@brief  Function for adding any type of filter to the scanning.
 *
 * @details This function adds a new filter by type @ref  nrf_ble_scan_filter_type_t.
 *          The filter will be added if the number of filters of a given type does not exceed @ref NRF_BLE_SCAN_UUID_CNT,
 *          @ref NRF_BLE_SCAN_NAME_CNT, @ref NRF_BLE_SCAN_ADDRESS_CNT, or @ref NRF_BLE_SCAN_APPEARANCE_CNT, depending on the filter type,
 *          and if the same filter has not already been set.
 *
 * @param[in,out] p_scan_ctx        Pointer to the Scanning Module instance.
 * @param[in]     type              Filter type.
 * @param[in]     p_data            The filter data to add.
 *
 * @retval NRF_SUCCESS                    If the filter is added successfully.
 * @retval NRF_ERROR_NULL                 If a NULL pointer is passed as input.
 * @retval NRF_ERROR_DATA_SIZE            If the name filter length is too long. Maximum name filter length corresponds to @ref NRF_BLE_SCAN_NAME_MAX_LEN.
 * @retval NRF_ERROR_NO_MEMORY            If the number of available filters is exceeded.
 * @retval NRF_ERROR_INVALID_PARAM        If the filter type is incorrect. Available filter types: @ref nrf_ble_scan_filter_type_t.
 * @retval BLE_ERROR_GAP_INVALID_BLE_ADDR If the BLE address type is invalid.
 */
ret_code_t nrf_ble_scan_filter_set(nrf_ble_scan_t     * const p_scan_ctx,
                                   nrf_ble_scan_filter_type_t type,
                                   void const               * p_data);

  首先,必须定义相关宏定义才会开启扫描过滤功能

image.png 除了扫描过滤使能,开启对应的过滤模式,还需要对应的过滤模式的数量大于0,如要开启name过滤模式,NRF_BLE_SCAN_NAME_CNT应大于0。

image.png 过滤模式有:name、address、UUID、appearance、short_name等。nrf_ble_scan_filter_type_t扫描过滤类型:

image.png

  • 扫描过滤使能nrf_ble_scan_filters_enable
/**@brief Function for enabling filtering.
 *
 * @details The filters can be combined with each other. For example, you can enable one filter or several filters.
 *          For example, (NRF_BLE_SCAN_NAME_FILTER | NRF_BLE_SCAN_UUID_FILTER) enables UUID and name filters.
 *
 * @param[in] mode                  Filter mode: @ref NRF_BLE_SCAN_FILTER_MODE.
 * @param[in] match_all             If this flag is set, all types of enabled filters must be matched
 *                                  before generating @ref NRF_BLE_SCAN_EVT_FILTER_MATCH to the main application. Otherwise, it is enough to match
 *                                  one filter to trigger the filter match event.
 * @param[in] p_scan_ctx            Pointer to the Scanning Module instance.
 *
 * @retval NRF_SUCCESS              If the filters are enabled successfully.
 * @retval NRF_ERROR_INVALID_PARAM  If the filter mode is incorrect. Available filter modes: @ref NRF_BLE_SCAN_FILTER_MODE.
 * @retval NRF_ERROR_NULL           If a NULL pointer is passed as input.
 */
ret_code_t nrf_ble_scan_filters_enable(nrf_ble_scan_t * const p_scan_ctx,
                                       uint8_t                mode,
                                       bool                   match_all);

   

最新回复

过滤功能还是很好用的,还有UUID搜索功能呢。   详情 回复 发表于 2023-7-10 17:53
 
 

回复
举报

5105

帖子

2

TA的资源

版主

 

过滤功能还是很好用的,还有UUID搜索功能呢。

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/8 下一条
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表