| New file | 
 |  |  | 
 |  |  | package com.dy.simRtu202404.tcpClient.upData; | 
 |  |  |  | 
 |  |  | import com.dy.common.mw.protocol.p206V202404.parse.global.GlCreate; | 
 |  |  | import com.dy.common.util.ByteUtil; | 
 |  |  | import org.apache.logging.log4j.LogManager; | 
 |  |  | import org.apache.logging.log4j.Logger; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @Author: liurunyu | 
 |  |  |  * @Date: 2025/02/26 11:10 | 
 |  |  |  * @Description | 
 |  |  |  */ | 
 |  |  | public class UpHeartBeat extends UpData { | 
 |  |  |  | 
 |  |  |     private static final Logger log = LogManager.getLogger(UpHeartBeat.class) ; | 
 |  |  |  | 
 |  |  |     public static void upCd02Data(String rtuAddr){ | 
 |  |  |         try{ | 
 |  |  |             if(UpData.session != null && UpData.session.isConnected()){ | 
 |  |  |                 byte[] bs = createCd02Data(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)0x81); | 
 |  |  |  | 
 |  |  |         byte[] bs = new byte[]{(byte)0x02} ;//0x02:表阀一体机 | 
 |  |  |         bytes = ByteUtil.bytesMerge(bytes, bs) ; | 
 |  |  |  | 
 |  |  |         bs = new byte[]{(byte)0x0A} ;//项目编号 | 
 |  |  |         bytes = ByteUtil.bytesMerge(bytes, bs) ; | 
 |  |  |  | 
 |  |  |         bs = new byte[]{(byte)0xF2} ;//保持在线 | 
 |  |  |         bytes = ByteUtil.bytesMerge(bytes, bs) ; | 
 |  |  |  | 
 |  |  |         GlCreate.createLen(bytes);//长度放字节数组中 | 
 |  |  |  | 
 |  |  |         byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRC和尾叠加字节数组中 | 
 |  |  |  | 
 |  |  |         bytes = ByteUtil.bytesMerge(bytes, bsTail) ; | 
 |  |  |  | 
 |  |  |         return bytes ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |