前言
对于BLE相关的知识学习,在实际开发中,大部分的开发人员不需要接触到底层的蓝牙协议,更多的是原厂提供的BLE收发或者广播包相关设置等接口,是不涉及到原理部分的内容. 而对于希望进一步的学习蓝牙知识的同学也可能只是搜索相关的博客进行碎片化的学习,而没有系统化的学习蓝牙知识. 希望能通过这这篇小博客能引导更多的同学通过阅读蓝牙官方的Spec进行蓝牙知识的系统化学习. 另外本篇博客是基于蓝牙Spec 5.2
BLE 广播的信道
以上截图是来自官方Spec的截图,主要是关于BLE广播信道的描述.
an advertising event and transmits advertising packets on one or more of the primary advertising PHY channels. Each advertising packet is sent on a different advertising PHY channel at a fixed interval. Seven types of advertising events can be used.
Some advertising events sent by the advertising device permit the listening device to concurrently send scan requests or connection requests packets on the same advertising PHY channel in which the advertising packet was received. The advertising device can send a scan response packet again on the same advertising PHY channel within the same advertising event. The payload of the scan response packet can vary in length from 6 to 37 octets.
补充说明: 需要特别注意的是在蓝牙5.0 后,广播通道除了37 38 39这三个primary channel外,还有37个secondary advertising physical channel
广播事件(Advertising events)
基于蓝牙官方Spec的定义,在BLE中将在广播信道进行广播数据传输 定义为广播事件(Advertising events).
如上面截图,Advertising events 可以在接收连接请求或者发出扫描响应包时关闭.
广播间隔(Advertising interval)
The advertising interval (advInterval) shall be an integer multiple of 0.625 ms in the range 20 ms to 10,485.759375 s
广播间隔 需要是0.625的整数倍,且范围为 20 ms to 10,485.759375 s.
LINK LAYER 层,广播物理通道的 传输的数据格式
从这一章节的内容看,扫描包、扫描响应包、广播包、广播响应包 从数据格式角度说是一样的, 另外也希望大家能从LINK LAYER层对BLE广播有更深入的学习.
可连接广播包和不可连接广播包
根据蓝牙官方Spec的定义,对于广播包的几种类型,实质只是协议数据的填充不同以及后续的响应动作不同.
例如,可连接可扫描广播包(Connectable and scannable undirected event type)也就是我们通俗说的配对广播包,
The connectable and scannable undirected advertising event type 允许scanner or initiato响应扫描或者连接请求(这里重点需要注意的是与不可连接广播包的区别)
The Link Layer shall listen on the same primary advertising channel index for requests from scanners or initiators
发起广播包的设备的Link Layer需要在相同的primary advertising channel 来监听scanner或者initiators的请求.
当advertiser接收到SCAN_REQ PDU(包含scanner的device address),而advertiser可以再相同的channel回复SCAN_RSP PDU.
补充说明: 这里需要注意的是advertising filter policy.