JLChen
2020-02-28 52f8575a2fa0590c28b5d784399c51a8af2f790a
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
package com.hdl.sdk.hdl_core.HDLDeviceManger.Core;
 
import android.content.Context;
 
import com.hdl.sdk.hdl_core.Config.Configuration;
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.DevicesData;
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.RemarkTimes;
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.SearchCountBean;
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.DevicesInfoEvent;
import com.hdl.sdk.hdl_core.Util.LogUtil.HDLLog;
import com.hdl.sdk.hdl_core.Util.NetUtil.NetWorkUtil;
import com.hdl.sdk.hdl_core.Util.SPUtil.SPUtils;
 
import org.greenrobot.eventbus.EventBus;
 
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
 
 
public class HandleSearch {
    public static boolean isSearching = false;
    public static int curSearchMode = 0;
    public static String rcuIp = "";//主动传入的rcu ip地址
    //    private static Timer getRcuIpTimer = null;//获取Rcuip Timer
//    private static Timer getRcuIpFailorSuccessTimer = null;//获取Rcuip Timer
    public static boolean isGetRcuIp = false;
    private static boolean isRefreshAllDevicesState = false;
 
    public static Timer searchTimer = null;//发送第一次搜索Timer
    public static Timer searchTwiceTimer = null;//发送第二次搜索Timer
    public static Timer searchFailTimer = null;//发送搜索失败Timer
    private static Timer remarkTimer = null;//搜索备注Timer
    private static Timer refreshTimer = null;
 
    private static int curDevSize;//记录设备总数。作用:比较搜索出来的总设备数
    public static byte random1 = 0;//随机数1
    public static byte random2 = 0;//随机数2
 
    public static final int GET_RCU_DEVICES = 0;//获取Rcu模块设备
    public static final int GET_BUS_DEVICES = 1;//获取家居模块 设备
 
    private static final int SEARCH_POINT_TO_POINT = 100;//点对点
    private static final int SEARCH_BROACAST = 101;//广播
    private static final int SEARCH_MULTICAST = 102;//组播
 
    /**
     * 酒店搜索
     * <p>
     * <p>
     * 这方法暂时不提供,获取备注当中也没有处理此类型。
     * <p>
     * 获取Rcu ip地址
     */
//    private static void getRcuIp() {
//        isGetRcuIp = true;
//        HDLUdpCore.closeMulticast6000();
//        HDLUdpCore.initMulticastSocket6008();
//        if (getRcuIpFailorSuccessTimer != null) {
//            getRcuIpFailorSuccessTimer.cancel();
//            getRcuIpFailorSuccessTimer = null;
//        }
//        if (getRcuIpTimer != null) {
//            getRcuIpTimer.cancel();
//            getRcuIpTimer = null;
//        }
//
//        getRcuIpTimer = new Timer();
//        getRcuIpFailorSuccessTimer = new Timer();
//        HDLDeviceManager.isGetRcuIpSuccess = false;
//        HDLDeviceManager.rcuIpList.clear();
//
//        getRcuIpTimer.schedule(new TimerTask() {
//            @Override
//            public void run() {
////                每400毫秒发送一次
//                if (!HDLDeviceManager.isGetRcuIpSuccess) {
//                    baseSearch(SEARCH_MULTICAST, Configuration.RCU_SEND_PORT);
//                }
//
//
//            }
//        }, 1, 200);
//
//
//        getRcuIpFailorSuccessTimer.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                isGetRcuIp = false;
//                if (getRcuIpTimer != null) {
//                    getRcuIpTimer.cancel();
//                    getRcuIpTimer = null;
//                }
////                若没有回复则失败,开始家居搜索。若有回复则保存Rcu ip地址,开始酒店协议搜索第二步
//                if (HDLDeviceManager.isGetRcuIpSuccess) {
//                    HDLDeviceManager.isGetRcuIpSuccess = false;
//                    //返回ip地址列表,如果只有一个不返回,直接搜索。
//                    switch (HDLDeviceManager.rcuIpList.size()) {
//                        case 0:
//                            searchDevices(GET_BUS_DEVICES, SEARCH_BROACAST, Configuration.PORT);//家居搜索
//                            break;
//                        case 1:
//                            rcuIp = HDLDeviceManager.rcuIpList.get(0);
//                            HDLLog.info("搜索到的rcu ip地址:" + rcuIp);
//                            searchDevices(GET_RCU_DEVICES, SEARCH_POINT_TO_POINT, Configuration.RCU_SEND_PORT);//RCU模块搜索
//                            break;
//                        default:
//                            //返回用户选择哪个rcuIp
//                            EventBus.getDefault().post(new RcuIpListEvent(HDLDeviceManager.rcuIpList));
//                            break;
//                    }
//
//                } else {
//                    HDLLog.info("开始家居协议搜索");
//                    searchDevices(GET_BUS_DEVICES, SEARCH_BROACAST, Configuration.PORT);//家居搜索
//                }
//            }
//        }, 1000);
//    }
 
    /**
     * 酒店搜索
     * 获取Rcu模块设备
     */
    public static void getRcuDevices(Context context, String newRcuIp) {
        curSearchMode = GET_RCU_DEVICES;
        rcuIp = newRcuIp;
        SPUtils.setParam(context, SPUtils.KEY_RCU_IP_, newRcuIp);
        searchDevices(GET_RCU_DEVICES, SEARCH_POINT_TO_POINT, Configuration.RCU_SEND_PORT);
    }
 
    public static void getHomeDevices(Context context) {
        SPUtils.setParam(context, SPUtils.KEY_RCU_IP_, "");
        curSearchMode = GET_BUS_DEVICES;
        rcuIp = "";
        searchDevices(GET_BUS_DEVICES, SEARCH_BROACAST, Configuration.PORT);//家居搜索
    }
 
    /**
     * 初始化搜索
     *
     * @param searchMode     搜索模式
     * @param baseSearchType 基础搜索类型
     * @param port
     */
    private static void searchDevices(final int searchMode, final int baseSearchType, final int port) {
        isSearching = true;
        isRefreshAllDevicesState = false;
        String newIpAddress = "";
        switch (searchMode) {
            case GET_BUS_DEVICES:
                HDLUdpCore.closeSocket6008();
                HDLUdpCore.init6000();
                newIpAddress = NetWorkUtil.getLocalBroadCast();
                break;
            case GET_RCU_DEVICES:
                HDLUdpCore.closeSocket6000();
                HDLUdpCore.init6008();
                newIpAddress = rcuIp;
                break;
            default:
                break;
        }
 
        final String secondSearchAddress = newIpAddress;//仅作为内部类需要定义为final
 
        if (searchTimer != null) {
            searchTimer.cancel();
            searchTimer.purge();
            searchTimer = null;
        }
 
        if (searchFailTimer != null) {
            searchFailTimer.cancel();
            searchFailTimer.purge();
            searchFailTimer = null;
        }
        if (remarkTimer != null) {
            remarkTimer.cancel();
            remarkTimer.purge();
            remarkTimer = null;
        }
 
        searchTimer = new Timer();
        searchFailTimer = new Timer();
 
        int max = 254;
        int min = 1;
        random1 = (byte) (new Random().nextInt(max + 1) % (max - min + 1) + min);
        random2 = (byte) (new Random().nextInt(max + 1) % (max - min + 1) + min);
 
        baseSearch(baseSearchType, port);
 
//        初始化搜索超时,5000毫秒后,无搜索设备数据返回则搜索超时
        searchFailTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (HDLDeviceManager.devicesDataList.size() == 0) {
//                    返回搜索超时
                    if (searchTimer != null) {
                        searchTimer.cancel();
                        searchTimer.purge();
                        searchTimer = null;
                    }
 
                    switch (searchMode) {
                        case GET_RCU_DEVICES:
                            HDLLog.info("Rcu设备搜索超时");
//                            searchDevices(GET_BUS_DEVICES, SEARCH_BROACAST, Configuration.PORT);//家居搜索
                            EventBus.getDefault().post(new DevicesInfoEvent(false));//不进行家居搜索,直接停止
                            break;
                        case GET_BUS_DEVICES:
                            //家居协议搜索超时
                            HDLLog.info("家居设备搜索超时");
                            EventBus.getDefault().post(new DevicesInfoEvent(false));
                            break;
                    }
                }
            }
        }, 5000);
 
        if (searchTimer == null) {
            return;
        }
 
        //TODO 可能会为空
        searchTimer.schedule(new TimerTask() {
            @Override
            public void run() {
//                每隔500毫秒判断当前的设备数与搜索出来的设备数是否一致
                if (curDevSize != HDLDeviceManager.realDevicesDataList.size() || HDLDeviceManager.realDevicesDataList.size() == 0) {
                    //有新设备,继续等待500毫秒
                    if (searchTwiceTimer != null) {
                        searchTwiceTimer.cancel();
                        searchTwiceTimer.purge();
                        searchTwiceTimer = null;
                        HDLLog.info("有新设备阻断发送搜索命令");
                    }
                    if (HDLDeviceManager.realDevicesDataList.size() == 0) {
                        baseSearch(baseSearchType, port);
                    } else {
                        curDevSize = HDLDeviceManager.realDevicesDataList.size();
 
                        HDLLog.info("有新设备,继续等待500毫秒");
 
                    }
 
                } else {
                    if (searchTwiceTimer == null) {
                        searchTwiceTimer = new Timer();
                        final SearchCountBean bean = new SearchCountBean();
                        bean.setCount(0);
                        searchTwiceTimer.schedule(new TimerTask() {
                            @Override
                            public void run() {
                                if (bean.getCount() < 3) {
                                    HDLLog.info("没有收到新设备,发送第 " + (bean.getCount() + 1) + " 次搜索命令");
                                    secondTimeSearch(random1, random2, HDLDeviceManager.realDevicesDataList, secondSearchAddress, port);
                                } else {
                                    if (searchTimer != null) {
                                        searchTimer.cancel();
                                        searchTimer.purge();
                                        searchTimer = null;
                                    }
                                    if (searchTwiceTimer != null) {
                                        searchTwiceTimer.cancel();
                                        searchTwiceTimer.purge();
                                        searchTwiceTimer = null;
                                    }
 
                                    isSearching = false;
                                    HDLLog.info("开始获取每个模块的回路状态与备注");
                                    getDevRemarks();//开始获取第一备注,逐一获取。
                                }
                                bean.setCount(bean.getCount() + 1);
                            }
                        }, 1, 800);
                    }
 
 
                }
            }
        }, 500, 500);
    }
 
    /**
     * 发送第一次搜索
     *
     * @param type 搜索类型
     * @param port 端口号
     */
    private static void baseSearch(int type, int port) {
//        设备列表、设备备注列表初始化清空
        if (remarkTimer != null) {
            remarkTimer.cancel();
            remarkTimer.purge();
            remarkTimer = null;
        }
        isRefreshAllDevicesState = false;
        HDLDeviceManager.devicesDataList.clear();
        HDLDeviceManager.realDevicesDataList.clear();
        HDLDeviceManager.listRemarks.clear();
        curDevSize = 0;
 
//        发送第一次搜索命令
        switch (type) {
            case SEARCH_POINT_TO_POINT:
                HDLLog.info("发送第一次RCU搜索");
                HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_COMMAND,
                        255, 255, new byte[]{random1, random2}, port, rcuIp);
                break;
            case SEARCH_BROACAST:
                HDLLog.info("发送第一次家居搜索");
                HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_COMMAND,
                        255, 255, new byte[]{random1, random2},
                        port, NetWorkUtil.getLocalBroadCast());
                break;
            case SEARCH_MULTICAST:
                HDLCommand.cusSendMulticastCommand(Configuration.DEVICES_SEARCH_COMMAND,
                        255, 255
                        , new byte[]{random1, random2}, port);
                break;
            default:
                break;
        }
 
 
    }
 
    /**
     * 发送第二次搜索
     *
     * @param arg1            随机数1
     * @param arg2            随机数2
     * @param devicesDataList 所有设备信息集
     * @param port            端口号
     */
    public static void secondTimeSearch(byte arg1, byte arg2, List<DevicesData> devicesDataList, String ipAddress, int port) {
        if (devicesDataList == null || devicesDataList.size() == 0) {
            return;
        }
        int devicesCount = 32;
        int count = devicesDataList.size() / devicesCount;
        int remainder = devicesDataList.size() % devicesCount;
        if (remainder != 0) {
            count++;
        }
        outter:
        for (int j = 0; j < count; j++) {
            byte[] bytes;
            int remainder2;
            if (j != count - 1
                    || (count == 1 && remainder == 0)
            ) {
                remainder2 = devicesCount;
            } else {
                remainder2 = remainder;
            }
 
            bytes = new byte[2 + remainder2 * 2];
            bytes[0] = arg1;
            bytes[1] = arg2;
            for (int k = 0; k < remainder2; k++) {
                if ((devicesCount * j + k >= devicesDataList.size()) || ((2 + 2 * k + 1) >= bytes.length)) {
                    break outter;
                }
                bytes[2 + 2 * k] = (byte) devicesDataList.get(devicesCount * j + k).getSourceSubnetID();
                bytes[2 + 2 * k + 1] = (byte) devicesDataList.get(devicesCount * j + k).getSourceDeviceID();
            }
 
            String sendData = "";
            for (int i = 0; i < bytes.length; i++) {
                if (i % 2 != 0) {
                    if ((i / 2) == 0) {
                        sendData += (bytes[i] & 0xff) + "(随机数)";
                    } else {
                        sendData += (bytes[i] & 0xff) + "(第" + (i / 2) + "个模块),";
                    }
 
                } else {
                    sendData += (bytes[i] & 0xff) + ",";
                }
 
 
            }
            HDLLog.info("第二次发送的搜索数据:" + sendData);
            HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_COMMAND, 255, 255, bytes, port, ipAddress);
        }
    }
 
    /**
     * 返回设备列表
     * 2019-10-14
     */
    public static void OnDeviceListGetSuccessCallBack() {
//        byte[] debugBytes = new byte[6 + HDLDeviceManager.devicesDataList.size() * 2];
//        debugBytes[0] = 1;
//        debugBytes[1] = 1;
//        debugBytes[2] = 1;
//        debugBytes[3] = 1;
//        debugBytes[4] = 1;
//        debugBytes[5] = 1;
//
//        for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
//
//            debugBytes[6 + i + i] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID();
//            debugBytes[6 + i + i + 1] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID();
//            String device = "第 " + (i + 1) + " 个模块:模块备注名称:" + HDLDeviceManager.devicesDataList.get(i).getRemark()
//                    + ",子网号:" + HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID()
//                    + ",设备号:" + HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID()
//                    + ",回路数:" + HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size() + "\n";
//            HDLLog.info(device);
//        }
 
        EventBus.getDefault().post(new DevicesInfoEvent(HDLDeviceManager.devicesDataList, true));
        /**搜索设备成功,执行一次保存到本地*/
        HDLDeviceManager.saveDevicesDataList();
    }
 
 
//    /**
//     * 返回设备列表
//     */
//    public static void deviceListCallBack() {
//        byte[] debugBytes = new byte[6 + HDLDeviceManager.devicesDataList.size() * 2];
//        debugBytes[0] = 1;
//        debugBytes[1] = 1;
//        debugBytes[2] = 1;
//        debugBytes[3] = 1;
//        debugBytes[4] = 1;
//        debugBytes[5] = 1;
//
//        for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
//
//            debugBytes[6 + i + i] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID();
//            debugBytes[6 + i + i + 1] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID();
//            String device = "第 " + (i + 1) + " 个模块:模块备注名称:" + HDLDeviceManager.devicesDataList.get(i).getRemark()
//                    + ",子网号:" + HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID()
//                    + ",设备号:" + HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID()
//                    + ",回路数:" + HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size() + "\n";
//            HDLLog.info(device);
//        }
//
////        HDLUdpCore.sendTestCMD(debugBytes, HDLTest.SEND_TEST_PORT);
//        EventBus.getDefault().post(new DevicesInfoEvent(HDLDeviceManager.devicesDataList, true));
//
//
//    }
 
    /**
     * 刷新所有设备状态和备注
     * 2019-10-15
     */
    public static void refreshAllDevicesStateAndRemarks() {
 
        if (isSearching) {
            isRefreshAllDevicesState = false;
            return;
        }
        isRefreshAllDevicesState = true;
        for (int i = 0; i < HDLDeviceManager.listRemarks.size(); i++) {
            HDLDeviceManager.listRemarks.get(i).setCallBack(false);
        }
        getDevRemarks();
    }
 
    /**
     * 1S
     * @param delayTime 单位秒
     */
    public static void refreshAllDevicesState(int delayTime) {
        if (refreshTimer != null) {
            refreshTimer.cancel();
            refreshTimer.purge();
            refreshTimer = null;
        }
        if (isSearching) {
            isRefreshAllDevicesState = false;
            return;
        }
 
        refreshTimer = new Timer();
        refreshTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                isRefreshAllDevicesState = true;
                for (int i = 0; i < HDLDeviceManager.listRemarks.size(); i++) {
                    HDLDeviceManager.listRemarks.get(i).setCallBack(false);
                }
                getDevRemarks();
            }
        }, 1000 * delayTime);
    }
 
 
    /**
     * 获取备注
     *
     * @param
     */
 
 
    public static void getDevRemarks() {
        if (remarkTimer != null) {
            remarkTimer.cancel();
//            remarkTimer.purge();
            remarkTimer = null;
        }
        if ((HDLDeviceManager.listRemarks != null && HDLDeviceManager.listRemarks.size() == 0) || isSearching) {
            isRefreshAllDevicesState = false;
            if(HDLDeviceManager.devicesDataList != null && HDLDeviceManager.devicesDataList.size() > 0){
                HandleSearch.OnDeviceListGetSuccessCallBack();
            }
            return;
        }
 
 
        int pos = -1;
        for (int i = 0; i < HDLDeviceManager.listRemarks.size(); i++) {
            if (!HDLDeviceManager.listRemarks.get(i).isCallBack()) {
                pos = i;
                break;
            }
        }
 
        //判断是否获取设备备注完全,若完全则返回所有设备列表。
        if (HDLDeviceManager.listRemarks != null && HDLDeviceManager.listRemarks.size() != 0 && pos == -1) {
            if (!isRefreshAllDevicesState) {
                HandleSearch.OnDeviceListGetSuccessCallBack();
            } else {
                //刷新完毕
                // TODO: 刷新完毕可能要做某些事情
                HDLLog.info("刷新设备状态完毕");
                isRefreshAllDevicesState = false;
                HandleSearch.OnDeviceListGetSuccessCallBack();
//                /**刷新设备状态完毕,执行一次保存到本地*/
//                HDLDeviceManager.saveDevicesDataList();
            }
 
            return;
        }
        remarkTimer = new Timer();
        final int newPos = pos;
        final RemarkTimes remarkTimes = new RemarkTimes();
        remarkTimes.setCount(0);
 
        if (remarkTimer == null) {
            return;
        }
        remarkTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (remarkTimes.getCount() < 3) {
                    remarkTimes.setCount(remarkTimes.getCount() + 1);
                    if (newPos < HDLDeviceManager.listRemarks.size()) {
                        int port = 0;
                        String ipAddress = "";
                        switch (curSearchMode) {
                            case HandleSearch.GET_RCU_DEVICES:
                                ipAddress = rcuIp;
                                port = Configuration.RCU_SEND_PORT;
                                break;
                            case HandleSearch.GET_BUS_DEVICES:
                                ipAddress = HDLCommand.getLocalBroadCastIp();//2019-10-16
//                                ipAddress = HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getIpAddress();
                                port = Configuration.PORT;
                                break;
                        }
                        HDLLog.info("----->发送获取备注命令。共" + HDLDeviceManager.listRemarks.size() + "个模块。第"
                                + newPos + "个模块。第 " + (HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getChannelNum())
                                + " 回路,子网号:" + HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getDeviceSubnetID()
                                + ",设备号:" + HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getDeviceDeviceID()
                                + " 第 " + remarkTimes.getCount() + " 次" + " ip = " + ipAddress);
                        HDLCommand.cusSendCommand(Configuration.DEVICES_READ_COMMAND,
                                HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getDeviceSubnetID()
                                , HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getDeviceDeviceID(),
                                new byte[]{
                                        (byte) HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getBigType(),
                                        (byte) HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getLittleType(),
                                        (byte) HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getChannelNum()},
                                port, ipAddress);
                    }
                } else {
 
                    if (HDLDeviceManager.listRemarks != null
                            && HDLDeviceManager.listRemarks.size() != 0
                            && newPos < HDLDeviceManager.listRemarks.size()) {
                        HDLDeviceManager.listRemarks.get(newPos).setCallBack(true);
                    }
                    getDevRemarks();
                }
            }
        }, 1, 1200);
 
    }
}