liurunyu
6 天以前 eb51cf4365f8a8eefc3c0a605071813e86ba0194
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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 ;
    }
 
}