gpt4 book ai didi

java - 使用小米手环和 BLE 测量心率

转载 作者:搜寻专家 更新时间:2023-10-30 21:10:35 26 4
gpt4 key购买 nike

我正在尝试实现简单的 sdk 以与健身追踪器小米手环配合使用。目前我可以跟踪步数、启动振动、处理传感器触摸,但我在心率测量方面遇到问题。我的 sdk 基于 https://github.com/pangliang/miband-sdk-android .为了测量心率,我需要将描述符写入适当的特性,以便在该特性的值更改时启用处理回调,然后将适当的数据写入心率控制点特性以直接启动心率测量过程。问题是在启动此过程的数据成功写入特征后心率测量过程未启动(当Mi Band开始测量心率时底部传感器闪烁绿色)。这可能是由于健身手环的新固件(固件版本:4.15.12.10;HeartRate 版本:1.3.74.64)引起的,或者我的代码存在一些缺陷:

/-------- MiBandProfile --------/
public static final UUID UUID_SERVICE_HEARTRATE = UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb");
public static final UUID UUID_NOTIFICATION_HEARTRATE = UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb");
public static final UUID UUID_CHAR_HEARTRATE = UUID.fromString("00002a39-0000-1000-8000-00805f9b34fb");
public static final UUID UUID_DESCRIPTOR_UPDATE_NOTIFICATION = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");

/-------- MiBandProtocol --------/
public static final byte[] START_HEART_RATE_SCAN = {21, 1, 1};

/-------- BleProvider --------/
public class BleProvider extends BluetoothGattCallback {

public interface NotifyListener {
void onNotify(byte[] data);
}

private HashMap<UUID, NotifyListener> mNotifyListeners = new HashMap<UUID, NotifyListener>();
.
.
.
public void setNotifyListener(UUID serviceUUID, UUID charaUUID, NotifyListener listener) {
//enable chara notofication
if (this.mGatt == null || !this.mIsServicesDiscovered) {
if (DBG) Log.d(Debug.TAG, "Device is not connected or services are not discovered");
return;
}

BluetoothGattCharacteristic chara = this.mGatt.getService(serviceUUID).getCharacteristic(charaUUID);

if (DBG) Log.d(Debug.TAG, "setCharacteristicNotification: " + this.mGatt.setCharacteristicNotification(chara, true));
BluetoothGattDescriptor descriptor = chara.getDescriptor(MiBandProfile.UUID_DESCRIPTOR_UPDATE_NOTIFICATION);
if (DBG) Log.d(Debug.TAG, "setValue: " + descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE));
if (DBG) Log.d(Debug.TAG, "writeDescriptor: " + this.mGatt.writeDescriptor(descriptor));
this.mNotifyListeners.put(charaUUID, listener);
}

@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
//this method must be called when the characteristic value was changed but nothing happened :(
super.onCharacteristicChanged(gatt, characteristic);

if (this.mNotifyListeners.containsKey(characteristic.getUuid())) {
this.mNotifyListeners.get(characteristic.getUuid()).onNotify(characteristic.getValue());
}
}
} //end BleProvider

.
.
.

setNotifyListener(MiBandProfile.UUID_SERVICE_HEARTRATE, MiBandProfile.UUID_NOTIFICATION_HEARTRATE, new BleProvider.NotifyListener(){...});
//waiting few seconds
writeCharacteristic(MiBandProfile.UUID_SERVICE_HEARTRATE, MiBandProfile.UUID_CHAR_HEARTRATE, MiBandProtocol.START_HEART_RATE_SCAN);

也许该协议(protocol)已被弃用,有人可以与我分享一个新协议(protocol)。我会很高兴)谢谢。

最佳答案

我解决了这个问题!在调用 setNotifyListener 跟踪脉搏值的变化之前,您必须将用户信息(年龄、体重)写入适当的特征,因为没有这个小米手环不会开始测量。

关于java - 使用小米手环和 BLE 测量心率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36311874/

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