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
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 9:30
 * @Description
 */
public class P206V1Cd10 extends P206V1Cd {
 
    public static final String ComCode = "10" ;
 
    public String checkParams(String ...params){
        if(params.length != 1){
            return "只有控制器地址一个参数" ;
        }
        if(!NumUtil.isPlusIntNumber(params[0])){
            return "控制器地址参数必须是正整数" ;
        }
        if(params[0].length() != 12){
            return "控制器地址参数必须是12位数字" ;
        }
        return null ;
    }
    public String helpInfo() {
        return ComCode + " *...*[Enter](设置控制器地址)" ;
    }
    /**
     * 构造心跳数据
     * @return 字节数组
     * @throws Exception 异常
     */
    public String hex(String rtuAddr, String ...params) throws Exception {
        byte[] bytes = bs(rtuAddr, params) ;
        String hex = ByteUtil.bytes2Hex(bytes, false) ;
        return hex ;
    }
 
    /**
     * 构造心跳数据
     * @return 字节数组
     * @throws Exception 异常
     */
    public byte[] bs(String rtuAddr, String ...params) throws Exception {
        byte[] bytes = createHead(rtuAddr, ComCode, P206V1Cd.CTRL);
 
        byte n = 0;
        byte[] bs = new byte[13];
        GlCreate.createRtuAddr4P206(params[0], bs, n);
        n += 5;
        GlCreate.createPw(bs, n);
        n += 2;
        GlCreate.createTp(bs, n);
        bytes = ByteUtil.bytesMerge(bytes, bs);
 
        GlCreate.createLen(bytes);//长度放字节数组中
 
        byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中
 
        bytes = ByteUtil.bytesMerge(bytes, bsTail) ;
 
        return bytes ;
    }
}