根據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成功的案例,以後有時間我再實測下速度。