package com.fzzy.protocol.zldz.analysis;
|
|
|
import com.fzzy.api.utils.BytesUtil;
|
import com.fzzy.gateway.entity.GatewayDevice;
|
import com.fzzy.protocol.ProtocolUtils;
|
import com.fzzy.protocol.data.THDto;
|
import com.fzzy.protocol.zldz.data.ReMessage;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* 解析温湿度信息
|
*
|
* @author Andy
|
*/
|
@Slf4j
|
@Component(AnalysisTH.BEAN_ID)
|
public class AnalysisTH {
|
|
public static final String BEAN_ID = "zldz.analysisTH";
|
|
|
public static int ERROR_TH_TAG = -50;
|
|
/**
|
* 解析仓库温湿度信息,将信息放在缓存中,以便粮情使用
|
*
|
* @param msg
|
* @param ser
|
*/
|
public void analysis8828(ReMessage msg, GatewayDevice ser) {
|
|
log.debug("-----------analysis8828------------{}.{}", ser.getIp(), ser.getPort());
|
|
String content = msg.getBody().getContent();
|
|
//温湿度地址,截取4位
|
String temp = content.substring(0, 0 + 2 * 2);
|
//高低位转换
|
temp = BytesUtil.tran_LH(temp);
|
int thAddr = BytesUtil.hexToInt(temp);
|
|
int t, h;
|
|
THDto th = new THDto();
|
th.setTempIn(ProtocolUtils.ERROR_TEMP);
|
th.setHumidityIn(ProtocolUtils.ERROR_TEMP);
|
|
//温度
|
int start = 2, len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
t = BytesUtil.hexToInt(temp);
|
if (t > 127) {//说明是负数
|
t = BytesUtil.hexToInt("FF" + temp);
|
}
|
if (t == ERROR_TH_TAG) {
|
log.error("{}温湿度解析异常,原因:没有检测到传感器", ser.getDeviceName());
|
th.setRemark(ser.getDeviceName() + "温湿度解析异常,原因:没有检测到传感器");
|
} else {
|
th.setTempIn(Double.valueOf(t));
|
}
|
|
//湿度
|
start = 3;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
h = BytesUtil.hexToInt(temp);
|
if (h > 127) {//说明是负数
|
h = BytesUtil.hexToInt("FF" + temp);
|
}
|
if (h == ERROR_TH_TAG) {
|
log.error("{}温湿度解析异常,原因:没有检测到传感器", ser.getDeviceName());
|
th.setRemark(ser.getDeviceName() + "温湿度解析异常,原因:没有检测到传感器");
|
} else {
|
th.setHumidityIn(Double.valueOf(h));
|
}
|
|
th.setSerId(ser.getId());
|
th.setThAddr(thAddr + "");
|
|
//存放缓存
|
ProtocolUtils.addTh2Map(ser.getDeviceId(), th);
|
|
log.info("仓温仓湿解析完成={}", th);
|
}
|
}
|