panlili2024
2024-09-19 071a8328823a2861f93ce556a4da3e4119cab1a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
//package com.hdl.sdk.ttl.HDLDeviceManger.Core;
//
//
//import android.serialport.api.SerialPort;
//
//import com.hdl.sdk.ttl.Config.Configuration;
//import com.hdl.sdk.ttl.Config.MCUConstants;
//import com.hdl.sdk.ttl.HDLDeviceManger.Bean.MCUDataBean;
//import com.hdl.sdk.ttl.HDLDeviceManger.Bean.UdpDataBean;
//import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.EventCode;
//import com.hdl.sdk.ttl.HDLDeviceManger.HDLListener.IMcuOtaListener;
//import com.hdl.sdk.ttl.Utils.HDLUtlis.HDLStringUtils;
//import com.hdl.sdk.ttl.Utils.HDLUtlis.HDLUtlis;
//import com.hdl.sdk.ttl.Utils.LogUtils.HDLLog;
//
//import java.io.File;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.security.InvalidParameterException;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by JLChen on 2019/6/26
// * 串口管理类
// */
//public class HDLSerialPortCore {
//    //串口设备路径名
//    private static String mPathname = "/dev/ttyS1";
//    //波特率
//    private static int mBaudrate = 115200;
//
//    //    public static SerialPortFinder mSerialPortFinder = new SerialPortFinder();
//    private static SerialPort mSerialPort = null;
//    private static InputStream mInputStream = null;
//    private static OutputStream mOutputStream = null;
//    //    private static HDLReadDatasThread mHDLReadDatasThread = new HDLReadDatasThread();
//    private static HDLReadMCUDatasThread mHDLReadMCUDatasThread = new HDLReadMCUDatasThread();
//    private static HDLSendDatasThread mHDLSendDatasThread = new HDLSendDatasThread();
//    public static List<byte[]> mSendDatasList = new ArrayList<byte[]>();//发送数据队列
//    private static List<Byte> mReceiveDatasList = new ArrayList<Byte>();//接收数据队列
////    private static List<Byte> mReceive485DatasList = new ArrayList<Byte>();//485接收数据队列
//
//    public static Boolean bPassThrough = false; //判断是否透传
//    public static IMcuOtaListener mIMcuOtaListener;
//    public static byte[] upgradeFileDatas;      //升级文件数据
//
//    /*** 串口是否打开成功*/
//    private static boolean bOpenSuccess = false;
//
//    public static SerialPort getSerialPort() throws SecurityException, IOException, InvalidParameterException {
//        if (mSerialPort == null) {
//            mSerialPort = new SerialPort(new File(mPathname), mBaudrate, 0);
//            mInputStream = mSerialPort.getInputStream();//调用对象SerialPort方法,获取串口中"读和写"的数据流
//            mOutputStream = mSerialPort.getOutputStream();
//            bOpenSuccess = true;
//        }
//        return mSerialPort;
//    }
//
//    /**
//     * 初始化串口
//     */
//    public static void initHDLSerialPort(String mmPathname, int mmBaudrate) {
//        openSerialPort(mmPathname, mmBaudrate);
//    }
//
//    /**
//     * 判断串口是否打开
//     */
//    public static Boolean getIsSerialPortOpen() {
//        return bOpenSuccess;
//    }
//
//    /**
//     * 打开串口,接收数据
//     * 通过串口,接收单片机发送来的数据
//     */
//    public static Boolean openSerialPort(String mmPathname, int mmBaudrate) {
//        if (mSerialPort != null) {
//            HDLLog.I("HDLSDK 串口 已启动");
//        } else {
//            HDLLog.I("HDLSDK 串口 init");
//            try {
//                mPathname = mmPathname;
//                mBaudrate = mmBaudrate;
//                mSerialPort = new SerialPort(new File(mPathname), mBaudrate, 0);
//                HDLLog.I("HDLSDK 串口启动成功");
//                //调用对象SerialPort方法,获取串口中"读和写"的数据流
//                mInputStream = mSerialPort.getInputStream();
//                mOutputStream = mSerialPort.getOutputStream();
//                bOpenSuccess = true;
//                startHDLThread();
//            } catch (IOException e) {
//                e.printStackTrace();
//                bOpenSuccess = false;
//                HDLLog.I("HDLSDK 串口启动失败 IOException");
//            } catch (InvalidParameterException e) {
//                e.printStackTrace();
//                bOpenSuccess = false;
//                HDLLog.I("HDLSDK 串口启动失败 InvalidParameterException");
//            } catch (SecurityException e) {
//                e.printStackTrace();
//                bOpenSuccess = false;
//                HDLLog.I("HDLSDK 串口启动失败 SecurityException");
//            }
//        }
//        return bOpenSuccess;
//    }
//
//    /**
//     * 关闭串口
//     * 关闭串口中的输入输出流
//     */
//    public static void closeSerialPort() {
//        HDLLog.I("关闭串口");
//        try {
//            mSendDatasList.clear();//清空发送队列
//            mReceiveDatasList.clear();//清空接收队列
//            bOpenSuccess = false;
////            HDLCommand.cancelSearching();
//            if (mHDLReadMCUDatasThread != null) mHDLReadMCUDatasThread.interrupt();
//            if (mHDLSendDatasThread != null) mHDLSendDatasThread.interrupt();
//
//            if (mInputStream != null) {
//                mInputStream.close();
//            }
//            if (mOutputStream != null) {
//                mOutputStream.close();
//            }
//            if (mSerialPort != null) {
//                mSerialPort.close();
//                mSerialPort = null;
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//    }
//
//    /**
//     * 启动串口 发送和接收线程
//     */
//    private static void startHDLThread() {
//        mHDLReadMCUDatasThread = new HDLReadMCUDatasThread();
//        mHDLSendDatasThread = new HDLSendDatasThread();
//        mHDLReadMCUDatasThread.start();
//        mHDLSendDatasThread.start();
//    }
//
////    /**
////     * 串口接收线程
////     *
////     * @author 2019年06月26日
////     */
////    private static class HDLReadDatasThread extends Thread {
////
////        @Override
////        public void run() {
////            super.run();
////            HDLLog.I("接收线程 开启");
////
////            while (bOpenSuccess) {
////                int size = 0;
////                try {
////                    if (mInputStream == null) return;
////
////                    byte[] buffer = new byte[64];
////                    size = mInputStream.read(buffer);
////                    for (int i = 0; i < size; i++) {
////                        mReceiveDatasList.add(buffer[i]);
////                    }
////
////                    while (0 < mReceiveDatasList.size()) {
////                        HDLLog.I("arraylist.size():" + mReceiveDatasList.size());
////                        if (mReceiveDatasList.size() < 3) break;//2019-07-02
////                        int len = -1;
////                        int startIndex = 0;
////                        for (startIndex = 0; startIndex < mReceiveDatasList.size(); startIndex++) {
////                            if ((mReceiveDatasList.get(startIndex) & 0xFF) == 0xAA
////                                    && (mReceiveDatasList.get(startIndex + 1) & 0xFF) == 0xAA) {
////                                len = (mReceiveDatasList.get(startIndex + 2) & 0xFF) + 2;//发现len会出现负数增加 & 0xFF 运算
////                                break;
////                            }
////                        }
////                        if (len == -1 || mReceiveDatasList.size() < len) break;
////
////                        HDLLog.I("startIndex:" + startIndex + "   LEN:" + len);
////                        for (int i = 0; i < startIndex; i++) {
////                            if (mReceiveDatasList.size() < 1) break;//2019-07-02
////                            mReceiveDatasList.remove(0);
////                        }
////                        byte[] tempBytes = new byte[len];
////                        for (int i = 0; i < tempBytes.length; i++) {
////                            if (mReceiveDatasList.size() < 1) break;//2019-07-02
////
////                            tempBytes[i] = mReceiveDatasList.get(0);
////                            mReceiveDatasList.remove(0);
////                        }
////                        HandleHDLdata(tempBytes);
////                    }
////                } catch (Exception e) {
////                    e.printStackTrace();
////                    HDLLog.I("error:" + e.getMessage());
////                }
////            }
////            HDLLog.I("接收线程 关闭");
////        }
////    }
//
//    /**
//     * 串口接收线程
//     * 对接MCU新协议
//     * 引导头 控制域 数据长度 数据 校验码
//     * 0xA8
//     *
//     * @author 2019年07月12日
//     */
//    private static class HDLReadMCUDatasThread extends Thread {
//
//        @Override
//        public void run() {
//            super.run();
//            HDLLog.I("接收线程 开启");
//
//            while (bOpenSuccess) {
//                int size = 0;
//                try {
//                    Thread.sleep(1);
//                    if (mInputStream == null) return;
//                    byte[] buffer = new byte[64];
//                    size = mInputStream.read(buffer);
//
////                    HDLLog.I("mReceiveDatasList: " + HDLStringUtils.ByteArrToHex(buffer, 0, buffer.length) );
//                    for (int i = 0; i < size; i++) {
//                        mReceiveDatasList.add(buffer[i]);
//                    }
//
//                    while (0 < mReceiveDatasList.size()) {
////                        HDLLog.I("arraylist.size():" + mReceiveDatasList.size());
//                        if (mReceiveDatasList.size() < 3) break;//2019-07-02
//                        if (mReceiveDatasList.size() > 3000) { //数据缓存太多错误情况下 清空一次
//                            mReceiveDatasList.clear();
//                            break;//2019-07-24
//                        }
//
//                        int len = -1;
//                        int startIndex = 0;
//                        for (startIndex = 0; startIndex < mReceiveDatasList.size(); startIndex++) {
//                            if ((mReceiveDatasList.get(startIndex) & 0xFF) == 0xA8) {
//                                len = (mReceiveDatasList.get(startIndex + 2) & 0xFF) * 256 + (mReceiveDatasList.get(startIndex + 3) & 0xFF) + 5;
//                                break;
//                            }
////                            else{
////                                HDLLog.I("mReceiveDatasList"+ (mReceiveDatasList.get(startIndex) & 0xFF) );
////                            }
//                        }
//
//                        if (len == -1 || mReceiveDatasList.size() < len) break;
//
////                        HDLLog.I("startIndex:" + startIndex + "   LEN:" + len);
//                        for (int i = 0; i < startIndex; i++) {
//                            if (mReceiveDatasList.size() < 1) break;//2019-07-02
//                            mReceiveDatasList.remove(0);
//                        }
//                        byte[] tempBytes = new byte[len];
//                        for (int i = 0; i < tempBytes.length; i++) {
//                            if (mReceiveDatasList.size() < 1) break;//2019-07-02
//
//                            tempBytes[i] = mReceiveDatasList.get(0);
//                            mReceiveDatasList.remove(0);
//                        }
//                        HandleMCUdata(tempBytes);
//
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    HDLLog.I("error:" + e.getMessage());
//                }
//            }
//            HDLLog.I("接收线程 关闭");
//        }
//    }
//
//
//    /**
//     * 串口发送线程
//     */
//    private static class HDLSendDatasThread extends Thread {
//        @Override
//        public void run() {
//            super.run();
//            HDLLog.I("发送线程 开启");
//            while (bOpenSuccess) {
//                try {
//                    Thread.sleep(100);
//                } catch (Exception e) {
//                    e.getMessage();
//                }
//                for (int i = 0; i < mSendDatasList.size(); i++) {
//                    try {
//                        Thread.sleep(100);
//                    } catch (Exception e) {
//
//                    }
//                    try {
//                        byte[] sendBytes = mSendDatasList.get(i);
//                        try {
//                            mOutputStream.flush();
//                            mOutputStream.write(sendBytes);
//                            HDLLog.I(
//                                    "sendBytes:" + HDLStringUtils.ByteArrToHex(sendBytes, 0, sendBytes.length));
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        mSendDatasList.remove(i);
//                        i--;
//                    } catch (Exception ex) {
//                        ex.getMessage();
//                    }
//                }
//            }
//            HDLLog.I("发送线程 关闭");
//        }
//    }
//
////    /**
////     * 发送MUC串口协议数据包
////     * @param mcuDataList
////     * @param bPassThrough 是否为透传
////     */
////    public static void sendMCUData(final MCUCrc mcuDataList, Boolean bPassThrough) {
////        if(HDLSerialPortCore.bPassThrough != bPassThrough ){
////            HDLSerialPortCore.bPassThrough = bPassThrough;
////        }
////        //打印接受数据
////        HDLLog.I("HHHHHsendMCUData:  "+ HDLStringUtils.ByteArrToHex(mcuDataList.getMCUSendBytes(),0, mcuDataList.getMCUSendBytes().length));
////        if (!bOpenSuccess) return;
////        mSendDatasList.add(mcuDataList.getMCUSendBytes());
////    }
//
//    /**
//     * 发送MUC串口协议数据包
//     *
//     * @param mcuDataList
//     */
//    public static void sendMCUData(final MCUCrc mcuDataList) {
//        //打印接受数据
////        HDLLog.I("HHHHHsendMCUData:  "+ HDLStringUtils.ByteArrToHex(mcuDataList.getMCUSendBytes(),0, mcuDataList.getMCUSendBytes().length));
//        if (!bOpenSuccess) return;
//        mSendDatasList.add(mcuDataList.getMCUSendBytes());
//    }
//
//
//    /**
//     * 发送数据包
//     * 点对点或广播
//     *
//     * @param sendDatas
//     */
//    public static void sendData(final Crc sendDatas) {
//        if (!bOpenSuccess) return;
//        mSendDatasList.add(sendDatas.GetSendBytes());
//    }
//
//    /**
//     * 发送组播
//     *
//     * @param sendDatas
//     */
//    public static void sendMulticastData(final Crc sendDatas) {
//        if (!bOpenSuccess) return;
//        mSendDatasList.add(sendDatas.GetSendBytes());
//    }
//
//
////    /**
////     * 判断是否为485HDL数据
////     * @param bytes
////     * @return
////     */
////    private static void HandleHDLAAAAdata(byte[] bytes) {
////        while (0 < mReceiveDatasList.size()) {
////            HDLLog.I("arraylist.size():" + mReceiveDatasList.size());
////            if (mReceiveDatasList.size() < 3) break;//2019-07-02
////            int len = -1;
////            int startIndex = 0;
////            for (startIndex = 0; startIndex < mReceiveDatasList.size(); startIndex++) {
////                if ((mReceiveDatasList.get(startIndex) & 0xFF) == 0xAA
////                        && (mReceiveDatasList.get(startIndex + 1) & 0xFF) == 0xAA) {
////                    len = (mReceiveDatasList.get(startIndex + 2) & 0xFF) + 2;//发现len会出现负数增加 & 0xFF 运算
////                    break;
////                }
////            }
////            if (len == -1 || mReceiveDatasList.size() < len) break;
////
////            HDLLog.I("startIndex:" + startIndex + "   LEN:" + len);
////            for (int i = 0; i < startIndex; i++) {
////                if (mReceiveDatasList.size() < 1) break;//2019-07-02
////                mReceiveDatasList.remove(0);
////            }
////            byte[] tempBytes = new byte[len];
////            for (int i = 0; i < tempBytes.length; i++) {
////                if (mReceiveDatasList.size() < 1) break;//2019-07-02
////
////                tempBytes[i] = mReceiveDatasList.get(0);
////                mReceiveDatasList.remove(0);
////            }
////            HandleHDLdata(tempBytes);
////        }
////
////    }
//
//    /**
//     * 判断是否为HDL AA AA 开头数据
//     * @param bytes
//     * @return
//     */
//    private static boolean isHDLDataWithHead(byte[] bytes) {
//        boolean isWant = true;
//        if ((bytes[0] & 0xFF) != 0xAA) {
//            isWant = false;
//        }
//        if ((bytes[1] & 0xFF) != 0xAA) {
//            isWant = false;
//        }
//        return isWant;
//    }
//
//
//    /**
//     * 处理HDL Data
//     *
//     * @param receiveBytes
//     */
//    private synchronized static void HandleHDLdata(byte[] receiveBytes) {
//        if (receiveBytes.length < 14) {
//            return;
//        }
//
//        //校验是否为0xAA 0xAA 开头数据数据
//        if (!isHDLDataWithHead(receiveBytes)) {
//            return;
//        }
//
//        //打印接收数据
//        HDLLog.I("receiveBytes HandleHDLdata: " + HDLStringUtils.ByteArrToHex(receiveBytes, 0, receiveBytes.length));
//
//        //数据长度
//        int addDataLength = (receiveBytes[2] & 0xFF) - 11;
//        //附加数据
//        byte[] usefulBytes = new byte[addDataLength];
//        //复制附加数据
//        System.arraycopy(receiveBytes, 11, usefulBytes, 0, addDataLength);
//        //操作码
//        int command = (receiveBytes[7] & 0xFF) * 256 + (receiveBytes[8] & 0xFF);
//        //源子网号
//        int sourceSubnetID = receiveBytes[3] & 0xFF;
//        //源设备号
//        int sourceDeviceID = receiveBytes[4] & 0xFF;
//        //目标子网号
//        int targetSubnetID = receiveBytes[9] & 0xFF;
//        //目标设备号
//        int targetDeviceID = receiveBytes[10] & 0xFF;
//        //参数
//        UdpDataBean udpDataBean = new UdpDataBean();
//        udpDataBean.sourceSubnetID = sourceSubnetID;
//        udpDataBean.sourceDeviceID = sourceDeviceID;
//        udpDataBean.desSubnetID = targetSubnetID;
//        udpDataBean.desDeviceID = targetDeviceID;
//        udpDataBean.command = command;
//
//        udpDataBean.addBytes = usefulBytes;
////        HandleOutsideData(targetSubnetID, targetDeviceID, command, usefulBytes, receiveBytes, udpDataBean);
//        HandleInsideData(udpDataBean);
//
//    }
//
//
//    /**
//     * 处理内部命令数据
//     *
//     * @param sendDatas
//     */
//    private static void HandleInsideData(UdpDataBean sendDatas) {
//        switch (sendDatas.command) {
//            case Configuration.DEVICES_SEARCH_BACK_COMMAND:
////                先判断搜索模式,家居搜索则只需要判断两个随机数。酒店搜索则需要判断两个随机数和ip地址
//                if (HandleSearch.curSearchMode == HandleSearch.GET_BUS_DEVICES) {
//                    if (sendDatas.addBytes[0] == HandleSearch.random1
//                            && sendDatas.addBytes[1] == HandleSearch.random2) {
//                        HDLDeviceManager.handle(sendDatas, sendDatas.command);
//                    }
//                } else {
////                    if (sendDatas.addBytes[0] == HandleSearch.random1
////                            && sendDatas.addBytes[1] == HandleSearch.random2
////                            && HandleSearch.rcuIp.equals(sendDatas.ipAddress)
////                            ) {
////                        HDLDeviceManager.handle(sendDatas, sendDatas.command);
////
////                    }
//                    if (sendDatas.addBytes[0] == HandleSearch.random1
//                            && sendDatas.addBytes[1] == HandleSearch.random2
//                    ) {
//                        HDLDeviceManager.handle(sendDatas, sendDatas.command);
//                    }
//                }
//
//                break;
//
//            case Configuration.LIGHT_CTRL_BACK_COMMAND:
//            case Configuration.CURTAIN_CTRL_BACK_COMMAND:
//            case Configuration.AIR_CTRL_BACK_COMMAND:
//            case Configuration.LOGIC_CTRL_BACK_COMMAND:
//            case Configuration.LIGHT_STATE_BACK_COMMAND:
//            case Configuration.SECURITY_ARMING_CTRL_BACK_COMMAND://20190729安防模块 布防设置反馈
//            case Configuration.SECURITY_STATE_BACK_COMMAND://20190729 读取安防设置反馈
//            case Configuration.SECURITY_ALARM_CTRL_BACK_COMMAND://20190729 报警设置反馈
//            case Configuration.CURTAIN_STATE_BACK_COMMAND:
//            case Configuration.AIR_STATE_BACK_COMMAND:
//            case Configuration.AIR_HVAC_CTRL_BACK_COMMAND:
//            case Configuration.AIR_HVAC_STATE_BACK_COMMAND:
////            case Configuration.RCU_ROOM_CAST_COMMAND:
////            case Configuration.RCU_CURTAIN_CAST_COMMAND:
//            case Configuration.DEVICES_READ_BACK_COMMAND://读取备注命令
//            case Configuration.DEVICES_MODIFY_BACK_COMMAND://修改基本信息回复
//            case Configuration.MODULE_UPDATE_REMARK_BACK_COMMAND://修改模块备注回复
//            case Configuration.WARNING_COMMAND:
//            case Configuration.SENSOR_STATE_BACK_COMMAND:
////            case Configuration.AUDIO_CTRL_READ_COMMAND:
//            case Configuration.AUDIO_CTRL_READ_BACK_COMMAND:
////            case Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND:
//            case Configuration.AUDIO_MenuPlay_INSTRUCTION_BACK_COMMAND:
//
//                HDLDeviceManager.handle(sendDatas, sendDatas.command);
//                break;
//
//
////            case Configuration.RCU_SEARCH_COMMAND:
//////                if (sendDatas.port == Configuration.RCU_SEND_PORT) {
////                    HDLLog.I( "收到搜索RCU命令");
////                    HDLDeviceManager.handle(sendDatas, sendDatas.command);
//////                }
////
////                break;
////            case Configuration.RCU_READ_SDK_INFO_COMMAND:
//////                if (sendDatas.desSubnetID == Crc.localSubnetID && sendDatas.desDeviceID == Crc.localDeviceID
//////                        ) {
//////                    HDLLog.I( "E508收到");
//////                    HDLDeviceManager.handle(sendDatas, Configuration.RCU_READ);
//////                }
//////                if (sendDatas.port == Configuration.RCU_SEND_PORT) {
////                    HDLLog.I( "收到读取SDK信息命令");
////                    HDLDeviceManager.handle(sendDatas, sendDatas.command);
//////                }
//
////                break;
//            case Configuration.MANUAL_ADD_DEVICE_COMMAND:
//                //固定随机数181、250
//                if (sendDatas.addBytes[0] == ((byte) 181)
//                        && sendDatas.addBytes[1] == ((byte) 250)) {
//                    HDLDeviceManager.handle(sendDatas, sendDatas.command);
//                }
//                break;
//            case Configuration.MANUAL_ADD_REMARK_COMMAND:
//                HDLDeviceManager.handle(sendDatas, sendDatas.command);
//                break;
//            default:
//                break;
//        }
//    }
//
//
////    /**
////     * 判断是否为HDL数据
////     * @param bytes
////     * @return
////     */
////    private static boolean isHDLData(byte[] bytes) {
////
////        boolean isWant = true;
////        for (int index = 0; index < bytes.length; index++) {
////            switch (index) {
////                case 0:
////                    if (bytes[index] != 0x48) {
////                        isWant = false;
////                    }
////                    break;
////                case 1:
////                    if (bytes[index] != 0x44) {
////                        isWant = false;
////                    }
////                    break;
////                case 2:
////                    if (bytes[index] != 0x4C) {
////                        isWant = false;
////                    }
////                    break;
////                case 3:
////                    if (bytes[index] != 0x4D) {
////                        isWant = false;
////                    }
////                    break;
////                case 4:
////                    if (bytes[index] != 0x49) {
////                        isWant = false;
////                    }
////                    break;
////                case 5:
////                    if (bytes[index] != 0x52) {
////                        isWant = false;
////                    }
////                    break;
////                case 6:
////                    if (bytes[index] != 0x41) {
////                        isWant = false;
////                    }
////                    break;
////                case 7:
////                    if (bytes[index] != 0x43) {
////                        isWant = false;
////                    }
////                    break;
////                case 8:
////                    if (bytes[index] != 0x4C) {
////                        isWant = false;
////                    }
////                    break;
////                case 9:
////                    if (bytes[index] != 0x45) {
////                        isWant = false;
////                    }
////                    break;
////
////                default:
////                    break;
////            }
////        }
////        return isWant;
////    }
//
//    /**
//     * 处理HDL Data
//     *
//     * @param receiveBytes
//     */
//    private synchronized static void HandleMCUdata(byte[] receiveBytes) {
//        if (receiveBytes.length < 5) {
//            return;
//        }
//        //打印接受数据
//        HDLLog.I("receiveBytes HandleMCUdata: " + HDLStringUtils.ByteArrToHex(receiveBytes, 0, receiveBytes.length));
//        //操作码
//        int command = receiveBytes[1] & 0xFF;
//        //数据长度
//        int addDataLength = (receiveBytes[2] & 0xFF) * 256 + (receiveBytes[3] & 0xFF);
//        //附加数据
//        byte[] usefulBytes = new byte[addDataLength];
//        //复制附加数据
//        System.arraycopy(receiveBytes, 4, usefulBytes, 0, addDataLength);
//
//        //参数
//        MCUDataBean mMCUDataBean = new MCUDataBean();
//        mMCUDataBean.command = command;
//        mMCUDataBean.receiveBytes = usefulBytes;
//
//        HandleMCUData(mMCUDataBean);
//
//    }
//
//
//    /**
//     * 处理MCU返回的命令数据
//     *
//     * @param mMCUDataBean
//     */
//    private static void HandleMCUData(MCUDataBean mMCUDataBean) {
//        switch (mMCUDataBean.command) {
//            case MCUConstants.MCU_COMMAND_SEND_BACK:    //0x80 上报数据
//                if (!bPassThrough) {
//                    HandleHDLdata(mMCUDataBean.receiveBytes);   //不是透传的话,处理485数据
//                } else {
//                    HDLDeviceManager.HandleMCUData(mMCUDataBean);
//                }
//                break;
//            case MCUConstants.MCU_SEND_UPGRADE_DATA_BACK: //0x05 发送升级数据返回 注意,当文件地址为0xF5F5F5F5的时候,代表发生错误,升级包不对,会退出升级模式。当文件地址为0xF8F8F8F8,代表成功,成功后会重启,监听到重启完毕,才代表完成。
//                handleSendUpgradeDataBack(mMCUDataBean);
//                break;
//            default:
//                HDLDeviceManager.HandleMCUData(mMCUDataBean);
//                break;
//        }
//    }
//
//
//    private static void handleSendUpgradeDataBack(MCUDataBean mMCUDataBean) {
//        try {
//            int addressIndex = HDLUtlis.byteArrayToInt(mMCUDataBean.receiveBytes);
//            HDLLog.I("addressIndex:" + addressIndex);
//            if (addressIndex == 0xF5F5F5F5) {
//                //当文件地址为0xF5F5F5F5的时候,代表发生错误,升级包不对,会退出升级模式
//                sendIMcuOtaListeneronFailure(EventCode.FAILURE_DATA_ERROR, "升级错误,升级包不对");
//            } else if (addressIndex == 0xF8F8F8F8) {
//                //当文件地址为0xF8F8F8F8,代表成功,成功后会重启,监听到重启完毕
//                sendIMcuOtaListenerOnProgress(100);
//                sendIMcuOtaListenerOnSuccess();
//                upgradeFileDatas = null;//升级文件清空
//            } else {
//                //继续升级 返送下一个升级包 并返回进度
//                if (addressIndex > upgradeFileDatas.length) {
//                    HDLLog.E("addressIndex 大于升级包长度");
//                    return;
//                }
//
//                HDLCommand.mcuSendUpgradeData(getNextUpgradebytes(mMCUDataBean.receiveBytes, addressIndex));
//                int progress = addressIndex * 100 / (upgradeFileDatas.length - 1);
//                sendIMcuOtaListenerOnProgress(progress);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            HDLLog.E("handleSendUpgradeDataBack 出错");
//        }
//
//    }
//
//    /**
//     * 获取下一段升级包数据
//     *
//     * @param index
//     */
//    private static byte[] getNextUpgradebytes(byte[] addressBytes, int index) {
//        byte[] newBytes = new byte[1030];//1024+6
//        System.arraycopy(addressBytes, 0, newBytes, 0, 4);
//        int sub = upgradeFileDatas.length - 1 - index;
//        if (sub >= 1024) {
//            System.arraycopy(upgradeFileDatas, index, newBytes, 6, 1024);
//        } else {
//            System.arraycopy(upgradeFileDatas, index, newBytes, 6, sub);
//        }
//        newBytes[4] = 0x04;//默认数据长度为1024
//        newBytes[5] = 0x00;
//
//        return newBytes;
//    }
//
//
//    /**
//     * 设置监听事件
//     *
//     * @param listener
//     */
//    public static void setIMcuOtaListener(IMcuOtaListener listener) {
//        mIMcuOtaListener = listener;
//    }
//
//    public static void removeIMcuOtaListener() {
//        mIMcuOtaListener = null;
//    }
//
//    /**
//     * onProgress
//     *
//     * @param progress
//     */
//    public static void sendIMcuOtaListenerOnProgress(int progress) {
//        if (mIMcuOtaListener != null) {
//            progress = HDLUtlis.getTrueProgressInt(progress);//确保progress 在0到100
//            mIMcuOtaListener.onProgress(progress);
//        }
//    }
//
//    /**
//     * onSuccess
//     */
//    public static void sendIMcuOtaListenerOnSuccess() {
//        if (mIMcuOtaListener != null) {
//            mIMcuOtaListener.onSuccess();
//        }
//    }
//
//    /**
//     * onFailure
//     *
//     * @param code  错误码
//     * @param error 失败原因
//     */
//    public static void sendIMcuOtaListeneronFailure(int code, String error) {
//        if (mIMcuOtaListener != null) {
//            mIMcuOtaListener.onFailure(code, error);
//        }
//    }
//
//
//}
//
//