panlili2024
2024-11-11 145de2dcd3124f236e7d06bcdee17c7be08048b1
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
//package com.hdl.sdk.ttl_sdk.activity;
//
//
//import android.Manifest;
//import android.app.Activity;
//import android.content.Intent;
//import android.net.Uri;
//import android.os.Bundle;
//import android.support.annotation.NonNull;
//import android.text.TextUtils;
//import android.util.Log;
//import android.view.View;
//import android.widget.AdapterView;
//import android.widget.ArrayAdapter;
//import android.widget.Button;
//import android.widget.RelativeLayout;
//import android.widget.Spinner;
//import android.widget.TextView;
//
//import com.hdl.sdk.ttl.Config.MCUConstants;
//import com.hdl.sdk.ttl.HDLDeviceManger.Bean.MCUConfigurationBean;
//import com.hdl.sdk.ttl.HDLDeviceManger.Bean.MCUDataBean;
//import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLCommand;
//import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLSerialPortCore;
//import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.EventCode;
//import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.MCUFeedBackEvent;
//import com.hdl.sdk.ttl.HDLDeviceManger.HDLListener.IMcuOtaListener;
//import com.hdl.sdk.ttl.Utils.HDLUtlis.HDLStringUtils;
//import com.hdl.sdk.ttl_sdk.R;
//import com.hdl.sdk.ttl_sdk.base.BaseActivity;
//import com.hdl.sdk.ttl_sdk.utlis.HDLLog;
//import com.hdl.sdk.ttl_sdk.utlis.HDLUriUtils;
//import com.hdl.sdk.ttl_sdk.utlis.HDLUtlis;
//
//import org.greenrobot.eventbus.EventBus;
//import org.greenrobot.eventbus.Subscribe;
//import org.greenrobot.eventbus.ThreadMode;
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileNotFoundException;
//import java.io.IOException;
//import java.util.List;
//import java.util.Timer;
//import java.util.TimerTask;
//
//import pub.devrel.easypermissions.AppSettingsDialog;
//import pub.devrel.easypermissions.EasyPermissions;
//
///**
// * MCU协议调试页面
// */
//public class MCUActivity extends BaseActivity implements EasyPermissions.PermissionCallbacks, IMcuOtaListener {
//    /**
//     * Topbar
//     */
//    private RelativeLayout topBarBack;
//    private TextView topBarTitle;
//    private Button btn_packet_loss, btn_read_config, btn_write_config, btn_update, btn_restart, btn_PassThrough, btn_PassThrough_close;
//    private Spinner sp_type, sp_Baudrate, sp_DataBit, sp_CheckBit, sp_StopBit;
//    private TextView tv_select_bin, tv_config_mes, tv_update_mes, tv_other_mes;
//
//    private MCUConfigurationBean mMCUConfigurationBean;
//    private static final String[] mcuTypeItems = {"Buspro", "zigbee", "KNX", "Modbus", "禁选", "自定义"};
//    private static final String[] mcuBaudrateItems = {"1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200", "250000"};
//    private static final String[] mcuDataItems = {"8", "9"};
//    private static final String[] mcuCheckItems = {"无", "奇", "偶"};
//    private static final String[] mcuStopItems = {"0.5bit", "1bit", "2bit", "1.5bit"};
//    private boolean bGetMCUConfiguration = false;
//
//    private byte[] upgradeFileDatas;//升级文件数据
//    private static final int SELECT_FILE_CODE = 10;
//    private static final int PERMISSION = 101;
//    private boolean bPermission = false;
//    private static IMcuOtaListener mIMcuOtaListener;
//    private boolean bUpdating = false;//是否更新中
//
//    /**
//     * 复写isRegisterEventBus()  要注册使用EventBus,这里要设置返回true
//     *
//     * @return true
//     */
//    @Override
//    protected boolean isRegisterEventBus() {
//        return true;
//    }
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_mcu);
//
//        initToolbar();
//
//        initView();
//        initOnClick();
//        getEasyPermissions();
//        initData();
//
//        HDLSerialPortCore.setIMcuOtaListener(this);//设置监听
//    }
//
//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        HDLSerialPortCore.removeIMcuOtaListener();
//    }
//
//    /**
//     * 初始化Toolbar
//     */
//    private void initToolbar() {
//        topBarBack = findViewById(R.id.ll_top_b_left);
//        setViewVisible(topBarBack);
//        topBarTitle = findViewById(R.id.tv_top_b_header_title);
//        topBarBack.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                finish();
//            }
//        });
//        topBarTitle.setText("MCU 协议调试");
//    }
//
//    /**
//     * initView
//     */
//    private void initView() {
//        btn_packet_loss = findViewById(R.id.btn_packet_loss);
//        btn_read_config = findViewById(R.id.btn_read_config);
//        btn_write_config = findViewById(R.id.btn_write_config);
//        btn_update = findViewById(R.id.btn_update);
//        btn_restart = findViewById(R.id.btn_restart);
//        tv_other_mes = findViewById(R.id.tv_other_mes);
//        tv_select_bin = findViewById(R.id.tv_select_bin);
//        tv_config_mes = findViewById(R.id.tv_config_mes);
//        tv_update_mes = findViewById(R.id.tv_update_mes);
//
//        sp_type = findViewById(R.id.spinner_type);
//        sp_Baudrate = findViewById(R.id.spinner_baudrate);
//        sp_DataBit = findViewById(R.id.spinner_dataBit);
//        sp_CheckBit = findViewById(R.id.spinner_checkBit);
//        sp_StopBit = findViewById(R.id.spinner_stopBit);
//
//        btn_PassThrough = findViewById(R.id.btn_PassThrough);
//        btn_PassThrough_close = findViewById(R.id.btn_PassThrough_close);
//
//        mMCUConfigurationBean = new MCUConfigurationBean();
//    }
//
//    /**
//     * initOnClick
//     */
//    private void initOnClick() {
//
//        btn_read_config.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                HDLCommand.mcuReadConfiguration();
//            }
//        });
//
//        btn_write_config.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                HDLCommand.mcuWriteConfiguration(mMCUConfigurationBean.getMCUConfigurationSendBytes());
//            }
//        });
//
//
//        btn_packet_loss.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                HDLCommand.mcuGetDetectPacketLossStatus();
//            }
//        });
//
//        tv_select_bin.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                selectBin();
//            }
//        });
//
//        btn_update.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//                if (upgradeFileDatas == null) {
//                    showToast("请先选择升级文件");
//                    return;
//                }
//
//                HDLCommand.mcuRequestUpgradeWithFile(upgradeFileDatas);//传入升级文件并开始升级
//            }
//        });
//
//        btn_restart.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                HDLCommand.mcuSendRestart();
//            }
//        });
//
//
//        /**
//         * 发送透传参数 ,不走bus协议
//         */
//        btn_PassThrough.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                mcuSendTransparentData();
//
//            }
//        });
//
//        btn_PassThrough_close.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                setHDLPassThroughOpen(false);
//                tv_other_mes.setText("关闭透传");
//
//            }
//        });
//
//        ArrayAdapter<String> sp_typeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mcuTypeItems);
//        sp_typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//        sp_type.setAdapter(sp_typeAdapter);
//        sp_type.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
//            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//                if (arg2 == 4) {
//                    //选择了禁选
//                    showToast("该项不能选择!");
//                    sp_type.setSelection(mMCUConfigurationBean.getMcuAgreementType());
//                } else {
//                    mMCUConfigurationBean.setMcuAgreementType(arg2);
//                }
//
//            }
//
//            public void onNothingSelected(AdapterView<?> arg0) {
//                //
//            }
//        });
//
//
//        ArrayAdapter<String> sp_BaudrateAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mcuBaudrateItems);
//        sp_BaudrateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//        sp_Baudrate.setAdapter(sp_BaudrateAdapter);
//        sp_Baudrate.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
//            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//                mMCUConfigurationBean.setMcuBaudrate(arg2);
//            }
//
//            public void onNothingSelected(AdapterView<?> arg0) {
//                //
//            }
//        });
//
//
//        ArrayAdapter<String> sp_DataBitAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mcuDataItems);
//        sp_DataBitAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//        sp_DataBit.setAdapter(sp_DataBitAdapter);
//        sp_DataBit.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
//            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//                mMCUConfigurationBean.setMcuDataBit(arg2);
//            }
//
//            public void onNothingSelected(AdapterView<?> arg0) {
//            }
//        });
//
//
//        ArrayAdapter<String> sp_CheckBitAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mcuCheckItems);
//        sp_CheckBitAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//        sp_CheckBit.setAdapter(sp_CheckBitAdapter);
//        sp_CheckBit.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
//            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//                mMCUConfigurationBean.setMcuCheckBit(arg2);
//            }
//
//            public void onNothingSelected(AdapterView<?> arg0) {
//
//            }
//        });
//
//        ArrayAdapter<String> sp_StopBitAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mcuStopItems);
//        sp_StopBitAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//        sp_StopBit.setAdapter(sp_StopBitAdapter);
//        sp_StopBit.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
//            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//                mMCUConfigurationBean.setMcuStopBit(arg2);
////                showToast("选择的是" + mcuStopItems[arg2]);
//            }
//
//            public void onNothingSelected(AdapterView<?> arg0) {
//                //
//            }
//        });
//
//    }
//
//
//
//
//    /**
//     * initData
//     */
//    private void initData() {
//        setEnabledConfigBtn();
//
//    }
//
//    private void setEnabledConfigBtn() {
//        btn_write_config.setEnabled(bGetMCUConfiguration);
//    }
//
//    private void updateMCUConfiguration(MCUConfigurationBean mMCUConfigurationBean) {
//        this.mMCUConfigurationBean = mMCUConfigurationBean;
//        sp_type.setSelection(mMCUConfigurationBean.getMcuAgreementType(), true);
//        sp_Baudrate.setSelection(mMCUConfigurationBean.getMcuBaudrate(), true);
//        sp_DataBit.setSelection(mMCUConfigurationBean.getMcuDataBit(), true);
//        sp_CheckBit.setSelection(mMCUConfigurationBean.getMcuCheckBit(), true);
//        sp_StopBit.setSelection(mMCUConfigurationBean.getMcuStopBit(), true);
//
//    }
//
//    private void resetMCUConfiguration() {
//        sp_type.setSelection(0, true);
//        sp_Baudrate.setSelection(0, true);
//        sp_DataBit.setSelection(0, true);
//        sp_CheckBit.setSelection(0, true);
//        sp_StopBit.setSelection(0, true);
//
//    }
//
//    /**
//     * ***********************************************************处理MCU回复数据***********************************************************
//     */
//    /**
//     * MCU控制回调Event
//     *
//     * @param event
//     */
//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void onMCUFeedBackEventMain(MCUFeedBackEvent event) {
//        if (event.getEventCode() == EventCode.FAILURE_TIMEOUT) {
//            if (TextUtils.isEmpty(event.getError())) {
//                showToast("MCU请求超时,请稍后再试");
//            } else {
//                showToast(event.getError());
//            }
//            return;
//        }
//
//        switch (event.getMCUDataBean().command) {
//            case MCUConstants.MCU_COMMAND_SEND_BACK:    //
//                //透传返回的数据
//                handleMCUPassThroughDataBack(event);
//                break;
//            case MCUConstants.MCU_READ_CONFIGURATION_BACK:// 读配置返回
//            case MCUConstants.MCU_WRITE_CONFIGURATION_BACK:// 写配置信息返回
//                handleMCUConfigurationBack(event);
//                break;
//            case MCUConstants.MCU_DETECT_PACKET_LOSS_STATUS_BACK:// 检测丢包状态返回
//                //待处理
//                handleDetectPacketLossStatusBack(event);
//                break;
//            case MCUConstants.MCU_REQUEST_UPGRADE_BACK:   // 请求升级返回
//                handleRequestUpgradeBack(event);
//                break;
////            case MCUConstants.MCU_SEND_UPGRADE_DATA_BACK: // 发送升级数据返回
////                handleSendUpgradeDataBack(event);
////                break;
//            case MCUConstants.MCU_RESTART_BACK:     //0x86 重启返回
//                handleRestartBack(event);
//                break;
//            default:
//                break;
//        }
//    }
//
//    /**
//     * 处理MCU透传回调数据
//     * 透传数据,不走bus协议,直接转发,不做数据格式处理
//     *
//     * @param event
//     */
//    private void handleMCUPassThroughDataBack(MCUFeedBackEvent event) {
//        if (event.getEventCode() != EventCode.SUCCESS) {
//            tv_other_mesSetText("MCU透传数据出错,返回数据异常");
//            return;
//        }
//        String receiveString = HDLStringUtils.ByteArrToHex(event.getMCUDataBean().receiveBytes, 0, event.getMCUDataBean().receiveBytes.length);
//
//        tv_other_mes.setText("收到的透传数据:" + receiveString);
//        HDLLog.Log("收到的透传数据:" + receiveString);
//    }
//
//    /**
//     * 处理MCU读写配置返回数据
//     *
//     * @param event
//     */
//    private void handleMCUConfigurationBack(MCUFeedBackEvent event) {
//        if (event.getEventCode() != EventCode.SUCCESS) {
//            tv_config_mesSetText("MCU读写配置出错,返回数据异常");
//            return;
//        }
//        tv_config_mesSetText("成功获取配置");
//        bGetMCUConfiguration = true;
//        setEnabledConfigBtn();
//        updateMCUConfiguration(event.getMCUDataBean().getMCUConfigurationBean());
//    }
//
//    /**
//     * 处理MCU丢包检测返回数据
//     *
//     * @param event
//     */
//    private void handleDetectPacketLossStatusBack(MCUFeedBackEvent event) {
//        if (event.getEventCode() != EventCode.SUCCESS) {
//            tv_other_mesSetText("MCU丢包检测出错,返回数据异常");
//            return;
//        }
//
//        String receiveString = HDLStringUtils.ByteArrToHex(event.getMCUDataBean().receiveBytes, 0, event.getMCUDataBean().receiveBytes.length);
//        HDLLog.Log("丢包检测返回数据:" + receiveString);
//        tv_other_mesSetText("丢包检测返回数据:" + receiveString);
//    }
//
//    /**
//     * 处理MCU请求重启返回数据
//     *
//     * @param event
//     */
//    private void handleRestartBack(MCUFeedBackEvent event) {
//        if (event.getEventCode() != EventCode.SUCCESS) {
//            showToast("MCU请求重启返回错误,重启失败");
//            return;
//        }
//        if (bUpdating) {
//            bUpdating = false;
//            tv_update_mes.setText("MCU重启成功,升级完成!");
//            tv_other_mesSetText("MCU重启成功,升级完成!");
//        } else {
//            tv_other_mesSetText("MCU重启成功!");
//        }
//    }
//
//    /**
//     * 处理MCU请求升级返回数据
//     *
//     * @param event
//     */
//    private void handleRequestUpgradeBack(MCUFeedBackEvent event) {
//        if (event.getEventCode() != EventCode.SUCCESS) {
//            tv_update_mesSetText("MCU请求升级出错");
//            return;
//        }
//        bUpdating = true;
//        tv_update_mesSetText("MCU请求升级成功,开始升级...");
//    }
//
////
////    private void handleSendUpgradeDataBack(MCUFeedBackEvent event) {
////        if (event.getEventCode() != EventCode.SUCCESS) {
////            showToast("MCU发送升级数据出错");
////            return;
////        }
//////        注意,当文件地址为0xF5F5F5F5的时候,代表发生错误,
//////        升级包不对,会退出升级模式。当文件地址为0xF8F8F8F8,代表成功,成功后会重启,监听到重启完毕,才代表完成。
////
////        showToast("收到回复,继续发送数据");
////
////    }
//
//    /**
//     * ***********************************************************选择升级文件***********************************************************
//     */
//    private void selectBin() {
////        {".bin", "application/octet-stream"}
//        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
////        intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
//        intent.setType("application/octet-stream");//设置类型,我这里是任意类型,任意后缀的可以这样写。 {".bin", "application/octet-stream"}
//        intent.addCategory(Intent.CATEGORY_OPENABLE);
//        startActivityForResult(intent, SELECT_FILE_CODE);
//    }
//
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        if (resultCode == Activity.RESULT_OK) {
//            if (requestCode == SELECT_FILE_CODE) {
//                if (data != null) {
//                    Uri fileUri = data.getData();
//                    if (fileUri != null) {
//                        getFileFromUri(fileUri);
//                    }
//                }
//
//            }
//        }
//    }
//
//    /**
//     * 根据uri 读取升级固件
//     *
//     * @param mUri
//     */
//    private void getFileFromUri(Uri mUri) {
//        String path = mUri.toString();
//        if (!HDLUtlis.checkIsBinFile(path)) {
//            tv_select_bin.setText(getString(R.string.select_bin_frist));
//            upgradeFileDatas = null;
//            btn_update.setEnabled(false);
//            showToast("升级固件格式不对,请选择.bin后缀的升级文件");
//            return;
//        }
//        btn_update.setEnabled(true);
//        tv_select_bin.setText(path);
//        File file = HDLUriUtils.uri2File(this, mUri);
//        FileInputStream fis = null;
//        try {
//            fis = new FileInputStream(file);
//            int length = fis.available();
//            upgradeFileDatas = new byte[length];
//            fis.read(upgradeFileDatas);
//            fis.close();
//            showToast("upgradeFileDatas 长度:" + upgradeFileDatas.length);
//
//
//            //打印接受数据
//            com.hdl.sdk.ttl.Utils.LogUtils.HDLLog.I("receiveBytes HandleMCUdata: " + HDLStringUtils.ByteArrToHex(upgradeFileDatas, 0, upgradeFileDatas.length));
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//
//    /**
//     * ***********************************************************权限管理***********************************************************
//     */
//    private void getEasyPermissions() {
//        /**
//         * 6.0+系统动态权限申请需要
//         */
//        String[] params = new String[]{
//                Manifest.permission.WRITE_EXTERNAL_STORAGE,
//        };
//        if (EasyPermissions.hasPermissions(this, params)) {
//            bPermission = true;
//        } else {
//            EasyPermissions.requestPermissions(this, "应用需要权限才能安全运行", PERMISSION, params);
//        }
//    }
//
//    @Override
//    public void onPermissionsGranted(int requestCode, List<String> perms) {
//        Log.i("hdlll", "onPermissionsGranted  permsSize:" + perms.size());
//        if (requestCode == PERMISSION) {
//            if (!perms.isEmpty()) {
//                if (perms.contains(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
//                    //全部权限授权通过才正常打开APP
//                    bPermission = true;
//                }
//            }
//        }
//
//    }
//
//    @Override
//    public void onPermissionsDenied(int requestCode, List<String> perms) {
//        switch (requestCode) {
//            case PERMISSION:
//                //引导用户跳转到设置界面
//                new AppSettingsDialog.Builder(this).setTitle("温馨提示").setRationale("无法正常启动APP,您需要授予权限!").build().show();
//                break;
//        }
//    }
//
//    @Override
//    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
//        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
//    }
//
//
//    /**
//     * ***********************************************************固件升级 回调***********************************************************
//     */
//    @Override
//    public void onSuccess() {
//        sendRestartTimer();//升级10S超时提示
//        HDLLog.Log("IMcuOtaListener onSuccess");
//        runOnUiThread(new Runnable() {  //要在主线程更新UI
//            public void run() {
//                tv_update_mesSetText("升级成功,等待重启...");
//            }
//        });
//    }
//
//    @Override
//    public void onFailure(int code, final String error) {
//        HDLLog.Log("IMcuOtaListener onFailure");
//        runOnUiThread(new Runnable() {
//            public void run() {
//                tv_update_mesSetText("升级失败: " + error);
//            }
//        });
//
//    }
//
//    @Override
//    public void onProgress(final int progress) {
//        HDLLog.Log("IMcuOtaListener onProgress:" + progress);
//        runOnUiThread(new Runnable() {
//            public void run() {
//                tv_update_mes.setText("升级进度:" + progress + "%");
//            }
//        });
//
//    }
//
//    /**
//     * TextView 显示信息并且showToast提示
//     *
//     * @param mes
//     */
//    private void tv_update_mesSetText(String mes) {
//        tv_update_mes.setText(mes);
//        showToast(mes);
//    }
//
//    private void tv_other_mesSetText(String mes) {
//        tv_other_mes.setText(mes);
//        showToast(mes);
//    }
//
//    private void tv_config_mesSetText(String mes) {
//        tv_config_mes.setText(mes);
//        showToast(mes);
//    }
//
//
//    /**
//     * 升级完成后判断 是否重启成功 设置10S超时等待
//     */
//    private void sendRestartTimer() {
//        Timer restartTimer = new Timer();
//        restartTimer.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                if (bUpdating) {
//                    runOnUiThread(new Runnable() {
//                        public void run() {
//                            tv_update_mesSetText("升级完成,MCU重启超时!");
//                        }
//                    });
//                }
//            }
//        }, 10000);//10s超时限制
//    }
//
//
//
//
//    /**
//     * 2019-8-9
//     * 发送透传参数
//     * 透传数据,不走bus协议,直接转发,不做数据格式处理
//     * mcuSendTransparentData接口调用一次以后,默认所有接收数据走透传
//     * 可以调用setHDLPassThroughOpen关闭透传数据
//     */
//    private void mcuSendTransparentData() {
//        byte[] sendBytes = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
//        HDLCommand.mcuSendTransparentData(sendBytes);
//    }
//
//    /**
//     * 设置是否开启透传数据
//     * 要想直接接收透传数据,直接调用这个接口打开就可以,不走bus协议处理
//     * 不想透传的话,要记得设置回关闭状态
//     */
//    private void setHDLPassThroughOpen(Boolean bOpen){
//        HDLCommand.setHDLPassThroughOpen(bOpen);
//
//    }
//
//}