简体   繁体   English

Android蓝牙LE连接至心率监测器

[英]Android Bluetooth LE connection to heart rate monitor

I am absolutely new to android programming and Bluetooth LE. 我绝对是android编程和Bluetooth LE的新手。 So pls be patient ;) I have a few example programs, but they are pretty hard to understand. 所以请耐心;)我有一些示例程序,但是很难理解。 I am currently working on an program, which should display the heart rate, received form a chest strap (Zephyr HXM2) by Bluetooth LE. 我目前正在开发一个程序,该程序应显示心率,并由Bluetooth LE从胸带(Zephyr HXM2)接收。 I managed to get a connection and to read characteristics like the serial number string. 我设法建立了连接并读取了诸如序列号字符串之类的特征。 But where I do have problems is in getting the heart rate measurement (UUID = 0x2A37) . 但是我确实遇到问题的是获取心率测量值(UUID = 0x2A37)

So what my program actually does is: 所以我的程序实际执行的是:

enabling the notification of the descriptor (UUID =00002902-0000-1000-8000-00805f9b34fb) 启用描述符的通知(UUID =00002902-0000-1000-8000-00805f9b34fb)

descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);

then I wait for the onCharacteristicChanged Method and do the getvalue function. 然后我等待onCharacteristicChanged方法并执行getvalue函数。

BluetoothGattCharacteristic.getValue()

First thing I don't know if this is the right way, secondly I get data, but it varies from 2,4 and 6 bytes. 首先,我不知道这是否正确,其次,我获取数据,但它的大小为2,4和6个字节。 Don't know what to do with them. 不知道该怎么办。

Last time I worked with the Zephyr heart rate monitor I simply set a few constants: 上一次我使用Zephyr心率监测器时,我只是设置了一些常数:

private static final int HEART_RATE = 0x100;
private static final int RESPIRATION_RATE = 0x101;
private static final int SKIN_TEMPERATURE = 0x102;
private static final int POSTURE = 0x103;
private static final int PEAK_ACCLERATION = 0x104;

then created a message handler with a switch statement: 然后使用switch语句创建消息处理程序:

@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case HEART_RATE:
            // do stuff
            break;
        case RESPIRATION_RATE:
            // do stuff
            break;
    }
}

then get data out with calls such as msg.getData().getString("RespirationRate"); 然后通过诸如msg.getData().getString("RespirationRate");调用获取数据 and msg.getData().getString("SkinTemperature"); msg.getData().getString("SkinTemperature");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM