[Server][Client] Add function to set data length.

Enables the use of BLE data length extension to improve data transfer rates.
This commit is contained in:
Author: Mr-Mime
2021-09-12 19:09:02 -06:00
committed by h2zero
parent ccea428b9e
commit 5925782a65
4 changed files with 41 additions and 2 deletions

View File

@@ -436,6 +436,24 @@ void NimBLEClient::updateConnParams(uint16_t minInterval, uint16_t maxInterval,
} // updateConnParams
/**
* @brief Request an update of the data packet length.
* * Can only be used after a connection has been established.
* @details Sends a data length update request to the server the client is connected to.
* The Data Length Extension (DLE) allows to increase the Data Channel Payload from 27 bytes to up to 251 bytes.
* The server needs to support the Bluetooth 4.2 specifications, to be capable of DLE.
* @param [in] tx_octets The preferred number of payload octets to use (Range 0x001B-0x00FB).
*/
void NimBLEClient::setDataLen(uint16_t tx_octets) {
uint16_t tx_time = (tx_octets + 14) * 8;
int rc = ble_gap_set_data_len(m_conn_id, tx_octets, tx_time);
if(rc != 0) {
NIMBLE_LOGE(LOG_TAG, "Set data length error: %d, %s", rc, NimBLEUtils::returnCodeToString(rc));
}
} // setDataLen
/**
* @brief Get detailed information about the current peer connection.
*/