package com.dy.pipIrrMwTestRtu.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.pipIrrMwTestRtu.ServerProperties;
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
/**
|
* @Author: liurunyu
|
* @Date: 2024/7/22 15:01
|
* @Description
|
*/
|
public class UpCd38 extends UpData {
|
|
private static final Logger log = LogManager.getLogger(UpCd38.class);
|
|
public static void upData() {
|
try {
|
if (UpData.session != null && UpData.session.isConnected()) {
|
byte[] bs = createData(ServerProperties.rtuAddr);
|
UpData.upSend(bs);
|
} else {
|
log.error("未连接通信中间件,不能发送数据");
|
}
|
} catch (Exception e) {
|
log.error("向通信中间件发送数据产生异常", e);
|
}
|
}
|
|
|
/**
|
* 构造数据
|
*
|
* @return 字节数组
|
* @throws Exception 异常
|
*/
|
private static byte[] createData(String rtuAddr) throws Exception {
|
byte[] bytes = creatHead(rtuAddr, "38", (byte)0xB0);
|
|
byte[] bs = new byte[1] ;
|
bs[0] = (byte)0x00 ;//报警金额高位
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[1] ;
|
ByteUtil.int2BCD_LE(40, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
|
bs = new byte[1] ;//秒钟
|
ByteUtil.int2BCD_LE(Integer.parseInt(DateTime.ss()), bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[1] ;//分钟
|
ByteUtil.int2BCD_LE(Integer.parseInt(DateTime.mm()), bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[1] ;//时钟
|
ByteUtil.int2BCD_LE(Integer.parseInt(DateTime.HH()), bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[1] ;//日
|
ByteUtil.int2BCD_LE(Integer.parseInt(DateTime.dd()), bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[]{(byte)0x0A} ;//
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
GlCreate.createLen(bytes);//长度放字节数组中
|
|
byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中
|
|
bytes = ByteUtil.bytesMerge(bytes, bsTail) ;
|
|
return bytes ;
|
}
|
}
|