From 7037f0de5c155c027b57380ecfd0925c8001b665 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期五, 13 十二月 2024 17:04:11 +0800
Subject: [PATCH] 同步配置文件

---
 pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu/src/main/java/com/dy/simRtu/tcpClient/upData/UpHeartBeat.java |   59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu/src/main/java/com/dy/simRtu/tcpClient/upData/UpHeartBeat.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu/src/main/java/com/dy/simRtu/tcpClient/upData/UpHeartBeat.java
index 944cadb..6acfbcc 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu/src/main/java/com/dy/simRtu/tcpClient/upData/UpHeartBeat.java
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu/src/main/java/com/dy/simRtu/tcpClient/upData/UpHeartBeat.java
@@ -2,6 +2,8 @@
 
 import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate;
 import com.dy.common.util.ByteUtil;
+import com.dy.common.util.DateTime;
+import com.dy.simRtu.ServerProperties;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -14,13 +16,20 @@
 
     private static final Logger log = LogManager.getLogger(UpHeartBeat.class) ;
 
+    private static boolean isFirst = true ;
+
     public static boolean upHeartBeat = true ;//鏄惁鍙互鍙戦�佸績璺�
 
     public static void upCd02Data(String rtuAddr){
         if(upHeartBeat){
             try{
                 if(UpData.session != null && UpData.session.isConnected()){
-                    byte[] bs = createData(rtuAddr) ;
+                    byte[] bs ;
+                    if(ServerProperties.argHeardBeatBy02True81False){
+                        bs = createCd02Data(rtuAddr) ;
+                    }else{
+                        bs = createCd81Data(rtuAddr) ;
+                    }
                     UpData.upSend(bs) ;
                 }else{
                     log.error("鏈繛鎺ラ�氫俊涓棿浠讹紝涓嶈兘鍙戦�佹暟鎹�");
@@ -37,11 +46,16 @@
      * @return 瀛楄妭鏁扮粍
      * @throws Exception 寮傚父
      */
-    private static byte[] createData(String rtuAddr) throws Exception {
+    private static byte[] createCd02Data(String rtuAddr) throws Exception {
         byte[] bytes = creatHead(rtuAddr, "02", (byte)0xB0);
 
         byte[] bs = new byte[1] ;
-        bs[0] = (byte)0xF2 ;//鏁版嵁鍩燂細 1 涓瓧鑺傦紝F0 鐧诲綍锛� F1 閫�鍑虹櫥褰曪紝F2 鍦ㄧ嚎淇濇寔銆�
+        if(isFirst){
+            isFirst = false ;
+            bs[0] = (byte)0xF0 ;//鏁版嵁鍩燂細 1 涓瓧鑺傦紝F0 鐧诲綍锛� F1 閫�鍑虹櫥褰曪紝F2 鍦ㄧ嚎淇濇寔銆�
+        }else{
+            bs[0] = (byte)0xF2 ;//鏁版嵁鍩燂細 1 涓瓧鑺傦紝F0 鐧诲綍锛� F1 閫�鍑虹櫥褰曪紝F2 鍦ㄧ嚎淇濇寔銆�
+        }
 
         bytes = ByteUtil.bytesMerge(bytes, bs) ;
 
@@ -53,4 +67,43 @@
 
         return bytes ;
     }
+
+
+
+    /**
+     * 鏋勯�犲績璺虫暟鎹�
+     * @return 瀛楄妭鏁扮粍
+     * @throws Exception 寮傚父
+     */
+    private static byte[] createCd81Data(String rtuAddr) throws Exception {
+        byte[] bytes = creatHead(rtuAddr, "81", (byte)0xB0);
+
+        int index = 0 ;
+        byte[] bs1 = new byte[4] ;
+        bs1[index++] = (byte)0x22 ;
+        bs1[index++] = (byte)0x6 ;
+        bs1[index++] = (byte)0x44 ;
+        bs1[index++] = (byte)0x00 ;
+        bytes = ByteUtil.bytesMerge(bytes, bs1) ;
+
+        int[] ymdhms = DateTime.yyyy_MM_dd_HH_MM_SS_2_ymdhmsGroup(DateTime.yyyy_MM_dd_HH_mm_ss()) ;
+        byte[] bs2 = new byte[6] ;
+        index = 0 ;
+        int index1 = 5 ;
+        bs2[index++] = ByteUtil.int2BCD_BE(ymdhms[index1--])[0] ;
+        bs2[index++] = ByteUtil.int2BCD_BE(ymdhms[index1--])[0] ;
+        bs2[index++] = ByteUtil.int2BCD_BE(ymdhms[index1--])[0] ;
+        bs2[index++] = ByteUtil.int2BCD_BE(ymdhms[index1--])[0] ;
+        bs2[index++] = ByteUtil.int2BCD_BE(ymdhms[index1--])[0] ;
+        bs2[index++] = ByteUtil.int2BCD_BE(ymdhms[index1--] - 2000)[0] ;
+        bytes = ByteUtil.bytesMerge(bytes, bs2) ;
+
+        GlCreate.createLen(bytes);//闀垮害鏀惧瓧鑺傛暟缁勪腑
+
+        byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC鍜屽熬鍙犲姞瀛楄妭鏁扮粍涓�
+
+        bytes = ByteUtil.bytesMerge(bytes, bsTail) ;
+
+        return bytes ;
+    }
 }

--
Gitblit v1.8.0