【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);
首先,必须定义相关宏定义才会开启扫描过滤功能
除了扫描过滤使能,开启对应的过滤模式,还需要对应的过滤模式的数量大于0,如要开启name过滤模式,NRF_BLE_SCAN_NAME_CNT应大于0。
过滤模式有:name、address、UUID、appearance、short_name等。nrf_ble_scan_filter_type_t扫描过滤类型:
- 扫描过滤使能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);