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
package com.hdl.sdk.hdl_core.HDLAppliances.HDLFreshAir.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/9
 */
public class FreshAirParser {
    //    附加数据:  新风通道号(1 - 200) + 开关(0,1) + 风速(0 关,1低,2中,3高) + 模式(0手动,1 自动,2 智能,3 定时)
    public static final int fail = 0;
 
    public static final int freshAirSwich = 0;
    public static final int freshAirOn = 1;//新风开
    public static final int freshAirOff = 0;//新风关
 
    public static final int freshAirSpeed = 1;//风速
    public static final int freshAirSpeedOff = 0;//风速关
    public static final int freshAirSpeedLow = 1;//风速低
    public static final int freshAirSpeedMid = 2;//风速中
    public static final int freshAirSpeedHigh = 3;//风速高
 
    public static final int freshAirMode = 2;//模式
    public static final int freshAirModeManual = 0;//手动
    public static final int freshAirModeAuto = 1;//自动
    public static final int freshAirModeIntelligent = 2;//智能
    public static final int freshAirModeTiming = 3;//定时
 
    public static byte[] getFreshAirAddByte(AppliancesInfo appliancesInfo, int type, int state) {
        if (state > 3) {
            return new byte[]{fail};
        }
 
        AppliancesInfo newInfo = null;
        byte[] freshAirBytes = 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.AIR_BIG_TYPE
                            && HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() != HDLApConfig.TYPE_AC_PANEL
                            && 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[30]);
                        }
                        break outter;
                    }
 
                }
            }
        }
 
 
        freshAirBytes = newInfo.getFeedbackState();
 
        if (freshAirBytes != null && freshAirBytes.length >= 4) {
            byte[] addBytes = new byte[4];
            addBytes[0] = (byte) appliancesInfo.getChannelNum();
            addBytes[1] = freshAirBytes[1];
            addBytes[2] = freshAirBytes[2];
            addBytes[3] = freshAirBytes[3];
 
            switch (type) {
                case freshAirSwich:
                    if (state == freshAirOff) {
                        addBytes[1] = 0;
                    } else {
                        addBytes[1] = 1;
                    }
                    break;
                case freshAirSpeed:
                    addBytes[2] = (byte) state;
 
                    break;
                case freshAirMode:
                    addBytes[3] = (byte) state;
                    break;
            }
            return addBytes;
        } else {
            return null;
        }
 
    }
 
}