命令生成器模块增加功能码97、98、99、A0、A1实现
| | |
| | | String json = obj.toJSONString(); |
| | | Com98Vo cvo = JSON.parseObject(json, Com98Vo.class) ; |
| | | if(cvo == null){ |
| | | throw new Exception("json转Com97Vo为null") ; |
| | | throw new Exception("json转Com98Vo为null") ; |
| | | } |
| | | if(cvo.icCardNo == null){ |
| | | throw new Exception("虚拟IC卡编号不能为空") ; |
| | |
| | | static{ |
| | | commands = new String[]{ |
| | | "config 查看配置信息", |
| | | "XY ... 协议命令", |
| | | "XY ... 协议命令(3C、10、21、37、50、65、66、67、91、92、93、97、98、99、A0、A1、A2)", |
| | | "XY -h 协议命令帮助", |
| | | "exit 退出", |
| | | }; |
| | |
| | | return null ; |
| | | } |
| | | public String helpInfo() { |
| | | return ComCode + " *...* *...*[Enter](设置服务端IP和端口)" ; |
| | | return ComCode + " *...*(IP) *...*(端口)[Enter](设置服务端IP和端口)" ; |
| | | } |
| | | /** |
| | | * 构造命令数据(十六进制) |
New file |
| | |
| | | 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.ByteUtilUnsigned; |
| | | import com.dy.common.util.IPUtils; |
| | | import com.dy.common.util.NumUtil; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2025/5/7 11:25 |
| | | * @Description |
| | | */ |
| | | public class P206V1Cd97 extends P206V1Cd { |
| | | |
| | | public static final String ComCode = "97" ; |
| | | |
| | | public String checkParams(String ...params){ |
| | | if(params.length != 3){ |
| | | 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的正数" ; |
| | | } |
| | | return null ; |
| | | } |
| | | public String helpInfo() { |
| | | return ComCode + " *...*(虚拟IC卡编号) *...*(剩余金额) *...*(水价)[Enter](APP远程开阀)" ; |
| | | } |
| | | /** |
| | | * 构造命令数据(十六进制) |
| | | * @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[14] ; |
| | | byte n = 0 ; |
| | | GlCreate.createIcCardNo(params[0], bs, n); |
| | | |
| | | n += 8 ; |
| | | 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[n++] = bTemp[i] ; |
| | | count ++ ; |
| | | if(count >= 4){ |
| | | break ; |
| | | } |
| | | } |
| | | for(; count < 4; count++){ |
| | | bs[n++] = 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[n++] = bTemp[i] ; |
| | | count ++ ; |
| | | if(count >= 2){ |
| | | break ; |
| | | } |
| | | } |
| | | for(; count < 2; count++){ |
| | | bs[n++] = 0 ; |
| | | } |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bs); |
| | | |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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 P206V1Cd98 extends P206V1Cd { |
| | | |
| | | public static final String ComCode = "98" ; |
| | | |
| | | public String checkParams(String ...params){ |
| | | if(params.length != 1){ |
| | | return "只有虚拟IC卡编号一个参数" ; |
| | | } |
| | | //62090200300400001 |
| | | if(!NumUtil.isPlusIntNumber(params[0])){ |
| | | return "虚拟IC卡编号必须是正整数" ; |
| | | } |
| | | if(params[0].length() != 17){ |
| | | return "虚拟IC卡编号必须是17位数字" ; |
| | | } |
| | | return null ; |
| | | } |
| | | public String helpInfo() { |
| | | return ComCode + " *...*(虚拟IC卡编号)[Enter](APP远程关阀)" ; |
| | | } |
| | | /** |
| | | * 构造命令数据(十六进制) |
| | | * @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); |
| | | |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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 ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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 P206V1CdA0 extends P206V1Cd { |
| | | |
| | | public static final String ComCode = "A0" ; |
| | | |
| | | 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 amount = Integer.parseInt(params[3]) ; |
| | | bTemp = ByteUtil.int2BCD_LE(amount) ; |
| | | 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 ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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.DateTime; |
| | | import com.dy.common.util.NumUtil; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2025/5/7 11:25 |
| | | * @Description |
| | | */ |
| | | public class P206V1CdA1 extends P206V1Cd { |
| | | |
| | | public static final String ComCode = "A1" ; |
| | | |
| | | public String checkParams(String ...params){ |
| | | if(params.length != 9){ |
| | | 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的正整数" ; |
| | | } |
| | | |
| | | if(!NumUtil.isPlusIntNumber(params[4])){ |
| | | return "年必须是正整数" ; |
| | | } |
| | | int year = Integer.parseInt(params[4]) ; |
| | | if(year < 2025){ |
| | | return "年必须是大于等于2025的正整数" ; |
| | | } |
| | | if(year > 9999){ |
| | | return "年必须是小于9999的正整数" ; |
| | | } |
| | | |
| | | if(!NumUtil.isPlusIntNumber(params[5])){ |
| | | return "月必须是正整数" ; |
| | | } |
| | | int month = Integer.parseInt(params[5]) ; |
| | | if(month <= 0){ |
| | | return "月必须是大于0的正整数" ; |
| | | } |
| | | if(month > 12){ |
| | | return "月必须是小于12的正整数" ; |
| | | } |
| | | |
| | | if(!NumUtil.isPlusIntNumber(params[6])){ |
| | | return "日必须是正整数" ; |
| | | } |
| | | temp = Integer.parseInt(params[6]) ; |
| | | if(temp <= 0){ |
| | | return "日必须是大于0的正整数" ; |
| | | } |
| | | if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){ |
| | | if(temp > 31){ |
| | | return "日必须是小于31的正整数" ; |
| | | } |
| | | }else if(month == 4 || month == 6 || month == 9 || month == 11){ |
| | | if(temp > 30){ |
| | | return "日必须是小于30的正整数" ; |
| | | } |
| | | }else if(month == 2){ |
| | | if(DateTime.isLeapYear(year)){ |
| | | //润年 |
| | | if(temp > 29){ |
| | | return "日必须是小于29的正整数" ; |
| | | } |
| | | }else{ |
| | | if(temp > 28){ |
| | | return "日必须是小于28的正整数" ; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(!NumUtil.isPlusIntNumber(params[7])){ |
| | | return "时必须是正整数" ; |
| | | } |
| | | temp = Integer.parseInt(params[7]) ; |
| | | if(temp < 0){ |
| | | return "时必须是大于等于0的正整数" ; |
| | | } |
| | | if(temp >= 24){ |
| | | return "时必须是小于24的正整数" ; |
| | | } |
| | | |
| | | if(!NumUtil.isPlusIntNumber(params[8])){ |
| | | return "分钟必须是正整数" ; |
| | | } |
| | | temp = Integer.parseInt(params[8]) ; |
| | | if(temp < 0){ |
| | | return "分钟必须是大于等于0的正整数" ; |
| | | } |
| | | if(temp > 59){ |
| | | return "分钟必须是小于等于59的正整数" ; |
| | | } |
| | | 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) ; |
| | | |
| | | bs = new byte[5] ; |
| | | Integer year = Integer.parseInt(params[4]) ; |
| | | if(year >= 2024){ |
| | | year = year - 2000 ; |
| | | } |
| | | bs[0] = ByteUtil.int2BCD_LE(Integer.parseInt(params[8]))[0] ; |
| | | bs[1] = ByteUtil.int2BCD_LE(Integer.parseInt(params[7]))[0] ; |
| | | bs[2] = ByteUtil.int2BCD_LE(Integer.parseInt(params[6]))[0] ; |
| | | bs[3] = ByteUtil.int2BCD_LE(Integer.parseInt(params[5]))[0] ; |
| | | bs[4] = ByteUtil.int2BCD_LE(year)[0] ; |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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.DateTime; |
| | | import com.dy.common.util.NumUtil; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2025/5/7 11:25 |
| | | * @Description |
| | | */ |
| | | public class P206V1CdA2 extends P206V1Cd { |
| | | |
| | | public static final String ComCode = "A2" ; |
| | | |
| | | public String checkParams(String ...params){ |
| | | if(params.length != 9){ |
| | | 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的正整数" ; |
| | | } |
| | | |
| | | if(!NumUtil.isPlusIntNumber(params[4])){ |
| | | return "年必须是正整数" ; |
| | | } |
| | | int year = Integer.parseInt(params[4]) ; |
| | | if(year < 2025){ |
| | | return "年必须是大于等于2025的正整数" ; |
| | | } |
| | | if(year > 9999){ |
| | | return "年必须是小于9999的正整数" ; |
| | | } |
| | | |
| | | if(!NumUtil.isPlusIntNumber(params[5])){ |
| | | return "月必须是正整数" ; |
| | | } |
| | | int month = Integer.parseInt(params[5]) ; |
| | | if(month <= 0){ |
| | | return "月必须是大于0的正整数" ; |
| | | } |
| | | if(month > 12){ |
| | | return "月必须是小于12的正整数" ; |
| | | } |
| | | |
| | | if(!NumUtil.isPlusIntNumber(params[6])){ |
| | | return "日必须是正整数" ; |
| | | } |
| | | temp = Integer.parseInt(params[6]) ; |
| | | if(temp <= 0){ |
| | | return "日必须是大于0的正整数" ; |
| | | } |
| | | if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){ |
| | | if(temp > 31){ |
| | | return "日必须是小于31的正整数" ; |
| | | } |
| | | }else if(month == 4 || month == 6 || month == 9 || month == 11){ |
| | | if(temp > 30){ |
| | | return "日必须是小于30的正整数" ; |
| | | } |
| | | }else if(month == 2){ |
| | | if(DateTime.isLeapYear(year)){ |
| | | //润年 |
| | | if(temp > 29){ |
| | | return "日必须是小于29的正整数" ; |
| | | } |
| | | }else{ |
| | | if(temp > 28){ |
| | | return "日必须是小于28的正整数" ; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(!NumUtil.isPlusIntNumber(params[7])){ |
| | | return "时必须是正整数" ; |
| | | } |
| | | temp = Integer.parseInt(params[7]) ; |
| | | if(temp < 0){ |
| | | return "时必须是大于等于0的正整数" ; |
| | | } |
| | | if(temp >= 24){ |
| | | return "时必须是小于24的正整数" ; |
| | | } |
| | | |
| | | if(!NumUtil.isPlusIntNumber(params[8])){ |
| | | return "分钟必须是正整数" ; |
| | | } |
| | | temp = Integer.parseInt(params[8]) ; |
| | | if(temp < 0){ |
| | | return "分钟必须是大于等于0的正整数" ; |
| | | } |
| | | if(temp > 59){ |
| | | return "分钟必须是小于等于59的正整数" ; |
| | | } |
| | | 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 amount = Integer.parseInt(params[3]) ; |
| | | bTemp = ByteUtil.int2BCD_LE(amount) ; |
| | | 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[5] ; |
| | | Integer year = Integer.parseInt(params[4]) ; |
| | | if(year >= 2024){ |
| | | year = year - 2000 ; |
| | | } |
| | | bs[0] = ByteUtil.int2BCD_LE(Integer.parseInt(params[8]))[0] ; |
| | | bs[1] = ByteUtil.int2BCD_LE(Integer.parseInt(params[7]))[0] ; |
| | | bs[2] = ByteUtil.int2BCD_LE(Integer.parseInt(params[6]))[0] ; |
| | | bs[3] = ByteUtil.int2BCD_LE(Integer.parseInt(params[5]))[0] ; |
| | | bs[4] = ByteUtil.int2BCD_LE(year)[0] ; |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
| | |
| | | case CodeV1.cd_91: cdWithoutParam(new P206V1Cd91(), comList, prtWrt); break; |
| | | case CodeV1.cd_92: cdWithoutParam(new P206V1Cd92(), comList, prtWrt); break; |
| | | case CodeV1.cd_93: cdWithoutParam(new P206V1Cd93(), comList, prtWrt); break; |
| | | case CodeV1.cd_97: cdWithParam(new P206V1Cd97(), comList, prtWrt); break; |
| | | case CodeV1.cd_98: cdWithParam(new P206V1Cd98(), comList, prtWrt); break; |
| | | case CodeV1.cd_99: cdWithParam(new P206V1Cd99(), comList, prtWrt); break; |
| | | case CodeV1.cd_A0: cdWithParam(new P206V1CdA0(), comList, prtWrt); break; |
| | | case CodeV1.cd_A1: cdWithParam(new P206V1CdA1(), comList, prtWrt); break; |
| | | case CodeV1.cd_A2: cdWithParam(new P206V1CdA2(), comList, prtWrt); break; |
| | | default: Command.outNoIdentify(prtWrt); break; |
| | | } |
| | | } |