我們正在將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?