2021与蓝度共同重构项目,服务端
liuhaonan
2022-02-14 366c79e61f0b3b1afe50d88733bf4f82da0575d8
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
package com.sandu.ximon.admin.entity;
 
import lombok.Data;
 
@Data
public class DataTransportMainResponse {
    //  功能码(1)
    private String functionCode;
    //  命令类型(1)
    private String orderType;
    //  负荷长度(2)
    private String payloadLength;
    //  响应payload
    private String payload;
    //  校验码(4)
    private String crc32;
    //  是否通过校验
    private boolean isValidate;
 
    public String getDefaultConnectCodePayload() {
        return payload.substring(2);
    }
 
    /**
     * 转为响应帧
     * @param hex   十六进制
     * @return
     */
    public DataTransportMainResponse convertInstance(String hex) {
        if(hex.length()<16){
            return null;
        }
        //  将十六进制数转为大写
        hex = hex.toUpperCase();
        //  功能码(1)
        this.functionCode = hex.substring(0, 2);
        //  命令类型(1)
        this.orderType = hex.substring(2, 4);
        //  负荷长度(2)
        this.payloadLength = hex.substring(4, 8);
        //  响应payload
        this.payload = hex.substring(8, hex.length()-8);
        //  校验码(4)
        this.crc32 = hex.substring(hex.length()-8);
        //  判断校验是否通过
        String frame = hex.substring(0, hex.length()-8);
        this.setValidate(CRC32Utils.validateFrame(frame, this.crc32));
 
        return this;
    }
 
}