Bluetooth low energy, how to parse R-R Interval value?

前端 未结 5 644
醉梦人生
醉梦人生 2021-01-07 02:18

My application is receiving information from smart heart device. Now i can see pulse value. Could you please help me to parse R-R Interval value? How can i check device supp

5条回答
  •  时光说笑
    2021-01-07 02:45

    Have you checked the Bluetooth spec? The sample code below is in C#, but I think it shows the way to parse the data in each heart rate packet.

    //first byte of heart rate record denotes flags
    byte flags = heartRateRecord[0];
    
    ushort offset = 1;
    
    bool HRC2 = (flags & 1) == 1;
    if (HRC2) //this means the BPM is un uint16
    {
        short hr = BitConverter.ToInt16(heartRateRecord, offset);
        offset += 2;
    }
    else //BPM is uint8
    {
        byte hr = heartRateRecord[offset];
        offset += 1;
    }
    
    //see if EE is available
    //if so, pull 2 bytes
    bool ee = (flags & (1 << 3)) != 0;
    if (ee)
        offset += 2;
    
    //see if RR is present
    //if so, the number of RR values is total bytes left / 2 (size of uint16)
    bool rr = (flags & (1 << 4)) != 0;
    if (rr)
    {
        int count = (heartRateRecord.Length - offset)/2;
        for (int i = 0; i < count; i++)
        {
            //each existence of these values means an R-Wave was already detected
            //the ushort means the time (1/1024 seconds) since last r-wave
            ushort value = BitConverter.ToUInt16(heartRateRecord, offset);
    
            double intervalLengthInSeconds = value/1024.0;
            offset += 2;
        }
    }
    

提交回复
热议问题