package com.dy.simRtu202404.tcpClient.upData;
|
|
import com.dy.common.mw.protocol.p206V202404.parse.global.GlCreate;
|
import com.dy.common.util.ByteUtil;
|
import com.dy.common.util.DateTime;
|
import com.dy.simRtu202404.ServerProperties;
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
/**
|
* @Author: liurunyu
|
* @Date: 2025/2/26 11:42
|
* @Description
|
*/
|
public class UpOpenCloseValve extends UpData {
|
|
private static final Logger log = LogManager.getLogger(UpOpenCloseValve.class) ;
|
|
private static String orderNo = null ;
|
private static String openValveDt = null ;
|
|
private static Double totalWaterAmount = 1234.56 ;//累计流量
|
private static Double remainMoney = 65.4321 ;//剩余金额
|
|
private static Double thisWaterAmount = 100.00 ;//本次使用水量
|
private static Double thisMoney = 10.00 ;//本次使用金额
|
|
public static void upCd84Data(String rtuAddr){
|
try{
|
if(UpData.session != null && UpData.session.isConnected()){
|
byte[] bs = createCd84Data(rtuAddr) ;
|
UpData.upSend(bs) ;
|
}else{
|
log.error("未连接通信中间件,不能发送数据");
|
}
|
}catch (Exception e){
|
log.error("向通信中间件发送数据产生异常", e);
|
}
|
}
|
|
public static void upCd85Data(String rtuAddr){
|
try{
|
if(UpData.session != null && UpData.session.isConnected()){
|
byte[] bs = createCd85Data(rtuAddr) ;
|
UpData.upSend(bs) ;
|
}else{
|
log.error("未连接通信中间件,不能发送数据");
|
}
|
}catch (Exception e){
|
log.error("向通信中间件发送数据产生异常", e);
|
}
|
}
|
|
|
/**
|
* 构造开阀数据
|
* @return 字节数组
|
* @throws Exception 异常
|
*/
|
private static byte[] createCd84Data(String rtuAddr) throws Exception {
|
orderNo = DateTime.yyyyMMddHHmmss() + "00" ;
|
openValveDt = DateTime.yyMMddhhmmss() ;
|
|
byte[] bytes = creatHead(rtuAddr, "84", (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)0xF0} ;//0xf0:阀门 0x00:水泵
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[]{(byte)0x00} ;//0x00:正常刷卡开泵/阀用水
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[4] ;//用户IC卡号 4字节HEX码(远程开泵/阀时此数据为0)
|
GlCreate.createIcCardAddr(ServerProperties.icCardAddr, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[8] ;//用户序列号 8字节 6字节BCD:行政编号 2字节HEX:用户编号
|
GlCreate.createIcCardNo(ServerProperties.icCardNo, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[8] ;//本次订单号 8字节 BCD码
|
ByteUtil.string2BCD_BE( bs, orderNo,0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[6] ;//开泵/阀时间 6字节的BCD码(秒分时日月年)
|
ByteUtil.string2BCD_LE( bs, openValveDt,0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[5] ;//水表累计水量 5字节BCD码,单位0.01立方米
|
ByteUtil.int2BCD_LE(Double.valueOf(totalWaterAmount * 100).intValue(), bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[5] ;//电表累计电量 5字节BCD码,单位0.01度
|
ByteUtil.int2BCD_LE(0, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[5] ;//用户剩余金额 5字节BCD码, 单位0.0001元
|
ByteUtil.int2BCD_LE(Double.valueOf(remainMoney * 10000).intValue(), bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[5] ;//用户剩余水量 5字节BCD码, 单位0.01m3
|
ByteUtil.int2BCD_LE(0, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[4] ;//机井/阀状态及报警信息 4字节HEX码 定义见表41
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
|
GlCreate.createLen(bytes);//长度放字节数组中
|
|
byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRC和尾叠加字节数组中
|
|
bytes = ByteUtil.bytesMerge(bytes, bsTail) ;
|
|
return bytes ;
|
}
|
|
/**
|
* 构造关阀数据
|
* @return 字节数组
|
* @throws Exception 异常
|
*/
|
private static byte[] createCd85Data(String rtuAddr) throws Exception {
|
if(orderNo == null){
|
orderNo = DateTime.yyyyMMddHHmmss() + "00" ;
|
}
|
if(openValveDt == null){
|
openValveDt = DateTime.yyMMddhhmmss() ;
|
}
|
|
totalWaterAmount += thisWaterAmount ;
|
remainMoney -= thisMoney ;
|
|
byte[] bytes = creatHead(rtuAddr, "85", (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)0x01} ;//关泵/阀方式 0x00:刷卡闭 0x01:平台关 0x02:APP关 0x03:非法卡关 0x04:水表通讯异常关 0x05:电表异常关 0x06:剩余水量不足关 0x07:剩余金额为0关 0x08:开泵/阀后管道没有流量关 0x09:掉电再上电关,0x0a:水表瞬时流量为0关,0x0b:刷卡开泵,远程关。0x0c:电池低电压关。
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[4] ;//用户IC卡号 4字节HEX码(远程开泵/阀时此数据为0)
|
GlCreate.createIcCardAddr(ServerProperties.icCardAddr, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[8] ;//用户序列号 8字节 6字节BCD:行政编号 2字节HEX:用户编号
|
GlCreate.createIcCardNo(ServerProperties.icCardNo, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[8] ;//本次订单号 8字节 BCD码
|
ByteUtil.string2BCD_BE( bs, orderNo,0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[6] ;//开始时间 6字节的BCD码(秒分时日月年)
|
ByteUtil.string2BCD_LE( bs, openValveDt,0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[6] ;//结束时间 6字节的BCD码(秒分时日月年)
|
ByteUtil.string2BCD_LE( bs, DateTime.yyMMddhhmmss(),0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[5] ;//水表累计水量 5字节BCD码,单位0.01立方米
|
ByteUtil.int2BCD_LE(Double.valueOf(totalWaterAmount * 100).intValue(), bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[5] ;//电表累计电量 5字节BCD码,单位0.01度
|
ByteUtil.int2BCD_LE(0, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[5] ;//用户剩余金额 5字节BCD码, 单位0.0001元
|
ByteUtil.int2BCD_LE(Double.valueOf(remainMoney * 10000).intValue(), bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[5] ;//用户剩余水量 5字节BCD码, 单位0.01m3
|
ByteUtil.int2BCD_LE(0, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[4] ;//本次使用电量 4字节BCD码 单位0.01度
|
ByteUtil.int2BCD_LE(0, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[4] ;//本次使用水量 4字节BCD码 单位0.01立方米
|
ByteUtil.int2BCD_LE(Double.valueOf(thisWaterAmount * 100).intValue(), bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[4] ;//本次使用金额 4字节BCD码 单位0.0001元
|
ByteUtil.int2BCD_LE(Double.valueOf(thisMoney * 10000).intValue(), bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[2] ;//本次使用时间长 2字节BCD码 单位:分钟
|
ByteUtil.int2BCD_LE(10, bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[4] ;//机井/阀状态及报警信息 4字节HEX码 定义见表41
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
GlCreate.createLen(bytes);//长度放字节数组中
|
|
byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRC和尾叠加字节数组中
|
|
bytes = ByteUtil.bytesMerge(bytes, bsTail) ;
|
|
return bytes ;
|
}
|
|
}
|