gpt4 book ai didi

安卓蓝牙获取心率测量

转载 作者:太空狗 更新时间:2023-10-29 16:01:15 27 4
gpt4 key购买 nike

我想获取“A&D UA-651BLE”设备的 HRM 值。这是该设备的数据表中用于获取 HRM 值的内容:

  1. Set the application to pairing mode to start scanning.
  2. Start pairing of A&D BLE device following each instruction manual.
  3. At pairing mode, the application should set time and date and any other device settings to A&D BLE device. After successful pairing, A&D BLE device shows “End” on the screen.
  4. Take a measurement and finish the measurement, then A&D BLE device start BLE connection with advertising. The application starts scanning with suitable interval so that the application catches the advertising of A&D BLE device as soon as it can.
  5. At initial connection or pairing, the Application set “2” to CCCD (Client Characteristic Configuration Descriptor) so that A&D BLE device sends a measurement data with Indication.
  6. After A&D device recognizes to be set “2” to CCCD and to be synchronized time and date within 5 seconds after connected, send the data with Indication.
  7. If the timeout set CCCD and time and date is expired, A&D BLE device will not send data and store the data in memory. The stored data in A&D BLE device can send next successful connection.

这是我的服务代码:

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);
}

问题是这段代码没有返回任何数据!!

最佳答案

有一个 Android Open Source Project example正是这样做的,最简单的选择是克隆 android-BluetoothLeGatt code ,构建并将其与您自己的进行比较。如果您无法发现差异/问题,只需部署这两个应用程序并逐步执行两组代码。拥有一些已知的工作代码也有助于排除 HRM 无法正常运行的可能性。

关于安卓蓝牙获取心率测量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31607936/

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