2021与蓝度共同重构项目,服务端
zhanzhiqin
2022-04-25 982359342d0a4c868580c1e7db9784865941b5e1
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
127
128
129
130
131
132
133
package com.sandu.ximon.admin.manager.iot.frame.inner.report;
 
import cn.hutool.core.util.StrUtil;
import com.sandu.ximon.admin.manager.iot.frame.inner.BaseResponseInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.IResponseInnerFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.util.CRC16Utils;
import com.sandu.ximon.admin.manager.iot.rrpc.util.CRC32Utils;
import lombok.Data;
 
import java.math.BigDecimal;
 
/**
 * @author ZZQ
 * @date 2022/4/25 10:55
 */
@Data
public class A5AtmosphereNewHeartbeatReportInnerFrame extends BaseResponseInnerFrame<A5AtmosphereNewHeartbeatReportInnerFrame> {
    //ff03200241000000000000000000000009000a198a186327b8000c000000000000000b8c35c1cad6bf
    private HeartBeatDataPackage heartBeatDataPackage;
 
    @Override
    public A5AtmosphereNewHeartbeatReportInnerFrame transformFrame(String hex) {
        //  长度不一致时,返回null
        if (StrUtil.isBlank(hex)) {
            return null;
        }
        //校验
        hex = hex.replaceAll(" ", "");
        if (hex.length() < 74) {
            return null;
        }
 
        // MQTT通信方式(1)
        setConnectType(hex.substring(0, 2));
        //  功能码(1)
        setFunctionCode(hex.substring(2, 4));
        //  负荷长度(2)
        setPayloadLength(hex.substring(4, 6));
 
 
        String heartBeatData = hex.substring(0, hex.length() - 4);
        HeartBeatDataPackage heartBeatDataPackage = new HeartBeatDataPackage();
        heartBeatDataPackage.transformFrame(heartBeatData);
        setHeartBeatDataPackage(heartBeatDataPackage);
 
        setCrc16(hex.substring(hex.length() - 4));
        //  校验CRC32
        String frame = hex.substring(0, hex.length() - 4);
        this.setValidate(getCrc16().equals(CRC16Utils.getCRC16(frame)));
        return this;
    }
 
    @Data
    public static class HeartBeatDataPackage implements IResponseInnerFrame<HeartBeatDataPackage> {
        //("噪声")
        private BigDecimal noise;
        //("硫化氢")
        private BigDecimal hydrogenSulfide;
        //("SO2 浓度")
        private BigDecimal so2;
        //("NO2 浓度")
        private BigDecimal no2;
        //("CO 浓度")
        private BigDecimal co;
        //("O3 浓度")
        private BigDecimal o3;
        //("PM2.5 浓度")
        private BigDecimal pm2point5;
        //("PM10")
        private BigDecimal pm10;
        //("空气温度")
        private BigDecimal airTemperature;
        //("空气湿度")
        private BigDecimal airHumidity;
        //("大气压强")
        private BigDecimal airPressure;
        //("风速")
        private BigDecimal windSpeed;
        //("风向")
        private BigDecimal windDirection;
        //("10 分钟雨量")
        private BigDecimal tenRainfallMin;
        //("辐射")
        private BigDecimal radiation;
        //("光照")
        private BigDecimal illumination;
 
        @Override
        public HeartBeatDataPackage transformFrame(String hex) {
            //ff   03  20   0241000000000000000000000009000a198a186327b8000c000000000000000b8c35c1ca(参考值)
            // 0241 0000  0000 0000 0000 0000 0009  000a  198a  1863  27b8  000c  0000  0000  0000  000b  8c35  c1ca
 
            //噪声
            this.noise = BigDecimal.valueOf(parseVal(hex, 6, 10) / 10.0);
            //硫化氢
            this.hydrogenSulfide = BigDecimal.valueOf(parseVal(hex, 10, 14) / 1.0);
            //SO2 浓度
            this.so2 = BigDecimal.valueOf(parseVal(hex, 14, 18) / 1.0);
            //NO2 浓度
            this.no2 = BigDecimal.valueOf(parseVal(hex, 18, 22) / 1.0);
            //CO 浓度
            this.co = BigDecimal.valueOf(parseVal(hex, 22, 26) / 1.0);
            //O3 浓度
            this.o3 = BigDecimal.valueOf(parseVal(hex, 26, 30) / 1.0);
            //PM2.5 浓度
            this.pm2point5 = BigDecimal.valueOf(parseVal(hex, 30, 34) / 1.0);
            //PM10 浓度
            this.pm10 = BigDecimal.valueOf(parseVal(hex, 34, 38) / 1.0);
            //空气温度
            this.airTemperature = BigDecimal.valueOf(parseVal(hex, 38, 42) / 100.0 - 40);
            //空气湿度
            this.airHumidity = BigDecimal.valueOf(parseVal(hex, 42, 46) / 100.0);
            //大气压强
            this.airPressure = BigDecimal.valueOf(parseVal(hex, 46, 50) / 10.0);
            //风速
            this.windSpeed = BigDecimal.valueOf(parseVal(hex, 50, 54) / 100.0);
            //风向
            this.windDirection = BigDecimal.valueOf(parseVal(hex, 54, 58) / 10.0);
            //10 分钟雨量
            this.tenRainfallMin = BigDecimal.valueOf(parseVal(hex, 58, 62) / 10.0);
            //辐射
            this.radiation = BigDecimal.valueOf(parseVal(hex, 62, 66) / 1.0);
            //光照
            this.illumination = BigDecimal.valueOf(parseVal(hex, 66, 70) / 100.0);
            return this;
        }
 
        private Integer parseVal(String frame, int start, int end) {
            return Integer.parseInt(frame.substring(start, end), 16);
        }
    }
 
}