zhubaomin
2025-04-21 346b480ab7848c742065e9bf989abaf43b515613
pipIrr-platform/pipIrr-web/pipIrr-mwTest-rtu/src/main/java/com/dy/pipIrrMwTestRtu/tcpClient/upData/UpCd83Close.java
New file
@@ -0,0 +1,109 @@
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.pipIrrMwTestRtu.ServerProperties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
 * @Author: liurunyu
 * @Date: 2024/7/15 14:58
 * @Description
 */
public class UpCd83Close extends UpData {
    private static final Logger log = LogManager.getLogger(UpCd83Close.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 {
        UpConstant.addValve();//调整流量
        byte[] bytes = creatHead(rtuAddr, "83", (byte)0xB0);
        byte[] bs = new byte[1] ;
        bs[0] = (byte)0x02 ;//刷卡关阀
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[5] ;//累计流量
        ByteUtil.int2BCD_LE(UpConstant.totalAmount, bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[8] ;//IC卡编号
        GlCreate.createIcCardNo(ServerProperties.icCardNo, bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[4] ;//IC卡地址
        ByteUtil.hex2Bytes_LE(ServerProperties.icCardAddr, bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[4] ;//用水户余额
        ByteUtil.int2BCD_LE(UpConstant.remainMoney, bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[6] ;//开阀时间
        GlCreate.createTp(UpConstant.openValveDt(), bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        UpConstant.clearOpenValveDt();//清空开阀时间
        bs = new byte[6] ;//关阀时间
        GlCreate.createTp(UpConstant.closeValveDt(), bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[5] ;//用水户本次用水量
        ByteUtil.int2BCD_LE(UpConstant.thisAmount, bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[4] ;//用水户本次消费金额
        ByteUtil.int2BCD_LE(UpConstant.thisMoney, bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[2] ;//用水户本次用水时长
        ByteUtil.int2BCD_LE(UpConstant.thisTime, bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[1] ;//水价类型
        bs[0] = ByteUtil.int2BCD_LE (1)[0] ;
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[2] ;//水价
        ByteUtil.int2BCD_LE(UpConstant.thisPrice, bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[1] ;//卡类型
        bs[0] = ByteUtil.int2BCD_LE (1)[0] ;
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        bs = new byte[6] ;//控制器时钟
        GlCreate.createTp(bs, 0);
        bytes = ByteUtil.bytesMerge(bytes, bs) ;
        GlCreate.createLen(bytes);//长度放字节数组中
        byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中
        bytes = ByteUtil.bytesMerge(bytes, bsTail) ;
        return bytes ;
    }
}