How to get data out of bluetooth characteristic in Swift

后端 未结 2 885
别那么骄傲
别那么骄傲 2021-02-04 16:41

I\'ve got a Polar h7 device around me right now (it\'s BTLE) and I\'ve got everything working but I am confused about how to get the BPM our of the characteristic.value

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 16:56

    If anyone's wondering how to calculate the RR value. Taking the first array as an example:

    [22, 77, 22, 3] in binary is 0001 0110  0100 1101  0001 0110 0000 0011
    

    If we break it a part we have:

    Flag (8bit) = 22 or 0001 0110
    HRV (8bit) = 77 or 0100 1101
    RR (16bit) = 22 & 3 or 0001 0110 0000 0011
    

    Because Bluetooth.org says the order is LSO (Least Significant Octet) to MSO (Most significant Octet) 22 and 3 need to be swapped leaving:

    790 or 0000 0011 0001 0110
    

    Because the resolution is 1/1024 seconds. The RR value = 790/1024 = 0.77s.

提交回复
热议问题