From 001f24d4efd7b818bc2224b976c82faf4f9e564c Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期五, 01 十一月 2024 11:25:00 +0800
Subject: [PATCH] 1、通信协议要增加版本号(目的为远程升级准备),原来没有版本号的协议默认为版本号为1,所以调整了程序命名; 2、流浪控制器与控制器数据库表都增加了协议版本号字段; 3、VO中Double和Float类型的属性增加注解@JsonFormat(shape = JsonFormat.Shape.NUMBER_FLOAT, pattern="0.00" )

---
 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java |  161 +++++++----------------------------------------------
 1 files changed, 23 insertions(+), 138 deletions(-)

diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java
index 0f58f3e..20a30f6 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java
@@ -1,8 +1,5 @@
 package com.dy.testClient.tcpClient;
 
-import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1;
-import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0;
-import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate;
 import com.dy.common.threadPool.ThreadPool;
 import com.dy.common.util.ByteUtil;
 import com.dy.testClient.ServerProperties;
@@ -13,6 +10,16 @@
 public class MyThreadJob  implements ThreadPool.Job {
 
     private static final Logger log = LogManager.getLogger(MyThreadJob.class) ;
+
+    public static String icCardAddr = "3B7D1E1A" ;
+    public static String icCardNo = "61181622830147821" ;
+    public static String openValveDt = "240711163700" ;
+    public static String cdC0 = "C0" ;
+    public static String cd83Open = "83Open" ;
+    public static String cd83Close = "83Close" ;
+
+
+    public static String curCd = cdC0 ;//閫氳繃淇敼杩欎釜鍊硷紝鏉ユ敼鍙樹笂鎶ユ暟鎹被鍨�
 
     public String rtuAddr;
     public String serverIp;
@@ -44,7 +51,7 @@
                 if(sendTimes <= ServerProperties.sendTimes){
                     log.info("RTU" + rtuAddr + "寮�濮嬩换鍔�");
                     log.info("RTU" + rtuAddr + "灏嗚鎵ц" + ServerProperties.sendTimes + "杞浠诲姟锛屽綋鍓嶈疆娆℃槸" + sendTimes);
-                    sendDataOfP206V1_0_0() ;
+                    sendDataOfP206V1(curCd) ;
                 }else{
                     if(ServerProperties.sendOverThenCloseConnect == 1){
                         log.info("RTU" + rtuAddr + "绛夊緟涓�浼氾紝浠ユ帴鏀堕�氫俊涓棿浠朵笅琛屾暟鎹�");
@@ -64,11 +71,20 @@
         }
     }
 
-    private void sendDataOfP206V1_0_0(){
+    private void sendDataOfP206V1(String cd){
         try{
             if(heartbeatTimes > ServerProperties.heartbeatTimes){
                 heartbeatTimes = 1 ;
-                this.sendReportData() ;
+                byte[] bs = null ;
+                if(cd.equals(cdC0)){
+                    bs = RtuUpData.createCdC0(this.rtuAddr) ;
+                }else if(cd.equals(cd83Open)){
+                    bs = RtuUpData.createCd83Open(this.rtuAddr, icCardAddr, icCardNo, openValveDt) ;
+                }else if(cd.equals(cd83Close)){
+                    bs = RtuUpData.createCd83Close(this.rtuAddr, icCardAddr, icCardNo, openValveDt) ;
+                }
+                this.session.write(bs) ;
+                log.info("RTU" + rtuAddr + "鍙戦�佷簡涓婅鏁版嵁锛�" + ByteUtil.bytes2Hex(bs, false));
                 TcpClUnit.clientSendData();
                 sendTimes++ ;
             }else{
@@ -82,7 +98,7 @@
     }
     private void sendHeartbeat(){
         try{
-            byte[] bs = this.createHeartbeat() ;
+            byte[] bs = RtuUpData.createHeartbeat(this.rtuAddr) ;
             this.session.write(bs) ;
             log.info("RTU" + rtuAddr + "鍙戦�佷簡蹇冭烦鏁版嵁锛�" + ByteUtil.bytes2Hex(bs, false));
         }catch (Exception e){
@@ -90,15 +106,6 @@
         }
     }
 
-    private void sendReportData(){
-        try{
-            byte[] bs = this.createReport() ;
-            this.session.write(bs) ;
-            log.info("RTU" + rtuAddr + "鍙戦�佷簡涓婃姤鏁版嵁锛�" + ByteUtil.bytes2Hex(bs, false));
-        }catch (Exception e){
-            e.printStackTrace();
-        }
-    }
 
     private void jobOver(){
         if(ServerProperties.sendOverThenCloseConnect == 1){
@@ -108,128 +115,6 @@
         TcpClUnit.clientOver() ;
     }
 
-    /**
-     * 鏋勯�犲績璺虫暟鎹�
-     * @return 瀛楄妭鏁扮粍
-     * @throws Exception 寮傚父
-     */
-    public byte[] createHeartbeat( ) 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 ;
-
-        index++ ;
-        bsHead[index] = 0 ;//甯ч暱搴�
-
-        index++ ;
-        bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ;
-
-        index++ ;
-        bsHead[index] = commonV1_0_1.createCtrl((byte)0x80, (byte)0) ;//鎺у埗鍩熷姛鑳界爜锛氱‘璁� 璁ゅ彲
-
-        index++ ;
-        GlCreate.createRtuAddr(this.rtuAddr, bsHead, index);
-        index += 5 ;
-
-        ByteUtil.hex2Bytes("02", bsHead, index) ;
-
-        byte[] bs = new byte[1] ;
-        bs[0] = (byte)0xF2 ;//鏁版嵁鍩燂細 1 涓瓧鑺傦紝F0 鐧诲綍锛� F1 閫�鍑虹櫥褰曪紝F2 鍦ㄧ嚎淇濇寔銆�
-
-        bytes = ByteUtil.bytesMerge(bsHead, bs) ;
-
-        GlCreate.createLen(bytes);//闀垮害鏀惧瓧鑺傛暟缁勪腑
-
-        byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRC鍜屽熬鍙犲姞瀛楄妭鏁扮粍涓�
-
-        bytes = ByteUtil.bytesMerge(bytes, bsTail) ;
-
-        return bytes ;
-    }
-
-    /**
-     * 鏋勯�犱笂鎶ユ暟鎹�
-     * @return 瀛楄妭鏁扮粍
-     * @throws Exception 寮傚父
-     */
-    public byte[] createReport( ) 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 ;
-
-        index++ ;
-        bsHead[index] = 0 ;//甯ч暱搴�
-
-        index++ ;
-        bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ;
-
-        index++ ;
-        bsHead[index] = commonV1_0_1.createCtrl((byte)0x80, (byte)3) ;//鎺у埗鍩熷姛鑳界爜3锛氳嚜鎶ュ抚锛屾祦閲忥紙姘撮噺锛夊弬鏁�
-
-        index++ ;
-        GlCreate.createRtuAddr(this.rtuAddr, bsHead, index);
-        index += 5 ;
-
-        ByteUtil.hex2Bytes("C0", bsHead, index) ;
-
-        byte[] bs = new byte[2] ;
-        bs[0] = (byte)0x04 ;//鏈夋祦閲忔暟鎹�
-        bs[1] = (byte)0xE0 ;//鏈夋按鍘嬨�佺數姹犵數鍘嬨�佷俊鍙峰己搴�
-
-        bytes = ByteUtil.bytesMerge(bsHead, bs) ;
-
-        bs = new byte[5] ;//鐬椂娴侀噺
-        bs[0] = ByteUtil.int2BCD_LE (21)[0] ;
-        bs[1] = ByteUtil.int2BCD_LE (43)[0] ;
-        bs[2] = ByteUtil.int2BCD_LE (65)[0] ;
-        bytes = ByteUtil.bytesMerge(bytes, bs) ;
-
-        bs = new byte[5] ;//绱娴侀噺
-        bs[0] = ByteUtil.int2BCD_LE (21)[0] ;
-        bs[1] = ByteUtil.int2BCD_LE (43)[0] ;
-        bs[2] = ByteUtil.int2BCD_LE (65)[0] ;
-        bs[3] = ByteUtil.int2BCD_LE (87)[0] ;
-        bytes = ByteUtil.bytesMerge(bytes, bs) ;
-
-        bs = new byte[5] ;//鎹熷け娴侀噺
-        bs[0] = ByteUtil.int2BCD_LE (10)[0] ;
-        bs[1] = ByteUtil.int2BCD_LE (32)[0] ;
-        bs[2] = ByteUtil.int2BCD_LE (54)[0] ;
-        bytes = ByteUtil.bytesMerge(bytes, bs) ;
-
-        bs = new byte[4] ;//姘村帇
-        bs[0] = ByteUtil.int2BCD_LE (10)[0] ;
-        bs[1] = ByteUtil.int2BCD_LE (32)[0] ;
-        bs[2] = ByteUtil.int2BCD_LE (4)[0] ;
-        bytes = ByteUtil.bytesMerge(bytes, bs) ;
-
-        bs = new byte[4] ;//鐢垫睜鐢靛帇
-        bs[0] = ByteUtil.int2BCD_LE (10)[0] ;
-        bs[1] = ByteUtil.int2BCD_LE (32)[0] ;
-        bs[2] = ByteUtil.int2BCD_LE (10)[0] ;
-        bs[3] = ByteUtil.int2BCD_LE (32)[0] ;
-        bytes = ByteUtil.bytesMerge(bytes, bs) ;
-
-        bs = new byte[1] ;//淇″彿寮哄害
-        bs[0] = ByteUtil.int2BCD_LE (21)[0] ;
-        bytes = ByteUtil.bytesMerge(bytes, bs) ;
-
-        bs = new byte[6] ;//鏃堕挓
-        GlCreate.createTp(bs, 0);
-        bytes = ByteUtil.bytesMerge(bytes, bs) ;
-
-        GlCreate.createLen(bytes);//闀垮害鏀惧瓧鑺傛暟缁勪腑
-
-        byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRC鍜屽熬鍙犲姞瀛楄妭鏁扮粍涓�
-
-        bytes = ByteUtil.bytesMerge(bytes, bsTail) ;
-
-        return bytes ;
-    }
 
 
 

--
Gitblit v1.8.0