Commit b3694a7e authored by 耿迪迪's avatar 耿迪迪

压力表上报 gengdidi

parent 14c2f6fd
...@@ -10,15 +10,15 @@ import java.text.ParseException; ...@@ -10,15 +10,15 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
public class DecryptReportedData { public class FlowmeterDecryptReportedData {
private Logger logger = LoggerFactory.getLogger(DecryptReportedData.class); private Logger logger = LoggerFactory.getLogger(FlowmeterDecryptReportedData.class);
private String reportedDataStr; private String reportedDataStr;
private String deviceType; private String deviceType;
public DecryptReportedData(String reportedDataStr,String deviceType) { public FlowmeterDecryptReportedData(String reportedDataStr, String deviceType) {
this.reportedDataStr = reportedDataStr; this.reportedDataStr = reportedDataStr;
this.deviceType = deviceType; this.deviceType = deviceType;
} }
......
package com.zehong.gassdevicereport.netty;
import com.zehong.gassdevicereport.entity.TDeviceReportData;
import com.zehong.gassdevicereport.utils.HexUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
public class PressureDecryptReportedData {
private Logger logger = LoggerFactory.getLogger(PressureDecryptReportedData.class);
private String reportedDataStr;
private String deviceType;
public PressureDecryptReportedData(String reportedDataStr) {
this.reportedDataStr = reportedDataStr;
}
public TDeviceReportData getReportedData(){
try {
TDeviceReportData tDeviceReportData = new TDeviceReportData();
//设备编号
tDeviceReportData.setDeviceNum(getDeviceNum());
//设备类型
getDeviceType();
//设备状态
String deviceStatus = getDeviceStatus();
tDeviceReportData.setDeviceStatus(deviceStatus);
float pressure = HexUtils.hexToFloat(reportedDataStr.substring(34, 42));
tDeviceReportData.setPressure(new BigDecimal(pressure));
return tDeviceReportData;
} catch (Exception e) {
logger.error("上报数据组装数据报错!"+e);
}
return null;
}
/**
* 获取设备编号
* @return
*/
private String getDeviceNum(){
String deviceNum = reportedDataStr.substring(0,30);
StringBuilder deviceNumStr = new StringBuilder("");
for(int i = 0; i < deviceNum.length(); i+=2){
String code = deviceNum.substring(i,i+2);
byte codeByte = HexUtils.hexToByte(code);
deviceNumStr.append(codeByte);
}
return deviceNum.toString();
}
/**
* 截取加密串获取设备类型
* @return
*/
private void getDeviceType(){
String deviceTypeNum = reportedDataStr.substring(30,32);
switch (deviceTypeNum){
case "A0":
this.deviceType = "ZH11-NB家用报警器";
break;
case "A1":
this.deviceType = "JT-ZH85N家用报警器";
break;
case "A2":
this.deviceType = "燃气压力监测仪";
break;
case "A3":
this.deviceType = "消防水压监测仪";
break;
default:
break;
}
}
/**
* 设备状态字段 16进制转为二进制 高位或地位不足8位时左边补0
* @return
*/
private String getDeviceStatus(){
String deviceStatus = reportedDataStr.substring(32, 34);
switch (deviceStatus){
case "01":
deviceStatus = "预热";
break;
case "02":
deviceStatus = "正常";
break;
case "03":
deviceStatus = "传感器故障";
break;
case "04":
deviceStatus = "报警";
break;
case "05":
deviceStatus = "低报";
break;
case "06":
deviceStatus = "高报";
break;
case "07":
deviceStatus = "通讯故障";
break;
case "08":
deviceStatus = "超量程";
break;
case "1x":
deviceStatus = "电池电量低";
break;
default:
break;
}
return deviceType+":"+deviceStatus;
}
}
...@@ -85,10 +85,11 @@ public class ServerHandler extends ChannelInboundHandlerAdapter { ...@@ -85,10 +85,11 @@ public class ServerHandler extends ChannelInboundHandlerAdapter {
int port = channel.localAddress().getPort(); int port = channel.localAddress().getPort();
TDeviceReportData tDeviceReportData; TDeviceReportData tDeviceReportData;
if(7397 == port){ if(7397 == port){
tDeviceReportData = new DecryptReportedData(msgStr,"nacangEVC300").getReportedData(); tDeviceReportData = new FlowmeterDecryptReportedData(msgStr,"nacangEVC300").getReportedData();
}else if (7398 == port){
tDeviceReportData = new FlowmeterDecryptReportedData(msgStr,"tianxinCPUcard").getReportedData();
}else{ }else{
tDeviceReportData = new DecryptReportedData(msgStr,"tianxinCPUcard").getReportedData(); tDeviceReportData = new PressureDecryptReportedData(msgStr).getReportedData();
} }
//缓存设备信息 //缓存设备信息
ReciveReportData reciveReportData = new ReciveReportData(); ReciveReportData reciveReportData = new ReciveReportData();
......
...@@ -64,4 +64,4 @@ logging: ...@@ -64,4 +64,4 @@ logging:
webSocektUrl: http://localhost:8903/gassafety/websocket/send webSocektUrl: http://localhost:8903/gassafety/websocket/send
netty: netty:
ports: 7397,7398 ports: 7397,7398,7399
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment