Files
UniversalTestSoftware/client/nginx/html/template/ParseTemplate.java

50 lines
1.5 KiB
Java
Raw Normal View History

package com.cbsd.client.parse;
import com.cbsd.client.parse.IParseDataInterface;
import java.util.ArrayList;
import java.util.List;
/**
* 解析脚本示例, 实现 IParseDataInterface 接口
*/
public class ParseTemplate implements IParseDataInterface{
/**
* 从数据解析物理值
*
* @param sn 当前字段序号
* @param sourceData 源数据
* @param fieldData 当前字段数据
* @param endian BIG大端序 LITTLE小端序
* @param binStr 二进制字符串
* @return 解析后的数据值
*/
@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);
}
/**
* 描述
*
* @return 描述内容
*/
@Override
public String comment() {
return "温湿度解析第一个字节乘256+第二个字节结果除10";
}
}