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
package com.hdl.sdk.hdl_core.HDLAppliances.HDLGeothermal.Parser;
 
import com.hdl.sdk.hdl_core.Config.Configuration;
import com.hdl.sdk.hdl_core.HDLAppliances.Config.HDLApConfig;
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.AppliancesInfo;
import com.hdl.sdk.hdl_core.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 = 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
                                && appliancesInfo.getChannelNum() == HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getChannelNum()) {
                            newInfo = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j);
                            if (newInfo.getFeedbackState() == null) {
                                newInfo.setFeedbackState(new byte[10]);
                            }
                            airBytes = newInfo.getFeedbackState();
                            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};
        }
 
    }
 
 
}