我们正在将MTU请求从Android发送到iOS
Android-从此函数onServicesDiscovered回调请求MTU
但是我不知道如何确定对等设备支持是否请求了MTU,以及如何实际协商的MTU。 仅在API级别22(Android L 5.1)中添加了必需的函数:BluetoothGattCallback.onMtuChanged(BluetoothGatt gatt,int mtu,int状态)。
我的问题是我不知道我可以发送多少个字节的数据包。
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
//requestPriorityHigh();
gatt.requestMtu(182);
broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
List Services = gatt.getServices();
for (BluetoothGattService gattService : Services) {
if (SERVICE_UUID.equals(gattService.getUuid())) {
List gattCharacteristics = gattService.getCharacteristics();
for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
if (CHARACTERISTIC_UUID.equals(gattCharacteristic.getUuid())) {
gatt.writeCharacteristic(gattCharacteristic);
List gattDescriptors = gattCharacteristic.getDescriptors();
for (BluetoothGattDescriptor gattDescriptor : gattDescriptors) {
gatt.readDescriptor(gattDescriptor);
}
}
}
}
}
} else {
Log.w(MainActivity.TAG, "onServicesDiscovered received: " + status);
}
}
例如:gatt.requestMtu(182)
iOS-未触发didSubscribeTo特征回调
- (void)peripheralManager:(CBPeripheralManager )peripheral central:(CBCentral )central didSubscribeToCharacteristic:(CBCharacteristic *)characteristic
{
NOTIFY_MTU = central.maximumUpdateValueLength;
NSLog(@"Central subscribed to characteristic");
NSLog(@"Supported to BLE Device Info:--> %lu",(unsigned long)[central maximumUpdateValueLength]);
[peripheral setDesiredConnectionLatency:CBPeripheralManagerConnectionLatencyLow forCentral:central];
}
我们需要根据连接的BLE Devices.U设置数据包大小,如果未请求MTU,则对didSubscribeTo特性进行回调,最小MTU大小为20。如何从android获取和设置此mtu大小。
我们如何设置MTU?