From caf2599a9869244ded811018811c37a2aabac3fc Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期三, 08 一月 2025 11:29:05 +0800
Subject: [PATCH] 优化测温协议

---
 src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java
index 4eae202..75489e9 100644
--- a/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java
+++ b/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java
@@ -160,7 +160,12 @@
 
         String tempStr = "";
         for (int j = 0;j<cableY;j++){
-            tempStr = strMsg.substring((6+2*cableZ) * j,(6+2*cableZ)  * j + (6+2*cableZ) );
+            String index = BytesUtil.intToHexStr1((msgId -1)*cableY + j +1);
+            tempStr = strMsg.substring(strMsg.indexOf(index),strMsg.indexOf(index) + (6+2*cableZ) );
+            strMsg = strMsg.substring(strMsg.indexOf(index) + (6+2*cableZ));
+            //tempStr = strMsg.substring((6+2*cableZ) * j,(6+2*cableZ)  * j + (6+2*cableZ) );
+            log.info("----绾跨紗鎶ユ枃----锛�"+tempStr);
+            log.info("----鍓╀綑鎶ユ枃----锛�"+strMsg);
             //瀵嗛挜鍜岀偣鏁� 02 A4 BB BA BA B4
             String kyeNumHex = tempStr.substring(2, 4);
             String kyeNumBin = BytesUtil.toBinary8String(BytesUtil.hexToInt(kyeNumHex));
@@ -173,10 +178,11 @@
             //02 A4 BB BA BA B4
             start = 2 * 2;
             String tempHex;
-
             double point = 0;
-            for (int i = 0; i < numValue; i++) {
-                start = start + i * 2;
+            log.info("----鎶ユ枃----锛�"+tempStr);
+            log.info("----瀵嗛挜="+keyValue +"----鐐规暟="+numValue+"----"+"灞傛暟="+cableZ+"----");
+            for (int i = 0; i < cableZ; i++) {
+                start = start + (i * 2);
                 tempHex = tempStr.substring(start, start + 2);
                 //瀹為檯娓╁害锛濆瘑閽�*瀵嗛挜*37(婧㈠嚭涓烘棤绗﹀彿瀛楄妭)鍐嶅紓鎴栧姞瀵嗗悗鐨勬俯搴�/2銆�
                 point = this.getGrainTemp(keyValue, tempHex);
@@ -251,11 +257,11 @@
         GrainOutPut outPut = new GrainOutPut();
 
 
-        double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0, sumNum = cableX * cableY * cableZ;
+        double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0;
 
         List<GrainTemp> temperature = new ArrayList<>();
         //鏍瑰彿
-        int cableNum = 1, position = 0;
+        int cableNum = 1, position = 0,sumNum = 0;
 
         double curTemp;
         int x = 0, y = 0, z = 0;
@@ -271,12 +277,15 @@
 
             temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + ""));
 
-            sumT += curTemp;
-            if (curTemp > max) {
+            if (curTemp > max  && curTemp < 40) {
                 max = curTemp;
             }
-            if (curTemp < min) {
+            if (curTemp < min && curTemp > 3) {
                 min = curTemp;
+            }
+            if(curTemp > 3 &&  curTemp < 40){
+                sumT += curTemp;
+                sumNum++;
             }
         }
 
@@ -295,7 +304,7 @@
         outPut.setTemperature(temperature);
         outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + "");
         outPut.setMinTemperature(min + "");
-        outPut.setMaxTemperature(min + "");
+        outPut.setMaxTemperature(max + "");
         List<GrainTH> ths = new ArrayList<>();
 
 
@@ -322,7 +331,7 @@
             weatherStation.setId(device.getDeviceId());
         }
         weatherStation.setAirPressure(weather.getPressure());
-        weatherStation.setHumidity(weather.getHumidity());
+        weatherStation.setHumidity(weather.getHumidity().replaceAll("%",""));
         weatherStation.setPm(weather.getAir_pm25());
         weatherStation.setRadiation("0");
         weatherStation.setRainfallAmount(weather.getWea());

--
Gitblit v1.9.3