DELL
2025-04-28 e6eb7fb0af366e370f125668d62e89eb0004f517
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
package com.dev.fbs9600_mon;
import gnu.io.SerialPort;
 
import java.awt.Toolkit;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Date;
import java.util.zip.CRC32;
 
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.SP_COMM;
import main.page_debug_inf;
 
import com.Com;
import com.Crc16;
import com.PlaySound;
import com.app.reg.RegistCoade;
 
public class SPCommMon implements Runnable/*, SerialPortEventListener*/ {
    public static final int COMM_PORT_TYPE_Serial = 0;
    public static final int COMM_PORT_TYPE_Socket = 1;
    
    public static final short CMD_TYPE_READ = 0x03;
    public static final short CMD_TYPE_WRITE = 0x05;
    
    public static final short UART_MonVolSetAddr_RegAddr = 0x000B;
    public static final short UART_MonVol1AdjSlope_RegAddr = 0x000C;
    public static final short UART_MonTmp1AdjSlope_RegAddr = 0x000D;
    public static final short UART_MonVol1AdjOffset_RegAddr = 0x000E;
    public static final short UART_MonVol1AdjReset_RegAddr  = 0x000F;
    public static final short UART_MonVol2AdjSlope_RegAddr = 0x00010;
    public static final short UART_MonTmp2AdjSlope_RegAddr = 0x00011;
    public static final short UART_MonVol2AdjOffset_RegAddr = 0x0012;
    public static final short UART_MonVol2AdjReset_RegAddr  = 0x0013;
    
    public static final short UART_CurrAddrSet_RegAddr = 0x1010;
    public static final short UART_CurrRangeSet_RegAddr = 0x1011;
    public static final short UART_CurrOffset_RegAddr = 0x1012;
    public static final short UART_SetCurrSlope_RegAddr = 0x1013;
    public static final short UART_CurrTestStart_RegAddr = 0x1014;
    public static final short UART_CurrFloat_Offset_RegAddr = 0x1016;    //ÇåÁ㸡³äµçÁ÷Áãµã
    public static final short UART_SetCurrFloat_Slope_RegAddr = 0x1017;    //У׼¸¡³äµçÁ÷бÂÊ
    
    public static final short UART_MonomerSetJunHengVol_RegAddr = 0x0008;
    public static final short UART_MonomerClrTmpAddr_RegAddr = 0x0009;
    public static final short UART_MonomerLowSign_RegAddr = 0x000A;
    public static final short UART_MonomerSetAddr_RegAddr = 0x000B;
    public static final short UART_MonomerResTest_RegAddr = 0x000C;
    public static final short UART_MonomerAdjVol_RegAddr  = 0x000D;
    public static final short UART_MonomerAdjTemp_RegAddr = 0x000E;
    public static final short UART_MonomerAdjRes_RegAddr  = 0x000F;
    public static final short UART_MonomerAdjOffSet_RegAddr = 0x0010;    //Æ«ÒÆÁ¿
    public static final short UART_MonomerAdjReset_RegAddr = 0x0011;    //¸´Î»
    public static final short UART_MonomerDFU_RegAddr = 0x0012;            //Æô¶¯dfu
    
    public static final byte CMD_FBS9100_WriteDFU = (byte) 0x86;
    public static final byte CMD_FBS9100_ReadDFU = (byte) 0x87;
    
    public static final byte BOOTLOADER_CMD_QUIT = 0;
    public static final byte BOOTLOADER_CMD_GETINF = 1;
    public static final byte BOOTLOADER_CMD_WRITE = 2;
    public static final byte BOOTLOADER_CMD_READ = 3;
    
    public static final int DEV_TYPE_MON_SAMD09 = 0;
    public static final int DEV_TYPE_MON_MSP430 = 1;
    public static final int DEV_TYPE_MON_MSP430_RF = 2;
    public static final int DEV_TYPE_MON_SWM = 3;        //»ªÐ¾ÍþÌØmcu
    public static final int DEV_TYPE_Curr = 100;
    public static final int DEV_TYPE_GroupVol = 110;
    public static final int DEV_TYPE_FCF651GroupVol = 111;
    public static final int DEV_TYPE_NTM = 120;
    public static final int DEV_TYPE_BYBB = 130;
    
    public int m_DEV_TYPE = DEV_TYPE_FCF651GroupVol;
 
    private SP_COMM m_COMM = null; 
    private SPCommMon_DFU m_SPCommDFU = null;
    
    // ÊäÈëÊä³öÁ÷
    public InputStream inputStream;
    public OutputStream outputStream;
    // RS-232µÄ´®ÐпÚ
    public SerialPort serialPort;
    
    public boolean CommThreadRunning = false;
    private ByteBuffer CommRxBuffer = ByteBuffer.allocate(512); 
    private ByteBuffer CommTxBuffer = ByteBuffer.allocate(512);
    
    public int comm_tx_cnt = 0;
    public int comm_rx_cnt = 0;
    
    public short comm_OK_cnt = 0;
    public short comm_Err_cnt = 0;
    public boolean dt_new_tag = false;
    
    private int comm_bautrate = 9600;
    public int dt_target_addr = 0;
    public short dt_dfu_addr_start = 0;
    public short dt_dfu_addr_end = 0;
    public short dt_addr = 0;
    public short dt_junhengcurr = 0;
    public short dt_vol = 0;
    public short dt_tmp = 0;
    public short dt_abn_curr = 0;
    public int dt_res = 0;
    public int dt_res_conn = 0;
    public short dt_louye = 0;
    public short dt_version = 0;
    public short dt_voltype = -1;
    public int dt_rescurr = 0;
    public int dt_res_asyscode = 0;
    public int dt_lockpage_count = 0;
    public int dt_ssb = 0;
    public short mAddrSettedNow = 0;
    public int mBianHao_TestRes = -1;
    public boolean mBianHaoPIN_Low = false;
    
    //----------------------------------------------------------//
    public short dt_curr = 0;
    public short dt_curr_dir = 0;
    public short dt_curr_float = 0;
    public short dt_curr_float_dir = 0;
    public short dt_peakavg_curr = 0;
    public int dt_peak_curr = 0;
    public int dt_currrange = 0;
    public int dt_curr_slope = 0;
    public int dt_curr_float_slope = 0;
    //----------------------------------------------------------//
    public short dt_vol_1 = 0;
    public short dt_tmp_1 = 0;
    public short dt_vol_2 = 0;
    public short dt_tmp_2 = 0;
    //----------------------------------------------------------//
    
    private short dt_cmd = CMD_TYPE_READ;
    private short dt_cmd_regaddr = 0;
    private short dt_cmd_regcnt = 0;
    private short dt_cmd_data = 0;
    private short dt_cmd_data1 = 0;
    private boolean dt_cmd_guangbo = false;
    
    private boolean dt_normal_comm_en = true;
    public boolean dt_update_en = false;
    private String dt_update_file = "";
    private int dt_dfu_bitrate = 9600;
    boolean dt_dfu_read_check_en = false;
    public JTextArea dt_show_dfu_inf = null;
    public String dt_set_addr_res_inf = "";
    public char[] dt_dfu_pwd = new char[6];
    public Date dt_app_start_time = new Date();
    public char[] dt_dfu_pwd_auto = new char[6];
    private String dt_dfu_pwd_sn = "";
    int dt_multy_comm_type = CommSerialPort.mutycomm_Type_Samd09;
    
    private JTextField addr_TextField = null;
    
    private boolean cmd_Null_En = false;
    
    private page_debug_inf dt_debug_inf;
    private int m_COMM_PORT_TYPE = 0;
    
    private Logger m_Log = null;
    
    public SPCommMon(int addr_t, int bitrate, int dev_type, int multy_com_type, 
                    JTextArea show_dfu_inf, page_debug_inf debug, Logger log) {
        dt_target_addr = addr_t & 0xFFFF;
        comm_bautrate = bitrate;
        dt_multy_comm_type = multy_com_type;
        dt_show_dfu_inf = show_dfu_inf;
        dt_debug_inf = debug;
        //-------------------------------------------------------------//
        m_DEV_TYPE = dev_type;
        //-------------------------------------------------------------//
        dt_dfu_pwd_sn = RegistCoade.getRegistSerialCoade("amtb_amtb_amtb", "37373737");
        CRC32 crc = new CRC32();
        crc.update((dt_dfu_pwd_sn + "ÄÏÎÞ°¢ÃÖÍÓ·ð").getBytes());
        char[] tmp_char = String.format("%06d", Math.abs(crc.getValue())%1000000).toCharArray();
        for(int n=0; n<dt_dfu_pwd_auto.length; n++) {
            dt_dfu_pwd_auto[n] = tmp_char[n];
        }
        //-------------------------------------------------------------//
        dt_show_dfu_inf.setText(dt_dfu_pwd_sn);
        m_Log = log;
    }
    
    public SPCommMon(JTextField addr_t, int bitrate, int dev_type, int multy_com, 
                        JTextArea show_area, page_debug_inf debug, Logger log) {
        //dt_target_addr = addr_t & 0xFFFF;
        addr_TextField = addr_t;
        comm_bautrate = bitrate;
        dt_multy_comm_type = multy_com;
        dt_show_dfu_inf = show_area;
        dt_debug_inf = debug;
        //-------------------------------------------------------------//
        m_DEV_TYPE = dev_type;
        //-------------------------------------------------------------//
        dt_dfu_pwd_sn = RegistCoade.getRegistSerialCoade("amtb_amtb_amtb", "37373737");
        CRC32 crc = new CRC32();
        crc.update((dt_dfu_pwd_sn + "ÄÏÎÞ°¢ÃÖÍÓ·ð").getBytes());
        char[] tmp_char = String.format("%06d", Math.abs(crc.getValue())%1000000).toCharArray();
        for(int n=0; n<dt_dfu_pwd_auto.length; n++) {
            dt_dfu_pwd_auto[n] = tmp_char[n];
        }
        //-------------------------------------------------------------//
        dt_show_dfu_inf.setText(dt_dfu_pwd_sn);
        m_Log = log;
    }
    
    public void setCmdNullEn(boolean en_st) {
        cmd_Null_En = en_st;
    }
    
    public void setCommAddr(int addr_t) {
        dt_target_addr = addr_t & 0xFFFF;
    }
    
    public void setDfuCommAddr(int addr_start_t, int addr_end_t) {
        dt_dfu_addr_start = (short) (addr_start_t & 0xFFFF);
        setCommAddr(dt_dfu_addr_start);
        dt_dfu_addr_end = (short) (addr_end_t & 0xFFFF);
    }
    
    public void setCommBautrate(int bt_rate) {
        if(COMM_PORT_TYPE_Serial != m_COMM_PORT_TYPE) {
            return;
        }
        
        //comm_bautrate = bt_rate;
        //System.out.println("setCommBautrate:" + bt_rate);
        m_COMM.m_SP_Comm.setCommBautrate(bt_rate);// .serialPort.setSerialPortParams(bt_rate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    }
    
    public String getBianHaoTest_Str() {
        String str = "δ²âÊÔ";
        
        if(1 == mBianHao_TestRes) {
            str = "À­µÍ¹ÊÕÏ";
        } else if(2 == mBianHao_TestRes) {
            str = "À­¸ß¹ÊÕÏ";
        } if(0 == mBianHao_TestRes) {
            str = "²âÊÔÕý³£";
        }
        
        return str;
    }
    
    //³õʼ»¯´®¿Ú
    public boolean OpenCommPort(int comm_port_type, String comm_name_or_ip, int bitrate_or_comm_port) {
        m_COMM = new SP_COMM(comm_port_type, 12345, m_Log);
        boolean res = m_COMM.openCommPort(comm_name_or_ip, bitrate_or_comm_port);
        if(true == res) {
            CommTxBuffer.order(ByteOrder.BIG_ENDIAN);
            CommRxBuffer.order(ByteOrder.BIG_ENDIAN);
            
            comm_tx_cnt = 0;
            comm_rx_cnt = 0;
            CommThreadRunning = true;
        }
        /*
        boolean res = false;
        m_COMM_PORT_TYPE = comm_port_type;
        if(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);
            comm_tx_cnt = 0;
            comm_rx_cnt = 0;
            CommThreadRunning = true;
        }
        
        return res;
    }
    
    private void makeCommTxData() {
        CommTxBuffer.clear();
        
        if(null != addr_TextField) {
            dt_target_addr = (short) Integer.parseInt(addr_TextField.getText()) & 0xFFFF;
        }
        
        if(CMD_TYPE_READ == dt_cmd) {
            CommTxBuffer.put((byte) dt_target_addr);
            CommTxBuffer.put((byte) 0x03);
            CommTxBuffer.put((byte) 0x00);
            CommTxBuffer.put((byte) 0x00);
            CommTxBuffer.put((byte) 0x00);
            CommTxBuffer.put((byte) 0x16);
        } else {
            byte addr_tmp = (byte) dt_target_addr;
            if(true == dt_cmd_guangbo) {
                addr_tmp = (byte) 255;
            }
            CommTxBuffer.put(addr_tmp);
            CommTxBuffer.put((byte) 0x05);
            CommTxBuffer.put((byte) (dt_cmd_regaddr>>8));
            CommTxBuffer.put((byte) dt_cmd_regaddr);
            CommTxBuffer.put((byte) (dt_cmd_regcnt>>8));
            CommTxBuffer.put((byte) dt_cmd_regcnt);
            CommTxBuffer.put((byte) (dt_cmd_data>>8));
            CommTxBuffer.put((byte) dt_cmd_data);
            CommTxBuffer.put((byte) (dt_cmd_data1>>8));
            CommTxBuffer.put((byte) dt_cmd_data1);
            dt_cmd = CMD_TYPE_READ;
            dt_cmd_guangbo = false;
        }
        
        int crc = Crc16.CalCRC16(CommTxBuffer, CommTxBuffer.position()) & 0xFFFF;
        CommTxBuffer.putShort((short) (crc>>8 | crc<<8));
        CommTxBuffer.flip();
    }
    
    private void makeVolModule_CommTxData() {
        CommTxBuffer.clear();
        
        if(null != addr_TextField) {
            dt_target_addr = (short) Integer.parseInt(addr_TextField.getText()) & 0xFFFF;
        }
        
        if(CMD_TYPE_READ == dt_cmd) {
            CommTxBuffer.put((byte) dt_target_addr);
            CommTxBuffer.put((byte) 0x03);
            CommTxBuffer.put((byte) 0x00);
            CommTxBuffer.put((byte) 0x00);
            CommTxBuffer.put((byte) 0x00);
            CommTxBuffer.put((byte) 0x09);
        } else {
            CommTxBuffer.put((byte) dt_target_addr);
            CommTxBuffer.put((byte) 0x05);
            CommTxBuffer.put((byte) (dt_cmd_regaddr>>8));
            CommTxBuffer.put((byte) dt_cmd_regaddr);
            CommTxBuffer.put((byte) (dt_cmd_regcnt>>8));
            CommTxBuffer.put((byte) dt_cmd_regcnt);
            CommTxBuffer.put((byte) (dt_cmd_data>>8));
            CommTxBuffer.put((byte) dt_cmd_data);
            dt_cmd = CMD_TYPE_READ;
        }
        
        int crc = Crc16.CalCRC16(CommTxBuffer, CommTxBuffer.position()) & 0xFFFF;
        CommTxBuffer.putShort((short) (crc>>8 | crc<<8));
        CommTxBuffer.flip();
    }
    
    private void makeCurrModule_CommTxData() {
        CommTxBuffer.clear();
        
        if(null != addr_TextField) {
            dt_target_addr = (short) Integer.parseInt(addr_TextField.getText()) & 0xFFFF;
        }
        
        if(CMD_TYPE_READ == dt_cmd) {
            CommTxBuffer.put((byte) dt_target_addr);
            CommTxBuffer.put((byte) 0x03);
            CommTxBuffer.put((byte) 0x10);
            CommTxBuffer.put((byte) 0x00);
            CommTxBuffer.put((byte) 0x00);
            if(dt_version < 20) {
                CommTxBuffer.put((byte) 8);
            } else {
                CommTxBuffer.put((byte) 11);
            }
        } else {
            CommTxBuffer.put((byte) dt_target_addr);
            CommTxBuffer.put((byte) 0x05);
            CommTxBuffer.put((byte) (dt_cmd_regaddr>>8));
            CommTxBuffer.put((byte) dt_cmd_regaddr);
            CommTxBuffer.put((byte) (dt_cmd_regcnt>>8));
            CommTxBuffer.put((byte) dt_cmd_regcnt);
            CommTxBuffer.put((byte) (dt_cmd_data>>8));
            CommTxBuffer.put((byte) dt_cmd_data);
            dt_cmd = CMD_TYPE_READ;
        }
        
        int crc = Crc16.CalCRC16(CommTxBuffer, CommTxBuffer.position()) & 0xFFFF;
        CommTxBuffer.putShort((short) (crc>>8 | crc<<8));
        CommTxBuffer.flip();
    }
    
    private void makeCommTxDataNull() {
        CommTxBuffer.clear();
        CommTxBuffer.put((byte) 0xFF);
        CommTxBuffer.put((byte) 0x00);
        CommTxBuffer.put((byte) (0));
        CommTxBuffer.put((byte) 0);
        CommTxBuffer.put((byte) (0));
        CommTxBuffer.put((byte) 0);
        CommTxBuffer.put((byte) 0);
        CommTxBuffer.put((byte) 0);
        
        int crc = Crc16.CalCRC16(CommTxBuffer, CommTxBuffer.position()) & 0xFFFF;
        CommTxBuffer.putShort((short) (crc>>8 | crc<<8));
        CommTxBuffer.flip();
    }
    
    private boolean checkCommBuf(ByteBuffer buf_t) {
        boolean res = false;
        if(buf_t.limit() >= 5) {
            buf_t.position(buf_t.limit()-2);
            int crc = buf_t.getShort() & 0xFFFF;
            crc = ((crc>>8) | (crc<<8)) & 0xFFFF;
            int crc_cal = Crc16.CalCRC16(buf_t, buf_t.limit()-2) & 0xFFFF;
            /*************************************************/
            if(crc_cal == crc) {
                res = true;
            }
            /*************************************************/
        } else {
            res = false;
        }
        
        return res;
    }
    
    public void tr_Msg(ByteBuffer bbf_tx, ByteBuffer bbf_rx, boolean showdat) {
        if(++comm_tx_cnt > 32500) {
            comm_tx_cnt = 0;
        }
        m_COMM.tr_Msg(bbf_tx, bbf_rx, dt_multy_comm_type, dt_debug_inf, showdat);
        /*
        if(COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) {
            m_COMM.m_SP_Comm.SP_Comm(bbf_tx, bbf_rx, dt_multy_comm, dt_debug_inf, showdat);
        } else {
            m_SocketComm.SocketComm(bbf_tx, bbf_rx, dt_debug_inf, showdat);
        }
        */
    }
    
    private void closeCommPort() {
        m_COMM.closeCommPort();
        /*
        if(COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) {
            m_SP_Comm.serialPort.close();
        } else {
            m_SocketComm.socketClose();
        }
        */
    }
    
    public void exitCommPortThread() {
        CommThreadRunning = false;
        setUpdateCmd(false, false, "", comm_bautrate);
    }
    
    public void setCommCmd(short cmd, short cmd_reg_addr, short cmd_reg_cnt, 
                            short cmd_data, short cmd_data1) {
        dt_cmd = cmd;
        dt_cmd_regaddr = cmd_reg_addr;
        dt_cmd_regcnt = cmd_reg_cnt;
        dt_cmd_data = cmd_data;
        dt_cmd_data1 = cmd_data1;
        
        if(UART_MonomerLowSign_RegAddr == dt_cmd_regaddr) {
            mBianHao_TestRes = -1;
        }
    }
    public void setCommCmd_gb(short cmd, short cmd_reg_addr, short cmd_reg_cnt, 
                            short cmd_data, short cmd_data1, boolean guangbo_t) {
        dt_cmd = cmd;
        dt_cmd_regaddr = cmd_reg_addr;
        dt_cmd_regcnt = cmd_reg_cnt;
        dt_cmd_data = cmd_data;
        dt_cmd_data1 = cmd_data1;
        
        dt_cmd_guangbo = guangbo_t;
        
        if(UART_MonomerLowSign_RegAddr == dt_cmd_regaddr) {
            mBianHao_TestRes = -1;
        }
    }
    
    public void clearResDataBuf() {
        dt_res = -1;
        dt_rescurr = -1;
        dt_res_asyscode = -1;
    }
    
    public void setUpdateCmd(boolean update_en, boolean read_ckeck_en, String filepath, int dfu_bitrate) {
        dt_update_en = update_en;
        dt_dfu_read_check_en = read_ckeck_en;
        dt_update_file = filepath;
        dt_dfu_bitrate = dfu_bitrate;
        
        if(false == dt_update_en) {
            if(null != m_SPCommDFU) {
                m_SPCommDFU.setDFUCommState(false, false);
            }
        }
    }
    
    public void setNormalCommState(boolean stat) {
        dt_normal_comm_en = stat;
    }
    
    private void processRxData(ByteBuffer bbf_rx, boolean check_en) {
        if(false == checkCommBuf(bbf_rx)) {
            if(true == check_en) {
                comm_OK_cnt = 0;
            }
            
            if((comm_OK_cnt<1) && (0==dt_res)) {
                dt_new_tag = false;
            }
            
            return;
        }
        
        if(bbf_rx.limit() > 16) {
            bbf_rx.position(0);
            dt_addr = bbf_rx.get();
            bbf_rx.get();
            bbf_rx.get();
            int tmp_val = bbf_rx.getShort()&0xFFFF;
            if((tmp_val & 0x8000) > 0) {
                dt_junhengcurr = (short) ((short)(tmp_val&(~0x8000)) * (-1));
            } else {
                dt_junhengcurr = (short)(tmp_val);
            }
            dt_vol = bbf_rx.getShort();
            dt_tmp = bbf_rx.getShort();
            dt_abn_curr = bbf_rx.getShort();
            dt_res = (int) (bbf_rx.getShort()&0xFFFF);
            dt_addr = bbf_rx.getShort();
            dt_version = bbf_rx.getShort();
            //dt_voltype = bbf_rx.getShort();
            
            short vol_type = bbf_rx.getShort();
            mBianHaoPIN_Low = ((vol_type&(1<<8)) > 0);
            dt_voltype = (short) (vol_type & 0x7F);
            
            dt_rescurr = (int)(bbf_rx.getShort()&0xFFFF);
            if(bbf_rx.hasRemaining()) {
                dt_res_asyscode = (int)(bbf_rx.getShort()&0xFFFF);
            }
            if(bbf_rx.hasRemaining()) {
                if(dt_version > 1000) {
                    dt_louye = (short) (bbf_rx.getShort()&0xFFFF);
                    dt_res_conn = (int) (bbf_rx.getShort()&0xFFFF);
                }
            }
            if(bbf_rx.hasRemaining()) {
                if(DEV_TYPE_MON_SWM == m_DEV_TYPE) {
                    dt_lockpage_count = (int)(bbf_rx.getShort());
                } else {
                    dt_lockpage_count = (int)(bbf_rx.getShort()&0xFFFF);
                }
            }
            if(bbf_rx.hasRemaining()) {
                dt_ssb = (int)(bbf_rx.getShort()&0xFFFF);
            }
            
            if(++comm_rx_cnt > 32500) {
                comm_rx_cnt = 0;
            }
            if(comm_OK_cnt < 1000) {
                comm_OK_cnt += 1;
            }
            
            if((comm_OK_cnt > 3) && (comm_OK_cnt < 5)) {
                if(0 == dt_res) {
                    dt_new_tag = true;
                    mBianHao_TestRes = -1;
                } else {
                    dt_new_tag = false;
                }
            }
        }
    }
    
    private void processVolModule_RxData(ByteBuffer bbf_rx) {
        if(false == checkCommBuf(bbf_rx)) {
            return;
        }
        
        if(bbf_rx.limit() >= 17) {
            bbf_rx.position(0);
            dt_addr = bbf_rx.get();
            bbf_rx.get();//cmd
            bbf_rx.get();//bytes
            dt_vol_1 = bbf_rx.getShort();
            dt_tmp_1 = bbf_rx.getShort();
            dt_vol_2 = bbf_rx.getShort();
            dt_tmp_2 = bbf_rx.getShort();
            
            bbf_rx.getShort();
            dt_version = bbf_rx.getShort();
            dt_voltype = bbf_rx.getShort();
            dt_lockpage_count = bbf_rx.getShort();
            dt_ssb = bbf_rx.getShort();
            
            if(++comm_rx_cnt > 32500) {
                comm_rx_cnt = 0;
            }
            if(comm_OK_cnt < 1000) {
                comm_OK_cnt += 1;
            }
        }
    }
    
    private void processCurrModule_RxData(ByteBuffer bbf_rx) {
        if(false == checkCommBuf(bbf_rx)) {
            return;
        }
        
        if(bbf_rx.limit() >= 17) {
            bbf_rx.position(0);
            dt_addr = bbf_rx.get();
            bbf_rx.get();//cmd
            bbf_rx.get();//bytes
            short ver = bbf_rx.getShort();
            bbf_rx.getShort();
            dt_curr = bbf_rx.getShort();
            dt_curr_dir = bbf_rx.getShort();
            dt_peakavg_curr = bbf_rx.getShort();
            dt_peak_curr = bbf_rx.getShort();
            dt_currrange = bbf_rx.getShort();
            dt_curr_slope = bbf_rx.getShort();
            if((dt_version >= 20) && (bbf_rx.remaining()>=6)) {
                dt_curr_float = bbf_rx.getShort();
                dt_curr_float_dir = bbf_rx.getShort();
                dt_curr_float_slope = bbf_rx.getShort();
            }
            dt_version = ver;
            
            if(++comm_rx_cnt > 32500) {
                comm_rx_cnt = 0;
            }
            if(comm_OK_cnt < 1000) {
                comm_OK_cnt += 1;
            }
        }
    }
    
    public void run() {
        int null_comm_cmd_cnt = 0;
        while(true == CommThreadRunning) {
            
            if(false == dt_update_en) {
                try {
                    if(false == dt_normal_comm_en) {
                        Thread.sleep(100);
                        continue;
                    }
                    
                    boolean cmd_set_addr = ((CMD_TYPE_WRITE==dt_cmd) && (UART_MonomerSetAddr_RegAddr==dt_cmd_regaddr));
                    boolean cmd_Set_bianhao_Low = ((CMD_TYPE_WRITE==dt_cmd) && (UART_MonomerLowSign_RegAddr==dt_cmd_regaddr));
                    boolean cmd_Set_bianhao_High = ((CMD_TYPE_WRITE==dt_cmd) && (UART_MonomerClrTmpAddr_RegAddr==dt_cmd_regaddr));
                    
                    if(true == dt_update_en) {
                        continue;
                    }
                    if(null_comm_cmd_cnt < 300) {
                        null_comm_cmd_cnt++;
                    } else {
                        null_comm_cmd_cnt = 0;
                    }
                    //---------------------- make tx data --------------------------//
                    if(SPCommMon.DEV_TYPE_Curr == m_DEV_TYPE) {
                        makeCurrModule_CommTxData();
                    } else if(SPCommMon.DEV_TYPE_GroupVol == m_DEV_TYPE) {
                        makeVolModule_CommTxData();
                    } else {
                        if((null_comm_cmd_cnt % 10) == 0) {
                            if(true == cmd_Null_En) {
                                makeCommTxDataNull();
                            } else {
                                makeCommTxData();
                            }
                        } else {
                            makeCommTxData();
                        }
                    }
                    //----------------------- tx rx data ---------------------------//
                    tr_Msg(CommTxBuffer, CommRxBuffer, true);
                    //----------------------- process data -------------------------//
                    if(SPCommMon.DEV_TYPE_Curr == m_DEV_TYPE) {
                        processCurrModule_RxData(CommRxBuffer);
                    } else if(SPCommMon.DEV_TYPE_GroupVol == m_DEV_TYPE) {
                        processVolModule_RxData(CommRxBuffer);
                    } else {
                        processRxData(CommRxBuffer, (false==cmd_Set_bianhao_Low)&&(false==cmd_Set_bianhao_High)&&(false==cmd_set_addr));
                    }
                    //-------------------------------------------------------------//
                    
                    Thread.sleep(100);
                    
                    if(true == cmd_set_addr) {
                        makeCommTxData();
                        tr_Msg(CommTxBuffer, CommRxBuffer, true);
                        processRxData(CommRxBuffer, true);
                        
                        String wav_f = "6133.wav";
                        dt_set_addr_res_inf = "ÉèÖñàºÅΪ" + dt_addr + "³É¹¦  @ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                        if(dt_addr != (mAddrSettedNow+1)) {
                            wav_f = "4577.wav";
                            dt_set_addr_res_inf = "ÉèÖñàºÅΪ" + (mAddrSettedNow+1) + "ʧ°Ü!!!!!!! @ " 
                                                    + Com.get_DTF(new Date(), Com.DTF_YMDhms);
                        }
                        mAddrSettedNow = dt_addr;
                        new PlaySound(wav_f);
                    }
                    
                    if(true == cmd_Set_bianhao_Low) {
                        makeCommTxData();
                        tr_Msg(CommTxBuffer, CommRxBuffer, true);
                        processRxData(CommRxBuffer, true);
                        
                        if((dt_ssb & (1<<8)) > 0) {
                            this.setCommCmd(CMD_TYPE_WRITE, UART_MonomerClrTmpAddr_RegAddr, (short)1, (short)0x00, (short)0x00);
                        } else {
                            mBianHao_TestRes = 1;
                        }
                    }
                    if(true == cmd_Set_bianhao_High) {
                        makeCommTxData();
                        tr_Msg(CommTxBuffer, CommRxBuffer,true);
                        processRxData(CommRxBuffer, true);
                        
                        if((dt_ssb & (1<<8)) == 0) {
                            mBianHao_TestRes = 0;
                        } else {
                            mBianHao_TestRes = 2;
                        }
                    }
                    
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    exitCommPortThread();
                    JOptionPane.showMessageDialog(null, "Monomer CommPort ´®¿ÚÒì³£: " + e.getMessage());
                }
            } else {
                try {
                    makeCommTxData();
                    tr_Msg(CommTxBuffer, CommRxBuffer, false);
                    Thread.sleep(100);
                } catch (InterruptedException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                
                setCommBautrate(dt_dfu_bitrate);
                String dfu_text_inf = "";
                m_SPCommDFU = new SPCommMon_DFU(m_COMM,
                                                m_DEV_TYPE,
                                                dt_target_addr,
                                                dt_dfu_read_check_en,
                                                dt_show_dfu_inf,
                                                dt_debug_inf);
                boolean check_res = m_SPCommDFU.runDFU(dt_update_file, dfu_text_inf);
                
                if((true == dt_update_en) && (true == CommThreadRunning)) {
                    if(false == check_res) {
                        Toolkit.getDefaultToolkit().beep();
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        Toolkit.getDefaultToolkit().beep();
                        dt_update_en = false;
                    } else {
                        if(dt_target_addr < dt_dfu_addr_end) {
                            dt_target_addr += 1;
                            this.setCommCmd(SPCommMon.CMD_TYPE_WRITE, SPCommMon.UART_MonomerDFU_RegAddr, (short)0x55AA, (short)0xAA55, (short) 0x7F7F);
                        } else {
                            dt_update_en = false;
                        }
                    }
                }
                //-----------------------------------------------------------------------------//
                dfu_text_inf = dt_show_dfu_inf.getText();
                dt_show_dfu_inf.setText(dfu_text_inf + "DFU Process Stopped!\n");
                //-----------------------------------------------------------------------------//
                setCommBautrate(comm_bautrate);
                //-----------------------------------------------------------------------------//
                //-----------------------------------------------------------------------------//
                for(int n=0; n<2; n++) {
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    makeCommTxDataNull();
                    tr_Msg(CommTxBuffer, CommRxBuffer, true);
                }
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //-----------------------------------------------------------------------------//
                //-----------------------------------------------------------------------------//
            }
        }
        /******************************************************************************/
        closeCommPort();
        /******************************************************************************/
        dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S) 
                                    + " CommPort is quit, Dev Id: " + m_DEV_TYPE 
                                    + ", COMM_PORT_TYPE: " + m_COMM_PORT_TYPE + "\n");
        /******************************************************************************/
    }
}