根据Bluetooth 4.0 BLE部分协议:
BLE中物理层physical layer的传输速率是1Mbps,除了这个外,数据传输速率与包大小、CPU处理时间相关。
包结构:
1.总体结构:
preamble(1 Byte)+ Access Address(4 Bytes)+ PDU + CRC(3 Bytes)
preamble = 10101010 or 01010101
Access Address = 0x8e89bedd6
2. 广播包
PDU = Header(2 Bytes)+ Payload (37 Bytes max.)
Header: 1)0000 - connected undirected advertising event 可连接非定向广播事件
2)0001 - connected directed advertising event 可连接定向广播事件
3)0010 - non-connected undirected advertising event 不可连接非定向广播事件
4)0011 - response to scan request form scanner扫描请求响应
5)0101 - connect request by initiator连接请求
6)0110 -connected directed advertising event 可发现非定向广播事件
- 非定向广播包(Undirected advertising packets)
Payload = AdvA (6 Bytes) + AdvData (31 Bytes max.) ;
// AdvA contains advertiser‘s public address if TxAdd = 1, or a random address if TxAdd = 0;
// AdvData advertising data;
- 定向广播包(Directed advertising packets)
Payload = AdvA (6 Bytes) + InitA(6 Bytes) ;
// AdvA contains advertiser‘s public address if TxAdd = 1, or a random address if TxAdd = 0;
// InitA contains initiator's address if RxAdd = 1, or a random address if RxAdd = 0;
3. 扫描请求及扫描响应
PDU = Header(2 Bytes)+ Payload (37 Bytes max.)
Header: 1)0011 - scan request for further information from advertiser 扫描请求
2)0100 - response to scan request from scanner 扫描响应
- 扫描请求
Payload = ScanA (6 Bytes) + AdvA(6 Bytes) ; // ScanA contains Scanner's public address if TxAdd = 1, or a random address if TxAdd = 0;
// AdvA contains advertiser‘s public address if TxAdd = 1, or a random address if TxAdd = 0;
- 扫描响应
Payload = AdvA(6 Bytes) + ScanRspData(0~31Bytes); // ScanRspData data from advertiser’s host;
// AdvA contains advertiser‘s public address if TxAdd = 1, or a random address if TxAdd = 0;
3. 连接请求
PDU = Header(2 Bytes)+ Payload (34 Bytes)
Header:0101 - connect request by initiator
Payload =InitA(6 Bytes)+ AdvA(6bytes)+ LLData(22 Bytes)
LLData 包含连接信息,详细结构参考bluetooth 4.0 协议。
4. LL 数据通道及控制包
PDU = Header(2 Bytes)+ Payload (27 Bytes max.)
Header:详细说明参考bluetooth 4.0 协议;
- LL 数据通道
Payload = 0~27 bytes
- LL 控制包
Payload = 1~23 Bytes
若只考虑蓝牙设备连接之后,评估数据传输速率
- 最大包长度:preamble(1 Byte)+ Access Address(4 Bytes)+ PDU(29 Bytes) + CRC(3 Bytes)= 41 Bytes
- 射频PHY传输速率 1Mbps
则传输有效payload 27字节耗时:41*8/1 = 328 us
一个27字节的传输周期 :328 + 150 + 80 + 150 = 708 us,若能持续传输,即传输速度:38KB/s,这样显然功耗不会低,也不符合BLE协议规范,真正的传输速度受连接事件间隔和间隔内能传输数据包数目相关。
如果连接时间间隔设置到7.5ms(协议规定最小值),一个连接事件传输3个包,则传输速率大约是10.8kB/s,一个连接事件能传输几个包与连接设备密切相关,看到很多CC2540实测数据,时间间隔7.5ms和一个传输时间3个包以上很多都达不到,51内核是其重要原因之一,在 http://processors.wiki.ti.com/index.php/CC2540_Data_Throughput有5.9KB/s,也有在论坛看到有40ms间隔,2个包,即1.4KB/s成功的案例,以后有时间我再实测下速度。