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
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
package com.hdl.sdk.ttl.HDLDeviceManger.Core;
 
import android.content.Context;
import android.util.Log;
 
import com.hdl.sdk.ttl.Config.Configuration;
import com.hdl.sdk.ttl.Config.MCUConstants;
import com.hdl.sdk.ttl.HDLAppliances.Config.HDLApConfig;
import com.hdl.sdk.ttl.HDLAppliances.HDLAirCondition.AirCtrlBackInfo;
import com.hdl.sdk.ttl.HDLAppliances.HDLAirCondition.Parser.AirCtrlParser;
import com.hdl.sdk.ttl.HDLAppliances.HDLAudio.HDLAudio;
import com.hdl.sdk.ttl.HDLAppliances.HDLCommonSwitch.CommonSwitchBackInfo;
import com.hdl.sdk.ttl.HDLAppliances.HDLCurtain.CurtainCtrlBackInfo;
import com.hdl.sdk.ttl.HDLAppliances.HDLCurtain.Parser.CurtainCtrlParser;
import com.hdl.sdk.ttl.HDLAppliances.HDLDoorMachine.DoorMachineBackInfo;
import com.hdl.sdk.ttl.HDLAppliances.HDLDoorMachine.Parser.DoorMachineParser;
import com.hdl.sdk.ttl.HDLAppliances.HDLFreshAir.FreshAirBackInfo;
import com.hdl.sdk.ttl.HDLAppliances.HDLFreshAir.FreshAirJinMaoBackInfo;
import com.hdl.sdk.ttl.HDLAppliances.HDLFreshAir.Parser.FreshAirJinMaoParser;
import com.hdl.sdk.ttl.HDLAppliances.HDLFreshAir.Parser.FreshAirParser;
import com.hdl.sdk.ttl.HDLAppliances.HDLGeothermal.GeothermalBackInfo;
import com.hdl.sdk.ttl.HDLAppliances.HDLGeothermal.Parser.GeothermalParser;
import com.hdl.sdk.ttl.HDLAppliances.HDLLight.ColourLightCtrlBackInfo;
import com.hdl.sdk.ttl.HDLAppliances.HDLLight.LightCtrlBackInfo;
import com.hdl.sdk.ttl.HDLAppliances.HDLLight.Parser.LightCtrlParser;
import com.hdl.sdk.ttl.HDLAppliances.HDLLogic.LogicCtrlBackInfo;
import com.hdl.sdk.ttl.HDLAppliances.HDLSecurity.Parser.SecurityParser;
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo;
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.DeviceStateBean;
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.MCUDataBean;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.AirFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.ColourLightFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.CommonSwitchCtrlBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.CurtainFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.DeviceStateEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.DoorMachineFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.EventCode;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.FreshAirFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.FreshAirJinMaoFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.GeothermalFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.LightFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.LogicFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.MCUFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.SecurityArmingFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.UpdateRemarkFeedBackEvent;
import com.hdl.sdk.ttl.Utils.HDLUtlis.HDLUtlis;
import com.hdl.sdk.ttl.Utils.LogUtils.HDLLog;
import com.hdl.sdk.ttl.Utils.SPUtils.SPUtils;
 
 
import org.greenrobot.eventbus.EventBus;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
 
/**
 * Modify by JLChen on 2019/6/27
 */
public class HDLCommand {
 
    public static int mRequestTimeout = 5000;//默认请求超时时间
    private static Timer getStateFailTimer = null;//获取设备状态失败Timer
    private static Timer lightCtrlFailTimer = null;//控制灯光失败Timer
    private static Timer curtainCtrlFailTimer = null;//控制窗帘失败Timer
    private static Timer acCtrlFailTimer = null;//控制空调失败Timer
    private static Timer sceneCtrlFailTimer = null;//控制场景失败Timer
    private static Timer remarkUpdateFailTimer = null;//更新备注失败Timer
    private static Timer mcuCtrlFailTimer = null;//MCU操作失败Timer
    private static Timer securityCtrlFailTimer = null;//安防模块操作失败Timer
    private static Timer commonSwitchCtrlFailTimer = null;//通用开关失败Timer
 
    private static Timer freshAirCtrlFailTimer = null;//控制新风失败Timer
    private static Timer geothermalCtrlFailTimer = null;//控制地热失败Timer 2020-07-20
    private static Timer doorMachineCtrlFailTimer = null;//控制门锁失败Timer
 
//    /**
//     * 初始化 SDK
//     *
//     * @param context
//     */
//    public static void init(Context context, String mPathname, int mBaudrate) {
//        HDLDeviceManager.init(context);
//        HDLSerialPortCore.initHDLSerialPort(mPathname, mBaudrate);
//    }
//
//    /**
//     * 是否开启SDK日志打印
//     *
//     * @param bOpen
//     */
//    public static void setHDLLogOpen(boolean bOpen) {
//        HDLLog.setHDLLogOpen(bOpen);
//    }
 
//    /**
//     * 释放资源
//     */
//    public static void release() {
//        HDLDeviceManager.release();
//    }
 
    /**
     * 获取家居设备
     */
    public static void getHomeDevices() {
        HandleSearch.getHomeDevices();
    }
 
 
    /**
     * 获取家居设备备注
     */
    public static void getDevRemarks() {
        HandleSearch.getDevRemarks();
    }
 
    /**
     * 发现新设备搜索,不会清空原设备列表数据
     */
    public static void getNewHomeDevices() {
        HandleSearch.getNewHomeDevices();
    }
 
    /**
     * 取消搜索等定时器
     */
    public static void cancelSearching() {
        HandleSearch.isSearching = false;
        if (HandleSearch.searchTimer != null) {
            HandleSearch.searchTimer.cancel();
            HandleSearch.searchTimer = null;
        }
 
        if (HandleSearch.searchTwiceTimer != null) {
            HandleSearch.searchTwiceTimer.cancel();
            HandleSearch.searchTwiceTimer = null;
        }
 
        if (HandleSearch.searchFailTimer != null) {
            HandleSearch.searchFailTimer.cancel();
            HandleSearch.searchFailTimer = null;
        }
 
        if (HandleSearch.remarkTimer != null) {
            HandleSearch.remarkTimer.cancel();
            HandleSearch.remarkTimer = null;
 
        }
    }
 
    /**
     * 修改更新模块备注名
     *
     * @param mSubnetID   子网号
     * @param mDeviceID   设备号
     * @param remakeBytes 20190701
     */
    public static void updateModuleRemark(int mSubnetID, int mDeviceID, byte[] remakeBytes) {
        /***备注名字限制为20字节以内*/
        if (remakeBytes.length > 20) return;
 
        HDLDeviceManager.isUpdateRemarkSuccess = false;
        if (remarkUpdateFailTimer != null) {
            remarkUpdateFailTimer.cancel();
            remarkUpdateFailTimer = null;
        }
 
        byte[] updateBytes = new byte[20];
 
 
        System.arraycopy(remakeBytes, 0, updateBytes, 0, remakeBytes.length);
        cusSendCommand(Configuration.MODULE_UPDATE_REMARK_COMMAND,
                mSubnetID, mDeviceID, updateBytes);
 
        remarkUpdateFailTimer = new Timer();
        remarkUpdateFailTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (!HDLDeviceManager.isUpdateRemarkSuccess) {
                    EventBus.getDefault().post(new UpdateRemarkFeedBackEvent(false));
                }
            }
        }, mRequestTimeout);
    }
 
//    /**
//     * 修改某回路备注名
//     * @param newName 20190701
//     */
//    public static void updateLoopRemark(final AppliancesInfo info, String newName) {
//        byte[] updateBytes = new byte[20];
//        byte[] remakeBytes = HDLStringUtils.stringtoBytes(newName);
//        System.arraycopy(remakeBytes, 0, updateBytes, 0, remakeBytes.length);
//
//        cusSendCommand(Configuration.DEVICES_MODIFY_COMMAND,
//                info.getDeviceSubnetID(), info.getDeviceDeviceID(), updateBytes);
//    }
 
    /**
     * 控制灯光
     *
     * @param info
     * @param state
     */
    public static void lightCtrl(final AppliancesInfo info, int state) {
//        HDLDeviceManager.isLightCtrlSuccess = false;
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (lightCtrlFailTimer != null) {
            lightCtrlFailTimer.cancel();
            lightCtrlFailTimer = null;
        }
        if ((!(state >= 0 && state <= 100))
                || (info.getBigType() != Configuration.LIGTH_BIG_TYPE)
                || info.getChannelNum() == 0
        ) {
            HDLLog.I("djlCtrl: " + "灯光设备控制不在范围内或不是灯光设备"
                    + " \nstate = " + state
                    + " \nLittleType = " + info.getLittleType()
                    + " \nBigType = " + info.getBigType()
            );
            return;
        }
 
        byte[] bytes;
        switch (info.getLittleType()) {
            case 0:
            case 1:
                //可能有区别
                bytes = new byte[]{(byte) info.getChannelNum(), (byte) state, 0, 0};
                break;
            case 9:
                bytes = new byte[]{(byte) info.getPhysicsChannelNum(), (byte) state, 0, 0};
                break;
            case 10:
                bytes = new byte[]{(byte) info.getPhysicsChannelNum(), (byte) state, 0, 0};
                break;
            default:
                bytes = new byte[]{0};
                break;
        }
        //酒店的是物理回路号,需要测试。可能会出现问题
//        HDLDeviceManager.curCtrlLightType = I.getDeviceType();
//        byte[] bytes = new byte[]{(byte) I.getChannelNum(), (byte) state, 0, 0};
        addSendData(info, bytes, Configuration.CONTROL);
 
        lightCtrlFailTimer = new Timer();
 
        lightCtrlFailTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                    LightCtrlBackInfo lightCtrlBackInfo = new LightCtrlBackInfo();
                    lightCtrlBackInfo.setAppliancesInfo(info);
                    lightCtrlBackInfo.setChannelNum(info.getChannelNum());
                    EventBus.getDefault().post(new LightFeedBackEvent(lightCtrlBackInfo, false));
                }
            }
        }, mRequestTimeout);
    }
 
    /**
     * 控制CCT OR RGB
     *
     * @param info
     * @param brightness 亮度
     * @param color
     */
    public static void colourLightCtrl(final AppliancesInfo info, int brightness, int color) {
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (lightCtrlFailTimer != null) {
            lightCtrlFailTimer.cancel();
            lightCtrlFailTimer = null;
        }
        if (info.getBigType() == Configuration.LIGTH_BIG_TYPE) {
            addSendData(info, LightCtrlParser.getColourLightAddByte(info, brightness, color), Configuration.CONTROL);
 
            lightCtrlFailTimer = new Timer();
            lightCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        ColourLightCtrlBackInfo colourLightCtrlBackInfo = new ColourLightCtrlBackInfo(info);
                        EventBus.getDefault().post(new ColourLightFeedBackEvent(colourLightCtrlBackInfo, false));
                    }
                }
            }, mRequestTimeout);
 
        } else {
            HDLLog.I("灯光设备控制不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
    /**
     * 控制窗帘
     *
     * @param info
     * @param state
     */
    public static void curtainCtrl(final AppliancesInfo info, int state) {
//        HDLDeviceManager.isCurtainCtrlSuccess = false;
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (curtainCtrlFailTimer != null) {
            curtainCtrlFailTimer.cancel();
            curtainCtrlFailTimer = null;
        }
        byte[] bytes;
        if (info.getBigType() == Configuration.CURTAIN_BIG_TYPE) {
            if (info.getLittleType() == 1 || info.getLittleType() == 0) {
                //这里是判断卷帘电机和开合帘电机
                int newChannelNum;
                if (state == CurtainCtrlParser.curtainOff
                        || state == CurtainCtrlParser.curtainOn
                        || state == CurtainCtrlParser.curtainPause) {
                    newChannelNum = info.getChannelNum();
                } else {
                    newChannelNum = info.getChannelNum() + 16;
                }
                bytes = CurtainCtrlParser.getCurtainAddByte(newChannelNum, state);
            } else {
                bytes = CurtainCtrlParser.getCurtainAddByte(info.getChannelNum(), state);
            }
 
            addSendData(info, bytes, Configuration.CONTROL);
 
            curtainCtrlFailTimer = new Timer();
 
            curtainCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        CurtainCtrlBackInfo curtainCtrlBackInfo = new CurtainCtrlBackInfo();
                        curtainCtrlBackInfo.setAppliancesInfo(info);
                        curtainCtrlBackInfo.setNum(info.getChannelNum());
                        EventBus.getDefault().post(new CurtainFeedBackEvent(curtainCtrlBackInfo, false));
                    }
                }
            }, mRequestTimeout);
 
 
        } else {
            HDLLog.I("djlCtrl;  不是窗帘设备"
                    + " \nstate = " + state
                    + " \nLittleType = " + info.getLittleType()
                    + " \nBigType = " + info.getBigType()
            );
        }
    }
 
 
    /**
     * 控制空调
     *
     * @param info
     * @param type
     * @param state //     * @param bCelsius 判断摄氏度 还是 华氏度(℉)
     */
    public static void airCtrl(final AppliancesInfo info, int type, int state) {
//        HDLDeviceManager.isACCtrlSuccess = false;
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (acCtrlFailTimer != null) {
            acCtrlFailTimer.cancel();
            acCtrlFailTimer = null;
        }
        if (info.getBigType() == Configuration.AIR_BIG_TYPE) {
            if (info.getDeviceType() == HDLApConfig.TYPE_AC_PANEL) {
                addSendData(info, AirCtrlParser.getAirPanelAddByte(type, state), Configuration.CONTROL);
            } else if (info.getDeviceType() == HDLApConfig.TYPE_AC_TECHSYS) {
                byte[] airbytes = AirCtrlParser.getAirTechAddByte(info, type, state);
                if (airbytes != null) {
                    addSendData(info, airbytes, Configuration.CONTROL);
                }
            } else {
                byte[] airbytes = AirCtrlParser.getAcAddByte(info, type, state);
                if (airbytes != null) {
                    addSendData(info, airbytes, Configuration.CONTROL);
                }
            }
 
            acCtrlFailTimer = new Timer();
            acCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        AirCtrlBackInfo airCtrlBackInfo = new AirCtrlBackInfo();
                        airCtrlBackInfo.setAppliancesInfo(info);
                        EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, false));
                    }
                }
            }, mRequestTimeout);
 
 
        } else {
            HDLLog.I("空调设备控制不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
 
    /**
     * 控制通用开关
     *
     * @param info
     */
    public static void commonSwitchCtrl(final AppliancesInfo info, int state) {
 
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (info.getBigType() == Configuration.COMMON_SWITCH_BIG_TYPE) {
 
            if (commonSwitchCtrlFailTimer != null) {
                commonSwitchCtrlFailTimer.cancel();
                commonSwitchCtrlFailTimer = null;
            }
 
            byte[] bytes = new byte[]{(byte) info.getChannelNum(), (byte) state};
 
            addSendData(info, bytes, Configuration.CONTROL);
 
            commonSwitchCtrlFailTimer = new Timer();
            commonSwitchCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        HDLLog.I("通用开关控制失败");
                        CommonSwitchBackInfo mCommonSwitchBackInfo = new CommonSwitchBackInfo();
                        mCommonSwitchBackInfo.setAppliancesInfo(info);
                        EventBus.getDefault().post(new CommonSwitchCtrlBackEvent(mCommonSwitchBackInfo, false));
                    }
                }
            }, mRequestTimeout);
        } else {
            HDLLog.I("djlCtrl: 通用开关设备控制不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
 
    /**
     * 获取通用开关状态
     *
     * @param info
     */
    public static void getCommonSwitchStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_COMMON_SWITCH:
                //发送获灯光状态数据
                addSendData(info, new byte[0], Configuration.STATE);
                break;
            default:
                HDLLog.I("不是通用开关设备");
                break;
        }
    }
 
    /**
     * 安防模块 布防设置
     * 2019-7-29
     *
     * @param info
     */
    public static void securityArmingCtrl(final AppliancesInfo info, int state) {
//        HDLDeviceManager.isSecurityCtrlSuccess = false;
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (securityCtrlFailTimer != null) {
            securityCtrlFailTimer.cancel();
            securityCtrlFailTimer = null;
        }
        if (info.getBigType() == Configuration.SECURITY_BIG_TYPE) {
            byte[] sendbytes = SecurityParser.getArmingByte(info, state);
            addSendData(info, sendbytes, Configuration.CONTROL);
            securityCtrlFailTimer = new Timer();
            securityCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        EventBus.getDefault().post(new SecurityArmingFeedBackEvent(info, 0, false));
                    }
                }
            }, 5000);
 
        } else {
            HDLLog.I("安防模块不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
    /**
     * 安防模块 报警设置
     * 2019-7-29
     *
     * @param info
     * @param state 发送的报警内容,只报警一种
     */
    public static void securitySendAlarm(final AppliancesInfo info, int state) {
        if (info.getBigType() == Configuration.SECURITY_BIG_TYPE) {
            byte[] sendbytes = SecurityParser.getAlarmByte(info, state);
            cusSendCommand(Configuration.SECURITY_ALARM_CTRL_COMMAND, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendbytes);
        } else {
            HDLLog.I("不是安防模块"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
    /**
     * 控制逻辑模块
     *
     * @param info
     */
    public static void logicCtrl(final AppliancesInfo info) {
//        HDLDeviceManager.isSceneCtrlSuccess = false;
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (info.getBigType() == Configuration.LOGIC_BIG_TYPE
                || info.getBigType() == Configuration.GLOBAL_LOGIC_BIG_TYPE) {
            if (info.getLogicMode() == null) {
//                HDLSerialPortCore.sendTestCMD(HDLTest.CODE_LOGIC_MODE_NULL, HDLTest.EXCEPTION_TEST_PORT);
                return;
            } else {
                addSendData(info, new byte[]{(byte) info.getLogicMode().getAreaNum(),
                        (byte) info.getLogicMode().getAreaSceneNum()}, Configuration.CONTROL);
            }
 
 
            if (sceneCtrlFailTimer != null) {
                sceneCtrlFailTimer.cancel();
                sceneCtrlFailTimer = null;
            }
            sceneCtrlFailTimer = new Timer();
            sceneCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        HDLLog.I("逻辑控制失败");
                        LogicCtrlBackInfo logicCtrlBackInfo = new LogicCtrlBackInfo();
                        logicCtrlBackInfo.setAppliancesInfo(info);
                        EventBus.getDefault().post(new LogicFeedBackEvent(logicCtrlBackInfo, false));
                    }
                }
            }, mRequestTimeout);
        } else {
            HDLLog.I("djlCtrl: 逻辑模块设备控制不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
    //  获取单一回路设备状态
    //  读取设备状态
//    public static void getDeviceState(final AppliancesInfo I) {
//        HDLDeviceManager.isGetDeviceStateSuccess = false;
//        switch (I.getBigType()) {
//            case Configuration.LIGTH_BIG_TYPE:
//                addSendData(I, new byte[]{}, Configuration.STATE);
//                break;
//            case Configuration.CURTAIN_BIG_TYPE:
//                if (I.getDeviceType() == HDLApConfig.TYPE_CURTAIN_MODULE) {
//                    addSendData(I, new byte[]{(byte) I.getChannelNum()}, Configuration.STATE);
//                } else {
//                    addSendData(I, new byte[]{(byte) (I.getChannelNum() + 16)}, Configuration.STATE);
//                }
//                break;
//            case Configuration.AIR_BIG_TYPE:
//                addSendData(I, new byte[]{AirCtrlParser.airSwich}, Configuration.STATE);
////                addSendData(I,new byte[]{AirCtrlParser.refTem},Configuration.STATE);
//                addSendData(I, new byte[]{AirCtrlParser.airSpeed}, Configuration.STATE);
//                addSendData(I, new byte[]{AirCtrlParser.airMode}, Configuration.STATE);
////                addSendData(I,new byte[]{AirCtrlParser.heatTem},Configuration.STATE);
////                addSendData(I,new byte[]{AirCtrlParser.autoTem},Configuration.STATE);
//                break;
//        }
//
//        if (I.getBigType() == Configuration.AIR_BIG_TYPE) {
//            return;
//        }
//        if (getStateFailTimer != null) {
//            getStateFailTimer.cancel();
//            getStateFailTimer = null;
//        }
//        getStateFailTimer = new Timer();
//        getStateFailTimer.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                if (!HDLDeviceManager.isGetDeviceStateSuccess) {
//                    EventBus.getDefault().post(new DeviceStateEvent(I, false));
//                }
//            }
//        }, mRequestTimeout);
//
//    }
 
    /**
     * 控制窗帘
     *
     * @param info
     */
    public static void curtainGetState(final AppliancesInfo info) {
        byte[] bytes = new byte[1];
        if (info.getBigType() == Configuration.CURTAIN_BIG_TYPE) {
            if (info.getLittleType() == 1 || info.getLittleType() == 0) {
                //这里是判断卷帘电机和开合帘电机
                int newChannelNum;
                int state = HDLUtlis.getIntegerByObject(info.getCurState());
                if (state == CurtainCtrlParser.TYPE_STATE_PAUSE
                        || state == CurtainCtrlParser.TYPE_STATE_OPEN
                        || state == CurtainCtrlParser.TYPE_STATE_CLOSE) {
                    newChannelNum = info.getChannelNum();
                } else {
                    newChannelNum = info.getChannelNum() + 16;
                }
                bytes[0] = (byte) newChannelNum;
            } else {
                bytes[0] = (byte) info.getChannelNum();
            }
 
            addSendData(info, bytes, Configuration.STATE);
        } else {
            HDLLog.I("djlCtrl;  不是窗帘设备"
                    + " \nLittleType = " + info.getLittleType()
                    + " \nBigType = " + info.getBigType()
            );
        }
    }
 
//
//    /**
//     * 网络上获取单一设备状态
//     * 通过发送查询指令获取
//     * 空调状态读取(目前仅支持通用空调面板)
//     *
//     * @param info
//     */
//    public static void getDeviceStateFromNetwork(final AppliancesInfo info) {
//        if (info == null) {
//            return;
//        }
//        HDLDeviceManager.isGetDeviceStateSuccess = false;
//        switch (info.getDeviceType()) {
//            case HDLApConfig.TYPE_LIGHT_DIMMER:
//            case HDLApConfig.TYPE_LIGHT_RELAY:
//            case HDLApConfig.TYPE_LIGHT_MIX_DIMMER:
//            case HDLApConfig.TYPE_LIGHT_MIX_RELAY:
//                //发送获灯光状态数据
//                addSendData(info, new byte[0], Configuration.STATE);
//                break;
//
//            case HDLApConfig.TYPE_CURTAIN_GLYSTRO:
//            case HDLApConfig.TYPE_CURTAIN_ROLLER:
//            case HDLApConfig.TYPE_CURTAIN_MODULE:
//                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
//                break;
//
//            case HDLApConfig.TYPE_AC_HVAC:
//            case HDLApConfig.TYPE_AC_COOLMASTER:
//            case HDLApConfig.TYPE_AC_INFRARED:
//            case HDLApConfig.TYPE_AC_PANEL:
//                //暂不支持
//
//                break;
//
//            default:
//                break;
//
//        }
//    }
 
    /**
     * 获取窗帘设备状态
     *
     * @param info
     */
    public static void getCurtainDeviceStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_CURTAIN_GLYSTRO:
            case HDLApConfig.TYPE_CURTAIN_ROLLER:
            case HDLApConfig.TYPE_CURTAIN_MODULE:
                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是窗帘设备");
                break;
        }
    }
 
    /**
     * 获取灯光设备状态
     *
     * @param info
     */
    public static void getLightDeviceStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_LIGHT_DIMMER:
            case HDLApConfig.TYPE_LIGHT_RELAY:
            case HDLApConfig.TYPE_LIGHT_MIX_DIMMER:
            case HDLApConfig.TYPE_LIGHT_MIX_RELAY:
                //发送获取灯光状态数据
                addSendData(info, new byte[0], Configuration.STATE);
                break;
            default:
                HDLLog.I("不是灯光设备");
                break;
        }
    }
 
    /**
     * 获取CTT or RGB灯设备状态
     *
     * @param info
     */
    public static void getColourLightDeviceStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_LIGHT_CCT:
            case HDLApConfig.TYPE_LIGHT_RGB:
            case HDLApConfig.TYPE_LIGHT_DALI:
            case HDLApConfig.TYPE_LIGHT_DMX:
                //发送获取灯光状态数据
                byte[] sendbytes = new byte[]{(byte) info.getChannelNum()};
                addSendData(info, sendbytes, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是CTT or RGB灯光设备");
                break;
        }
    }
 
 
    /**
     * 获取逻辑 场景号
     *
     * @param info
     */
    public static void getLogicDeviceStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_LOGIC_MODULE:
            case HDLApConfig.TYPE_GLOBAL_LOGIC_MODULE:
                //发送获取场景号
                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是逻辑设备");
                break;
        }
    }
 
    /**
     * 获取安防模块状态
     *
     * @param info
     */
    public static void getSecurityStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_SECURITY_MODULE:
                //发送获安防模块状态数据
                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是安防模块");
                break;
        }
    }
 
    /**
     * 获取传感器模块状态
     *
     * @param info
     */
    public static void getSensorStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_SENSOR_DRY_CONTACT:
            case HDLApConfig.TYPE_SENSOR_MOVEMENT_DETECTOR:
            case HDLApConfig.TYPE_SENSOR_TEMP:
            case HDLApConfig.TYPE_SENSOR_HUMIDITY:
            case HDLApConfig.TYPE_SENSOR_ILLUMINACE:
            case HDLApConfig.TYPE_SENSOR_VOC:
            case HDLApConfig.TYPE_SENSOR_PM_2_POINT_5:
            case HDLApConfig.TYPE_SENSOR_C02:
            case HDLApConfig.TYPE_SENSOR_LPG:
            case HDLApConfig.TYPE_SENSOR_CO_H2:
            case HDLApConfig.TYPE_SENSOR_CH4:
            case HDLApConfig.TYPE_SENSOR_SMOG:
            case HDLApConfig.TYPE_SENSOR_WIND_SPEED:
            case HDLApConfig.TYPE_SENSOR_WIND_PRESSURE:
            case HDLApConfig.TYPE_SENSOR_LIQUID_FLOW:
            case HDLApConfig.TYPE_SENSOR_LIQUID_PRESSURE:
            case HDLApConfig.TYPE_SENSOR_LIQUID_DEPTH:
            case HDLApConfig.TYPE_SENSOR_RAIN_FALL:
            case HDLApConfig.TYPE_SENSOR_WEIGHT:
            case HDLApConfig.TYPE_SENSOR_HEIGHT_LENGTH:
            case HDLApConfig.TYPE_SENSOR_OBJECT_SPEED:
            case HDLApConfig.TYPE_SENSOR_SHAKE:
            case HDLApConfig.TYPE_SENSOR_VOLTAGE:
            case HDLApConfig.TYPE_SENSOR_ELECTRICITY:
            case HDLApConfig.TYPE_SENSOR_POWER:
            case HDLApConfig.TYPE_SENSOR_FLOODING:
            case HDLApConfig.TYPE_SENSOR_DOOR_MAGNET:
            case HDLApConfig.TYPE_SENSOR_EMERGENCY_BUTTON:
                //发送获传感器模块状态数据
                byte[] sendDatabyte = new byte[]{
                        (byte) info.getBigType(),
                        (byte) info.getLittleType(),
                        (byte) info.getChannelNum()
                };
 
                addSendData(info, sendDatabyte, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是传感器模块");
                break;
        }
    }
 
    /**
     * 获取干接点传感器模块状态
     *
     * @param info
     */
    public static void getDryContactSensorStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_SENSOR_DRY_CONTACT:
            case HDLApConfig.TYPE_SENSOR_MOVEMENT_DETECTOR:
            case HDLApConfig.TYPE_SENSOR_TEMP:
            case HDLApConfig.TYPE_SENSOR_HUMIDITY:
            case HDLApConfig.TYPE_SENSOR_ILLUMINACE:
            case HDLApConfig.TYPE_SENSOR_VOC:
            case HDLApConfig.TYPE_SENSOR_PM_2_POINT_5:
            case HDLApConfig.TYPE_SENSOR_C02:
            case HDLApConfig.TYPE_SENSOR_LPG:
            case HDLApConfig.TYPE_SENSOR_CO_H2:
            case HDLApConfig.TYPE_SENSOR_CH4:
            case HDLApConfig.TYPE_SENSOR_SMOG:
            case HDLApConfig.TYPE_SENSOR_WIND_SPEED:
            case HDLApConfig.TYPE_SENSOR_WIND_PRESSURE:
            case HDLApConfig.TYPE_SENSOR_LIQUID_FLOW:
            case HDLApConfig.TYPE_SENSOR_LIQUID_PRESSURE:
            case HDLApConfig.TYPE_SENSOR_LIQUID_DEPTH:
            case HDLApConfig.TYPE_SENSOR_RAIN_FALL:
            case HDLApConfig.TYPE_SENSOR_WEIGHT:
            case HDLApConfig.TYPE_SENSOR_HEIGHT_LENGTH:
            case HDLApConfig.TYPE_SENSOR_OBJECT_SPEED:
            case HDLApConfig.TYPE_SENSOR_SHAKE:
            case HDLApConfig.TYPE_SENSOR_VOLTAGE:
            case HDLApConfig.TYPE_SENSOR_ELECTRICITY:
            case HDLApConfig.TYPE_SENSOR_POWER:
            case HDLApConfig.TYPE_SENSOR_FLOODING:
            case HDLApConfig.TYPE_SENSOR_DOOR_MAGNET:
            case HDLApConfig.TYPE_SENSOR_EMERGENCY_BUTTON:
                //发送获传感器模块状态数据
                byte[] sendDatabyte = new byte[]{
                        (byte) 1,
                        (byte) info.getChannelNum()
                };
 
                addSendData(info, sendDatabyte, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是传感器模块");
                break;
        }
    }
 
    /**
     * 获取HVAC空调设备状态
     *
     * @param info
     */
    public static void getHVACDeviceStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_AC_HVAC:
//            case HDLApConfig.TYPE_AC_PANEL:
                //发送HVAC状态数据
                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是HVAC空调设备");
                break;
        }
    }
 
 
    /**
     * 获取科技系统状态
     *
     * @param info
     */
    public static void getTechSysDeviceStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_AC_TECHSYS:
                //发送科技系统状态数据
                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是科技系统设备");
                break;
        }
    }
 
 
    /**
     * 获取单一设备状态
     * 从SDK本地获取
     *
     * @param info
     */
    public static void getDeviceStateFromLocal(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_LIGHT_DIMMER:
            case HDLApConfig.TYPE_LIGHT_RELAY:
            case HDLApConfig.TYPE_LIGHT_MIX_DIMMER:
            case HDLApConfig.TYPE_LIGHT_MIX_RELAY:
                int lightState = getLightState(info);
                info.setCurState(lightState);
                EventBus.getDefault().post(new DeviceStateEvent(info, true));
                break;
 
            case HDLApConfig.TYPE_CURTAIN_GLYSTRO:
            case HDLApConfig.TYPE_CURTAIN_ROLLER:
            case HDLApConfig.TYPE_CURTAIN_MODULE:
                int curtainState = getCurtainState(info);
                info.setCurState(curtainState);
                EventBus.getDefault().post(new DeviceStateEvent(info, true));
                break;
 
            case HDLApConfig.TYPE_AC_HVAC:
            case HDLApConfig.TYPE_AC_COOLMASTER:
            case HDLApConfig.TYPE_AC_INFRARED:
            case HDLApConfig.TYPE_AC_PANEL:
            case HDLApConfig.TYPE_AC_TECHSYS:
                //2019-8-21 增加判空
                byte[] acState = getACState(info);
                if (acState != null && acState.length >= 4) {
                    info.setArrCurState(new byte[]{AirCtrlParser.airSwich, acState[0]});
                    EventBus.getDefault().post(new DeviceStateEvent(info, true));
 
                    info.setArrCurState(new byte[]{AirCtrlParser.airMode, acState[1]});
                    EventBus.getDefault().post(new DeviceStateEvent(info, true));
 
                    switch (acState[1] & 0xff) {
                        case AirCtrlParser.airModeRefTem:
                            info.setArrCurState(new byte[]{AirCtrlParser.refTem, acState[2]});
                            EventBus.getDefault().post(new DeviceStateEvent(info, true));
                            break;
                        case AirCtrlParser.airModeHeatTem:
                            info.setArrCurState(new byte[]{AirCtrlParser.heatTem, acState[2]});
                            EventBus.getDefault().post(new DeviceStateEvent(info, true));
                            break;
                        case AirCtrlParser.airModeAuto:
                            info.setArrCurState(new byte[]{AirCtrlParser.autoTem, acState[2]});
                            EventBus.getDefault().post(new DeviceStateEvent(info, true));
                            break;
                        case AirCtrlParser.airModeDehum:
                            info.setArrCurState(new byte[]{AirCtrlParser.autoTem, acState[2]});
                            EventBus.getDefault().post(new DeviceStateEvent(info, true));
                            break;
                        default:
                            break;
                    }
 
                    if ((acState[1] & 0xff) != AirCtrlParser.airModeDehum) {
                        info.setArrCurState(new byte[]{AirCtrlParser.airSpeed, acState[3]});
                        EventBus.getDefault().post(new DeviceStateEvent(info, true));
                    }
                }
                break;
            case HDLApConfig.TYPE_SECURITY_MODULE://2019-7-29
                byte[] ArrCurState = getSecurityState(info);
                info.setArrCurState(ArrCurState);
                EventBus.getDefault().post(new DeviceStateEvent(info, true));
                break;
 
//            case HDLApConfig.TYPE_SENSOR_DRY_CONTACT://屏蔽20190703
//            case HDLApConfig.TYPE_SENSOR_MOVEMENT_DETECTOR:
//            case HDLApConfig.TYPE_SENSOR_TEMP:
//            case HDLApConfig.TYPE_SENSOR_HUMIDITY:
//            case HDLApConfig.TYPE_SENSOR_ILLUMINACE:
//            case HDLApConfig.TYPE_SENSOR_VOC:
//            case HDLApConfig.TYPE_SENSOR_PM_2_POINT_5:
//            case HDLApConfig.TYPE_SENSOR_C02:
//            case HDLApConfig.TYPE_SENSOR_LPG:
//            case HDLApConfig.TYPE_SENSOR_CO_H2:
//            case HDLApConfig.TYPE_SENSOR_CH4:
//            case HDLApConfig.TYPE_SENSOR_SMOG:
//            case HDLApConfig.TYPE_SENSOR_WIND_SPEED:
//            case HDLApConfig.TYPE_SENSOR_WIND_PRESSURE:
//            case HDLApConfig.TYPE_SENSOR_LIQUID_FLOW:
//            case HDLApConfig.TYPE_SENSOR_LIQUID_PRESSURE:
//            case HDLApConfig.TYPE_SENSOR_LIQUID_DEPTH:
//            case HDLApConfig.TYPE_SENSOR_RAIN_FALL:
//            case HDLApConfig.TYPE_SENSOR_WEIGHT:
//            case HDLApConfig.TYPE_SENSOR_HEIGHT_LENGTH:
//            case HDLApConfig.TYPE_SENSOR_OBJECT_SPEED:
//            case HDLApConfig.TYPE_SENSOR_SHAKE:
//            case HDLApConfig.TYPE_SENSOR_VOLTAGE:
//            case HDLApConfig.TYPE_SENSOR_ELECTRICITY:
//            case HDLApConfig.TYPE_SENSOR_POWER:
//            case HDLApConfig.TYPE_SENSOR_FLOODING:
//            case HDLApConfig.TYPE_SENSOR_DOOR_MAGNET:
//            case HDLApConfig.TYPE_SENSOR_EMERGENCY_BUTTON:
//                //发送获取传感器所有数据
//                addSendData(info, new byte[]{(byte) info.getBigType(), (byte) info.getLittleType(), (byte) info.getChannelNum()}, Configuration.STATE);
//                break;
            default:
                break;
 
        }
    }
 
    /**
     * 获取所有设备状态
     *
     * @return
     */
    public static List<DeviceStateBean> getAllDevicesState() {
        List<DeviceStateBean> deviceStateBeanList = new ArrayList<>();
        for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
            List<AppliancesInfo> appliancesInfos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList();
            for (int j = 0; j < appliancesInfos.size(); j++) {
                if (appliancesInfos.get(j).getBigType() == Configuration.LIGTH_BIG_TYPE
                        || appliancesInfos.get(j).getBigType() == Configuration.CURTAIN_BIG_TYPE
                        || appliancesInfos.get(j).getBigType() == Configuration.AIR_BIG_TYPE
                ) {
                    DeviceStateBean deviceStateBean = new DeviceStateBean();
                    deviceStateBean.setDeviceSubnetID(appliancesInfos.get(j).getDeviceSubnetID());
                    deviceStateBean.setDeviceDeviceID(appliancesInfos.get(j).getDeviceDeviceID());
                    deviceStateBean.setBigType(appliancesInfos.get(j).getBigType());
                    deviceStateBean.setLittleType(appliancesInfos.get(j).getLittleType());
                    deviceStateBean.setDeviceType(appliancesInfos.get(j).getDeviceType());
                    deviceStateBean.setChannelNum(appliancesInfos.get(j).getChannelNum());
                    if (deviceStateBean.getBigType() == Configuration.AIR_BIG_TYPE) {
                        if (appliancesInfos.get(j).getArrCurState() != null) {
                            deviceStateBean.setArrCurState(appliancesInfos.get(j).getArrCurState());
                        }
 
                    } else {
                        deviceStateBean.setCurState(appliancesInfos.get(j).getIntCurState());
 
                    }
                    deviceStateBeanList.add(deviceStateBean);
                }
 
            }
        }
//        //更新所有设备状态 2019-07-03去掉
//        HandleSearch.refreshAllDevicesState();
        if (!deviceStateBeanList.isEmpty()) {
            return deviceStateBeanList;
        } else {
            return null;
        }
 
 
    }
 
 
    /**
     * 获取灯光状态
     *
     * @param info
     * @return
     */
    private static int getLightState(final AppliancesInfo info) {
        int curState = 0;
        outter:
        for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) {
            if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID()
                    && HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID()
            ) {
                List<AppliancesInfo> infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList();
                for (int j = 0, len2 = infos.size(); j < len2; j++) {
                    if (info.getBigType() == infos.get(j).getBigType()
                            && info.getLittleType() == infos.get(j).getLittleType()
                            && info.getChannelNum() == infos.get(j).getChannelNum()
                    ) {
                        curState = HDLUtlis.getIntegerByObject(infos.get(j).getCurState());
                        break outter;
                    }
 
                }
            }
        }
        return curState;
    }
 
    /**
     * 获取窗帘状态
     *
     * @param info
     * @return
     */
    private static int getCurtainState(final AppliancesInfo info) {
        int curState = 0;
        outter:
        for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) {
            if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID()
                    && HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID()
            ) {
                List<AppliancesInfo> infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList();
                for (int j = 0, len2 = infos.size(); j < len2; j++) {
                    if (info.getBigType() == infos.get(j).getBigType()
                            && info.getLittleType() == infos.get(j).getLittleType()
                            && info.getChannelNum() == infos.get(j).getChannelNum()
                    ) {
                        //这里应该是要修复的,暂时未找到。
                        //2019-07 修改
                        int mCurState = HDLUtlis.getIntegerByObject(infos.get(j).getCurState());
                        switch (mCurState) {
                            case -1:
                                curState = 0;
                                break;
                            case -2:
                                curState = 1;
                                break;
                            case -3:
                                curState = 2;
                                break;
                            default:
                                curState = mCurState;
                                break;
 
                        }
 
                        break outter;
                    }
 
                }
            }
        }
        return curState;
    }
 
    /**
     * 获取空调状态
     *
     * @param info
     * @return
     */
    private static byte[] getACState(final AppliancesInfo info) {
        byte[] curState = new byte[0];
        outter:
        for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) {
            if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID()
                    && HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID()
            ) {
                List<AppliancesInfo> infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList();
                for (int j = 0, len2 = infos.size(); j < len2; j++) {
                    if (info.getBigType() == infos.get(j).getBigType()
                            && info.getLittleType() == infos.get(j).getLittleType()
                            && info.getChannelNum() == infos.get(j).getChannelNum()
                    ) {
                        switch (info.getDeviceType()) {
                            case HDLApConfig.TYPE_AC_HVAC:
                            case HDLApConfig.TYPE_AC_PANEL:
                            case HDLApConfig.TYPE_AC_TECHSYS:
                                curState = infos.get(j).getArrCurState();
                                break;
                            default:
                                break;
                        }
                        break outter;
                    }
 
                }
            }
        }
        return curState;
    }
 
    /**
     * 获取安防模块本地状态
     *
     * @param info
     * @return
     */
    private static byte[] getSecurityState(final AppliancesInfo info) {
        byte[] curState = new byte[0];
        outter:
        for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) {
            if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID()
                    && HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID()
            ) {
                List<AppliancesInfo> infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList();
                for (int j = 0, len2 = infos.size(); j < len2; j++) {
                    if (info.getBigType() == infos.get(j).getBigType()
                            && info.getLittleType() == infos.get(j).getLittleType()
                            && info.getChannelNum() == infos.get(j).getChannelNum()
                    ) {
                        curState = infos.get(j).getArrCurState();
                        break outter;
                    }
                }
 
                break outter;
            }
 
        }
        return curState;
    }
 
 
    /**
     * 获取新风
     *
     * @param info
     */
    public static void getFreshAirDeviceStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_FRESH_AIR:
            case HDLApConfig.TYPE_FRESH_AIR_JINMAO:
                //发送获取新风系统所有数据
                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是新风系统设备");
                break;
        }
    }
 
    /**
     * 控制新风系统
     *
     * @param info
     * @param type
     * @param state 2020-07-20
     */
    public static void freshAirCtrl(final AppliancesInfo info, int type, int state) {
//        HDLDeviceManager.isFreshAirCtrlSuccess = false;
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (freshAirCtrlFailTimer != null) {
            freshAirCtrlFailTimer.cancel();
            freshAirCtrlFailTimer = null;
        }
        if (info.getBigType() == Configuration.FRESH_AIR_BIG_TYPE) {
            byte[] freshAirbytes = FreshAirParser.getFreshAirAddByte(info, type, state);
            addSendData(info, freshAirbytes, Configuration.CONTROL);
            freshAirCtrlFailTimer = new Timer();
            freshAirCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        FreshAirBackInfo mFreshAirBackInfo = new FreshAirBackInfo();
                        mFreshAirBackInfo.setAppliancesInfo(info);
                        EventBus.getDefault().post(new FreshAirFeedBackEvent(mFreshAirBackInfo, false));
                    }
                }
            }, mRequestTimeout);
 
 
        } else {
            HDLLog.I("新风设备控制不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
 
    /**
     * 获取金茂新风状态
     *
     * @param info
     */
    public static void getFreshAirJinMaoDeviceStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_FRESH_AIR_JINMAO:
                //发送获取新风系统所有数据
                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是金茂新风系统设备");
                break;
        }
    }
 
    /**
     * 控制金茂新风
     *
     * @param info
     * @param type
     * @param state 2020-07-20
     */
    public static void freshAirJinMaoCtrl(final AppliancesInfo info, int type, int state) {
//        HDLDeviceManager.isFreshAirCtrlSuccess = false;
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (freshAirCtrlFailTimer != null) {
            freshAirCtrlFailTimer.cancel();
            freshAirCtrlFailTimer = null;
        }
        if (info.getDeviceType() == HDLApConfig.TYPE_FRESH_AIR_JINMAO) {
            byte[] sendBytes = FreshAirJinMaoParser.getFreshAirAddByte(info, type, state);
            addSendData(info, sendBytes, Configuration.CONTROL);
            freshAirCtrlFailTimer = new Timer();
            freshAirCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        FreshAirJinMaoBackInfo mFreshAirJinMaoBackInfo = new FreshAirJinMaoBackInfo();
                        mFreshAirJinMaoBackInfo.setAppliancesInfo(info);
                        EventBus.getDefault().post(new FreshAirJinMaoFeedBackEvent(mFreshAirJinMaoBackInfo, false));
                    }
                }
            }, mRequestTimeout);
 
 
        } else {
            HDLLog.I("不是金茂新风系统设备");
        }
    }
 
 
    /**
     * 获取地热状态
     *
     * @param info
     */
    public static void getGeothermalStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_GEOTHERMAL_JINMAO:
            case HDLApConfig.TYPE_GEOTHERMAL_MODULE:
                //发送获取地热系统所有数据
                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是地热设备");
                break;
        }
    }
 
    /**
     * 控制地热模块温度
     *
     * @param info
     * @param tempInt 2020-03-15
     */
    public static void geothermalCtrlTemp(final AppliancesInfo info, int tempInt) {
//        HDLDeviceManager.isGeothermalCtrlSuccess = false;
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (geothermalCtrlFailTimer != null) {
            geothermalCtrlFailTimer.cancel();
            geothermalCtrlFailTimer = null;
        }
        if (info.getBigType() == Configuration.GEOTHERMAL_BIG_TYPE) {
            byte[] sendbytes = GeothermalParser.getGeothermalAddByteTemp(info, tempInt);
            addSendData(info, sendbytes, Configuration.CONTROL);
 
            geothermalCtrlFailTimer = new Timer();
            geothermalCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        GeothermalBackInfo mGeothermalBackInfo = new GeothermalBackInfo();
                        mGeothermalBackInfo.setAppliancesInfo(info);
                        EventBus.getDefault().post(new GeothermalFeedBackEvent(mGeothermalBackInfo, EventCode.FAILURE_TIMEOUT));
                    }
                }
            }, mRequestTimeout);
 
 
        } else {
            HDLLog.I("地热模块控制不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
    /**
     * 控制地热模块
     *
     * @param info
     * @param type
     * @param state 2019-07-10
     */
    public static void geothermalCtrl(final AppliancesInfo info, int type, int state) {
//        HDLDeviceManager.isGeothermalCtrlSuccess = false;
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (geothermalCtrlFailTimer != null) {
            geothermalCtrlFailTimer.cancel();
            geothermalCtrlFailTimer = null;
        }
        if (info.getBigType() == Configuration.GEOTHERMAL_BIG_TYPE) {
            byte[] sendbytes = GeothermalParser.getGeothermalAddByte(info, type, state);
            addSendData(info, sendbytes, Configuration.CONTROL);
 
            geothermalCtrlFailTimer = new Timer();
            geothermalCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        GeothermalBackInfo mGeothermalBackInfo = new GeothermalBackInfo();
                        mGeothermalBackInfo.setAppliancesInfo(info);
                        EventBus.getDefault().post(new GeothermalFeedBackEvent(mGeothermalBackInfo, EventCode.FAILURE_TIMEOUT));
                    }
                }
            }, 5000);
 
 
        } else {
            HDLLog.I("地热模块控制不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
 
    /**
     * 获取门锁状态
     *
     * @param info
     */
    public static void getDoorMachineDeviceStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_DOOR_MACHINE:
                //发送获取门锁所有数据
                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
                break;
            default:
                HDLLog.I("不是门锁设备");
                break;
        }
    }
 
    /**
     * 门锁模块 远程开锁获取密钥
     * 2023-8-25
     *
     * @param info
     */
    public static void doorMachineGetSecret(final AppliancesInfo info) {
        if (info.getBigType() == Configuration.DOOR_MACHINE_BIG_TYPE) {
            byte[] sendbytes = new byte[]{(byte) info.getChannelNum()};
            cusSendCommand(Configuration.DOOR_MACHINE_MODULE_CTRL_FRIST_COMMAND, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendbytes);
        } else {
            HDLLog.I("不是门锁模块"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
    /**
     * 控制门锁远程开锁
     *
     * @param info
     * @param secretBytes 密钥
     * @param password    开锁密码 2023-08-22
     */
    public static void doorMachineCtrl(final AppliancesInfo info, byte[] secretBytes, String password, int doorStatus) {
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (doorMachineCtrlFailTimer != null) {
            doorMachineCtrlFailTimer.cancel();
            doorMachineCtrlFailTimer = null;
        }
        if (info.getBigType() == Configuration.DOOR_MACHINE_BIG_TYPE) {
            byte[] doorMachinebytes = DoorMachineParser.getDoorMachineAddByte(info, secretBytes, password, doorStatus);
            addSendData(info, doorMachinebytes, Configuration.CONTROL);
            doorMachineCtrlFailTimer = new Timer();
            doorMachineCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        DoorMachineBackInfo mDoorMachineBackInfo = new DoorMachineBackInfo();
                        mDoorMachineBackInfo.setAppliancesInfo(info);
                        EventBus.getDefault().post(new DoorMachineFeedBackEvent(mDoorMachineBackInfo, false));
                    }
                }
            }, mRequestTimeout);
 
 
        } else {
            HDLLog.I("门锁控制不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
 
    /**
     * 门锁模块 设置临时密码
     * 2023-8-25
     *
     * @param info
     * @param tempPassword 临时密码
     * @param startTime    开始时间戳
     * @param endTime      结束时间戳
     */
    public static void doorMachineSettingPwd(final AppliancesInfo info, String tempPassword, String startTime, String endTime) {
        if (info.getBigType() == Configuration.DOOR_MACHINE_BIG_TYPE) {
            byte[] sendbytes = DoorMachineParser.getDoorMachineSettingPwdByte(info, tempPassword, startTime, endTime);
            cusSendCommand(Configuration.DOOR_MACHINE_MODULE_SETTING_PASSWORD_COMMAND, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendbytes);
        } else {
            HDLLog.I("不是门锁模块"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
 
    /**
     * 背景音乐控制
     *
     * @param info
     * @param type
     */
    public static void audioCtrl(AppliancesInfo info, int type) {
        byte[] musicBytes;
        int command;
        switch (type) {
            case HDLAudio.SET_AUDIO_PLAYSTOP:
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x53, 0x54, 0x4F, 0x50, 0x0D};
                break;
            case HDLAudio.SET_AUDIO_PLAYPAUSE:
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                musicBytes = new byte[]{42, 83, 49, 80, 76, 65, 89, 80, 65, 85, 83, 69, 0x0D};
                break;
            case HDLAudio.SET_NEXT_SONG:
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4E, 0x45, 0x58, 0x54, 0x0D};
                break;
            case HDLAudio.SET_PRE_SONG:
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x52, 0x45, 0x56, 0x0D};
                break;
            case HDLAudio.GET_AUDIO_MODE:
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x4D, 0x4F, 0x44, 0x45, 0x3F, 0x0D};
                break;
            case HDLAudio.SET_AUDIO_MODE_UP:
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4D, 0x4F, 0x44, 0x45, 0x2B, 0x0D};
                break;
            case HDLAudio.SET_AUDIO_MODE_DOWN:
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4D, 0x4F, 0x44, 0x45, 0x2D, 0x0D};
                break;
            case HDLAudio.GET_AUDIO_CURRRENT_INFO:
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                //*Z1STAUS?归为键
                musicBytes = new byte[]{0x2A, 0x5A, 0x31, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x3F, 0x0D};
                break;
            case HDLAudio.SET_PRE_LIST:
                HDLAudio.isSetPreNextList = true;
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x52, 0x45, 0x56, 0x4C, 0x49, 0x53, 0x54, 0x0D};
                break;
            case HDLAudio.SET_NEXT_LIST:
                HDLAudio.isSetPreNextList = true;
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4E, 0x45, 0x58, 0x54, 0x4C, 0x49, 0x53, 0x54, 0x0D};
                break;
            case HDLAudio.TEXT:
                command = Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND;
                musicBytes = new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x4C, 0x49, 0x53, 0x54, 0x30, 0x30, 0x31, 0x30, 0x30, 0x32, 0x31, 0x0D};
                break;
            default:
                command = 0;
                musicBytes = null;
                break;
        }
        if (musicBytes != null) {
//            String sendData = "";
//            for(int i = 0,len = musicBytes.length;i<len;i++){
//                sendData += musicBytes[i]+",";
//            }
//            sendData = HDLStringUtils.asciiToString(sendData);
//            HDLLog.I("发出数据:"+sendData+"子网id:"+I.getDeviceSubnetID()+" 设备id:"+I.getDeviceDeviceID());
            cusSendCommand(command,
                    info.getDeviceSubnetID(), info.getDeviceDeviceID(), musicBytes);
        }
 
    }
 
    /**
     * 背景音乐控制
     *
     * @param info
     * @param type
     * @param value
     */
    public static void audioCtrl(AppliancesInfo info, int type, int value) {
        byte[] musicBytes;
        int command;
        switch (type) {
            case HDLAudio.GET_AUDIO_LIST:
                HDLAudio.numStr.clear();
                HDLAudio.songNameList.clear();
                HDLAudio.curListNum = value;
                command = Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND;
                //*Z011TYPE0011归位键
                musicBytes = new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x54, 0x59, 0x50, 0x45, 0x30, 0x30, 0x31, 0x31, 0x0D};
                break;
            case HDLAudio.SET_AUDIO_VOL:
                command = Configuration.AUDIO_CTRL_READ_COMMAND;
                musicBytes = HDLAudio.audioVolparse(value);
                break;
            default:
                command = 0;
                musicBytes = null;
                break;
        }
        if (musicBytes != null) {
//            String sendData = "";
//            for(int i = 0,len = musicBytes.length;i<len;i++){
//                sendData += musicBytes[i]+",";
//            }
//            sendData = HDLStringUtils.asciiToString(sendData);
//            HDLLog.I("发出数据:"+sendData+"子网id:"+I.getDeviceSubnetID()+" 设备id:"+I.getDeviceDeviceID());
            cusSendCommand(command,
                    info.getDeviceSubnetID(), info.getDeviceDeviceID(), musicBytes);
        }
    }
 
    /**
     * @param info
     * @param type
     * @param listId 列表号
     * @param songId 歌曲号
     */
    public static void audioCtrl(AppliancesInfo info, int type, int listId, int songId) {
        byte[] musicBytes;
        int command;
        switch (type) {
 
            case HDLAudio.SET_CHOOSE_PLAY_SONG:
                command = Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND;
                musicBytes = HDLAudio.audioChooseSongParse(listId, songId);
                break;
            default:
                command = 0;
                musicBytes = null;
                break;
        }
 
        if (musicBytes != null) {
//            String sendData = "";
//            for(int i = 0,len = musicBytes.length;i<len;i++){
//                sendData += musicBytes[i]+",";
//            }
//            sendData = HDLStringUtils.asciiToString(sendData);
//            HDLLog.I("发出数据:"+sendData+"子网id:"+I.getDeviceSubnetID()+" 设备id:"+I.getDeviceDeviceID());
            cusSendCommand(command,
                    info.getDeviceSubnetID(), info.getDeviceDeviceID(), musicBytes);
        }
 
    }
 
 
//    /**
//     * 提供第三方调用设置本地子网号、设备号
//     * @param context
//     * @param subId
//     * @param deviceId
//     */
//    public static void setLocalId(Context context, int subId, int deviceId) {
//        Crc.localDeviceID = deviceId;
//        Crc.localSubnetID = subId;
//        SPUtils.setParam(context, SPUtils.KEY_SUB_ID, subId);
//        SPUtils.setParam(context, SPUtils.KEY_DEVICE_ID, deviceId);
//    }
 
    /**
     * 判断ID是否在要求范围内
     */
    public static Boolean getIfValueInScope(int mValue) {
        return mValue >= 0 && mValue < 255;
    }
 
    /**
     * 提供第三方调用设置本地子网号、设备号 范围0 - 254
     *
     * @param context
     * @param mSubnetID
     * @param mDeviceID
     */
    public static boolean saveSubnetAndDeviceID(Context context, int mSubnetID, int mDeviceID) {
        try {
            if (getIfValueInScope(mSubnetID) && getIfValueInScope(mDeviceID)) {
                Crc.localSubnetID = mSubnetID;
                Crc.localDeviceID = mDeviceID;
                SPUtils.setParam(context, SPUtils.KEY_SUB_ID, mSubnetID);
                SPUtils.setParam(context, SPUtils.KEY_DEVICE_ID, mDeviceID);
                return true;
            } else {
                throw new SecurityException("====saveSubnetAndDeviceID ID范围0-254=======");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
 
    /**
     * 单设备发送命令
     * 目前控制发送次数为3次
     * 发一条,补发3条,间隔500ms
     *
     * @param info
     * @param addBytes
     * @param type
     */
    private static void addSendData(final AppliancesInfo info, byte[] addBytes, final int type) {
 
        final Crc sendDatas = new Crc(info.getStateCommand(), info.getDeviceSubnetID(), info.getDeviceDeviceID(), addBytes);
        sendDatas.count = 0;
 
        final Timer sendCycleTimer = new Timer();
        sendCycleTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                //2019-07 控制发送次数
                if (sendDatas.count >= 4) {
                    sendCycleTimer.cancel();
                } else {
                    sendDatas.count++;
                    if (type == Configuration.STATE) {
                        sendDatas.command = info.getStateCommand();
                        HDLLog.I("---getDevice: " + info.getDeviceKey() + " ---getStateCommand: " + Integer.toHexString(info.getStateCommand()));//2019-8-2
                        sendDatas.isCtrlSuccess = HDLDeviceManager.isGetDeviceStateSuccess;
                    } else if (type == Configuration.CONTROL) {
                        sendDatas.command = info.getCtrlCommand();
                        HDLLog.I("---getDevice: " + info.getDeviceKey() + " ---getCtrlCommand: " + Integer.toHexString(info.getCtrlCommand()));//2019-8-2
                        sendDatas.isCtrlSuccess = HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info);
                    }
                    if (!sendDatas.isCtrlSuccess) {
                        if (type == Configuration.STATE) {
                            HDLLog.I("读取发送第" + sendDatas.count + "次");
                        } else if (type == Configuration.CONTROL) {
                            HDLLog.I("控制发送第" + sendDatas.count + "次");
                        }
                        cusSendCommand(sendDatas.command, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendDatas.addBytes);
                    } else {
                        sendCycleTimer.cancel();
                    }
                }
 
            }
        }, 1, 500);
 
 
    }
 
 
    /**
     * 发送广播或点对点命令
     *
     * @param command  操作码
     * @param subnetID 子网号
     * @param deviceID 设备号
     * @param addBytes 附加数据
     */
    public static void cusSendCommand(int command, int subnetID, int deviceID, byte[] addBytes) {
        Crc sendDatas = new Crc(command, subnetID, deviceID, addBytes);
        HDLSerialPortCore.sendData(sendDatas);
 
    }
 
    /**
     * 发送组播命令
     * 这个方法目前仅用在拿到Rcu ip地址
     *
     * @param command  操作码
     * @param subnetID 子网号
     * @param deviceID 设备号
     * @param addBytes 附加数据
     */
    public static void cusSendMulticastCommand(int command, int subnetID, int deviceID, byte[] addBytes) {
        Crc sendDatas = new Crc(command, subnetID, deviceID, addBytes);
        HDLSerialPortCore.sendMulticastData(sendDatas);
    }
 
//
//    /**
//     * 设置是否开启透传
//     * 透传数据,不走bus协议,直接转发,不做数据格式处理
//     * @param bOpen
//     */
//    public static void setHDLPassThroughOpen(boolean bOpen){
//        if(HDLSerialPortCore.bPassThrough != bOpen){
//            HDLSerialPortCore.bPassThrough = bOpen;
//        }
//    }
//
//
//    //**************************MCU串口协议指令**************************
//    /**
//     * 发送数据
//     */
//    private static void HDLSendMCUData(final MCUCrc mcuDataList, boolean bPassThrough){
//        if(HDLSerialPortCore.bPassThrough != bPassThrough){
//            HDLSerialPortCore.bPassThrough = bPassThrough;
//        }
//        if(bPassThrough){
//            HDLSerialPortCore.sendMCUData(mcuDataList);
//        }else {
//            HDLDeviceManager.isMCUCtrlSuccess = false;
//            if (mcuCtrlFailTimer != null) {
//                mcuCtrlFailTimer.cancel();
//                mcuCtrlFailTimer = null;
//            }
//            HDLSerialPortCore.sendMCUData(mcuDataList);
//
//            mcuCtrlFailTimer = new Timer();
//            mcuCtrlFailTimer.schedule(new TimerTask() {
//                @Override
//                public void run() {
//                    if (!HDLDeviceManager.isMCUCtrlSuccess) {
////                    MCUDataBean mMCUDataBean = new MCUDataBean();
////                    mMCUDataBean.command = mcuDataList.mcuCommand;
//                        EventBus.getDefault().post(new MCUFeedBackEvent(new MCUDataBean(), EventCode.FAILURE_TIMEOUT, "MCU请求超时,请稍后再试"));
//                    }
//                }
//            }, mRequestTimeout);
//        }
//
//    }
//
//    /**
//     * 2019-8-9
//     * 透传数据
//     * 透传数据,不走bus协议,直接转发,不做数据格式处理
//     */
//    public static void mcuSendTransparentData(byte[] sendData) {
//        MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_COMMAND_SEND, sendData);
//        HDLSendMCUData(sendDatas, true);
//    }
//
//
//    /**
//     * 检测丢包状态
//     */
//    public static void mcuGetDetectPacketLossStatus() {
//        MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_DETECT_PACKET_LOSS_STATUS, new byte[0]);
//        HDLSendMCUData(sendDatas, false);
//    }
//
//    /**
//     * 读配置信息
//     */
//    public static void mcuReadConfiguration() {
//        MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_READ_CONFIGURATION, new byte[0]);
//        HDLSendMCUData(sendDatas, false);
//    }
//
//    /**
//     * 写配置信息
//     */
//    public static void mcuWriteConfiguration(byte[] sendData) {
//        MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_WRITE_CONFIGURATION, sendData);
//        HDLSendMCUData(sendDatas, false);
//    }
//
//    /**
//     * 请求升级
//     * sendData 文件大小[4byte]
//     */
//    public static void mcuRequestUpgrade(byte[] sendData) {
//        MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_REQUEST_UPGRADE, sendData);
//        HDLSendMCUData(sendDatas, false);
//    }
//
//    /**
//     * 请求升级
//     * sendData 升级文件
//     */
//    public static void mcuRequestUpgradeWithFile(byte[] upgradeFileDatas) {
//        try {
//            HDLSerialPortCore.upgradeFileDatas = upgradeFileDatas;
//            mcuRequestUpgrade(HDLUtlis.intToByteArray(upgradeFileDatas.length));
//        } catch (Exception e) {
//            e.printStackTrace();
//            HDLSerialPortCore.upgradeFileDatas = null;//释放
//            HDLLog.E("mcuRequestUpgradeWithFile 出错");
//        }
//    }
//
//
//    /**
//     * 发送升级数据
//     * sendData 文件地址[4byte]    数据长度[2byte]
//     * 固定:1024,否则不处理
//     */
//    public static void mcuSendUpgradeData(byte[] sendData) {
//        MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_SEND_UPGRADE_DATA, sendData);
////        HDLSendMCUData(sendDatas, false);
//        HDLSerialPortCore.sendMCUData(sendDatas);
//    }
//
//    /**
//     * 重启MCU
//     * 时间(1byte):范围1-10s
//     * 当为0xF8的时候,代表重启成功
//     */
//    public static void mcuSendRestart() {
//        MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_RESTART, new byte[0]);
//        HDLSendMCUData(sendDatas, false);
//    }
 
}