DELL
2024-10-15 e19d9c8d612dbaa7a8cf4925d762236f93d85548
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
package com.dev.bts4810;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Date;
 
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
 
import org.apache.logging.log4j.Logger;
 
import sp_comm.CommSerialPort;
import sp_comm.Comm_Socket;
import main.page_debug_inf;
 
import com.Com;
import com.ComFn;
import com.PlaySound;
import com.dev.bts.data.FBS9100S_SystemControl;
import com.dev.bts.data.FBS9100_CapState;
import com.dev.bts.data.FBS9100_ChargeState;
import com.dev.bts.data.FBS9100_Cmd;
import com.dev.bts.data.FBS9100_ComBase;
import com.dev.bts.data.FBS9100_ComBuf;
import com.dev.bts.data.FBS9100_DFU;
import com.dev.bts.data.FBS9100_DeviceInf;
import com.dev.bts.data.FBS9100_JuHengParam;
import com.dev.bts.data.FBS9100_ParamBatt;
import com.dev.bts.data.FBS9100_ParamCharge;
import com.dev.bts.data.FBS9100_ParamDischarge;
import com.dev.bts.data.FBS9100_ParamSystem;
import com.dev.bts.data.FBS9100_ResCapData;
import com.dev.bts.data.FBS9100_ResState;
import com.dev.bts.data.FBS9100_SysState;
import com.dev.bts.data.FBS9100_VCData;
import com.dev.fbs9600_mon.SPCommMon;
 
/**
 * BTSÉ豸ͨÐÅÏß³Ì
 * @author LiJun
 *
 */
public class CommBTS4810 implements Runnable/*, SerialPortEventListener*/ {
    
    public static final short CMD_TYPE_READ = 0x03;
    public static final short CMD_TYPE_WRITE = 0x05;
    public static final short CMD_TYPE_WRITE_MULTY = 0x10;
    
    public static final int DEV_PARAM_DATA_STATE_NULL         = 0;    //
    public static final int DEV_PARAM_DATA_STATE_DISQUERY     = 1;    //¶ÁÈ¡ºËÈݲÎÊý
    public static final int DEV_PARAM_DATA_STATE_BATTQUERY     = 2;    //¶ÁÈ¡µç³Ø²ÎÊý
    public static final int DEV_PARAM_DATA_STATE_SYSQUERY     = 3;    //¶Áȡϵͳ²ÎÊý
    public static final int DEV_PARAM_DATA_STATE_UPDATE        = 4;    //ÉèÖòÎÊý
    /*********************************************************************/
    public static final int DEV_DATA_AUTO_READ             = 0;        //×Ô¶¯¶ÁÈ¡
    public static final int DEV_DATA_MANUAL_SET         = 1;        //ÊÖ¶¯ÉèÖÃ
    public static final int DEV_DATA_AUTO_RANDOM         = 2;        //×Ô¶¯Ëæ»ú
    
    private boolean alearyMaxCurr = false;
    /*********************************************************************/
    public int dev_data_type = DEV_DATA_AUTO_READ;
    /*********************************************************************/
    public boolean DEV_DATA_ENCIPHER                    = false;    //ͨÐÅÊý¾ÝÊÇ·ñ¼ÓÃÜ
    public boolean DEV_DATA_AESCHECK                    = false;    //É豸ͨÐÅЭÒéÒѾ­¼ì²â³É¹¦
    /*********************************************************************/
    final public static String[] ZDHJ_OP_REST_INF_TEXT = new String[] {
            "ÎÞ²Ù×÷",
    };
    
    // ÊäÈëÊä³öÁ÷
    public static InputStream inputStream;
    public static OutputStream outputStream;
    // RS-232µÄ´®ÐпÚ
    public static SerialPort serialPort;
    
    private boolean CommThreadRunning = false;
    private boolean dt_dfu_en = false;
    BTS_Ecb_Aes my_aes = new BTS_Ecb_Aes();
    private ByteBuffer CommRxBuffer = ByteBuffer.allocate(1500); 
    private ByteBuffer CommTxBuffer = ByteBuffer.allocate(1048);
    
    private ByteBuffer DFUCommRxBuffer = ByteBuffer.allocate(1048); 
    private ByteBuffer DFUCommTxBuffer = ByteBuffer.allocate(1048);
    
    private ByteBuffer FBS9100TxBuffer = ByteBuffer.allocate(1048);
    private ByteBuffer FBS9100RxBuffer = ByteBuffer.allocate(1500);
    
    public int comm_tx_cnt = 0;
    public int comm_rx_cnt = 0;
    
    private int comm_bautrate = 9600;
    public int dt_target_addr = 0;
    //--------------------------------------------------------//
    public int dev_param_data_state = DEV_PARAM_DATA_STATE_NULL;
    public int dev_param_addr = 0;
    public int[] dev_param_ch_mon_cnt = new int[5];
    public int dev_param_curr_range = 0;
    public double dev_param_wenbo_curr_lev = 0;
    public int dev_param_auto_restest_interval = 0;
    public int dev_param_res_test_type = 0;
    //--------------------------------------------------------//
    public String dev_stat_version_Str = "";
    
    public String dev_control_Str = "";
    public int dev_stat_version = 0;
    public int dev_stat_state = 0;
    public double GroupVol = 0;
    public double BattCurr = 0;
    public int BattCurrDir = 0;
    public double AvgWenBoCurr = 0;
    public double PeakWenBoCurr = 0;
    //--------------------------------------------------------//
    @SuppressWarnings("unused")
    private JTextArea dt_show_msg = new JTextArea();
    private int dt_cmd = FBS9100_ComBase.CMD_GetVIData;
    private int dt_usr_cmd = FBS9100_ComBase.CMD_NULL;
    private ByteBuffer dt_datatofbs9100 = ByteBuffer.allocate(0);
    public int dt_cmd_ack = 0;
    public Date dt_cmd_ack_time = new Date();
    private int dt_cmd_cnt = 0;
    public int m_BTSDevSoftType = 0;
    //--------------------------------------------------------//
    //--------------------------------------------------------//
    public FBS9100_Cmd m_FBS_Cmd = new FBS9100_Cmd();
    public FBS9100_VCData m_FBS_VCData = new FBS9100_VCData();
    public FBS9100_ParamBatt m_FBS_BattParam;
    public FBS9100_ParamSystem m_FBS_SystemParam;
    public FBS9100_ParamDischarge m_FBS_DiscParam = new FBS9100_ParamDischarge();            //ÉèÖõIJÎÊý
    public FBS9100_ParamDischarge m_FBS_DiscParamFromDev = new FBS9100_ParamDischarge();    //´ÓÉ豸¶ÁÈ¡µÄ²ÎÊý    
 
    public FBS9100_JuHengParam m_FBS_JHParam = new FBS9100_JuHengParam();                    //ÉèÖõľùºâ²ÎÊý
    public FBS9100_JuHengParam m_FBS_JHParamFromDev = new FBS9100_JuHengParam();            //´ÓÉ豸¶ÁÈ¡µÄ¾ùºâ²ÎÊý    
    
    public FBS9100S_SystemControl m_FBS_SysControl = new FBS9100S_SystemControl();            //ÉèÖõĿØÖƲÎÊý
    public FBS9100S_SystemControl m_FBS_SysControlFromDev = new FBS9100S_SystemControl();    //´ÓÉ豸¶ÁÈ¡µÄ¿ØÖƲÎÊý    
    
    
    public FBS9100_DeviceInf deviceinf = new FBS9100_DeviceInf();
    
    public FBS9100_ParamCharge m_FBS_ChargeParam = new FBS9100_ParamCharge();
    public FBS9100_ResState m_ResTestState = new FBS9100_ResState();
    public FBS9100_CapState m_CapTestState = new FBS9100_CapState();
    public FBS9100_ChargeState m_ChrTestState = new FBS9100_ChargeState();
    public FBS9100_ResCapData m_FBS_ResCapData = new FBS9100_ResCapData();
    public ByteBuffer m_TaskList = ByteBuffer.allocate(1024); 
    
    public FBS9100_DFU m_FBS9100_DFU = new FBS9100_DFU();
    //--------------------------------------------------------//
    private page_debug_inf dt_debug_inf;
    private int m_COMM_PORT_TYPE = 0;
    private CommSerialPort m_SP_Comm = null;
    private Comm_Socket m_SocketComm = null;
    private Logger m_Log = null;
    
    
    private String dt_dfuFileName;                    //Éý¼¶Îļþ
    //--------------------------------------------------------//
    
    public CommBTS4810(int addr_t, int bitrate, page_debug_inf debug, Logger log) {
        dt_target_addr = addr_t & 0x00FF;
        comm_bautrate = bitrate;
        dt_debug_inf = debug;
        m_Log = log;
        
    }
    
    public void setCommBautrate(int bt_rate) {
        if(SPCommMon.COMM_PORT_TYPE_Serial != m_COMM_PORT_TYPE) {
            return;
        }
        
        try {
            comm_bautrate = bt_rate;
            serialPort.setSerialPortParams(comm_bautrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {
            e.printStackTrace();
        }
    }
    
    //³õʼ»¯´®¿Ú
    public boolean OpenCommPort(int comm_port_type, String comm_name_or_ip, int bitrate_or_comm_port) {
        boolean res = false;
        m_COMM_PORT_TYPE = comm_port_type;
        if(SPCommMon.COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) {
            m_SP_Comm = new CommSerialPort(bitrate_or_comm_port, m_Log);
            res = m_SP_Comm.OpenCommPort(comm_name_or_ip);
        } else {
            m_SocketComm = new Comm_Socket(comm_name_or_ip, bitrate_or_comm_port);
            res = true;
        }
        
        if(true == res) {
            CommTxBuffer.order(ByteOrder.BIG_ENDIAN);
            CommRxBuffer.order(ByteOrder.BIG_ENDIAN);
            DFUCommTxBuffer.order(ByteOrder.LITTLE_ENDIAN);
            DFUCommRxBuffer.order(ByteOrder.LITTLE_ENDIAN);
            FBS9100TxBuffer.order(ByteOrder.LITTLE_ENDIAN);
            FBS9100RxBuffer.order(ByteOrder.LITTLE_ENDIAN);
            comm_tx_cnt = 0;
            comm_rx_cnt = 0;
            CommThreadRunning = true;
        }
        DEV_DATA_AESCHECK = false;
        return res;
    }
    
    private byte[] makeCommTxData() {
        dt_cmd = FBS9100_ComBase.CMD_GetDeviceInf;
        
        if(0 == dev_stat_version) {
            dt_cmd = FBS9100_ComBase.CMD_GetDeviceInf;
        } else {            
            if(FBS9100_ComBase.CMD_NULL == dt_usr_cmd) {
                if(++dt_cmd_cnt  > 1000) {
                    dt_cmd_cnt = 0;
                }
 
                if(dev_data_type == DEV_DATA_AUTO_READ) {
                    //×Ô¶¯¶ÁÈ¡Êý¾Ý
                    dt_cmd = FBS9100_ComBase.CMD_GetVIData;
                    if(0 == dt_cmd_cnt%3) {
                        dt_cmd = FBS9100_ComBase.CMD_GetMonomerRES;
                    }
                    if(0 == dt_cmd_cnt%5) {
                        dt_cmd = FBS9100_ComBase.CMD_GetMonomerTMP;
                    }
                    dt_datatofbs9100 = ByteBuffer.allocate(0);
                }else if(dev_data_type == DEV_DATA_AUTO_RANDOM) {
                    
                    dt_cmd = FBS9100_ComBase.CMD_SetVIData;
                    if(0 == dt_cmd_cnt%3) {
                        dt_cmd = FBS9100_ComBase.CMD_SetMonomerRes;
                    }
                    if(0 == dt_cmd_cnt%5) {
                        dt_cmd = FBS9100_ComBase.CMD_SetMonomerTMP;
                    }
                    if(m_FBS_VCData.m_SysState.WorkState == FBS9100_SysState.SYS_STATE_CHARGING || (0 == dt_cmd_cnt%12)) {
                        //³äµçʱ£¬Ç°1·ÖÖÓ²»Ä£ÄâµçÁ÷
                        if(0 == dt_cmd_cnt%6) {
                            dt_cmd = FBS9100_ComBase.CMD_GetChargeState;
                        }
                    }
                    //Ëæ»úÄ£Äâʱ
                    if(0 == dt_cmd_cnt%4) {
                        dt_cmd = FBS9100_ComBase.CMD_GetVIData;
                    }
                    
                    if(dt_cmd == FBS9100_ComBase.CMD_GetChargeState || (dt_cmd == FBS9100_ComBase.CMD_GetVIData)) {                        
                        dt_datatofbs9100 = ByteBuffer.allocate(0);
                    }else {
                        //Ëæ»úÄ£ÄâÊý¾Ý
                        makeRandomData(dt_cmd);
                        
                        dt_datatofbs9100 = makeRandomDataBuffer(dt_cmd);                        
                    }
                    
                    
                }else if(dev_data_type == DEV_DATA_MANUAL_SET) {
                    //ÊÖ¶¯ÉèÖÃÊý¾Ý
                    //System.err.println("ÊÖ¶¯ÉèÖÃ");
                    dt_cmd = FBS9100_ComBase.CMD_SetVIData;
                    if(0 == dt_cmd_cnt%3) {
                        dt_cmd = FBS9100_ComBase.CMD_SetMonomerRes;
                    }
                    if(0 == dt_cmd_cnt%5) {
                        dt_cmd = FBS9100_ComBase.CMD_SetMonomerTMP;
                    }                    
                    dt_datatofbs9100 = makeRandomDataBuffer(dt_cmd);
                }
                
            } else {
                dt_cmd = dt_usr_cmd;
                dt_usr_cmd = FBS9100_ComBase.CMD_NULL;
            }
        }
        
        //System.out.println("dt_cmd:"+dt_cmd+"\tdt_datatofbs9100"+ComFn.bytesToHexString(dt_datatofbs9100.array(), dt_datatofbs9100.array().length));
        
        ByteBuffer buf_t = FBS9100_ComBuf.makeFbs9100CommBuf(255, dt_cmd, dt_datatofbs9100, DEV_DATA_ENCIPHER);
        
        byte[] plain_tx_t = new byte[buf_t.limit()];
        byte[] cipher_tx_t = new byte[buf_t.limit()];
        buf_t.get(plain_tx_t);
 
        //System.out.println("plain_tx_t:"+ComFn.bytesToHexString(plain_tx_t, plain_tx_t.length));
        if(DEV_DATA_ENCIPHER) {
            //¼ÓÃܸñʽ
            my_aes.ecb_encrypt(plain_tx_t, cipher_tx_t, plain_tx_t.length);
        }else {
            //·Ç¼ÓÃܸñʽ
            cipher_tx_t = plain_tx_t;
        }
        
        //System.out.println("TX:" + ComFn.bytesToHexString(plain_tx_t, plain_tx_t.length));
        
        return cipher_tx_t;
    }
    
    private ByteBuffer makeRandomDataBuffer(int dt_cmd) {
        int datatype = FBS9100_ComBase.DataType_MonVol;
        if(dt_cmd == FBS9100_ComBase.CMD_SetVIData) {
            datatype = FBS9100_ComBase.DataType_MonVol;
        }else if(dt_cmd == FBS9100_ComBase.CMD_SetMonomerRes) {
            datatype = FBS9100_ComBase.DataType_MonRes;
        }else if(dt_cmd == FBS9100_ComBase.CMD_SetMonomerTMP) {
            datatype = FBS9100_ComBase.DataType_MonTmp;
        }
        
        ByteBuffer buff = m_FBS_VCData.getByteBuffer(datatype, m_FBS_ResCapData);
        return buff;
    }
 
 
    public void tr_Msg(ByteBuffer bbf_tx, ByteBuffer bbf_rx, boolean showdat) {
        if(++comm_tx_cnt > 32500) {
            comm_tx_cnt = 0;
        }
        if(SPCommMon.COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) {
            m_SP_Comm.SP_Comm(bbf_tx, bbf_rx, CommSerialPort.mutycomm_Type_Samd09, dt_debug_inf, showdat);
        } else {
            m_SocketComm.SocketComm(bbf_tx, bbf_rx, dt_debug_inf, showdat);
        }
    }
    
    public void exitCommPortThread() {
        CommThreadRunning = false;
    }
    
    private void closeCommPort() {
        if(SPCommMon.COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) {
            m_SP_Comm.serialPort.close();
        } else {
            m_SocketComm.socketClose();
        }
    }
    
    public void setCommCmd(int cmd, ByteBuffer data_buf) {
        dt_usr_cmd = cmd;
        dt_datatofbs9100 = data_buf;
    }
    
    public void setCommCmd_DFU(boolean dfu_en, String dfu_file, JTextArea show_area) {
        dt_dfu_en = dfu_en;
        dt_show_msg = show_area;
        
        dt_dfuFileName = dfu_file;
    }
    
    public void setDataType(int datatype) {
        this.dev_data_type = datatype;
    }
    
    public void setCommCmdAck(int ack_t) {
        dt_cmd_ack = ack_t;
        dt_cmd_ack_time = new Date();
        String wav_f = "6133.wav";
        if(ack_t%2 == 0) {
            wav_f = "4577.wav";
        }
        if(ack_t > 0) {
            new PlaySound(wav_f);
        }
    }
    
    public void sendFBS9100Data(int cmd, ByteBuffer bbf_tx) throws IOException {
        ByteBuffer bf_t = FBS9100_ComBuf.makeFbs9100CommBuf(255, cmd, bbf_tx, true);
        byte[] cipher_tx_t = new byte[bf_t.limit()];
        bf_t.get(cipher_tx_t);
        //byte[] bt_t = FBS9100_ComBuf.makeFbs9100CommBuf(21, 0x15, ByteBuffer.allocate(0)).array();
        
        //byte[] cipher_tx_t = new byte[bf_t.limit()];
        //my_aes.ecb_encrypt(plain_tx_t, cipher_tx_t, plain_tx_t.length);
        
        //System.out.println(ComFn.bytesToHexString(plain_tx_t, plain_tx_t.length));
        outputStream.write(cipher_tx_t);
        if(++comm_tx_cnt > 1000000) {
            comm_tx_cnt = 0;
        }
    }
    
    public void run() {
        System.out.println("CommThreadRunning:"+CommThreadRunning);
        while(true == CommThreadRunning) {
            try {                
                if(false == dt_dfu_en) {
                    //sendMsg(makeCommTxData());
                    //readMsg(CommRxBuffer);
                    CommTxBuffer.clear();
                    CommTxBuffer.put(makeCommTxData());
                    CommTxBuffer.flip();
                    tr_Msg(CommTxBuffer, CommRxBuffer, true);
                    byte[] cipher_buf = new byte[CommRxBuffer.limit()];
                    byte[] plain_buf = new byte[CommRxBuffer.limit()];
                    CommRxBuffer.get(cipher_buf);                    
                    if(DEV_DATA_ENCIPHER) {
                        //¼ÓÃÜÊý¾Ý·µ»Ø
                        my_aes.ecb_decrypt(cipher_buf, plain_buf, cipher_buf.length);
                    }else {
                        plain_buf = cipher_buf;
                    }
                    System.out.println("RX:" + ComFn.bytesToHexString(cipher_buf, cipher_buf.length));
                    System.out.println("δ¼ÓÃÜRX:" + ComFn.bytesToHexString(plain_buf, plain_buf.length));
                    
                    if(getDataFromCommBuf(plain_buf)) {
                        //Êý¾ÝУÑé³É¹¦ºó¼´È·¶¨µ±Ç°Ð­Òé°æ±¾
                        if(!DEV_DATA_AESCHECK) {
                            DEV_DATA_AESCHECK = true;
                        }                        
                    }else {
                        //Èôµ±Ç°Êý¾Ý·µ»Ø²»³É¹¦¼´Çл»µ±Ç°µÄÇл»µ±Ç°Êý¾Ý¼ÓÃÜÀàÐÍ
                        if(!DEV_DATA_AESCHECK) {
                            DEV_DATA_ENCIPHER = !DEV_DATA_ENCIPHER;
                        }
                    }
                    //System.out.println("DEV_DATA_ENCIPHER:"+DEV_DATA_ENCIPHER);
                    Thread.sleep(500);
                }
                
                
                else {
                    //--------------------------- BOOTLOADER_CMD_WRITE-----------------------------//
                    String dfu_text_inf = "FBS9100S DFU Start.";
                    dt_show_msg.setText(dfu_text_inf);
                    boolean prog_ok = false;
                    FileInputStream fis = null;
                    try {
                        File f = new File(dt_dfuFileName);
                        long file_len = f.length();
                        byte[] buf_to_flash = new byte[FBS9100_DFU.DFU_BUF_LEN];
                        
                        Thread.sleep(100);
                        fis = new FileInputStream(f);
                        int dfu_datablock_num = 1;
                        int percent = 0;
                        while(true)
                        {
                            //====================================//
                            if((false == dt_dfu_en) || (false == CommThreadRunning)) {
                                dfu_text_inf = "DFU Manual Stop . . .";
                                dt_show_msg.setText(dfu_text_inf);
                                break;
                            }
                            //====================================//
                            for(int n=0; n<buf_to_flash.length; n++) {
                                buf_to_flash[n] = (byte) 0xFF;
                            }
                            //====================================//
                            int data_len_towrite = fis.read(buf_to_flash);
                            if(data_len_towrite > 0) {
                                Thread.sleep(1);
                                for(int cnt_t=0; cnt_t<3; cnt_t++) {                            
                                    
                                    CommTxBuffer.clear();
                                    CommTxBuffer.put(makeDFUData(FBS9100_ComBase.CMD_FBS9100_WriteDFU, 
                                            m_FBS9100_DFU.getWriteByteBuffer(dfu_datablock_num, buf_to_flash, data_len_towrite),DEV_DATA_ENCIPHER));
                                    CommTxBuffer.flip();
                                    tr_Msg(CommTxBuffer, CommRxBuffer, true);
                                    byte[] cipher_buf = new byte[CommRxBuffer.limit()];
                                    byte[] plain_buf = new byte[CommRxBuffer.limit()];
                                    //sendFBS9100Data(FBS9100_ComBase.CMD_FBS9100_WriteDFU, 
                                    //                m_FBS9100_DFU.getWriteByteBuffer(dfu_datablock_num, buf_to_flash, data_len_towrite));
                                    //readMsg(FBS9100RxBuffer);
                                    
                                    CommRxBuffer.get(cipher_buf);
                                    if(DEV_DATA_ENCIPHER) {
                                        //¼ÓÃÜÊý¾Ý·µ»Ø
                                        my_aes.ecb_decrypt(cipher_buf, plain_buf, cipher_buf.length);
                                    }else {
                                        plain_buf = cipher_buf;
                                    }                                    
                                    //System.err.println(ComFn.bytesToHexString(plain_buf, plain_buf.length));
                                    FBS9100RxBuffer.clear();
                                    FBS9100RxBuffer.position(0);
                                    FBS9100RxBuffer.put(plain_buf);
                                    FBS9100RxBuffer.flip();
                                    if(true == m_FBS9100_DFU.checkDfuWriteAckBuf(FBS9100RxBuffer)) {
                                        if(m_FBS9100_DFU.DataBlockIndex == dfu_datablock_num) {
                                            prog_ok = true;
                                            addRXData();   //ÀÛ¼Ó·µ»Ø¼ÆÊý
                                            break;
                                        }
                                    } else {
                                        prog_ok = false;
                                        Thread.sleep(500);
                                    }
                                }
                                if(false == prog_ok) {
                                    dfu_text_inf = "DFU Write Error!";
                                    dt_show_msg.setText(dfu_text_inf);
                                    break;
                                } else {
                                    dfu_datablock_num += 1;
                                }
                                
                                int tran_len_t = dfu_datablock_num*FBS9100_DFU.DFU_BUF_LEN;
                                if(percent < (tran_len_t*100)/file_len) {
                                    percent = (int) ((tran_len_t*100)/file_len);
                                    if(percent > 100) {
                                        percent = 100;
                                    }
                                    dt_show_msg.setText(String.format("DFU Write: %d%% Done.\n", percent));
                                }
                            } else {
                                dfu_text_inf = "DFU Write: 100% Done!\n";
                                dt_show_msg.setText(dfu_text_inf);
                                System.out.println(dfu_text_inf);
                                break;
                            }
                        }
                    } catch (IOException | InterruptedException e1) {
                        e1.printStackTrace();
                    } finally {
                        try {
                            fis.close();
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                    }
                    
                    if((true == prog_ok) && (true == dt_dfu_en) && (true == CommThreadRunning)) {
                        boolean check_ok = false;
                        FileInputStream fis_ck = null;
                        try {
                            File f_ck = new File(dt_dfuFileName);
                            long file_len_ck = f_ck.length();
                            byte[] buf_check = new byte[FBS9100_DFU.DFU_BUF_LEN];
                            
                            Thread.sleep(100);
                            fis_ck = new FileInputStream(f_ck);
                            int check_datablock_num = 1;
                            int percent = 0;
                            while(true)
                            {
                                //====================================//
                                if((false == dt_dfu_en) || (false == CommThreadRunning)) {
                                    dfu_text_inf = "DFU Check Manual Stop . . .";
                                    dt_show_msg.setText(dfu_text_inf);
                                    break;
                                }
                                //====================================//
                                for(int n=0; n<buf_check.length; n++) {
                                    buf_check[n] = (byte) 0xFF;
                                }
                                //====================================//
                                int len_buf_check = fis_ck.read(buf_check);
                                if(len_buf_check > 0) {
                                    Thread.sleep(1);
                                    for(int cnt_t=0; cnt_t<3; cnt_t++) {
                                        CommTxBuffer.clear();
                                        CommTxBuffer.put(makeDFUData(FBS9100_ComBase.CMD_FBS9100_ReadDFU, 
                                                m_FBS9100_DFU.getReadByteBuffer(check_datablock_num, len_buf_check),DEV_DATA_ENCIPHER));
                                        CommTxBuffer.flip();
                                        tr_Msg(CommTxBuffer, CommRxBuffer, true);
                                        byte[] cipher_buf = new byte[CommRxBuffer.limit()];
                                        byte[] plain_buf = new byte[CommRxBuffer.limit()];
                                        
                                        //sendFBS9100Data(FBS9100_ComBase.CMD_FBS9100_ReadDFU, 
                                        //                m_FBS9100_DFU.getReadByteBuffer(check_datablock_num, len_buf_check));
                                        //readMsg(FBS9100RxBuffer);
                                        
                                        CommRxBuffer.get(cipher_buf);
                                        if(DEV_DATA_ENCIPHER) {
                                            //¼ÓÃÜÊý¾Ý·µ»Ø
                                            my_aes.ecb_decrypt(cipher_buf, plain_buf, cipher_buf.length);
                                        }else {
                                            plain_buf = cipher_buf;
                                        }
                                        FBS9100RxBuffer.clear();
                                        FBS9100RxBuffer.position(0);
                                        FBS9100RxBuffer.put(plain_buf);
                                        FBS9100RxBuffer.flip();
                                        if(true == m_FBS9100_DFU.checkDfuReadAckBuf(FBS9100RxBuffer)) {
                                            if(m_FBS9100_DFU.DataBlockIndex == check_datablock_num) {
                                                byte[] s_buf = new byte[len_buf_check];
                                                FBS9100RxBuffer.get(s_buf);
                                                check_ok = true;
                                                for(int cn=0; cn<len_buf_check; cn++) {
                                                    if(buf_check[cn] != s_buf[cn]) {
                                                        check_ok = false;
                                                        break;
                                                    }
                                                }
                                                addRXData();   //ÀÛ¼Ó·µ»Ø¼ÆÊý
                                            }
                                        } else {
                                            check_ok = false;
                                            Thread.sleep(500);
                                        }
                                        if(true == check_ok) {
                                            break;
                                        }
                                    }
                                    if(false == check_ok) {
                                        dfu_text_inf = "DFU File Check Error!";
                                        dt_show_msg.setText(dfu_text_inf);
                                        break;
                                    } else {
                                        check_datablock_num += 1;
                                    }
                                    
                                    int tran_len_t = check_datablock_num*FBS9100_DFU.DFU_BUF_LEN;
                                    if(percent < (tran_len_t*100)/file_len_ck) {
                                        percent = (int) ((tran_len_t*100)/file_len_ck);
                                        if(percent > 100) {
                                            percent = 100;
                                        }
                                        dt_show_msg.setText(String.format("DFU File Check: %d%% Done.\n", percent));
                                    }
                                } else {
                                    dfu_text_inf = "DFU File Check: 100% Done!\n";
                                    dt_show_msg.setText(dfu_text_inf);
                                    setCommCmd(FBS9100_ComBase.CMD_SystemUpdate, ByteBuffer.allocate(0));
                                    break;
                                }
                            }
                        } catch (IOException | InterruptedException e1) {
                            e1.printStackTrace();
                        } finally {
                            try {
                                fis_ck.close();
                            } catch (IOException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            }
                        }
                    }
                    //---------------------------------------------------------------------------------//
                    dt_dfu_en = false;
                    //---------------------------------------------------------------------------------//
                }
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                exitCommPortThread();
                JOptionPane.showMessageDialog(null, "BTS ÉÏλ»ú´®¿ÚÒì³£: " + e.getMessage());
            }
        }
        /******************************************/
        closeCommPort();
        /******************************************/
        System.out.println("BTS CommPort is quit!");
    }
    /*********************************************************************************************/
    /*********************************************************************************************/
    /**
     *     ¹¹ÔìÉý¼¶·¢ËÍÊý¾Ý
     * @param cmd
     * @param bbf_tx
     * @param Aes
     * @return
     */
    public byte[] makeDFUData(int cmd, ByteBuffer bbf_tx,boolean Aes) {
        ByteBuffer bf_t = FBS9100_ComBuf.makeFbs9100CommBuf(255, cmd, bbf_tx, true);
        
        byte[] plain_tx_t = new byte[bf_t.limit()];
        byte[] cipher_tx_t = new byte[bf_t.limit()];
        bf_t.get(plain_tx_t);
        if(Aes) {
            //¼ÓÃܸñʽ
            my_aes.ecb_encrypt(plain_tx_t, cipher_tx_t, plain_tx_t.length);
        }else {
            //·Ç¼ÓÃܸñʽ
            cipher_tx_t = plain_tx_t;
        }
        return cipher_tx_t;
    }
    
    /*********************************************************************************************/
    /*********************************************************************************************/
    public boolean getDataFromCommBuf(final byte[] bytes)
      {
        boolean comm_res = false;
        ByteBuffer bf = ByteBuffer.allocate(bytes.length);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.put(bytes);
        bf.flip();
        //System.err.println(ComFn.bytesToHexString(bytes, bytes.length));
        String msg = "";
        if(true == m_FBS_Cmd.putByteBuffer(bf))
        {
            //------------------- ¶ÁÈ¡FBS9100µçѹµçÁ÷Êý¾Ý --------------------
            if(FBS9100_ComBase.CMD_GetVIData == m_FBS_Cmd.CMD)
            {
                
                //int last_workState = m_FBS_VCData.m_SysState.WorkState;
                if(true == m_FBS_VCData.m_SysState.putByteBuffer(bf))
                {
                    if(true == m_FBS_VCData.putByteBuffer(bf, 0x08, this.dev_stat_version)) {
                        comm_res = true;                
                    }
                }
            }else if(FBS9100_ComBase.CMD_StartDischarge == m_FBS_Cmd.CMD){
                if(m_FBS_Cmd.RES_Index == FBS9100_ComBase.CMD_Result_Success) {                    
                    comm_res = true;
                    dev_control_Str = "Æô¶¯ºËÈݲâÊԳɹ¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_StartResDischarge == m_FBS_Cmd.CMD) {
                if(m_FBS_Cmd.RES_Index == FBS9100_ComBase.CMD_Result_Success) {                    
                    comm_res = true;
                    dev_control_Str = "Æô¶¯ÄÚ×è²âÊԳɹ¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_StartCharge == m_FBS_Cmd.CMD) {
                if(m_FBS_Cmd.RES_Index == FBS9100_ComBase.CMD_Result_Success) {                    
                    comm_res = true;
                    dev_control_Str = "Æô¶¯³äµç²âÊԳɹ¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_Stop == m_FBS_Cmd.CMD) {
                if(m_FBS_Cmd.RES_Index == FBS9100_ComBase.CMD_Result_Success) {                    
                    comm_res = true;
                    dev_control_Str = "Í£Ö¹²âÊԳɹ¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_ResetSystem == m_FBS_Cmd.CMD) {
                if(m_FBS_Cmd.RES_Index == FBS9100_ComBase.CMD_Result_Success) {                    
                    comm_res = true;
                    dev_control_Str = "ÖØÆôÉ豸³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_SystemUpdate == m_FBS_Cmd.CMD) {
                if(m_FBS_Cmd.RES_Index == FBS9100_ComBase.CMD_Result_Success) {                    
                    comm_res = true;
                    //dev_control_Str = "Éý¼¶É豸³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_Start_KD_Test == m_FBS_Cmd.CMD) {
                if(m_FBS_Cmd.RES_Index == FBS9100_ComBase.CMD_Result_Success) {                    
                    comm_res = true;
                    dev_control_Str = "Æô¶¯KD²âÊÔ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_GetResTestState == m_FBS_Cmd.CMD){
                //------------------- ¶ÁÈ¡FBS9100ÄÚ×è²âÊÔ״̬ -----------------------
                if(true == m_ResTestState.putByteBuffer(bf)) {
                    comm_res = true;
                    msg = "Get ResTest State from FBS9100 OK!!!";
                }
            }else if(FBS9100_ComBase.CMD_GetDischargeState == m_FBS_Cmd.CMD){
                //------------------- ¶ÁÈ¡FBS9100ÈÝÁ¿²âÊÔ״̬ -----------------------
                if(true == m_CapTestState.putByteBuffer(bf)) {
                    comm_res = true;
                    msg = "Get CapTest State from FBS9100 OK!!!";
                }
            }else if(FBS9100_ComBase.CMD_GetChargeState == m_FBS_Cmd.CMD){
                //------------------- ¶ÁÈ¡FBS9100³äµç²âÊÔ״̬ -----------------------
                //System.out.println("¶ÁÈ¡³äµç״̬³É¹¦");
                if(true == m_ChrTestState.putByteBuffer(bf)) {
                    comm_res = true;
                    msg = "Get ChrTest State from FBS9100 OK!!!";
                }
            }else if(FBS9100_ComBase.CMD_GetBattParam == m_FBS_Cmd.CMD){
                //------------------- ¶ÁÈ¡FBS9100µç³Ø²ÎÊý -------------------------
                if(null == m_FBS_BattParam) {
                    m_FBS_BattParam = new FBS9100_ParamBatt();
                }
                if(true == m_FBS_BattParam.putByteBuffer(bf)) {
                    dev_param_data_state = DEV_PARAM_DATA_STATE_BATTQUERY;
                    comm_res = true;
                    dev_control_Str = "¶ÁÈ¡µç³Ø²ÎÊý³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_SetBattParam == m_FBS_Cmd.CMD) {
                //------------------- ÉèÖÃFBS9100µç³Ø²ÎÊý -------------------------
                if(true == m_FBS_BattParam.putByteBuffer(bf)) {
                    comm_res = true;
                    dev_control_Str = "ÉèÖÃµç³Ø²ÎÊý³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_GetSYSSetParam == m_FBS_Cmd.CMD){
                //------------------- ¶ÁÈ¡FBS9100ϵͳ²ÎÊý -------------------------
                if(null == m_FBS_SystemParam) {
                    m_FBS_SystemParam = new FBS9100_ParamSystem();
                }
                if(true == m_FBS_SystemParam.putByteBuffer(bf)) {
                    comm_res = true;
                    dev_param_data_state = DEV_PARAM_DATA_STATE_SYSQUERY;
                    dev_control_Str = "¶Áȡϵͳ²ÎÊý³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_SetSYSSetParam == m_FBS_Cmd.CMD){
                //------------------- ÉèÖÃFBS9100ϵͳ²ÎÊý -------------------------
                System.err.println(ComFn.bytesToHexString(bf.array(), bf.array().length));
                if(true == m_FBS_SystemParam.putByteBuffer(bf)) {
                    System.out.println("ÉèÖòÎÊý"+m_FBS_SystemParam);
                    comm_res = true;
                    dev_control_Str = "ÉèÖÃϵͳ²ÎÊý³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_GetDischargeParm == m_FBS_Cmd.CMD){
                //------------------- ¶ÁÈ¡FBS9100·Åµç²ÎÊý -------------------------
                if(true == m_FBS_DiscParamFromDev.putByteBuffer(bf)) {
                    comm_res = true;                    
                    dev_param_data_state = DEV_PARAM_DATA_STATE_DISQUERY;
                    dev_control_Str = "¶ÁÈ¡ºËÈݲÎÊý³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_SetDischargeParm == m_FBS_Cmd.CMD){
                //------------------- ÉèÖÃFBS9100·Åµç²ÎÊý -------------------------
                //if(true == m_FBS_DiscParam.putByteBuffer(bf)) {
                if(true == m_FBS_DiscParamFromDev.putByteBuffer(bf)) {
                    comm_res = true;
                    dev_control_Str = "ÉèÖÃµç³Ø²ÎÊý³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_GetChargeParm == m_FBS_Cmd.CMD){
                //------------------- ¶ÁÈ¡FBS9100³äµç²ÎÊý -------------------------
                if(true == m_FBS_ChargeParam.putByteBuffer(bf)) {
                    comm_res = true;
                    msg = "Get ChargeParam from FBS9100 OK!!!";
                }
            }else if(FBS9100_ComBase.CMD_SetChargeParm == m_FBS_Cmd.CMD){
                //------------------- ÉèÖÃFBS9100³äµç²ÎÊý -------------------------
                if(true == m_FBS_ChargeParam.putByteBuffer(bf)) {
                    comm_res = true;
                    msg = "Set ChargeParam to FBS9100 OK!!!";
                }
            }else if((FBS9100_ComBase.CMD_GetMonomerRES == m_FBS_Cmd.CMD)
                    ||(FBS9100_ComBase.CMD_GetMonomerTMP == m_FBS_Cmd.CMD)){
                //------------------- ¶ÁÈ¡FBS9100ÈÝÁ¿ÄÚ×è²âÊÔÊý¾Ý ------------------
                if(true == m_FBS_ResCapData.putByteBuffer(bf, m_FBS_Cmd.CMD)) {
                    comm_res = true;
                    msg = "Get MonomerCAP or MonomerRES from FBS9100 OK!!!";
                }
            }else if(FBS9100_ComBase.CMD_GetDeviceInf == m_FBS_Cmd.CMD) {
                if(true == deviceinf.putByteBuffer(bf)) {
                    comm_res = true;
                    m_BTSDevSoftType = deviceinf.DeviceType;
                    dev_stat_version = deviceinf.SoftwareVersion;
                    dev_stat_version_Str = String.format("%s-V%d.%02d.%02d-%s", 
                                                    deviceinf.getBTSDevTypeStr(),
                                                    deviceinf.DeviceVersion,
                                                    deviceinf.HardwareVersion,
                                                    deviceinf.SoftwareVersion,
                                                    checkDevAESVer());
                    //System.out.println(dev_stat_version_Str);
                    msg = "Get CMD_GetDeviceInf From FBS9100 OK: " + dev_stat_version_Str;
                    System.err.println("DevId:" + deviceinf.getDeviceId());
                }
            }else if(FBS9100_ComBase.CMD_GetDeviceTaskInf == m_FBS_Cmd.CMD){
                //------------------- ¶ÁÈ¡FBS9100ÈÎÎñÁбí -------------------------
                comm_res = true;
                m_TaskList = (bf);
                msg = "Get CMD_GetDeviceTaskInf From FBS9100 OK!!!";
            }else if(FBS9100_ComBase.CMD_SetVIData == m_FBS_Cmd.CMD || 
                    FBS9100_ComBase.CMD_SetMonomerRes == m_FBS_Cmd.CMD ||
                    FBS9100_ComBase.CMD_SetMonomerTMP == m_FBS_Cmd.CMD) {
                comm_res = true;
                msg = "Set Data Success ...... ";
            }else if(FBS9100_ComBase.CMD_ReadJunHengParam == m_FBS_Cmd.CMD) {
                //¶ÁÈ¡¾ùºâ²ÎÊý
                if(true == m_FBS_JHParamFromDev.putByteBuffer(bf)) {
                    comm_res = true;
                    dev_param_data_state = DEV_PARAM_DATA_STATE_SYSQUERY;
                    dev_control_Str = "¶Áȡϵͳ²ÎÊý³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_WriteJunHengParam == m_FBS_Cmd.CMD) {
                if(true == m_FBS_JHParamFromDev.putByteBuffer(bf)) {
                    comm_res = true;
                    dev_control_Str = "ÉèÖÃϵͳ²ÎÊý³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_GetHostWorkMode == m_FBS_Cmd.CMD) {
                //¶ÁÈ¡¿ØÖÆÐÅÏ¢
                if(true == m_FBS_SysControlFromDev.putByteBuffer(bf)) {
                    comm_res = true;
                    dev_param_data_state = DEV_PARAM_DATA_STATE_BATTQUERY;
                    dev_control_Str = "¶ÁÈ¡µç³Ø²ÎÊý³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }else if(FBS9100_ComBase.CMD_SetHostWorkMode == m_FBS_Cmd.CMD) {
                System.err.println(m_FBS_Cmd);
                if(true == m_FBS_SysControlFromDev.putByteBuffer(bf)) {
                    comm_res = true;
                    dev_control_Str = "ÉèÖÃµç³Ø²ÎÊý³É¹¦ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                }
            }
        }
        
        if(true == comm_res) {
            if(++comm_rx_cnt > 1000000) {
                comm_rx_cnt = 0;
            }
        }
        return comm_res;
    }
    /*********************************************************************************************/
    
    public void makeRandomData(int dt_cmd) {
        
        float targetCurr = 0;
        int testGroupNum = m_FBS_VCData.m_SysState.TestGroupNum;        //²âÊÔ×éºÅ
        int workState = m_FBS_VCData.m_SysState.WorkState;                //É豸¹¤×÷״̬
        float groupVolLimit = 0;                                        //×é¶Ëµçѹ
        int eveBattGroupNum = 0;                                        //ÿ×éµ¥Ìå¸öÊý
        eveBattGroupNum = m_FBS_VCData.battSum/m_FBS_VCData.battGroup;
        boolean isTest = false;
        //System.out.println("³äµçµçÁ÷£º"+m_FBS_DiscParamFromDev.ChargeCurrSet);
        if((m_FBS_VCData.m_SysState.WorkState == FBS9100_SysState.SYS_STATE_DISCHARGING && m_FBS_VCData.m_SysState.TestType!=FBS9100_ComBase.TestType_SwitchDiode)) {
            //·Åµç²âÊÔ            
            targetCurr = m_FBS_DiscParamFromDev.DisCurr;
            groupVolLimit = 35f;
            isTest = true;
            alearyMaxCurr = false;
        }else if(m_FBS_VCData.m_SysState.WorkState == FBS9100_SysState.SYS_STATE_CHARGING){
            m_FBS_VCData.m_SysState.checkState();
            //³äµç²âÊÔ            
            if(m_FBS_VCData.m_SysState.getCharTestTime() >60) {
                //·Ç¾²ÖÃʱ
                targetCurr = m_FBS_DiscParamFromDev.ChargeCurrSet;
                groupVolLimit = 53.5f;
                isTest = true;
                if(Math.abs(m_FBS_VCData.battcurr[testGroupNum-1] - targetCurr) <= 0.5) {
                    alearyMaxCurr = true;
                    targetCurr = 1;
                }
            }else {
                alearyMaxCurr = false;
                //Ä£Äâ¾²ÖÃ
                targetCurr =  0;
            }            
        }else if(m_FBS_VCData.m_SysState.WorkState == FBS9100_SysState.SYS_STATE_STOPPED){
            //¸¡³äʱ
            alearyMaxCurr = false;
        }
        
        //System.err.println("Start:"+alearyMaxCurr+"####²âÊÔʱ³¤£º"+m_FBS_VCData.m_SysState.getCharTestTime()+"&&targetCurr:"+targetCurr);
        
//        System.err.println("ϵͳ¹¤×÷״̬£º"+m_FBS_VCData.m_SysState.WorkState + "\t±»²â×éºÅ£º" + m_FBS_VCData.m_SysState.TestGroupNum+
//                            "\n ·ÅµçµçÁ÷£º"+m_FBS_DiscParamFromDev.DisCurr + "\tÏÞÖÆµçÁ÷£º"+targetCurr) ;
        for(int i = 0 ; i< m_FBS_VCData.onlinevol.length;i++) {            
            if((i+1) == testGroupNum && (workState == FBS9100_SysState.SYS_STATE_CHARGING || workState == FBS9100_SysState.SYS_STATE_DISCHARGING)) {
                //²âÊÔʱ
                
                m_FBS_VCData.onlinevol[i] = (double)FBS9100_ComBase.CreateIntRanDom(5350,5360)/100;                
                m_FBS_VCData.batttemp[i] = (double)FBS9100_ComBase.CreateIntRanDom(200,400)/10;
 
                //m_FBS_VCData.groupvol[i] = (double)FBS9100_ComBase.CreateIntRanDom(5310,5690)/100;
                //m_FBS_VCData.battcurr[i] = (double)FBS9100_ComBase.CreateIntRanDom(0,30)/10;
                if(workState == FBS9100_SysState.SYS_STATE_CHARGING) {
                    if(alearyMaxCurr) {
                        //³äµçʱ£¬ÈôÔÚÏßµçѹºÍ×é¶Ëµçѹѹ²îСÓÚµÈÓÚ4V,Ä£ÄâµçÁ÷ϽµÖÁ1A×óÓÒ
                        float testCurr = 0;    
                        double test_curr = m_FBS_VCData.battcurr[testGroupNum-1];
                        if(test_curr > (testCurr+1)) {                        
                            m_FBS_VCData.battcurr[testGroupNum-1] = m_FBS_VCData.battcurr[testGroupNum-1] - (double)FBS9100_ComBase.CreateIntRanDom(0,5)/10;
                        }else {                        
                            m_FBS_VCData.battcurr[testGroupNum-1] = testCurr + (double)FBS9100_ComBase.CreateIntRanDom(0,10)/10;
                        }
                    }else if(m_FBS_VCData.m_SysState.getCharTestTime() >60){
                        //»¹Î´µÖ´ï×î´óµçÁ÷
                        m_FBS_VCData.setRandomTestCurr(testGroupNum, targetCurr);
                    }else {
                        //¾²ÖÃ
                        m_FBS_VCData.battcurr[i] = (double)FBS9100_ComBase.CreateIntRanDom(0,10)/10;
                    }
                    
                    
                    
                }else {    
                    m_FBS_VCData.setRandomTestCurr(testGroupNum, targetCurr);
                }
                
            }else {            
                m_FBS_VCData.onlinevol[i] = (double)FBS9100_ComBase.CreateIntRanDom(5350,5360)/100;
                //m_FBS_VCData.groupvol[i] = (double)FBS9100_ComBase.CreateIntRanDom(5310,5690)/100;
                m_FBS_VCData.battcurr[i] = (double)FBS9100_ComBase.CreateIntRanDom(0,30)/10;
                m_FBS_VCData.batttemp[i] = (double)FBS9100_ComBase.CreateIntRanDom(200,400)/10;
            
            }        
        }
        if(FBS9100_ComBase.CMD_SetVIData == dt_cmd) {            
            for(int i = 0 ;i<m_FBS_VCData.vol.length;i++) {
                if(isTest && (i >= (testGroupNum-1)*eveBattGroupNum) && (i<(testGroupNum)*eveBattGroupNum)) {
                    if(m_FBS_VCData.m_SysState.WorkState == FBS9100_SysState.SYS_STATE_DISCHARGING) {
                        //·Åµçʱµ¥Ìåµçѹ
                        m_FBS_VCData.vol[i] = RandomDisMonVol(m_FBS_VCData.vol[i]);
                        //System.out.println("·Åµç²âÊÔÖÐ#"+(i+1)+":"+m_FBS_VCData.vol[i]);
                    }else{            
                        //³äµçʱµ¥Ìåµçѹ
                        m_FBS_VCData.vol[i] = RandomChrMonVol(m_FBS_VCData.vol[i]);    
                        //System.out.println("³äµç²âÊÔÖÐ#"+(i+1)+":"+m_FBS_VCData.vol[i]);
                    }
                }else {
                    m_FBS_VCData.vol[i] = (double)FBS9100_ComBase.CreateIntRanDom(2229,2231)/1000;
                }
                
            }
            
            for(int n = 0;n<m_FBS_VCData.groupvol.length;n++) {
                double sumVol = 0;
                for(int k = (n*eveBattGroupNum);k<((n+1)*eveBattGroupNum);k++) {
                    sumVol += m_FBS_VCData.vol[k];
                }        
                m_FBS_VCData.groupvol[n] = sumVol;
            }
        }
        if(FBS9100_ComBase.CMD_SetMonomerRes == dt_cmd) {            
            for(int i = 0 ;i<m_FBS_ResCapData.m_res.length;i++) {
                m_FBS_ResCapData.m_res[i] = (double)FBS9100_ComBase.CreateIntRanDom(99,1000)/1000;
            }
        }
        if(FBS9100_ComBase.CMD_SetMonomerTMP == dt_cmd) {            
            for(int i = 0 ;i<m_FBS_ResCapData.m_tmp.length;i++) {
                m_FBS_ResCapData.m_tmp[i] = (double)FBS9100_ComBase.CreateIntRanDom(200,400)/10;
            }
        }
        
        
        
        System.err.println("End:"+alearyMaxCurr);
        //System.out.println("m_res[i]:" + Arrays.toString(m_FBS_ResCapData.m_res));
        //System.out.println("m_tmp[i]:" + Arrays.toString(m_FBS_ResCapData.m_tmp));
    }
    
    //Ä£Äâ·Åµçʱµ¥Ìåµçѹ
    public static double RandomDisMonVol(double monvol) {        
        if(monvol <= 1.7) {
            return (double)FBS9100_ComBase.CreateIntRanDom(1690,1710)/1000;
        }else {
            return monvol - (double)FBS9100_ComBase.CreateIntRanDom(0,2)/10000;
        }
    }
    
    //Ä£Äâ³äµçʱµ¥Ìåµçѹ
    public static double RandomChrMonVol(double monvol) {
        if(monvol >= 2.230) {
            return (double)FBS9100_ComBase.CreateIntRanDom(2229,2231)/1000;
        }else {
            return monvol + (double)FBS9100_ComBase.CreateIntRanDom(0,10)/10000;
        }    
    }
    
    public String checkDevAESVer() {
        String msg = "·Ç¼ÓÃÜ";
        if(DEV_DATA_ENCIPHER) {
            msg = "¼ÓÃÜ";
        }
        return msg;
    }
    
    public static void main(String[] args) {
        for(int i  =0 ;i<100;i++) {
            System.out.println(RandomDisMonVol(2.16));
            
        }
    }
    
    public void addRXData() {
        if(++comm_rx_cnt > 1000000) {
            comm_rx_cnt = 0;
        }
    }
}