gpt4 book ai didi

Android Ble 在 BLE 设备上的 GATT 服务中找不到特征

转载 作者:行者123 更新时间:2023-11-29 00:23:45 29 4
gpt4 key购买 nike

我在为我的 BLE 设备开发安卓软件时遇到了问题。我的软件可以找到我的设备和 GATT 服务,但在我的服务中找不到任何特征。

我检查了 android-sdk-4.4.2 源码,找到了一些代码。 https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-sdk-4.4.2_r1 https://android.googlesource.com/platform/packages/apps/Bluetooth/+/android-sdk-4.4.2_r1

static char BASE_UUID[16] = {
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

int uuidType(unsigned char* p_uuid)
{
int i = 0;
int match = 0;
int all_zero = 1;

for(i = 0; i != 16; ++i)
{
if (i == 12 || i == 13)
continue;

if (p_uuid[i] == BASE_UUID[i])
++match;

if (p_uuid[i] != 0)
all_zero = 0;
}
if (all_zero)
return 0;
if (match == 12)
return LEN_UUID_32;
if (match == 14)
return LEN_UUID_16;
return LEN_UUID_128;
}

我的 BLE 设备 UUID 是 0000XXXX-AABB-1000-8000-00805F9B34FB。这段代码会导致这种麻烦吗?还是我的 BLE 设备 UUID 有问题?

最佳答案

这就是您要找的。它是 gatt.discoverServices(); 的回调,并返回每个服务的 UUID,并为每个服务返回特征 UUID。

@Override
// New services discovered
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
for (BluetoothGattService gattService : gatt.getServices()) {
for (BluetoothGattCharacteristic mCharacteristic : gattService.getCharacteristics()) {
Log.i(TAG, "Found Characteristic: " + mCharacteristic.getUuid().toString());
}
Log.i(TAG, "onServicesDiscovered UUID: " + gattService.getUuid().toString());
}
} else {
Log.w(TAG, "onServicesDiscovered received: " + status);
}

关于Android Ble 在 BLE 设备上的 GATT 服务中找不到特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21298780/

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