From a376b30e63684f1a0f5b7f45322801be9145c09f Mon Sep 17 00:00:00 2001
From: CZT <czt18638530771@163.com>
Date: 星期六, 07 十月 2023 10:43:19 +0800
Subject: [PATCH] 贝博粮情解析4

---
 igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grainv1/analysis/AnalysisService.java |   75 +++++++++++++++++++++++--------------
 1 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grainv1/analysis/AnalysisService.java b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grainv1/analysis/AnalysisService.java
index 297fd5c..f93e77b 100644
--- a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grainv1/analysis/AnalysisService.java
+++ b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grainv1/analysis/AnalysisService.java
@@ -20,6 +20,7 @@
 import com.ld.igds.protocol.beibo.grainv1.util.BeiboGrainServerUtils;
 import com.ld.igds.util.BytesUtil;
 import com.ld.igds.util.ContextUtil;
+import com.ld.igds.util.NumberUtil;
 import com.ld.igds.warn.WarnUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -51,7 +52,9 @@
     @Autowired
     private ExeOrderService exeOrderService;
 
-    public static Map<String, Map<String, String>> contextMap = new HashMap<>();
+    public static String result = "";
+
+    public static Map<String, String> contextMap = new HashMap<>();
 
     public static double ERROR_CHECK_TAG = -100.0;
 
@@ -62,19 +65,32 @@
     public static double MAX_TEMP = -50.0;
     public static double MIN_TEMP = 50.0;
 
+    public static void main(String[] args) {
+        String str = "00000000FFEB90FEAA41E821EC21EA21EC21ED21EC21E921E221E921E921E921EC21E921ED21F021E521E521E221E421E321E321E121DE21D721E021DD21DC21DF21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
+        System.out.println(str.substring(9*2, 10*2));
+    }
     /**
-     * 00000000FFEB90FEAA 41 E821EC21EA21EC21ED21EC21E921E221E921E921E921EC21E921ED21F021E521E521E221E421E321E321E121DE21D721E021DD21DC21DF21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+     * 00000000FFEB90FEAA41E821EC21EA21EC21ED21EC21E921E221E921E921E921EC21E921ED21F021E521E521E221E421E321E321E121DE21D721E021DD21DC21DF21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      *
      * @param hexStr
      */
     public void analysis(String ip, int port, String hexStr) {
 
-        ReMessage reMessage = ReMessageBuilder.getInstance().buildMessage(hexStr);
+        result += hexStr;
+        if(result.length() < 1066*2){
+            log.info("鍒嗘満------->>骞冲彴锛屾姤鏂囬暱搴︿笉澶燂紝绛夊緟涓嬩竴鍖呮暟鎹�");
+            return;
+        }
 
-        log.info("鍒嗘満------->>骞冲彴锛氫俊鎭姤鏂�={}", reMessage);
-
+        //灏佽鏁版嵁
+        ReMessage reMessage = ReMessageBuilder.getInstance().buildMessage(result);
+        reMessage.setIp(ip);
+        reMessage.setPort(port);
+        log.info("鍒嗘満------->>骞冲彴锛氱伯鎯呭畬鏁存姤鏂囦俊鎭�={}", reMessage);
+        result = "";
         if (!BeiboGrainServerUtils.MSG_START.startsWith(reMessage.getStartStr())) {
             log.error("鍒嗘満------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ細鎶ユ枃璧峰绗�={}閿欒锛屼笉瑙f瀽", reMessage.getStartStr());
+            return;
         }
 
         //鏍规嵁鍒嗘満鍦板潃鑾峰彇鍒嗘満淇℃伅
@@ -100,8 +116,7 @@
             return;
         }
 
-        DepotConf depotConf = commonService.getCacheDepotConf(
-                exeRequest.getCompanyId(), exeRequest.getDepotId());
+        DepotConf depotConf = commonService.getCacheDepotConf(exeRequest.getCompanyId(), exeRequest.getDepotId());
         if (null == depotConf) {
             String info = "绮儏瑙f瀽澶辫触:鍒嗘満=" + ser.getName() + "娌℃湁鑾峰彇鍒扮伯鎯呭弬鏁伴厤缃俊鎭��";
             log.error("鍒嗘満------>>>骞冲彴锛�" + info);
@@ -156,23 +171,6 @@
         }
 
         // 涓�鍒嗗嚑澶氫粨鎯呭喌锛岃�冭檻鍗曚粨閲囬泦鍜屽浠撻噰闆�
-        // 鍗曚粨閲囬泦鏃跺�欐暟鎹粠0杩斿洖
-        if (StringUtils.isEmpty(exeRequest.getDepotIds())) {
-
-            depotConf.setCableEnd(depotConf.getCableEnd() - depotConf.getCableStart() + 1);
-            depotConf.setCableStart(ser.getCableStart());
-
-            if (DepotType.TYPE_02.getCode().equals(depotConf.getDepotType())) {
-                analysisStep2(depotConf, ser, exeRequest, reMessage, sysConf);
-            } else if (DepotType.TYPE_04.getCode().equals(depotConf.getDepotType())) {
-                analysisStep2(depotConf, ser, exeRequest, reMessage, sysConf);
-            } else {
-                analysisStep1(depotConf, ser, exeRequest, reMessage, sysConf);
-            }
-
-            return;
-
-        }
 
         // 鎵归噺閲囬泦鎵�鏈夊叧鑱斾竴璧烽噰闆嗭紝閬嶅巻鎵ц
         for (DepotConf depotConfTemp : depotConfs) {
@@ -250,12 +248,22 @@
         int curRoot = 1;//鎵�鍦ㄦ牴
         int curCir = 1;//鎵�鍦ㄥ湀
         int cirLay = 1;//褰撳墠鍦堢殑灞�
+        int symbol = 0; //绗﹀彿浣�
         for (int i = 0; i < strPoints.length() / 4; i++) {
             temp = strPoints.substring(i * 4, i * 4 + 4);
             if (temp == null) {
                 temp = "0000";
             }
-            tempValue = BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) / 10.0;
+            //楂樹綆浣嶈浆鎹㈠悗杞负16浣嶄簩杩涘埗瀛楃涓�
+            temp = BytesUtil.toBinary8StringSame(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)), 16);
+            //绗﹀彿浣�
+            symbol = Integer.valueOf(temp.substring(0, 1));
+            //鑾峰彇娓╁害鍊�
+            tempValue = BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))) * 0.0625;
+            if(symbol == 1){
+                tempValue = (1- BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))))*0.0625;
+            }
+            tempValue = NumberUtil.keepPrecision(tempValue, 1);
 
             //闈炴甯稿��
             if (tempValue > ERROR_CHECK_TAG2) {
@@ -355,12 +363,23 @@
         List<Double> temps = new ArrayList<>();
         double tempValue;
         String temp;
+        int symbol = 0;
         for (int i = 0; i < strPoints.length() / 4; i++) {
             temp = strPoints.substring(i * 4, i * 4 + 4);
             if (temp == null) {
                 temp = "0000";
             }
-            tempValue = BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) / 10.0;
+
+            //楂樹綆浣嶈浆鎹㈠悗杞负16浣嶄簩杩涘埗瀛楃涓�
+            temp = BytesUtil.toBinary8StringSame(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)), 16);
+            //绗﹀彿浣�
+            symbol = Integer.valueOf(temp.substring(0, 1));
+            //鑾峰彇娓╁害鍊�
+            tempValue = BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))) * 0.0625;
+            if(symbol == 1){
+                tempValue = (1- BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))))*0.0625;
+            }
+            tempValue = NumberUtil.keepPrecision(tempValue, 1);
             // 璇存槑瑙f瀽鐨勬暟鎹湁闂
             if (tempValue == ERROR_CHECK_TAG || tempValue == ERROR_CHECK_TAG2) {
                 tempValue = Constant.ERROR_TEMP;
@@ -646,7 +665,7 @@
         return msg.getSerId() + "_" + curPacket;
     }
 
-    private String buildContextKey(ReMessage msg, String depotId) {
-        return msg.getCompanyId() + "_" + msg.getSerId() + "_" + depotId;
+    private String buildContextKey(String companyId, String serId) {
+        return companyId + "_" + serId;
     }
 }

--
Gitblit v1.9.3