562935844@qq.com
2023-11-27 566ddb2ea03e2514de50f2ca861a2674f6e840ac
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package com.hdl.sdk.ttl.HDLAppliances.HDLGeothermal.Parser;
 
 
import com.hdl.sdk.ttl.Config.Configuration;
import com.hdl.sdk.ttl.HDLAppliances.Config.HDLApConfig;
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo;
import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLDeviceManager;
 
/**
 * Created by JLChen on 2019/7/10
 */
public class GeothermalParser {
 
    public static final int fail = 0;
 
    public static final int gSwich = 2;
    public static final int gSwichOn = 1;//地热模块开
    public static final int gSwichOff = 0;//地热模块关
 
 
    public static final int gMode = 4;      //模式
    public static final int gModeNormal = 1;//普通模式
    public static final int gModeDay = 2;//白天模式
    public static final int gModeNight = 3;//夜间模式
    public static final int gModeLeave = 4;//离开模式
    public static final int gModeAuto = 5;//自动模式
 
    public static final int gNormalTemp = 5;//普通模式温度
    public static final int gDayTemp = 6;//白天模式温度
    public static final int gNightTemp = 7;//夜间模式温度
    public static final int gLeaveTemp = 8;//离开模式温度
 
    //    feedbackState [回路,开关状态,温度类型,模式,普通温度,白天温度,夜间温度,离开温度,自动温度,当前温度]
    public static byte[] getGeothermalAddByte(AppliancesInfo appliancesInfo, int type, int state) {
        try {
            AppliancesInfo newInfo = appliancesInfo;
            byte[] airBytes = null;
            outter:
            for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
                if (appliancesInfo.getDeviceSubnetID() == HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID()
                        && appliancesInfo.getDeviceDeviceID() == HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID()) {
                    for (int j = 0; j < HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
                        if (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.GEOTHERMAL_BIG_TYPE
                                && (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() == HDLApConfig.TYPE_GEOTHERMAL_MODULE
                                    || HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() == HDLApConfig.TYPE_GEOTHERMAL_JINMAO)
                                && appliancesInfo.getChannelNum() == HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getChannelNum()) {
                            newInfo = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j);
                            if (newInfo.getArrCurState() == null) {
                                newInfo.setArrCurState(new byte[10]);
                            }
                            airBytes = newInfo.getArrCurState();
                            break outter;
                        }
 
                    }
                }
            }
 
            byte[] addBytes = new byte[10];
            if (airBytes != null && airBytes.length >= 10) {
                addBytes[0] = (byte) newInfo.getChannelNum();
                addBytes[1] = airBytes[1];
                addBytes[2] = 0;
                addBytes[3] = airBytes[3];
                addBytes[4] = airBytes[4];
                addBytes[5] = airBytes[5];
                addBytes[6] = airBytes[6];
                addBytes[7] = airBytes[7];
                addBytes[8] = 0;
                addBytes[9] = 0;
            } else {
                addBytes[0] = (byte) newInfo.getChannelNum();
                addBytes[1] = 0;
                addBytes[2] = 0;
                addBytes[3] = 1;
                addBytes[4] = 30;
                addBytes[5] = 30;
                addBytes[6] = 30;
                addBytes[7] = 30;
                addBytes[8] = 0;
                addBytes[9] = 0;
            }
 
            switch (type) {
                case gSwich:
                    if (state == gSwichOff) {
                        addBytes[1] = 0;
                    } else {
                        addBytes[1] = 1;
                    }
                    break;
                case gMode:
                    addBytes[1] = 1;
                    addBytes[3] = (byte) state;
                    break;
                case gNormalTemp:
                    addBytes[1] = 1;//打开
                    addBytes[4] = (byte) state;
                    break;
                case gDayTemp:
                    addBytes[1] = 1;//打开
                    addBytes[5] = (byte) state;
                    break;
                case gNightTemp:
                    addBytes[1] = 1;//打开
                    addBytes[6] = (byte) state;
                    break;
                case gLeaveTemp:
                    addBytes[1] = 1;//打开
                    addBytes[7] = (byte) state;
                    break;
            }
            return addBytes;
 
 
        } catch (Exception e) {
            e.printStackTrace();
            return new byte[]{fail};
        }
 
    }
 
    //根据当前模式设置温度
    public static byte[] getGeothermalAddByteTemp(AppliancesInfo appliancesInfo, int state) {
        try {
            AppliancesInfo newInfo = null;
            byte[] airBytes = null;
            outter:
            for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
                if (appliancesInfo.getDeviceSubnetID() == HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID()
                        && appliancesInfo.getDeviceDeviceID() == HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID()) {
                    for (int j = 0; j < HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
                        if (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.GEOTHERMAL_BIG_TYPE
                                && (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() == HDLApConfig.TYPE_GEOTHERMAL_MODULE
                                || HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() == HDLApConfig.TYPE_GEOTHERMAL_JINMAO)
                                && appliancesInfo.getChannelNum() == HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getChannelNum()) {
                            newInfo = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j);
                            if (newInfo.getArrCurState() == null) {
                                newInfo.setArrCurState(new byte[10]);
                            }
                            airBytes = newInfo.getArrCurState();
                            break outter;
                        }
 
                    }
                }
            }
 
            byte[] addBytes = new byte[10];
            if (airBytes != null && airBytes.length >= 10) {
                addBytes[0] = (byte) newInfo.getChannelNum();
                addBytes[1] = airBytes[1];
                addBytes[2] = 0;
                addBytes[3] = airBytes[3];
                addBytes[4] = airBytes[4];
                addBytes[5] = airBytes[5];
                addBytes[6] = airBytes[6];
                addBytes[7] = airBytes[7];
                addBytes[8] = 0;
                addBytes[9] = 0;
            } else {
                addBytes[0] = (byte) newInfo.getChannelNum();
                addBytes[1] = 0;
                addBytes[2] = 0;
                addBytes[3] = 1;
                addBytes[4] = 30;
                addBytes[5] = 30;
                addBytes[6] = 30;
                addBytes[7] = 30;
                addBytes[8] = 0;
                addBytes[9] = 0;
            }
 
            switch (addBytes[3]) {
                case gModeNormal:
                    addBytes[1] = 1;//打开
                    addBytes[4] = (byte) state;
                    break;
                case gModeDay:
                    addBytes[1] = 1;//打开
                    addBytes[5] = (byte) state;
                    break;
                case gModeNight:
                    addBytes[1] = 1;//打开
                    addBytes[6] = (byte) state;
                    break;
                case gModeLeave:
                    addBytes[1] = 1;//打开
                    addBytes[7] = (byte) state;
                    break;
            }
            return addBytes;
 
 
        } catch (Exception e) {
            e.printStackTrace();
            return new byte[]{fail};
        }
 
    }
}