2021与蓝度共同重构项目,服务端
zhanzhiqin
2022-07-27 8dcbf0608171abce431df0356f11efbbc6c2de40
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
package com.sandu.ximon.admin.manager.iot.frame.inner.report;
 
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
import com.sandu.ximon.admin.manager.iot.frame.inner.BaseResponseInnerFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.util.CRC32Utils;
import lombok.Data;
import lombok.ToString;
 
/**
 * C3充电桩故障上报帧
 */
@Data
@ToString(callSuper = true)
public class A5C3ErrorCodeReportInnerFrame extends BaseResponseInnerFrame<A5C3ErrorCodeReportInnerFrame> {
 
    /**
     * 目标地址 2
     */
    private String destinationAddress;
    /**
     * 故障码
     */
    private int errorCode;
 
    @Override
    public A5C3ErrorCodeReportInnerFrame transformFrame(String hex) {
        if (StrUtil.isBlank(hex)) {
            return null;
        }
        // MQTT通信方式(1)
        setConnectType(hex.substring(0, 2));
        //  功能码(1)
        setFunctionCode(hex.substring(2, 4));
        //  负荷长度(2)
        setPayloadLength(hex.substring(4, 8));
 
        setDestinationAddress(hex.substring(8, 16));
 
        //故障码
        String errorCodeHex = hex.substring(16, hex.length() - 8);
        errorCode = HexUtil.hexToInt(errorCodeHex);
 
        setCrc32(hex.substring(hex.length() - 8));
        //  校验CRC32
        String frame = getFunctionCode() + getPayloadLength() + getDestinationAddress() + errorCodeHex;
        this.setValidate(CRC32Utils.validateFrame(frame, getCrc32()));
        return this;
    }
}