Android 温度转换2字节
我很难在温度上转换两个字节。 我有一个控制单元(温度传感器),在那里我得到两个字节的温度信息 1)例如:Android 温度转换2字节,android,temperature,can-bus,Android,Temperature,Can Bus,我很难在温度上转换两个字节。 我有一个控制单元(温度传感器),在那里我得到两个字节的温度信息 1)例如: message: [ 40 ][ 25 ] LSBYTE : [ 40 ] MSBYTE : [ 25 ] 0.03125 C/bit temperature: 25C° ( seen from the display of the control unit ) message: [ 40 ][ 26 ] LSBYTE : [ 40 ] MSBYTE : [ 26 ] 0.03125 C/
message: [ 40 ][ 25 ]
LSBYTE : [ 40 ]
MSBYTE : [ 25 ]
0.03125 C/bit
temperature: 25C° ( seen from the display of the control unit )
message: [ 40 ][ 26 ]
LSBYTE : [ 40 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 30C° ( seen from the display of the control unit )
message: [ 20 ][ 26 ]
LSBYTE : [ 20 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 32C° ( seen from the display of the control unit )
message: [ c0 ][ 25 ]
LSBYTE : [ c0 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 29C° ( seen from the display of the control unit )
2)例如:
message: [ 40 ][ 25 ]
LSBYTE : [ 40 ]
MSBYTE : [ 25 ]
0.03125 C/bit
temperature: 25C° ( seen from the display of the control unit )
message: [ 40 ][ 26 ]
LSBYTE : [ 40 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 30C° ( seen from the display of the control unit )
message: [ 20 ][ 26 ]
LSBYTE : [ 20 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 32C° ( seen from the display of the control unit )
message: [ c0 ][ 25 ]
LSBYTE : [ c0 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 29C° ( seen from the display of the control unit )
3)例如:
message: [ 40 ][ 25 ]
LSBYTE : [ 40 ]
MSBYTE : [ 25 ]
0.03125 C/bit
temperature: 25C° ( seen from the display of the control unit )
message: [ 40 ][ 26 ]
LSBYTE : [ 40 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 30C° ( seen from the display of the control unit )
message: [ 20 ][ 26 ]
LSBYTE : [ 20 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 32C° ( seen from the display of the control unit )
message: [ c0 ][ 25 ]
LSBYTE : [ c0 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 29C° ( seen from the display of the control unit )
4)例如:
message: [ 40 ][ 25 ]
LSBYTE : [ 40 ]
MSBYTE : [ 25 ]
0.03125 C/bit
temperature: 25C° ( seen from the display of the control unit )
message: [ 40 ][ 26 ]
LSBYTE : [ 40 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 30C° ( seen from the display of the control unit )
message: [ 20 ][ 26 ]
LSBYTE : [ 20 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 32C° ( seen from the display of the control unit )
message: [ c0 ][ 25 ]
LSBYTE : [ c0 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 29C° ( seen from the display of the control unit )
我不知道如何将信息转换为温度
我请求你的支持。
谁能给我一个解决方案,它可以在我的项目中进行协作(创建一个android应用程序来接收来自控制单元的消息)它似乎在上面的字节中给出了整个temp,在下面的字节中给出了分数。这将是25.15625(25+40/256) 我不知道0.03125 C/位是从哪里来的。这意味着16位=0.5C。好像是胡说八道 另一种可能的解释是.03125*total=摄氏度。如果MSB为25,LSB为40,则总和为201.25度。所以…可能不对 编辑: 0.03125=1/32 没有一个点使用最后5位。这是分数分量。取高位字节、低位字节,右移5位,然后减去273(用于开尔文到C的转换)。这只是字节顺序。最重要的字节是MSB。它看起来像是以摄氏度为单位的。因此,只需这样读(请原谅伪代码):
在你的例子中,温度仅为25.40℃解决方案是:如果我有一个示例消息:[20][26],温度为32℃
公式是:十进制2620是9760(9760*0.03125)-273.15=31.85=32°C谢谢你的回答,但这不是正确的公式,因为需要另一条信息:“[40][26]温度是30°A,请相信模块的数据表在这里会有所帮助。你的数据没有意义。它甚至不是线性的。但是,如果取完整的2字节数乘以0.03125(MSBYTE*256+LSBYTE)/32-273,则接近开尔文值。解决方案是:如果我有一个示例消息:[20][26],温度是32℃,则公式是:十进制的2620是9760(9760*0.03125)-273.15=31.85=32℃,谢谢你的回答,但这不是正确的公式,因为另一条信息:[40][26]温度是30摄氏度