panlili2024
2024-09-19 071a8328823a2861f93ce556a4da3e4119cab1a3
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
121
122
123
124
125
126
package com.hdl.sdk.ttl.HDLDeviceManger.Bean;
 
/**
 * Created by JLChen on 2019/7/24
 */
public class MCUConfigurationBean {
 
//    协议类型[1byte  0:Buspro,1:zigbee,2:KNX,3:Modbus, 5:自定义]
//    波特率[1byte  0:1200,1:2400,2:4800:3:9600,4:19200,5:38400,6:57600,7:115200,8:250000]
//    开始位[1byte  0: 固定1bit]
//    数据位[1byte  0:8bit,1:9bit]
//    校验位[1byte  0:无, 1:偶, 2:奇,]
//    停止位[1byte  0:0.5bit, 1:bit,  2:2bit,  3:1.5bit]
    public static final int TYPE_BUSPRO = 0;
    public static final int TYPE_ZIGBEE = 1;
    public static final int TYPE_KNX = 2;
    public static final int TYPE_MODBUS = 3;
    public static final int TYPE_DIY = 5;
 
//    波特率[1byte  0:1200,1:2400,2:4800:3:9600,4:19200,5:38400,6:57600,7:115200,8:250000]
    public static final int BAUDRATE_1200 = 0;
    public static final int BAUDRATE_2400 = 1;
    public static final int BAUDRATE_4800 = 2;
    public static final int BAUDRATE_9600 = 3;
    public static final int BAUDRATE_19200 = 4;
    public static final int BAUDRATE_38400 = 5;
    public static final int BAUDRATE_57600 = 6;
    public static final int BAUDRATE_115200 = 7;
    public static final int BAUDRATE_250000 = 8;
 
    //校验位[1byte  0:无, 1:偶, 2:奇,]
    public static final int CHECKBIT_NO = 0;
    public static final int CHECKBIT_EVEN = 1;
    public static final int CHECKBIT_ODD = 2;
    //停止位[1byte  0:0.5bit, 1:bit,  2:2bit,  3:1.5bit]
    public static final int STOPBIT_0_5 = 0;
    public static final int STOPBIT_1 = 1;
    public static final int STOPBIT_2 = 2;
    public static final int STOPBIT_1_5 = 3;
 
 
    //协议类型
    private int mcuAgreementType;
    //波特率
    private int mcuBaudrate;
    //开始位
    private int mcuStartBit;
    //数据位
    private int mcuDataBit;
    //检验位
    private int mcuCheckBit;
    //停止位
    private int mcuStopBit;
 
    /**
     * 魔镜MCU协议
     * @return
     */
    public byte[] getMCUConfigurationSendBytes() {
        //纠正异常数据
        if(this.mcuAgreementType < 0 || this.mcuAgreementType > 5) this.mcuAgreementType = 0;
        if(this.mcuBaudrate < 0 || this.mcuBaudrate > 8) this.mcuBaudrate = 0;
        if(this.mcuDataBit < 0 || this.mcuDataBit > 1) this.mcuDataBit = 0;
        if(this.mcuCheckBit < 0 || this.mcuCheckBit > 2) this.mcuCheckBit = 0;
        if(this.mcuStopBit < 0 || this.mcuStopBit > 3) this.mcuStopBit = 0;
 
 
        byte[] sendBytes = new byte[6];
        //Boot code
        sendBytes[0] = (byte) this.mcuAgreementType;
        sendBytes[1] = (byte) this.mcuBaudrate;   //波特率
        sendBytes[2] = (byte) 0;                            //开始位
        sendBytes[3] = (byte) this.mcuDataBit;              //数据位
        sendBytes[4] = (byte) this.mcuCheckBit;             //检验位
        sendBytes[5] = (byte) this.mcuStopBit;              //停止位
        return sendBytes;
    }
 
    public int getMcuAgreementType() {
        return mcuAgreementType;
    }
 
    public void setMcuAgreementType(int mcuAgreementType) {
        this.mcuAgreementType = mcuAgreementType;
    }
 
    public int getMcuBaudrate() {
        return mcuBaudrate;
    }
 
    public void setMcuBaudrate(int mcuBaudrate) {
        this.mcuBaudrate = mcuBaudrate;
    }
 
    public int getMcuStartBit() {
        return mcuStartBit;
    }
 
    public void setMcuStartBit(int mcuStartBit) {
        this.mcuStartBit = mcuStartBit;
    }
 
    public int getMcuDataBit() {
        return mcuDataBit;
    }
 
    public void setMcuDataBit(int mcuDataBit) {
        this.mcuDataBit = mcuDataBit;
    }
 
    public int getMcuCheckBit() {
        return mcuCheckBit;
    }
 
    public void setMcuCheckBit(int mcuCheckBit) {
        this.mcuCheckBit = mcuCheckBit;
    }
 
    public int getMcuStopBit() {
        return mcuStopBit;
    }
 
    public void setMcuStopBit(int mcuStopBit) {
        this.mcuStopBit = mcuStopBit;
    }
}