panlili2024
2024-09-19 071a8328823a2861f93ce556a4da3e4119cab1a3
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
package com.hdl.sdk.ttl.HDLAppliances.HDLFreshAir.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 2020-07-20
 * 附加数据:
 * 编号    备注    值域
 * 0    新风编号    1~200
 * 1    类型    第三方类型  0:金茂新风
 * 2    开关    0-关机,1-开机
 * 3    运行模式    1-通风,2-加湿
 * 4    节能舒适选择    1-舒适,2-节能
 * 5    风速档位    0-自动,1-1档,2-2档,3-3档
 * 6    湿度设定    %
 * 7    室内温度值    ℃
 * 8    室内湿度值    ℃
 * 9    过滤网剩余    %
 * 10    过滤网使用超时
 */
public class FreshAirJinMaoParser {
 
    public static final int fail = 0;
 
    public static final int SetSwich = 0;//设置开关状态
    public static final int freshAirOn = 1;//新风开
    public static final int freshAirOff = 0;//新风关
 
    public static final int SetSpeed = 1;//设置风速
    public static final int freshAirSpeedAuto = 0;//风速 自动
    public static final int freshAirSpeed1 = 1;//风速 1档
    public static final int freshAirSpeed2 = 2;//风速 2档
    public static final int freshAirSpeed3 = 3;//风速 3档
 
    public static final int SetMode = 2;//设置运行模式
    public static final int freshAirModeVentilation = 1;//通风模式
    public static final int freshAirModeHumidify= 2;//加湿模式
 
    public static final int SetEnergySavingMode = 3;//设置节能模式
    public static final int energySavingModeComfortable = 1;//舒适
    public static final int energySavingModeEs= 2;//节能
 
    public static final int SetHumidty= 4;//设置湿度
 
 
 
 
    public static byte[] getFreshAirAddByte(AppliancesInfo appliancesInfo, int type, int state) {
 
        try {
            AppliancesInfo newInfo = appliancesInfo;
            byte[] freshAirBytes = null;
 
            outter:
            for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
                if (appliancesInfo.getDeviceSubnetID() == HDLDeviceManager.devicesDataList.get(i).getDeviceSubnetID()
                        && appliancesInfo.getDeviceDeviceID() == HDLDeviceManager.devicesDataList.get(i).getDeviceDeviceID()) {
                    for (int j = 0; j < HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
                        if (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.FRESH_AIR_BIG_TYPE
                                && HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() == HDLApConfig.TYPE_FRESH_AIR_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(GetNewData(newInfo.getChannelNum()));
                            }
                            freshAirBytes = newInfo.getArrCurState();
                            break outter;
                        }
 
                    }
                }
            }
 
            byte[] addBytes = new byte[11];
            if (freshAirBytes != null && freshAirBytes.length >= 11) {
                System.arraycopy(freshAirBytes, 0, addBytes, 0, freshAirBytes.length);
                addBytes[0] = (byte) newInfo.getChannelNum();
            }else {
                addBytes = GetNewData(newInfo.getChannelNum());
            }
 
 
            switch (type) {
                case SetSwich://设置开关状态
                    if (state == freshAirOn) {
                        addBytes[2] = 1;
                    } else {
                        addBytes[2] = 0;
                    }
                    break;
                case SetMode://设置运行模式
                    addBytes[2] = 1;
                    addBytes[3] = (byte) state;
                    break;
                case SetEnergySavingMode://设置节能模式
                    addBytes[2] = 1;
                    addBytes[4] = (byte) state;
                    break;
                case SetSpeed://设置风速
                    addBytes[2] = 1;
                    addBytes[5] = (byte) state;
                    break;
                case SetHumidty://设置湿度
                    addBytes[2] = 1;
                    addBytes[6] = (byte) state;
                    break;
 
            }
 
            return addBytes;
        } catch (Exception e) {
            e.printStackTrace();
            return new byte[]{fail};
        }
 
    }
 
 
    public static byte[] GetNewData(int mChannelNum){
        byte[] addBytes = new byte[11];
        addBytes[0] = (byte) mChannelNum;
        addBytes[1] = 0;
        addBytes[2] = 0;//开关
        addBytes[3] = (byte)1;
        addBytes[4] = (byte)1;
        addBytes[5] = (byte)0;
        addBytes[6] = (byte)0;
        addBytes[7] = (byte)28;
        addBytes[8] = (byte)0;
        addBytes[9] = (byte)100;
        addBytes[10] = (byte)1;
        return addBytes;
    }
 
}