• 正文
  • 相关推荐
申请入驻 产业图谱

BLE主机实战:修改代码打印扫描回复数据

08/21 08:25
98
加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论

一、前言

本篇会编写代码,将打印扫描回复的数据。

二、阅读说明

1、泰凌微芯片学习者。2、蓝牙 spec学习者

三、正文

1、扫描回复数据

如上图所示,扫描回复数据是在主动发送了扫描请求之后得到的,我们在配置扫描参数的时候,可以配置为被动扫描和主动扫描,如果配置为了被动扫描,那么就只能得到Advert信息,如果配置为了主动扫描,那么既能得到Advert,也能得到SCAN_RSP信息。

备注:Advert代表的是广播信息。SCAN_RSP代表的是扫描回复信息

2、配置参数为主动扫描

 blc_ll_setScanParameter(SCAN_TYPE_ACTIVE, SCAN_INTERVAL_100MS, SCAN_INTERVAL_100MS,                             OWN_ADDRESS_PUBLIC, SCAN_FP_ALLOW_ADV_ANY);

如上所示,将blc_ll_setScanParameter函数中的第一个参数更改为SCAN_TYPE_ACTIVE,该参数的含义为主动扫描的意思,关于该API的具体描述如下:

/** * @brief      This function is used to set the scan parameters *             Please refer to BLE Core Specification: Vol 4, Part E, 7.8.10 for more information to understand the meaning of each parameters and *             the return values. * @param[in]  scan_type - passive Scanning or active scanning. * @param[in]  scan_interval - time interval from when the Controller started its last LE scan until it begins the subsequent LE scan * @param[in]  scan_window - The duration of the LE scan. * @param[in]  ownAddrType - Own_Address_Type * @param[in]  scan_fp - Scanning_Filter_Policy * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed */ble_sts_t   blc_ll_setScanParameter (scan_type_t scan_type, u16 scan_interval, u16 scan_window, own_addr_type_t  ownAddrType, scan_fp_type_t scan_fp);

备注:更改点在app.c文件中的user_init函数中。

2、设置条件,过滤扫描回复消息

    if(pa->event_type == 0x04)    {        printf("adv report:n");        for(int i = 0; i < pa->len; i++)        {            printf("0x%02x ", pa->data[i]);        }        printf("n");    }

如上图所示在blm_le_adv_report_event_handle函数中增加如上的过滤代码,判断event_type等于0x04的时候,将数据打印出来。

备注:至于为什么是0x04,请看我上一篇的广播数据分析。

四、结尾

本篇主要讲解了如何修改代码,将扫描回复数据打印出来,至于测试的打印的结果留给大家自行去测试,本章节不再进行展示,下一篇将讲解连接指定的从机设备。

相关推荐

专注BLE实战开发,也分享物联网、嵌入式等相关技术

微信公众号