// All BLE characteristic UUIDs are of the form:
// 0000XXXX-0000-1000-8000-00805f9b34fb
// The assigned number for the Heart Rate Measurement characteristic UUID is
// listed as 0x2A37, which is how the developer of the sample code could arrive at:
// 00002a37-0000-1000-8000-00805f9b34fb
public static class Characteristic {
final static public UUID HEART_RATE_MEASUREMENT = UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb");
final static public UUID CSC_MEASUREMENT = UUID.fromString("00002a5b-0000-1000-8000-00805f9b34fb");
final static public UUID MANUFACTURER_STRING = UUID.fromString("00002a29-0000-1000-8000-00805f9b34fb");
final static public UUID MODEL_NUMBER_STRING = UUID.fromString("00002a24-0000-1000-8000-00805f9b34fb");
final static public UUID FIRMWARE_REVISION_STRING = UUID.fromString("00002a26-0000-1000-8000-00805f9b34fb");
final static public UUID APPEARANCE = UUID.fromString("00002a01-0000-1000-8000-00805f9b34fb");
final static public UUID BODY_SENSOR_LOCATION = UUID.fromString("00002a38-0000-1000-8000-00805f9b34fb");
final static public UUID BATTERY_LEVEL = UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb");
final static public UUID CLIENT_CHARACTERISTIC_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
}
字符串 然后,当你从gatt回调函数中接收到特征时,试着检查(对照列表)它是哪个特征:
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
...
@Override
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
getCharacteristicValue(characteristic);
}
}
@Override
public void onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {
getCharacteristicValue(characteristic);
}
}
private void getCharacteristicValue(BluetoothGattCharacteristic characteristic) {
if(characteristic.getUuid().equals(Characteristic.HEART_RATE_MEASUREMENT)) {
if (mType == Accessory.Type.HRM && mBtLeGattServiceHeartrate != null) {
mBtLeGattServiceHeartrate.onCharacteristicChanged(mContext, BtLeDevice.this, characteristic);
}
}
}
3条答案
按热度按时间mbzjlibv1#
我解决这个问题的唯一方法是使用从
ScanResult
检索的ScanRecord
。ScanRecord
存储有关每个扫描设备的一些信息,包括服务的UUID。一旦通过initScanning()
方法开始扫描并在onScanResult()
中返回任何结果,我们就可以访问ScanRecord
对象:字符串
因此,当我们知道服务UUID时,我们可以得到特征和描述符的UUID:
型
我希望,我也能帮助那些与类似问题作斗争的人。
gg58donl2#
这里有一个所有可用特性的列表:https://www.bluetooth.com/specifications/gatt/characteristics
现在你可以遍历UUID列表并与它们进行比较。下面是一个包含其中一些UUID的类:
字符串
然后,当你从gatt回调函数中接收到特征时,试着检查(对照列表)它是哪个特征:
型
希望这对你有帮助。
mnemlml83#
以下是如何列出关贸总协定服务的所有服务特性和描述符。
字符串