Android BluetoothGatt:协商新MTU成功,但无法使用新大小(3字节差异)
我正在开发一个应用程序,使用BLE在设备之间交换数据 为了获得更好的性能,在连接两台设备后,我正在协商增加MTU,以便通过BLE交换更大的数据包 连接Bluetooth设备并读取所有服务和特征后,我请求使用以下方法增加MTU:Android BluetoothGatt:协商新MTU成功,但无法使用新大小(3字节差异),android,bluetooth-lowenergy,gatt,Android,Bluetooth Lowenergy,Gatt,我正在开发一个应用程序,使用BLE在设备之间交换数据 为了获得更好的性能,在连接两台设备后,我正在协商增加MTU,以便通过BLE交换更大的数据包 连接Bluetooth设备并读取所有服务和特征后,我请求使用以下方法增加MTU: private void requestMtu() { //gatt is a BluetoothGatt instance and MAX_MTU is 512 this.gatt.requestMtu(MAX_MTU); } 之后,在Bluetoot
private void requestMtu() {
//gatt is a BluetoothGatt instance and MAX_MTU is 512
this.gatt.requestMtu(MAX_MTU);
}
之后,在BluetoothGattCallback
实现中,我成功地获得了MTU请求,并且新的MTU与我请求的MTU匹配:
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
super.onMtuChanged(gatt, mtu, status);
if (status == BluetoothGatt.GATT_SUCCESS) {
this.supportedMTU = mtu;
}
}
问题是,当我尝试发送512字节的数据包时,在另一端(onCharacteristicWriteRequest:
)我得到509字节
有什么想法吗?MTU大小表示ATT有效负载中可以使用的最大字节数。ATT写入请求有效负载(为特征写入而发送)如下所示: 1字节属性操作码 2字节属性句柄 N字节属性值 由于MTU大小为512字节,因此最大大小N可以为512-3=509字节