android蓝牙LE,如何获得RR间隔
我正在开发一个android应用程序,使用蓝牙LE,我需要获得RR间隔。我从android开发者网站上的这个例子开始:android蓝牙LE,如何获得RR间隔,android,ios,bluetooth-lowenergy,Android,Ios,Bluetooth Lowenergy,我正在开发一个android应用程序,使用蓝牙LE,我需要获得RR间隔。我从android开发者网站上的这个例子开始: private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); // This
private void broadcastUpdate(final String action,
final BluetoothGattCharacteristic characteristic) {
final Intent intent = new Intent(action);
// This is special handling for the Heart Rate Measurement profile. Data
// parsing is carried out as per profile specifications.
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
int flag = characteristic.getProperties();
int format = -1;
if ((flag & 0x01) != 0) {
format = BluetoothGattCharacteristic.FORMAT_UINT16;
Log.d(TAG, "Heart rate format UINT16.");
} else {
format = BluetoothGattCharacteristic.FORMAT_UINT8;
Log.d(TAG, "Heart rate format UINT8.");
}
final int heartRate = characteristic.getIntValue(format, 1);
Log.d(TAG, String.format("Received heart rate: %d", heartRate));
intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));
} else {
// For all other profiles, writes the data formatted in HEX.
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));
intent.putExtra(EXTRA_DATA, new String(data) + "\n" +
stringBuilder.toString());
}
}
sendBroadcast(intent);
}
如何获得RR间隔?我只是在iOS上做,但在java上我不知道怎么做
这是我在iOS上的代码,非常有效:
- (void) updateWithHRMData:(NSData *)datas {
const uint8_t *reportData = [datas bytes];
uint16_t bpm = 0;
uint16_t bpm2 = 0;
if ((reportData[0] & 0x04) == 0)
{
NSLog(@"%@", @"Data are not present");
}
else
{
bpm = CFSwapInt16LittleToHost(*(uint16_t *)(&reportData[2]));
bpm2 = CFSwapInt16LittleToHost(*(uint16_t *)(&reportData[4]));
if (bpm != 0 || bpm2 != 0) {
self.deviceReady = true;
[lblNofascia setAlpha:0.0];
[btnMonitor setAlpha:1.0];
if (isRunning) {
[self.elencoBattiti addObject:[NSString stringWithFormat:@"%u", bpm]];
NSLog(@"%u", bpm);
if (bpm2 != 0) {
[self.elencoBattiti addObject:[NSString stringWithFormat:@"%u", bpm2]];
NSLog(@"%u", bpm2);
}
}
} else {
if (isRunning) {
totErrori++;
NSLog(@"Dato non trasmesso");
if (totErrori > 5) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attenzione" message:@"Ho perso la connettività con la fascia. Ripetere la misurazione" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Continua", nil];
[alert show];
[self stopRunning];
}
}
}
}
}
谢谢我有以下几点
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
int flag = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
int format = -1;
int energy = -1;
int offset = 1;
int rr_count = 0;
if ((flag & 0x01) != 0) {
format = BluetoothGattCharacteristic.FORMAT_UINT16;
Logger.trace("Heart rate format UINT16.");
offset = 3;
} else {
format = BluetoothGattCharacteristic.FORMAT_UINT8;
Logger.trace("Heart rate format UINT8.");
offset = 2;
}
final int heartRate = characteristic.getIntValue(format, 1);
Logger.trace("Received heart rate: {}", heartRate);
if ((flag & 0x08) != 0) {
// calories present
energy = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
offset += 2;
Logger.trace("Received energy: {}", energy);
}
if ((flag & 0x10) != 0){
// RR stuff.
rr_count = ((characteristic.getValue()).length - offset) / 2;
for (int i = 0; i < rr_count; i++){
mRr_values[i] = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
offset += 2;
Logger.trace("Received RR: {}", mRr_values[i]);
}
}
if(UUID\u HEART\u RATE\u MEASUREMENT.equals(characteristic.getUuid()){
int flag=characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8,0);
int格式=-1;
int能量=-1;
int offset=1;
int rr_计数=0;
如果((标志&0x01)!=0){
格式=BluetoothGattCharacteristic.format_UINT16;
trace(“心率格式UINT16”);
偏移量=3;
}否则{
格式=BluetoothGattCharacteristic.format_UINT8;
trace(“心率格式UINT8”);
偏移量=2;
}
最终整数心率=characteristic.getIntValue(格式1);
trace(“接收到的心率:{}”,心率);
如果((标志&0x08)!=0){
//卡路里含量
能量=特征.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16,偏移量);
偏移量+=2;
trace(“接收能量:{}”,能量);
}
如果((标志&0x10)!=0){
//RR的东西。
rr_计数=((characteristic.getValue()).length-offset)/2;
对于(int i=0;i
我有以下几点
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
int flag = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
int format = -1;
int energy = -1;
int offset = 1;
int rr_count = 0;
if ((flag & 0x01) != 0) {
format = BluetoothGattCharacteristic.FORMAT_UINT16;
Logger.trace("Heart rate format UINT16.");
offset = 3;
} else {
format = BluetoothGattCharacteristic.FORMAT_UINT8;
Logger.trace("Heart rate format UINT8.");
offset = 2;
}
final int heartRate = characteristic.getIntValue(format, 1);
Logger.trace("Received heart rate: {}", heartRate);
if ((flag & 0x08) != 0) {
// calories present
energy = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
offset += 2;
Logger.trace("Received energy: {}", energy);
}
if ((flag & 0x10) != 0){
// RR stuff.
rr_count = ((characteristic.getValue()).length - offset) / 2;
for (int i = 0; i < rr_count; i++){
mRr_values[i] = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
offset += 2;
Logger.trace("Received RR: {}", mRr_values[i]);
}
}
if(UUID\u HEART\u RATE\u MEASUREMENT.equals(characteristic.getUuid()){
int flag=characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8,0);
int格式=-1;
int能量=-1;
int offset=1;
int rr_计数=0;
如果((标志&0x01)!=0){
格式=BluetoothGattCharacteristic.format_UINT16;
trace(“心率格式UINT16”);
偏移量=3;
}否则{
格式=BluetoothGattCharacteristic.format_UINT8;
trace(“心率格式UINT8”);
偏移量=2;
}
最终整数心率=characteristic.getIntValue(格式1);
trace(“接收到的心率:{}”,心率);
如果((标志&0x08)!=0){
//卡路里含量
能量=特征.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16,偏移量);
偏移量+=2;
trace(“接收能量:{}”,能量);
}
如果((标志&0x10)!=0){
//RR的东西。
rr_计数=((characteristic.getValue()).length-offset)/2;
对于(int i=0;i
谢谢Ifor。通过一些修复,android代码应该可以工作。根据规范,RR数据标志的位掩码应该是16,并且数组应该声明为:
if ((flag & 0x16) != 0){
// RR stuff.
rr_count = ((characteristic.getValue()).length - offset) / 2;
Integer[] mRr_values = new Integer[rr_count];
for (int i = 0; i < rr_count; i++){
mRr_values[i] = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
offset += 2;
Logger.trace("Received RR: {}", mRr_values[i]);
}
}
if((标志&0x16)!=0){
//RR的东西。
rr_计数=((characteristic.getValue()).length-offset)/2;
整数[]mRr_值=新整数[rr_计数];
对于(int i=0;i
谢谢Ifor。通过一些修复,android代码应该可以工作。根据规范,RR数据标志的位掩码应该是16,并且数组应该声明为:
if ((flag & 0x16) != 0){
// RR stuff.
rr_count = ((characteristic.getValue()).length - offset) / 2;
Integer[] mRr_values = new Integer[rr_count];
for (int i = 0; i < rr_count; i++){
mRr_values[i] = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
offset += 2;
Logger.trace("Received RR: {}", mRr_values[i]);
}
}
if((标志&0x16)!=0){
//RR的东西。
rr_计数=((characteristic.getValue()).length-offset)/2;
整数[]mRr_值=新整数[rr_计数];
对于(int i=0;i
16是十六进制的0x10。用0x16屏蔽实际上匹配了3个不同的位,这是错误的。最好读一读十六进制格式…16是十六进制的0x10。用0x16屏蔽实际上匹配了3个不同的位,这是错误的。最好读一读十六进制格式。。。