package com.dy.pipirrComCreator.p206V1;
|
|
import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate;
|
import com.dy.common.util.ByteUtil;
|
import com.dy.common.util.NumUtil;
|
|
/**
|
* @Author: liurunyu
|
* @Date: 2025/5/7 11:25
|
* @Description
|
*/
|
public class P206V1Cd99 extends P206V1Cd {
|
|
public static final String ComCode = "99" ;
|
|
public String checkParams(String ...params){
|
if(params.length != 4){
|
return "只有虚拟IC卡编号、剩余金额、水价、用水时长(分钟)四个参数" ;
|
}
|
//62090200300400001
|
if(!NumUtil.isPlusIntNumber(params[0])){
|
return "虚拟IC卡编号必须是正整数" ;
|
}
|
if(params[0].length() != 17){
|
return "虚拟IC卡编号必须是17位数字" ;
|
}
|
//2.10
|
if(!NumUtil.isPlusDoubleNumber(params[1])){
|
return "剩余金额必须是正数" ;
|
}
|
Integer temp = (Double.valueOf(Double.parseDouble(params[1]) * 100.0D)).intValue() ;
|
if(temp <= 0){
|
return "剩余金额必须是大于0的正数" ;
|
}
|
if(temp >= 99999999){
|
return "剩余金额必须是小于999999.99的正数" ;
|
}
|
//1.23
|
if(!NumUtil.isPlusDoubleNumber(params[2])){
|
return "水价必须是正数" ;
|
}
|
temp = (Double.valueOf(Double.parseDouble(params[2]) * 100.0D)).intValue() ;
|
if(temp <= 0){
|
return "水价必须是大于0的正数" ;
|
}
|
if(temp >= 9999){
|
return "水价必须是小于99.99的正数" ;
|
}
|
|
if(!NumUtil.isPlusIntNumber(params[3])){
|
return "用水时长必须是正整数" ;
|
}
|
temp = Integer.parseInt(params[3]) ;
|
if(temp <= 0){
|
return "用水时长必须是大于0的正整数" ;
|
}
|
if(temp > 9999){
|
return "用水时长必须是小于9999的正整数" ;
|
}
|
return null ;
|
}
|
public String helpInfo() {
|
return ComCode + " *...*(虚拟IC卡编号) *...*(剩余金额) *...*(水价) *...*(分钟时长)[Enter](定时关阀式开阀)" ;
|
}
|
/**
|
* 构造命令数据(十六进制)
|
* @return 字符串
|
* @throws Exception 异常
|
*/
|
public String hex(String rtuAddr, String ...params) throws Exception {
|
byte[] bytes = bs(rtuAddr, params) ;
|
return ByteUtil.bytes2Hex(bytes, false) ;
|
}
|
|
/**
|
* 构造命令数据(字节数组)
|
* @return 字节数组
|
* @throws Exception 异常
|
*/
|
public byte[] bs(String rtuAddr, String ...params) throws Exception {
|
byte[] bytes = createHead(rtuAddr, ComCode, P206V1Cd.CTRL);
|
|
byte[] bs = new byte[8] ;
|
GlCreate.createIcCardNo(params[0], bs, 0);
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
|
bs = new byte[4] ;
|
byte index = 0 ;
|
Integer money = Double.valueOf(Double.parseDouble(params[1]) * 100.0D).intValue() ;
|
byte[] bTemp = ByteUtil.int2BCD_LE(money) ;
|
int bTempLen = bTemp.length ;
|
int count = 0 ;
|
for(int i = 0 ; i < bTempLen; i++){
|
bs[index++] = bTemp[i] ;
|
count ++ ;
|
if(count >= 4){
|
break ;
|
}
|
}
|
for(; count < 4; count++){
|
bs[index++] = 0 ;
|
}
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
bs = new byte[2] ;
|
index = 0 ;
|
Integer price = Double.valueOf(Double.parseDouble(params[2]) * 100.0D).intValue() ;
|
bTemp = ByteUtil.int2BCD_LE(price) ;
|
bTempLen = bTemp.length ;
|
count = 0 ;
|
for(int i = 0 ; i < bTempLen; i++){
|
bs[index++] = bTemp[i] ;
|
count ++ ;
|
if(count >= 2){
|
break ;
|
}
|
}
|
for(; count < 2; count++){
|
bs[index++] = 0 ;
|
}
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
|
bs = new byte[2] ;
|
index = 0 ;
|
Integer minutes = Integer.parseInt(params[3]) ;
|
bTemp = ByteUtil.int2BCD_LE(minutes) ;
|
bTempLen = bTemp.length ;
|
count = 0 ;
|
for(int i = 0 ; i < bTempLen; i++){
|
bs[index++] = bTemp[i] ;
|
count ++ ;
|
if(count >= 2){
|
break ;
|
}
|
}
|
for(; count < 2; count++){
|
bs[index++] = 0 ;
|
}
|
bytes = ByteUtil.bytesMerge(bytes, bs) ;
|
|
|
GlCreate.createLen(bytes);//长度放字节数组中
|
|
byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中
|
|
bytes = ByteUtil.bytesMerge(bytes, bsTail) ;
|
|
return bytes ;
|
}
|
|
}
|