From d8eb22351c6d0bfe0c9f233edfd593538e6838c9 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期四, 24 四月 2025 13:58:49 +0800 Subject: [PATCH] 1、表阀一体机协议开阀类型变化; 2、表阀一体机协议开关阀报中增加水价数据; --- pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu/src/main/java/com/dy/simRtu/tcpClient/upData/UpHeartBeat.java | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 109 insertions(+), 0 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 new file mode 100644 index 0000000..6acfbcc --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu/src/main/java/com/dy/simRtu/tcpClient/upData/UpHeartBeat.java @@ -0,0 +1,109 @@ +package com.dy.simRtu.tcpClient.upData; + +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; + +/** + * @Author: liurunyu + * @Date: 2024/7/15 14:18 + * @Description + */ +public class UpHeartBeat extends UpData { + + 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 ; + if(ServerProperties.argHeardBeatBy02True81False){ + bs = createCd02Data(rtuAddr) ; + }else{ + bs = createCd81Data(rtuAddr) ; + } + UpData.upSend(bs) ; + }else{ + log.error("鏈繛鎺ラ�氫俊涓棿浠讹紝涓嶈兘鍙戦�佹暟鎹�"); + } + }catch (Exception e){ + log.error("鍚戦�氫俊涓棿浠跺彂閫佹暟鎹骇鐢熷紓甯�", e); + } + } + } + + + /** + * 鏋勯�犲績璺虫暟鎹� + * @return 瀛楄妭鏁扮粍 + * @throws Exception 寮傚父 + */ + private static byte[] createCd02Data(String rtuAddr) throws Exception { + byte[] bytes = creatHead(rtuAddr, "02", (byte)0xB0); + + byte[] bs = new byte[1] ; + 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) ; + + GlCreate.createLen(bytes);//闀垮害鏀惧瓧鑺傛暟缁勪腑 + + byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC鍜屽熬鍙犲姞瀛楄妭鏁扮粍涓� + + bytes = ByteUtil.bytesMerge(bytes, bsTail) ; + + 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