如何从Bluetooth LE(SIG)十六进制值提取温度十进制值 [英] How to extract temperature decimal value from a Bluetooth LE (SIG) hex value

查看:147
本文介绍了如何从Bluetooth LE(SIG)十六进制值提取温度十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个xamarin android应用程序,以连接到蓝牙低能耗温度计.我已经可以连接并读取其值.我的问题是它采用十六进制格式,但我还没有找到一种以十进制(摄氏度)格式提取其值的方法.

I'm developing a xamarin android app to connect to a bluetooth low energy thermometer. I can already connect and read its value. My problem is that it's in hexadecimal format and i haven't found a way to extract its value in a decimal (celsius) format.

以下是一些示例读数:

  • 对于36.0摄氏度,我得到06-68-01-00-FF-E2-07-03-0A-15-34-00-02
  • 对于36.2摄氏度,我得到06-6A-01-00-FF-E2-07-03-0A-14-14-00-02
  • 36.8摄氏度时,我得到06-70-01-00-FF-E2-07-03-0A-14-1B-00-02
  • 对于34.6摄氏度,我得到06-5A-01-00-FF-E2-07-03-0A-14-1F-00-02

据我了解,它必须是上面2º的列"(十六进制值68、6A,70、5A).10º和11º柱"接缝中的值与测量时间(hh-mm)有关.

From what i understand, it must be the 2º "column" above (hexadecimal values 68, 6A, 70, 5A). The values in the 10º and 11º "columns" seams to be related to measurement time (hh-mm).

我如何提取价值?我可以使用通用公式吗?有没有办法知道它的度量单位,以便我可以转换为摄氏度(如果尚未转换为摄氏度)?

How can i extract the value? Is there a generic formula i can use? Is there a way to know it's unit of measure so i can convert to celsius (if it isn't already)?

推荐答案

我的问题是它采用十六进制格式".我确定您会收到一个字节数组,只是以十六进制格式读取或打印它.

"My problem is that it's in hexadecimal format". I'm sure that you receive a byte-array, you just read or print it in hexadecimal format.

要获得有用的信息,您必须从原始字节数组中获取相关数据.

To get something useful, you have to get the relevant data from the original byte array.

06-68-01-00-FF-E2-07-03-0A-15-34-00-02是[6,104,1,0,255,226,7,3,10,21,52,0,2]

06-68-01-00-FF-E2-07-03-0A-15-34-00-02 is [6,104,1,0,255,226,7,3,10,21,52,0,2]

第一个字节(字节[0] = 6是位标记:00000110.

The first byte (byte[0] = 6 is a bit-flag: 00000110.

最右边的位0 = 0,表示以摄氏度为单位的温度测量值.(如果为1华氏度).位1 = 1,表示时间戳字段存在(如果不存在0时间戳字段).位2 = 1,表示存在温度类型字段(如果不存在0温度类型字段).

bit 0 is the most right = 0 , meaning Temperature Measurement Value in units of Celsius. (if 1 Fahrenheit). bit 1 = 1, meaning Time Stamp field present, if 0 Time Stamp field not present. bit 2 = 1, meaning Temperature Type field present, if 0 Temperature Type field not present.

所有其他位都不相关,它们保留以备将来使用.

All other bits are not relevant, they are reserved for future use.

Bites [1](104)和[2](1)是摄氏* 10的温度,以FLOAT表示.要获得temp乘以256的字节[2]并加上字节[1],将总数除以10.结果:1 * 256 + 104 =360.温度为36.0

Bites[1] (104) and [2] (1) is the temperature as FLOAT in Celsius * 10. To get the temp multiply byte[2] by 256 and add byte[1], divide total by 10. result: 1 * 256 + 104 = 360. Temperature is 36.0

Bites3和4在这里没有意义.通常,它们是4字节温度浮动的一部分.

Bites3 and 4 have no meaning here. normally they are part of the 4 byte temperature float.

[5](226)和[6](7)是INT16年:7 * 256 + 226 = 2018.

Bites [5] (226) and [6] (7) is the Year as INT16: 7 * 256 + 226 = 2018.

字节[7](3)是月份.0表示未知,1 = 1月,此处3 = 3月.

Byte[7] (3) is the month. 0 meaning unknown, 1 = January , here 3 = March.

Byte [8](10)是一个月中的某天,这里是10.

Byte[8] (10) is the day of the month, here 10.

Byte [10](21)是小时(午夜之后的小时数),这里是21.

Byte[10] (21) is the Hour(Number of hours past midnight), here 21.

字节[11](52)是分钟,这里是52.

Byte[11] (52) is the Minute, here 52.

Byte [12](0)是秒,这里是0.

Byte[12] (0) is the Second, here 0.

Byte [13](2)是温度类型,这里是主体(常规).

Byte[13] (2) is the Temperature Type, here Body (general).

1个腋窝
2身(一般)

1 Armpit
2 Body (general)

3个耳朵(通常是耳垂)

3 Ear (usually ear lobe)

4指

5条胃肠道

6口

7直肠

8趾

9个鼓膜(耳鼓)

10-255保留以供将来使用

10 - 255 Reserved for future use

0保留以备将来使用

这篇关于如何从Bluetooth LE(SIG)十六进制值提取温度十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆