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
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
package com.sandu.ximon.admin.entity;
 
import lombok.Data;
 
@Data
public class AtmoHeartBeatDataPackage implements MainBoardResponse<AtmoHeartBeatDataPackage> {
 
    public enum DeviceType {
 
        SENSOR_V1("0101");
 
        private String type;
 
        DeviceType(String type) {
            this.type = type;
        }
 
        public String getType() {
            return type;
        }
    }
    //  设备型号    2
    private String deviceType;
    //  模块预热状态标志    1
    private String moduleWarmUpStatusFlag;
    //  温度值
    private Double temperature;
    //  湿度值
    private Double humidity;
    //  风速
    private Double windSpeed;
    //  风向
    private Double windDirection;
    //  大气压
    private Integer pressure;
    //  光强
    private Integer lightIntensity;
    //  噪音
    private Integer noise;
    //  PM2.5
    private Integer PM25;
    //  PM10
    private Integer PM10;
    //  总悬浮颗粒物(TSP)
    private Integer TSP;
    //  SO2二氧化硫/甲醛相对值
    private Integer SO2;
    private Integer eCH2O;
    //  NO2二氧化氮/TVOC
    private Integer NO2;
    private Integer TVOC;
    //  CO一氧化碳 /二氧化碳
    private Integer CO;
    private Integer CO2;
    //  O3臭氧
    private Integer O3;
    //  F氟化物
    private Integer fluoride;
 
    @Override
    public AtmoHeartBeatDataPackage convertInstance(String hex) {
 
        if (hex.length() != 64) {
            LogUtils.error("转换大气心跳包长度错误:"+hex);
            return null;
        }
        Integer type = 0;
        this.deviceType = hex.substring(0, 4);
        if(this.deviceType.equals(DeviceType.SENSOR_V1.getType())) {
            type = 1;
        }
        this.moduleWarmUpStatusFlag = hex.substring(4, 6);
        this.temperature = Double.parseDouble(
                parseVal(hex,6,8)
                + "."
                + parseVal(hex,8,10)
        );
        this.humidity = Double.parseDouble(
                parseVal(hex,10,12)
                        + "."
                        + parseVal(hex,12,14)
        );
        this.windSpeed = parseVal(hex,14,18) * .1;
        this.windDirection = parseVal(hex,18,22) * .1;
        this.pressure = parseVal(hex,22,26);
        this.lightIntensity = parseVal(hex,26,32);
        this.noise = parseVal(hex,32, 36);
        this.PM25 = parseVal(hex,36, 40);
        this.PM10 = parseVal(hex,40,44);
        this.TSP = parseVal(hex,44,48);
 
        /**
         * 以下区分版本
         */
        if(type.equals(1)) {
            this.eCH2O = parseVal(hex,48, 52);
            this.TVOC = parseVal(hex,52, 56);
            this.CO2 = parseVal(hex,56, 60);
        } else {
            this.SO2 = parseVal(hex,48, 52);
            this.eCH2O = parseVal(hex,48, 52);
            this.TVOC = parseVal(hex,52, 56);
            this.NO2 = parseVal(hex,52, 56);
            this.CO = parseVal(hex,56, 60);
            this.CO2 = parseVal(hex,56, 60);
        }
 
        this.O3 = parseVal(hex,60, 62);
        this.fluoride = parseVal(hex,62, 64);
 
        return this;
    }
 
 
    private Integer parseVal (String frame, int start, int end) {
        return Integer.parseInt(frame.substring(start,end),16);
    }
 
}