From 420908594a3a926765c37cb1c6bd20ba74556109 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 25 七月 2024 16:07:43 +0800
Subject: [PATCH] 1、完善协议解析(RTU地址解析); 2、测试系统增加设置RTU地址的命令测试。

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java                      |    2 
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_10_Down.java                  |   80 +++++++++++++++++++++++----------------
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/downVos/Com10Vo.java                   |   10 +++++
 pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/ComSupportP206V1_0_0.java  |    2 
 pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/CommandP206V1_0_0Ctrl.java |   10 ++++
 5 files changed, 68 insertions(+), 36 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java
index 3e347ff..929f503 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java
@@ -99,7 +99,7 @@
 	public String parseRtuAddr(byte[] bs, int index)throws Exception{
 		String rtuAddrBCD = "" + ByteUtil.BCD2Long_BE(bs, index, index + 2) ;//鍦板潃鏄ぇ绔ā寮�
 		String rtuAddrStr = "" + ByteUtilUnsigned.bytes2Short_LE(bs, index + 3) ;
-		while(rtuAddrStr.length() < 5){
+		while(rtuAddrStr.length() <= 5){
 			rtuAddrStr = "0" + rtuAddrStr ;
 		}
 		return rtuAddrBCD + rtuAddrStr ;
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/downVos/Com10Vo.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/downVos/Com10Vo.java
new file mode 100644
index 0000000..ee265ff
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/downVos/Com10Vo.java
@@ -0,0 +1,10 @@
+package com.dy.common.mw.protocol.p206V1_0_0.downVos;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2024/7/25 15:27
+ * @Description
+ */
+public class Com10Vo {
+    public String rtuAddr ;
+}
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_10_Down.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_10_Down.java
index 356d492..f550915 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_10_Down.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_10_Down.java
@@ -1,10 +1,14 @@
 package com.dy.common.mw.protocol.p206V1_0_0.parse;
 
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
 import com.dy.common.mw.protocol.*;
 import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1;
 import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1;
 import com.dy.common.mw.protocol.p206V1_0_0.ParseParamsForDownV1_0_1;
 import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0;
+import com.dy.common.mw.protocol.p206V1_0_0.downVos.Com10Vo;
+import com.dy.common.mw.protocol.p206V1_0_0.downVos.Com3AVo;
 import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate;
 import com.dy.common.util.ByteUtil;
 
@@ -51,48 +55,58 @@
      * @throws Exception 寮傚父
      */
     public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception {
-        CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ;
-        byte[] bytes ;
-        byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ;
-        byte index = 0 ;
-        bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ;
+        if(para.param == null) {
+            throw new Exception("鍛戒护鍙傛暟涓簄ull") ;
+        }else {
+            JSONObject obj = (JSONObject) para.param;
+            String json = obj.toJSONString();
+            Com10Vo cvo = JSON.parseObject(json, Com10Vo.class);
+            if (cvo == null) {
+                throw new Exception("json杞珻om10Vo涓簄ull");
+            }
+            if (cvo.rtuAddr == null) {
+                throw new Exception("娴嬭瘯鏂板湴鍧�涓嶈兘涓虹┖");
+            }
 
-        index++ ;
-        bsHead[index] = 0 ;//甯ч暱搴�
+            CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1();
+            byte[] bytes;
+            byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code];
+            byte index = 0;
+            bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte;
 
-        index++ ;
-        bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ;
+            index++;
+            bsHead[index] = 0;//甯ч暱搴�
 
-        index++ ;
-        bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ;
+            index++;
+            bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte;
 
-        index++ ;
-        GlCreate.createRtuAddr(para.rtuAddr, bsHead, index);
-        index += 5 ;
+            index++;
+            bsHead[index] = commonV1_0_1.createCtrl((byte) 0, (byte) 0);
 
-        ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ;
+            index++;
+            GlCreate.createRtuAddr(para.rtuAddr, bsHead, index);
+            index += 5;
 
-        if(para.param == null){
-            throw new Exception("鏈彁渚涘懡浠ゅ弬鏁版暟鎹紝涓嶈兘鏋勯�犲姛鑳界爜涓�" + para.commandCode + "鐨勪笅琛屽懡浠�") ;
-        }else{
-            index = 0 ;
-            byte[] bs = new byte[13] ;
-            String newRtuAddr = (String)para.param ;
-            GlCreate.createRtuAddr(newRtuAddr, bs, index);
-            index += 5 ;
+            ByteUtil.hex2Bytes(para.commandCode, bsHead, index);
+
+            index = 0;
+            byte[] bs = new byte[13];
+
+            GlCreate.createRtuAddr(cvo.rtuAddr, bs, index);
+            index += 5;
             GlCreate.createPw(bs, index);
-            index += 2 ;
+            index += 2;
             GlCreate.createTp(bs, index);
-            bytes = ByteUtil.bytesMerge(bsHead, bs) ;
+            bytes = ByteUtil.bytesMerge(bsHead, bs);
+
+            GlCreate.createLen(bytes);//闀垮害鏀惧瓧鑺傛暟缁勪腑
+
+            byte[] bsTail = GlCreate.createCrcTail(bytes);//CRC鍜屽熬鍙犲姞瀛楄妭鏁扮粍涓�
+
+            bytes = ByteUtil.bytesMerge(bytes, bsTail);
+
+            return bytes;
         }
-
-        GlCreate.createLen(bytes);//闀垮害鏀惧瓧鑺傛暟缁勪腑
-
-        byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRC鍜屽熬鍙犲姞瀛楄妭鏁扮粍涓�
-
-        bytes = ByteUtil.bytesMerge(bytes, bsTail) ;
-
-        return bytes ;
     }
 
 }
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/ComSupportP206V1_0_0.java b/pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/ComSupportP206V1_0_0.java
index 6b98168..ed8e68c 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/ComSupportP206V1_0_0.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/ComSupportP206V1_0_0.java
@@ -20,7 +20,7 @@
 public class ComSupportP206V1_0_0 {
     protected static String mwUrlTest = "http://127.0.0.1:8070/rtuMw/com/test" ;
     protected static String mwUrlSendCom = "http://127.0.0.1:8070/rtuMw/com/send" ;
-    protected static String rtuAddr = "532328059995" ;
+    protected static String rtuAddr = "370829000001" ;
 
 //    protected static String mwUrlTest = "http://8.140.179.55:8071/rtuMw/com/test" ;
 //    protected static String mwUrlSendCom = "http://8.140.179.55:8071/rtuMw/com/send" ;
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/CommandP206V1_0_0Ctrl.java b/pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/CommandP206V1_0_0Ctrl.java
index f784196..48e0a22 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/CommandP206V1_0_0Ctrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/CommandP206V1_0_0Ctrl.java
@@ -29,7 +29,9 @@
         if(com == null){
             rt = this.connect() ;//杩炴帴閫氫俊涓棿浠舵祴璇�
         }else{
-            if(com.equals("21")){
+            if(com.equals("10")){
+                rt = this.cd10() ;
+            }else if(com.equals("21")){
                 rt = this.cd21() ;
             }else if(com.equals("37")){
                 rt = this.cd37() ;
@@ -81,6 +83,12 @@
         return this.sendTest() ;
     }
 
+    private BaseResponse cd10(){
+        Com10Vo comVo = new Com10Vo() ;
+        comVo.rtuAddr = "532328059995" ;//鍓�6浣嶆槸琛屾斂鍖哄垝鐮侊紝鍚�6浣嶆槸搴忓垪鍙锋渶澶ф槸065535
+        return this.sendCom2Mw(this.command(CodeV1_0_1.cd_10, comVo, null)) ;
+    }
+
     private BaseResponse cd21(){
         Com21Vo comVo = new Com21Vo() ;
         comVo.ip = "8.140.180.59" ;//IP锛堜緥濡� 125.235.35.89锛�

--
Gitblit v1.8.0