我想获取"A&D UA-651BLE"设备的HRM值。根据该设备的数据表,需要执行以下操作来获取HRM值:
这段代码的问题在于它没有返回任何数据!!
这是我的服务代码:
- 将应用设置为配对模式以开始扫描。
- 按照每个说明手册启动A&D BLE设备的配对。
- 在配对模式下,应用程序应将时间和日期以及任何其他设备设置设为A&D BLE设备。配对成功后,A&D BLE设备屏幕上显示“End”。
- 进行一次测量并完成测量,然后A&D BLE设备启动带广告的BLE连接。应用程序开始扫描,间隔合适,以便尽快捕获A&D BLE设备的广告。
- 在初始连接或配对时,应用程序将“2”设置为CCCD(客户端特性配置描述符),以便A&D BLE设备使用Indication发送测量数据。
- 在A&D设备识别到CCCD设置为“2”以及在连接后5秒内同步时间和日期之后,使用Indication发送数据。
- 如果超时设置了CCCD和时间和日期,则A&D BLE设备不会发送数据,并将数据存储在内存中。在下次成功连接时,A&D BLE设备可以发送存储的数据。
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
boolean enabled) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
// This is specific to Heart Rate Measurement.
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
}
}
这是读取数据的方法:
final byte[] data = characteristic.getValue();
if (data != null && data.length > 0) {
final StringBuilder stringBuilder = new StringBuilder(data.length);
for(byte byteChar : data)
stringBuilder.append(String.format("%02X ", byteChar));
Log.e("HRM value",stringBuilder.toString());
dataComposition.put(characteristic.getUuid().toString(),stringBuilder.toString());
intent.putExtra(EXTRA_DATA,dataComposition);
}
这段代码的问题在于它没有返回任何数据!!