BLE如何發送超過一包爲20個字節的問題

大家都知道藍牙 BLE 4.0發送數據時都是 20 字節一個包,協議規定,payload 最大 27。在協議第六章中的 2.4,刨去 L2CAP 的頭,4 個字節,剩下的就 23 個字節 MTU。就是你看到的。ATT 層會用掉上 1 個字節的 op code, 2 個字節的 attribute handle,就剩下 20了。這剩下的 20 字節就是我們常說的發送的 20 字節的數據。

BLE5.0

數據長度擴展
總結
數據長度的擴展功能允許LE控制器發送數據信道的分組數據單元(PDU)高達251字節的數據應用負載,而在連接狀態。此外,一個新的PDU的大小是可以協商的任何一方在任何時間在一個連接。
以前,控制器最大的數據通道有效載荷爲27字節。相比藍牙核心規範版本4和4.1設備(如果兩個設備支持擴展的包長度並正確配置),這將提高數據速率約2.5倍。

LE Data Length Extension

Summary

The data length extension feature allows the LE controller to send data channel packet data units (PDUs) with payloads of up to 251 bytes of application data, while in the connected state. Furthermore, a new PDU size can be negotiated by either side at any time during a connection.

Previously, the controller’s largest data channel payload was 27 bytes. This increases the data rate by around 2.5*, compared to Bluetooth Core Specification Versions 4.0 and 4.1 devices (if both devices support extended packet length and are configured properly).

在CC2640R2F中如何實現:

這是BLE4.1 4.2的PDU部分:

#define APP_TX_PDU_SIZE 27
#define APP_RX_PDU_SIZE 27
#define APP_TX_TIME 328
#define APP_RX_TIME 328

//This API is documented in hci.h
HCI_EXT_SetMaxDataLenCmd(APP_TX_PDU_SIZE ,  APP_TX_TIME,
   APP_RX_PDU_SIZE, APP_RX_TIME);
我們要修改爲:

#define APP_SUGGESTED_PDU_SIZE 251
#define APP_SUGGESTED_TX_TIME 2120

//This API is documented in hci.h
HCI_LE_WriteSuggestedDefaultDataLenCmd(APP_SUGGESTED_PDU_SIZE ,
APP_SUGGESTED_TX_TIME)

在初始化中:

uint16_t cxnHandle; //Request max supported size
uint16_t requestedPDUSize = 251;
uint16_t requestedTxTime = 2120;

GAPRole_GetParameter(GAPROLE_CONNHANDLE, &cxnHandle); //This API is documented in hci.h

if (SUCCESS != HCI_LE_SetDataLenCmd(cxnHandle, requestedPDUSize, requestedTxTime))
   DISPLAY_WRITE_STRING("Data length update failed", LCD_PAGE0);

Youneed to set the MAX_PDU_SIZE 251 and adjust the heap size accordingly so thatyou can send packets that are > 20 bytes data. 

參考:http://dev.ti.com/tirex/content/simplelink_cc2640r2_sdk_1_35_00_33/docs/ble5stack/ble_user_guide/html/ble-stack/data-length-extensions.html#sec-utilizing-data-length-ext-at-run-time

發佈了67 篇原創文章 · 獲贊 22 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章