|
|
|
|
@ -21,8 +21,8 @@ import java.util.*;
|
|
|
|
|
public class AnalysisReceiveOrder485 { |
|
|
|
|
|
|
|
|
|
// 调用service
|
|
|
|
|
private final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
private final DecimalFormat df = new DecimalFormat("#.##"); |
|
|
|
|
// private final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
// private final DecimalFormat df = new DecimalFormat("#.##");
|
|
|
|
|
|
|
|
|
|
//解析冷量表
|
|
|
|
|
public void analysisCloudOrder485(final String dataStr1, final CollectionParamsManage deviceCodeParam) { |
|
|
|
|
@ -37,9 +37,8 @@ public class AnalysisReceiveOrder485 {
|
|
|
|
|
|
|
|
|
|
if (checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) { |
|
|
|
|
//创建SimpleDateFormat对象,指定样式 2019-05-13 22:39:30
|
|
|
|
|
Date date = new Date(); |
|
|
|
|
String dateStr = sdf1.format(date); |
|
|
|
|
; |
|
|
|
|
// Date date = new Date();
|
|
|
|
|
// String dateStr = sdf1.format(date);
|
|
|
|
|
//保留两位小数处理
|
|
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("0.00"); |
|
|
|
|
// 表号
|
|
|
|
|
@ -52,11 +51,11 @@ public class AnalysisReceiveOrder485 {
|
|
|
|
|
+ dataStr.substring(dataStr.length() - 10, dataStr.length() - 8); |
|
|
|
|
|
|
|
|
|
String registerAddr = deviceCodeParam.getRegisterAddr(); |
|
|
|
|
if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) { |
|
|
|
|
dateStr = dateStr.substring(0, 17) + "00"; |
|
|
|
|
} else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) { |
|
|
|
|
dateStr = dateStr.substring(0, 17) + "30"; |
|
|
|
|
} |
|
|
|
|
// if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) {
|
|
|
|
|
// dateStr = dateStr.substring(0, 17) + "00";
|
|
|
|
|
// } else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) {
|
|
|
|
|
// dateStr = dateStr.substring(0, 17) + "30";
|
|
|
|
|
// }
|
|
|
|
|
try { |
|
|
|
|
if (registerAddr.equals("32") || registerAddr.equals("33") || registerAddr.equals("35") || registerAddr.equals("36")) { |
|
|
|
|
data = decimalFormat.format(Math.abs(ExchangeStringUtil.hexToSingle(data)));//十六进制字符串转IEEE754浮点型
|
|
|
|
|
@ -90,9 +89,8 @@ public class AnalysisReceiveOrder485 {
|
|
|
|
|
|
|
|
|
|
if (checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) { |
|
|
|
|
//创建SimpleDateFormat对象,指定样式 2019-05-13 22:39:30
|
|
|
|
|
Date date = new Date(); |
|
|
|
|
String dateStr = sdf1.format(date); |
|
|
|
|
; |
|
|
|
|
// Date date = new Date();
|
|
|
|
|
// String dateStr = sdf1.format(date);
|
|
|
|
|
//保留两位小数处理
|
|
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("0.00"); |
|
|
|
|
// 表号
|
|
|
|
|
@ -105,13 +103,13 @@ public class AnalysisReceiveOrder485 {
|
|
|
|
|
+ dataStr.substring(dataStr.length() - 10, dataStr.length() - 8); |
|
|
|
|
|
|
|
|
|
int dataType = deviceCodeParam.getDataType(); |
|
|
|
|
if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) { |
|
|
|
|
dateStr = dateStr.substring(0, 17) + "00"; |
|
|
|
|
System.out.println("插入时间00" + dateStr); |
|
|
|
|
} else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) { |
|
|
|
|
dateStr = dateStr.substring(0, 17) + "30"; |
|
|
|
|
System.out.println("插入时间30" + dateStr); |
|
|
|
|
} |
|
|
|
|
// if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) {
|
|
|
|
|
// dateStr = dateStr.substring(0, 17) + "00";
|
|
|
|
|
// // System.out.println("插入时间00" + dateStr);
|
|
|
|
|
// } else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) {
|
|
|
|
|
// dateStr = dateStr.substring(0, 17) + "30";
|
|
|
|
|
// // System.out.println("插入时间30" + dateStr);
|
|
|
|
|
// }
|
|
|
|
|
try { |
|
|
|
|
if (dataType == 3) { |
|
|
|
|
data = decimalFormat.format(Math.abs(ExchangeStringUtil.hexToSingle(data)));//十六进制字符串转IEEE754浮点型
|
|
|
|
|
@ -160,8 +158,8 @@ public class AnalysisReceiveOrder485 {
|
|
|
|
|
|
|
|
|
|
if (checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) { |
|
|
|
|
//创建SimpleDateFormat对象,指定样式 2019-05-13 22:39:30
|
|
|
|
|
Date date = new Date(); |
|
|
|
|
String dateStr = sdf1.format(date); |
|
|
|
|
// Date date = new Date();
|
|
|
|
|
// String dateStr = sdf1.format(date);
|
|
|
|
|
; |
|
|
|
|
//保留两位小数处理
|
|
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("0.00"); |
|
|
|
|
@ -175,13 +173,13 @@ public class AnalysisReceiveOrder485 {
|
|
|
|
|
+ dataStr.substring(dataStr.length() - 10, dataStr.length() - 8); |
|
|
|
|
|
|
|
|
|
int dataType = deviceCodeParam.getDataType(); |
|
|
|
|
if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) { |
|
|
|
|
dateStr = dateStr.substring(0, 17) + "00"; |
|
|
|
|
System.out.println("插入时间00" + dateStr); |
|
|
|
|
} else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) { |
|
|
|
|
dateStr = dateStr.substring(0, 17) + "30"; |
|
|
|
|
System.out.println("插入时间30" + dateStr); |
|
|
|
|
} |
|
|
|
|
// if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) {
|
|
|
|
|
// dateStr = dateStr.substring(0, 17) + "00";
|
|
|
|
|
// // System.out.println("插入时间00" + dateStr);
|
|
|
|
|
// } else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) {
|
|
|
|
|
// dateStr = dateStr.substring(0, 17) + "30";
|
|
|
|
|
// // System.out.println("插入时间30" + dateStr);
|
|
|
|
|
// }
|
|
|
|
|
try { |
|
|
|
|
if (dataType == 3) { |
|
|
|
|
data = decimalFormat.format(Math.abs(ExchangeStringUtil.hexToSingle(data)));//十六进制字符串转IEEE754浮点型
|
|
|
|
|
@ -212,7 +210,7 @@ public class AnalysisReceiveOrder485 {
|
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
long min1 = calendar.getTimeInMillis(); |
|
|
|
|
long subtract = min1 - min; |
|
|
|
|
// System.out.println("相减值: " + subtract/(1000*60));
|
|
|
|
|
// // System.out.println("相减值: " + subtract/(1000*60));
|
|
|
|
|
return (int) subtract / (1000 * 60); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -241,8 +239,8 @@ public class AnalysisReceiveOrder485 {
|
|
|
|
|
|
|
|
|
|
if (checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) { |
|
|
|
|
//创建SimpleDateFormat对象,指定样式 2019-05-13 22:39:30
|
|
|
|
|
Date date = new Date(); |
|
|
|
|
String dateStr = sdf1.format(date); |
|
|
|
|
// Date date = new Date();
|
|
|
|
|
// String dateStr = sdf1.format(date);
|
|
|
|
|
|
|
|
|
|
//保留两位小数处理
|
|
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("0.00"); |
|
|
|
|
@ -254,13 +252,13 @@ public class AnalysisReceiveOrder485 {
|
|
|
|
|
+ dataStr.substring(dataStr.length() - 6, dataStr.length() - 4); |
|
|
|
|
|
|
|
|
|
int dataType = deviceCodeParam.getDataType(); |
|
|
|
|
if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) { |
|
|
|
|
dateStr = dateStr.substring(0, 17) + "00"; |
|
|
|
|
System.out.println("插入时间00" + dateStr); |
|
|
|
|
} else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) { |
|
|
|
|
dateStr = dateStr.substring(0, 17) + "30"; |
|
|
|
|
System.out.println("插入时间30" + dateStr); |
|
|
|
|
} |
|
|
|
|
// if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) {
|
|
|
|
|
// dateStr = dateStr.substring(0, 17) + "00";
|
|
|
|
|
// // System.out.println("插入时间00" + dateStr);
|
|
|
|
|
// } else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) {
|
|
|
|
|
// dateStr = dateStr.substring(0, 17) + "30";
|
|
|
|
|
// // System.out.println("插入时间30" + dateStr);
|
|
|
|
|
// }
|
|
|
|
|
try { |
|
|
|
|
if (dataType == 3) { |
|
|
|
|
data = decimalFormat.format(Math.abs(ExchangeStringUtil.hexToSingle(data)));//十六进制字符串转IEEE754浮点型
|
|
|
|
|
@ -283,4 +281,56 @@ public class AnalysisReceiveOrder485 {
|
|
|
|
|
} |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String analysisLiquidOrder485(String receiveStr, CollectionParamsManage deviceCodeParam) { |
|
|
|
|
// 去掉空格
|
|
|
|
|
String dataStr = receiveStr.replace(" ", "").toUpperCase(); |
|
|
|
|
// 检验报文
|
|
|
|
|
String checkStr = dataStr.substring(0, dataStr.length() - 4); |
|
|
|
|
byte[] strOrder = ExchangeStringUtil.hexStrToBinaryStr(checkStr); |
|
|
|
|
int checkNum = CRC16.CRC16_MODBUS(strOrder); |
|
|
|
|
String checkWord = ExchangeStringUtil.decToHex(String.valueOf(checkNum)); |
|
|
|
|
checkWord = checkWord.substring(2, 4) + checkWord.substring(0, 2); |
|
|
|
|
|
|
|
|
|
if (checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) { |
|
|
|
|
//创建SimpleDateFormat对象,指定样式 2019-05-13 22:39:30
|
|
|
|
|
// Date date = new Date();
|
|
|
|
|
// String dateStr = sdf1.format(date);
|
|
|
|
|
|
|
|
|
|
// 表号
|
|
|
|
|
String cloudId = ExchangeStringUtil.hexToDec(dataStr.substring(0, 2)); |
|
|
|
|
// 读数
|
|
|
|
|
String data = ""; |
|
|
|
|
data = dataStr.substring(dataStr.length() - 8, dataStr.length() - 4); |
|
|
|
|
|
|
|
|
|
int dataType = deviceCodeParam.getDataType(); |
|
|
|
|
// if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) {
|
|
|
|
|
// dateStr = dateStr.substring(0, 17) + "00";
|
|
|
|
|
// //// System.out.println("插入时间00" + dateStr);
|
|
|
|
|
// } else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) {
|
|
|
|
|
// dateStr = dateStr.substring(0, 17) + "30";
|
|
|
|
|
// //.out.println("插入时间30" + dateStr);
|
|
|
|
|
// }
|
|
|
|
|
try { |
|
|
|
|
if (dataType == 2 && (deviceCodeParam.getParamType().equals("11"))) { |
|
|
|
|
data = ExchangeStringUtil.hexToDec(data); |
|
|
|
|
BigDecimal bigDecimal = new BigDecimal(data); |
|
|
|
|
bigDecimal = bigDecimal.divide(new BigDecimal((int) Math.pow(10, deviceCodeParam.getDigits()))).setScale(3, RoundingMode.HALF_UP); // 除以1000并保留整数
|
|
|
|
|
data = bigDecimal.toString(); |
|
|
|
|
log.info("液位==>{},寄存器地址==>{},实时读数==>{}", cloudId, deviceCodeParam.getRegisterAddr(), data); |
|
|
|
|
} |
|
|
|
|
// 判断data大于99999999,就返回空
|
|
|
|
|
if (new BigDecimal(data).intValue() > 100) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
return data; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("保存液位数据失败!", e); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
log.info("液位===>{}", dataStr); |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|