Files
UniversalTestSoftware/client/script/parse/TemperatureParser.java

35 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.cbsd.client.parse;
import com.cbsd.client.parse.IParseDataInterface;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Component
public class TemperatureParser implements IParseDataInterface{
@Override
public String parsePhysicalFromData(int sn, byte[] sourceData, byte[] fildData, String endian, String binStr) {
List<String> serialPortDataHexList = new ArrayList<>();
for (byte b : fildData) {
int h = (b >>> 4) & 0xF;
int l = b & 0xF;
char ch = (char) ((h < 10) ? ('0' + h) : ('A' + h - 10));
char cl = (char) ((l < 10) ? ('0' + l) : ('A' + l - 10));
String sb = String.valueOf(ch) + cl;
serialPortDataHexList.add(sb);
}
//温度
String temperatureChar = serialPortDataHexList.get(0) + serialPortDataHexList.get(1);
double temperature = Integer.parseInt(temperatureChar, 16) / 10.0;
return String.valueOf(temperature);
}
@Override
public String comment() {
return "温湿度解析第一个字节乘256+第二个字节结果除10";
}
}