gpt4 book ai didi

android - 如何设置/获取/请求从安卓到 iOS 或反之亦然的 BLE 的 MTU?

转载 作者:行者123 更新时间:2023-11-29 13:54:33 25 4
gpt4 key购买 nike

我们正在从 android 向 iOS 发送 mtu 请求

Android - 从此函数 onServicesDiscovered 回调请求 mtu

但我不知道如何确定对等设备支持是否请求了 MTU 以及实际协商的 MTU 是什么。所需函数:BluetoothGattCallback.onMtuChanged(BluetoothGatt gatt, int mtu, int status) 仅在 API 级别 22 (Android L 5.1) 中添加。

我的问题是我不知道我可以发送多少字节的数据包。

 @Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
//requestPriorityHigh();

gatt.requestMtu(182);

broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
List<BluetoothGattService> Services = gatt.getServices();
for (BluetoothGattService gattService : Services) {
if (SERVICE_UUID.equals(gattService.getUuid())) {
List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
if (CHARACTERISTIC_UUID.equals(gattCharacteristic.getUuid())) {
gatt.writeCharacteristic(gattCharacteristic);
List<BluetoothGattDescriptor> 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 设备设置数据包大小。如果未请求 MTU,我们会在 didSubscribeTo 特征 上进行回调,最小 MTU 大小为 20。如何获取和设置此 mtu尺寸形式 android.

我们如何设置 MTU?

最佳答案

方法requestMtu在两个蓝牙设备之间启动 MTU 交换。他们将就两种设备都支持的值达成一致。

因此您可以请求高 MTU:

gatt.requestMtu(2000);

然后等待onMtuChanged打回来。它会告诉你已经同意的MTU:

@Override
public void onMtuChanged(BluetoothDevice device, int mtu) {
Log.i(TAG, "MTU: " + mtu);
}

关于android - 如何设置/获取/请求从安卓到 iOS 或反之亦然的 BLE 的 MTU?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57392754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com