gpt4 book ai didi

android - BLE扫描记录说明

转载 作者:太空宇宙 更新时间:2023-11-03 10:18:14 25 4
gpt4 key购买 nike

我正在尝试从以 字节形式收到的 BLE 广告中获取 UUIDMajorMinor ID []。我使用了建议的代码 here但我无法理解解析器的输出。这是我为其中一个 BLE 设备获得的输出

Length: 2 Type : 1 Data : 6,   
Length: 26 Type : -1 Data : 76 0 2 21 -9 -126 109 -90 79 -94 78 -104 -128 36 -68 91 113 -32 -119 62 12 -121 -79 52 -77,
Length: 8 Type : 9 Data : 75 111 110 116 97 107 116,
Length: 2 Type : 10 Data : -12,
Length: 10 Type : 22 Data : 13 -48 117 76 106 98 50 55 100

如何理解哪个字段包含 UUID 、主要 ID 和次要 ID? .我从 stackoverflow 上的同一篇文章中读到 0x07 表示 UUID,我如何从上述数据中了解类型是 0x07

这是我在这里的第一个问题,对于提问方式中的任何错误,我们深表歉意。

为了以防万一,下面是代码:

public void printScanRecord (byte[] scanRecord) {
// Simply print all raw bytes
try {
String decodedRecord = new String(scanRecord,"UTF-8");
Log.d("DEBUG","decoded String : " + ByteArrayToString(scanRecord));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}

// Parse data bytes into individual records
List<AdRecord> records = AdRecord.parseScanRecord(scanRecord);


// Print individual records
if (records.size() == 0) {
Log.i("DEBUG", "Scan Record Empty");
} else {
Log.i("DEBUG", "Scan Record: " + TextUtils.join(",", records));
}

}


public static String ByteArrayToString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.length * 2);
for (byte b : ba)
hex.append(b + " ");
return hex.toString();
}


public static class AdRecord {

public AdRecord(int length, int type, byte[] data) {
String decodedRecord = "";
try {
decodedRecord = new String(data,"UTF-8");

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}

Log.d("DEBUG", "Length: " + length + " Type : " + type + " Data : " + ByteArrayToString(data));
}

// ...

public static List<AdRecord> parseScanRecord(byte[] scanRecord) {
List<AdRecord> records = new ArrayList<AdRecord>();

int index = 0;
while (index < scanRecord.length) {
int length = scanRecord[index++];
//Done once we run out of records
if (length == 0) break;

int type = scanRecord[index];
//Done if our record isn't a valid type
if (type == 0) break;

byte[] data = Arrays.copyOfRange(scanRecord, index+1, index+length);

records.add(new AdRecord(length, type, data));
//Advance
index += length;
}

return records;
}

// ...
}

最佳答案

我想 Type 值的解释是:Generic Access Profile

我还制作了一些解析器代码,您可以在 mybletest/BLEBase.java 的底部找到这些代码文件。

关于android - BLE扫描记录说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31417489/

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