Jieli-Tech/Android-JL_OTA

您好,再来打扰,关于自定义蓝牙协议有使用到其他服务和UUID,如何做兼容

Closed this issue · 1 comments

目前在OTA开始就报错Send Command Fail, 我觉得是OTA的特征UUID没有设置, 我们自定义了蓝牙的其他功能,有使用到AE01以外的UUID来进行读写服务,我看到BleManager有设置了UUID,是下面代码里这样的,这里可以调整做到兼容两个服务UUID吗?

public void onServicesDiscovered(BluetoothGatt gatt, int status)

/ if (BLE_UUID_SERVICE.equals(service.getUuid())
// && null != service.getCharacteristic(BLE_UUID_WRITE)
// && null != service.getCharacteristic(BLE_UUID_NOTIFICATION)) {
// JL_Log.i(TAG, "start NotifyCharacteristicRunnable...");
// mNotifyCharacteristicRunnable = new NotifyCharacteristicRunnable(gatt,
// BLE_UUID_SERVICE, BLE_UUID_NOTIFICATION);
// mHandler.post(mNotifyCharacteristicRunnable);
// ret = true;
// break;
// }

public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
if (mNotifyCharacteristicRunnable != null && BluetoothUtil.deviceEquals(device, mNotifyCharacteristicRunnable.getBleDevice())
&& serviceUuid != null && serviceUuid.equals(mNotifyCharacteristicRunnable.getServiceUUID())
&& characteristicUuid != null && characteristicUuid.equals(mNotifyCharacteristicRunnable.getCharacteristicUUID())) {
if (status == BluetoothGatt.GATT_SUCCESS) {
mNotifyCharacteristicRunnable = null;
startChangeMtu(gatt, BluetoothConstant.BLE_MTU_MAX);
} else {
int num = mNotifyCharacteristicRunnable.getRetryNum();
if (num < 3) {
mNotifyCharacteristicRunnable.setRetryNum(++num);
mHandler.postDelayed(mNotifyCharacteristicRunnable, 100);
} else {
disconnectBleDevice(device);
}
}
}

如果你是多个UUID使用,就使能多个notify属性的UUID就可以,通讯会在BluetoothGattCallback回调,再按照UUID来区分数据就行。队列式使能就可以了。