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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
package com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.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 Tommy on 2017/7/20.
 */
 
public class AirCtrlParser {
    public static final int fail = 0;
    public static final int infrared = 1;
    public static final int panelLock = 2;
 
    public static final int airSwich = 3;
    public static final int airOn = 1;//空调开
    public static final int airOff = 0;//空调关
 
    public static final int refTem = 4;//制冷温度
 
    public static final int airSpeed = 5;//风速
    public static final int airSpeedAuto = 0;//风速自动
    public static final int airSpeedHigh = 1;//风速高风
    public static final int airSpeedMid = 2;//风速中风
    public static final int airSpeedLow = 3;//风速低风
 
    public static final int airMode = 6;//空调模式
    public static final int airModeRefTem = 0;//空调模式制冷
    public static final int airModeHeatTem = 1;//空调模式制热
    public static final int airModeVen = 2;//空调模式通风
    public static final int airModeAuto = 3;//空调模式自动
    public static final int airModeDehum = 4;//空调模式抽湿
 
    public static final int heatTem = 7;//制热温度
    public static final int autoTem = 8;//自动温度
    public static final int upTem = 9;//上升温度
    public static final int downTem = 10;//下降温度
 
    public static final int dehumTem = 19;//抽湿温度
 
 
    public static byte[] getAirPanelAddByte(int type, int arg2) {
        byte[] addBytes;
        switch (type) {
            case airSwich:
                if (arg2 == airOff) {
                    addBytes = new byte[]{airSwich, (byte) arg2};
                } else if (arg2 == airOn) {
                    addBytes = new byte[]{airSwich, (byte) arg2};
                } else {
                    addBytes = new byte[]{fail};
                }
                break;
            case refTem:
                addBytes = new byte[]{refTem, (byte) arg2};
                break;
            case airSpeed:
                switch (arg2) {
                    case airSpeedAuto:
                        addBytes = new byte[]{airSpeed, airSpeedAuto};
                        break;
                    case airSpeedHigh:
                        addBytes = new byte[]{airSpeed, airSpeedHigh};
                        break;
                    case airSpeedMid:
                        addBytes = new byte[]{airSpeed, airSpeedMid};
                        break;
                    case airSpeedLow:
                        addBytes = new byte[]{airSpeed, airSpeedLow};
                        break;
                    default:
                        addBytes = new byte[]{fail};
                        break;
                }
                break;
            case airMode:
                switch (arg2) {
                    case airModeRefTem:
                        addBytes = new byte[]{airMode, airModeRefTem};
                        break;
                    case airModeHeatTem:
                        addBytes = new byte[]{airMode, airModeHeatTem};
                        break;
                    case airModeVen:
                        addBytes = new byte[]{airMode, airModeVen};
                        break;
                    case airModeAuto:
                        addBytes = new byte[]{airMode, airModeAuto};
                        break;
                    case airModeDehum:
                        addBytes = new byte[]{airMode, airModeDehum};
                        break;
                    default:
                        addBytes = new byte[]{fail};
                        break;
                }
                break;
            case heatTem:
                addBytes = new byte[]{heatTem, (byte) arg2};
                break;
            case autoTem:
                addBytes = new byte[]{autoTem, (byte) arg2};
                break;
            case dehumTem:
                addBytes = new byte[]{dehumTem, (byte) arg2};
                break;
            case upTem:
                addBytes = new byte[]{upTem, (byte) arg2};
                break;
            case downTem:
                addBytes = new byte[]{downTem, (byte) arg2};
                break;
            default:
                addBytes = new byte[]{fail};
                break;
        }
        return addBytes;
    }
 
    public static byte[] getAcAddByte(AppliancesInfo appliancesInfo, int type, int state) {
        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.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);
                        switch (newInfo.getChannelNum()) {
                            case 1:
                                airBytes = HDLDeviceManager.air1Info;
                                break;
                            case 2:
                                airBytes = HDLDeviceManager.air2Info;
                                break;
                            case 3:
                                airBytes = HDLDeviceManager.air3Info;
                                break;
                            case 4:
                                airBytes = HDLDeviceManager.air4Info;
                                break;
                            default:
                                airBytes = new byte[6];
                                break;
 
                        }
                        if (newInfo.getArrCurState() == null) {
                            newInfo.setArrCurState(new byte[6]);
                        }
                        break outter;
                    }
 
                }
            }
        }
 
        if (airBytes != null && airBytes.length >= 6) {
            byte[] addBytes = new byte[13];
            addBytes[0] = (byte) newInfo.getChannelNum();
            addBytes[1] = 0;
            addBytes[2] = airBytes[4];
            addBytes[3] = airBytes[2];
            addBytes[4] = airBytes[2];
            addBytes[5] = airBytes[2];
            addBytes[6] = airBytes[2];
            addBytes[7] = (byte) ((airBytes[1] & 0xff) * 16 + (airBytes[3] & 0xff));
            addBytes[8] = airBytes[0];
            addBytes[9] = airBytes[1];
            addBytes[10] = airBytes[3];
            addBytes[11] = airBytes[2];
            addBytes[12] = airBytes[5];
 
            switch (type) {
                case airSwich:
                    if (state == airOff) {
                        addBytes[8] = 0;
                    } else {
                        addBytes[8] = 1;
                    }
                    break;
                case refTem:
                case heatTem:
                case autoTem:
                case dehumTem:
                    addBytes[8] = 1;
                    addBytes[3] = (byte) state;
                    addBytes[4] = (byte) state;
                    addBytes[5] = (byte) state;
                    addBytes[6] = (byte) state;
                    addBytes[11] = (byte) state;
                    break;
                case upTem:
                    addBytes[8] = 1;
                    addBytes[3] = (byte) ((airBytes[2] & 0xff) + state);
                    addBytes[4] = (byte) ((airBytes[2] & 0xff) + state);
                    addBytes[5] = (byte) ((airBytes[2] & 0xff) + state);
                    addBytes[6] = (byte) ((airBytes[2] & 0xff) + state);
                    addBytes[11] = (byte) ((airBytes[2] & 0xff) + state);
                    break;
                case downTem:
                    addBytes[8] = 1;
                    addBytes[3] = (byte) ((airBytes[2] & 0xff) - state);
                    addBytes[4] = (byte) ((airBytes[2] & 0xff) - state);
                    addBytes[5] = (byte) ((airBytes[2] & 0xff) - state);
                    addBytes[6] = (byte) ((airBytes[2] & 0xff) - state);
                    addBytes[11] = (byte) ((airBytes[2] & 0xff) - state);
                    break;
                case airMode:
                    addBytes[8] = 1;
                    addBytes[7] = (byte) (state * 16 + (airBytes[3] & 0xff));
                    addBytes[9] = (byte) state;
                    break;
                case airSpeed:
                    addBytes[8] = 1;
                    addBytes[7] = (byte) ((airBytes[1] & 0xff) * 16 + state);
                    addBytes[10] = (byte) state;
                    break;
            }
            return addBytes;
        } else {
            return null;
        }
 
    }
 
//    public static byte[] getRcuAirAddByte(AppliancesInfo info,int type, int arg2){
//        byte[] addBytes = new byte[9];
//        addBytes[4] = 1;
//        byte[] curAirInfo = info.getArrCurState();
//        switch (info.getChannelNum()){
//            case 1:
//                curAirInfo = HDLDeviceManager.air1Info;
//                break;
//            case 2:
//                curAirInfo = HDLDeviceManager.air2Info;
//                break;
//            case 3:
//                curAirInfo = HDLDeviceManager.air3Info;
//                break;
//            case 4:
//                curAirInfo = HDLDeviceManager.air4Info;
//                break;
//        }
//
//        byte airSwitch = curAirInfo[0];
//        byte aircurMode = curAirInfo[1];
//        byte airTem = curAirInfo[2];
//        byte aircurSpeed = curAirInfo[3];
//        byte aircurTem = curAirInfo[4];
//        byte airBAIFENG = curAirInfo[5];
//
//        addBytes[0] = (byte) info.getChannelNum();
//        addBytes[1] = airSwitch;
//        switch (aircurMode){
//            case 0:
//                addBytes[2] = airTem;
//                break;
//            case 1:
//                addBytes[5] = airTem;
//                break;
//            case 2:
//                break;
//            case 3:
//                addBytes[6] = airTem;
//                break;
//        }
//        addBytes[3] = (byte) ((aircurMode << 4) | aircurSpeed);
//        addBytes[4] = 1;
//        addBytes[8] = airBAIFENG;
//        switch (type){
//            case airSwich:
//                if(arg2 == airOff){
//                    addBytes[1] = 0;
//                }else if(arg2 == airOn){
//                    addBytes[1] = 1;
//                }
//                break;
//            case refTem:
//                addBytes[2] = (byte) arg2;
//                addBytes[5] = (byte) arg2;
//                addBytes[6] = (byte) arg2;
//                addBytes[7] = (byte) arg2;
//                break;
//            case airSpeed :
//                int modifyLow;
//                int height = ((addBytes[3] & 0xf0) >> 4);//获取高4位
//                switch (arg2){
//                    case airSpeedAuto:
//                        modifyLow = 0;
//                        addBytes[3] = (byte)((height<<4)|modifyLow);
//                        break;
//                    case airSpeedHigh:
//                        modifyLow = 1;
//                        addBytes[3] = (byte)((height<<4)|modifyLow);
//                        break;
//                    case airSpeedMid:
//                        modifyLow = 2;
//                        addBytes[3] = (byte)((height<<4)|modifyLow);
//                        break;
//                    case airSpeedLow:
//                        modifyLow = 3;
//                        addBytes[3] = (byte)((height<<4)|modifyLow);
//                        break;
//                    default:
//                        addBytes = new byte[]{fail};
//                        break;
//                }
//                break;
//            case airMode:
//                int modify;
//                int low = (addBytes[3] & 0x0f);//获取低4位
//                switch (arg2){
//                    case airModeRefTem:
//
//                        modify = 0;
//                        addBytes[3] = (byte)((modify<<4)|low);
//                        break;
//                    case airModeHeatTem:
//                        modify = 1;
//                        addBytes[3] = (byte)((modify<<4)|low);
//                        break;
//                    case airModeVen:
//                        modify = 2;
//                        addBytes[3] = (byte)((modify<<4)|low);
//                        break;
//                    case airModeAuto:
//                        modify = 3;
//                        addBytes[3] = (byte)((modify<<4)|low);
//                        break;
//                    case airModeDehum:
//                        modify = 4;
//                        addBytes[3] = (byte)((modify<<4)|low);
//                        break;
//                    default:
//                        addBytes = new byte[]{fail};
//                        break;
//                }
//                break;
//            case heatTem:
//                addBytes[2] = (byte) arg2;
//                addBytes[5] = (byte) arg2;
//                addBytes[6] = (byte) arg2;
//                addBytes[7] = (byte) arg2;
//                break;
//            case autoTem:
//                addBytes[2] = (byte) arg2;
//                addBytes[5] = (byte) arg2;
//                addBytes[6] = (byte) arg2;
//                addBytes[7] = (byte) arg2;
//                break;
//            case dehumTem:
//                addBytes[2] = (byte) arg2;
//                addBytes[5] = (byte) arg2;
//                addBytes[6] = (byte) arg2;
//                addBytes[7] = (byte) arg2;
//                break;
//            case upTem:
////                int height2 = ((addBytes[3] & 0xf0) >> 4);//获取高4位
////                switch (height2){
////                    case 0:
////                        addBytes[2] = (byte) (arg2 + (airTem & 0xFF));
////                        break;
////                    case 1:
////                        addBytes[5] = (byte) (arg2 + (airTem & 0xFF));
////                        break;
////                    case 3:
////                        addBytes[6] = (byte) (arg2 + (airTem & 0xFF));
////                        break;
////                    case 4:
////                        addBytes[7] = (byte) (arg2 + (airTem & 0xFF));
////                        break;
////                }
//                addBytes[2] = (byte) (arg2 + (airTem & 0xFF));
//                addBytes[5] = (byte) (arg2 + (airTem & 0xFF));
//                addBytes[6] = (byte) (arg2 + (airTem & 0xFF));
//                addBytes[7] = (byte) (arg2 + (airTem & 0xFF));
//                break;
//            case downTem:
////                int height3= ((addBytes[3] & 0xf0) >> 4);//获取高4位
////                switch (height3){
////                    case 0:
////                        addBytes[2] = (byte) ((airTem & 0xFF)-arg2 );
////                        break;
////                    case 1:
////                        addBytes[5] = (byte) ((airTem & 0xFF)-arg2 );
////                        break;
////                    case 3:
////                        addBytes[6] = (byte) ((airTem & 0xFF)-arg2 );
////                        break;
////                    case 4:
////                        addBytes[7] = (byte) ((airTem & 0xFF)-arg2 );
////                        break;
////                }
//                addBytes[2] = (byte) ((airTem & 0xFF)-arg2 );
//                addBytes[5] = (byte) ((airTem & 0xFF)-arg2 );
//                addBytes[6] = (byte) ((airTem & 0xFF)-arg2 );
//                addBytes[7] = (byte) ((airTem & 0xFF)-arg2 );
//                break;
//            default:
//                addBytes = new byte[]{fail};
//                break;
//        }
//        return addBytes;
//    }
}