2017-06-20 77 views
1

我擁有一臺Polar H10設備,我對心率和RR間隔感興趣,我使用官方的藍牙低功耗API讀出Android系統。 Polar設備每隔一秒發送一次心率和RR間隔的數據包。現在我已經認識到,在每個這樣的包中是心率值,但是在一些包中沒有RR間隔值(RR間隔的值是-1)。RR間隔缺失值(BLE/Polar設備)

爲什麼會發生這種情況?我的設備是否損壞或者我在執行過程中犯了錯誤還是其他人也面臨此問題?

編輯:這是代碼。在public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)方法中,我收到來自Polar設備的更改值。這種方法大約每秒觸發一次。然後我解析如下特徵:

public int[] parse(BluetoothGattCharacteristic characteristic) { 

     double heartRate = extractHeartRate(c); 
     Integer[] interval = extractBeatToBeatInterval(c); 

     int[] result = null; 
     if (interval != null) { 
      result = new int[interval.length + 1]; 
     } else { 
      result = new int[2]; 
      result[1] = -1; 
     } 
     result[0] = (int) heartRate; 

     if (interval != null) { 
      for (int i = 0; i < interval.length; i++) { 
       result[i+1] = interval[i]; 
      } 
     } 

     return result; 
    } 


private static double extractHeartRate(
     BluetoothGattCharacteristic characteristic) { 

    int flag = characteristic.getProperties(); 
    Log.d(TAG, "Heart rate flag: " + flag); 
    int format = -1; 
    // Heart rate bit number format 
    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)); 
    return heartRate; 
} 

private static Integer[] extractBeatToBeatInterval(
     BluetoothGattCharacteristic characteristic) { 

    int flag = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0); 
    int format = -1; 
    int energy = -1; 
    int offset = 1; // This depends on hear rate value format and if there is energy data 
    int rr_count = 0; 

    if ((flag & 0x01) != 0) { 
     format = BluetoothGattCharacteristic.FORMAT_UINT16; 
     Log.d(TAG, "Heart rate format UINT16."); 
     offset = 3; 
    } else { 
     format = BluetoothGattCharacteristic.FORMAT_UINT8; 
     Log.d(TAG, "Heart rate format UINT8."); 
     offset = 2; 
    } 
    if ((flag & 0x08) != 0) { 
     // calories present 
     energy = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset); 
     offset += 2; 
     Log.d(TAG, "Received energy: {}"+ energy); 
    } 
    if ((flag & 0x16) != 0){ 
     // RR stuff. 
     Log.d(TAG, "RR stuff found at offset: "+ offset); 
     Log.d(TAG, "RR length: "+ (characteristic.getValue()).length); 
     rr_count = ((characteristic.getValue()).length - offset)/2; 
     Log.d(TAG, "RR length: "+ (characteristic.getValue()).length); 
     Log.d(TAG, "rr_count: "+ rr_count); 
     if (rr_count > 0) { 
      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; 
       Log.d(TAG, "Received RR: " + mRr_values[i]); 
      } 
      return mRr_values; 
     } 
    } 
    Log.d(TAG, "No RR data on this update: "); 
    return null; 
} 

解析方法返回的第一個元素是心率,第二個元素是RR間隔。碰巧有時第二個元素是-1(即沒有檢測到RR間隔)。

+0

向我們展示代碼 – pablisco

+0

@pablisco我已經添加了一些代碼 – machinery

回答

0

您的Polar設備或您發佈的軟件沒有任何問題。

對於這種情況,某些傳輸的數據包可能會丟失RR間隔測量值,並且該數值爲if ((flag & 0x16) != 0)

例如,假設您的設備每秒發送一次心臟測量值,並且您有50次節拍/秒:將會有一些RR間隔未測量的時間間隔,因爲該秒內沒有檢測到節拍(這是一個簡化解釋,只是爲了得到這一點)。