zhubaomin
2025-04-07 1a2b07f01ba4616fd9e894dddf474b56d020158c
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;
@@ -22,7 +24,12 @@
        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("未连接通信中间件,不能发送数据");
@@ -39,7 +46,7 @@
     * @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] ;
@@ -60,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 ;
    }
}