DELL
2024-04-01 3724852a7dd499f54740cd682aa7cfe89aea384d
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
package com.ueky;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
 
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.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.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_DeviceInf;
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.bts4810.BTS_Ecb_Aes;
import com.dev.fbs9600_mon.SPCommMon;
 
/**
 * BTSÉ豸ͨÐÅÏß³Ì
 * @author LiJun
 *
 */
public class CommUKEY implements Runnable/*, SerialPortEventListener*/ {
    
    public static final short CMD_TYPE_NULL = 0x00;
    public static final short CMD_TYPE_READ = 0x03;
    public static final short CMD_TYPE_WRITE_WEBUKEY = 0x04;
    public static final short CMD_TYPE_WRITE_DEVUKEY = 0x05;
    public static final short CMD_TYPE_WRITE_SETUKEY = 0x06;
    
    public static final int DEV_PARAM_DATA_STATE_NULL         = 0;    //
    public static final int DEV_PARAM_DATA_STATE_UKEYQUERY     = 1;    //¶ÁÈ¡UKEYÐÅÏ¢
    public static final int DEV_PARAM_DATA_STATE_UEKYWEB    = 2;    //ÉèÖÃÆ½Ì¨UKEY
    public static final int DEV_PARAM_DATA_STATE_UEKYDEV     = 3;    //ÉèÖÃÉ豸UKEY
    public static final int DEV_PARAM_DATA_STATE_SETUKEY    = 4;    //ÉèÖÃUKEY
 
    public static final int DEV_PARAM_DATA_STATE_CLEAR        = 5;    //UKEYÒѰγö,Çå¿ÕukeyÐÅÏ¢
    /*********************************************************************/
    
    public static final int Comm_State_NotFount    = 0;    //δÕÒµ½UKEY
    public static final int Comm_State_Success    = 1;    //²åÈëÕý³£
    
    
    private int comm_state = Comm_State_Success;
    
    
    private boolean alearyMaxCurr = false;
    /*********************************************************************/
    /*********************************************************************/
    public boolean DEV_DATA_ENCIPHER                    = true;        //ͨÐÅÊý¾ÝÊÇ·ñ¼ÓÃÜ
    /*********************************************************************/
    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;
    
    //--------------------------------------------------------//
    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 JTextField dt_show_msg = new JTextField();
    private int dt_cmd = CMD_TYPE_READ;
    private int dt_usr_cmd = CMD_TYPE_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_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); 
    //--------------------------------------------------------//
    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;
    //--------------------------------------------------------//
    public String DevicePath;
    
    private String ukeyid_str = "";    
    private String publicx_str = "";    
    private String publicy_str = "";    
    
    public String publicx_set = "";    
    public String publicy_set = "";    
    private com.softkey.jsyunew3 mD8=new  com.softkey.jsyunew3();
    //--------------------------------------------------------//
    
    public CommUKEY(page_debug_inf debug, Logger log) {
        dt_debug_inf = debug;
        m_Log = log;
        
        comm_tx_cnt = 0;
        comm_rx_cnt = 0;
        CommThreadRunning = true;
    }
    
    
    
    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) {
        dt_usr_cmd = cmd;
    }
    
    public void setCommCmd_DFU(boolean dfu_en, String dfu_file, JTextField show_area) {
        dt_dfu_en = dfu_en;
        dt_show_msg = show_area;
    }
    
    
    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) {
                    //¼ì²âUKEYÊÇ·ñ°Î³ö
                    checkUkey();
                    
                    if(CMD_TYPE_NULL != dt_usr_cmd) {
                        if(CMD_TYPE_READ == dt_usr_cmd) {
                            readUkeyInfo();
                        }else if(CMD_TYPE_WRITE_WEBUKEY == dt_usr_cmd) {
                            writeWebUkey();
                        }else if(CMD_TYPE_WRITE_DEVUKEY == dt_usr_cmd) {
                            writeDevUkey();
                        }else if(CMD_TYPE_WRITE_SETUKEY == dt_usr_cmd) {
                            writeRanUkey();
                        }
                        dt_usr_cmd = CMD_TYPE_NULL;
                    }                    
                    Thread.sleep(500);
                }
            } 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!");
    }
    
    /**
     * ÉèÖÃUKEYΪ×Ô¶¨ÒåUKEY
     */
    private void writeRanUkey() {
        boolean isSuccess = false;
        String PriKey = "";
        if(null != this.DevicePath && this.DevicePath.trim().length()>0) {            
            /*
             * //¿ªÊ¼Éú³ÉÃÜÔ¿ int code = mD8.StarGenKeyPair(DevicePath); long last_code =
             * mD8.get_LastError(); if (last_code != 0) {
             * m_Log.error("ÉèÖÿªÊ¼Éú³Éƽ̨ÃÜÔ¿,´íÎóÂë:"+last_code); isSuccess = false; }else {
             * isSuccess = true; }
             */
            PriKey = "A3A96FD399FB5CD5761D1624571E4158FC8D6E896A7754D62E3EA47DC766BF9B";
           
            String dev_str = "123";
            
             int last_code = mD8.Set_SM2_KeyPair(PriKey,publicx_set,publicy_set, dev_str,DevicePath);
             if(last_code != 0) {
                 dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"ÉèÖÃUkeyÃÜÔ¿¶Ôʱ±¨´í,´íÎóÂë:"+last_code+"\n"); 
                 isSuccess = false;
             }else {
                 isSuccess = true;
             }             
        }
        if(isSuccess) {
            publicx_str = publicx_set;
            publicy_str = publicy_set;
            dev_param_data_state = DEV_PARAM_DATA_STATE_SETUKEY;
            dev_control_Str = "ÉèÖÃUKEYÃÜÔ¿¶Ô³É¹¦" + Com.get_DTF(new Date(), Com.DTF_YMDhms);
            dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S) + "ÉèÖÃUKEYÃÜÔ¿¶Ô³É¹¦" + "\n"); 
        }else {
            dev_param_data_state = DEV_PARAM_DATA_STATE_NULL;
            dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S) + "ÉèÖÃUKEYÃÜÔ¿¶Ôʧ°Ü" + "\n"); 
        }
    }
    
    /**
     * ÉèÖÃUKEYΪÉ豸°æUKEY
     */
    private void writeDevUkey() {
        boolean isSuccess = false;
        String PriKey = "";
        String PubKeyX = "";
        String PubKeyY = "";
        if(null != this.DevicePath && this.DevicePath.trim().length()>0) {            
            /*
             * //¿ªÊ¼Éú³ÉÃÜÔ¿ int code = mD8.StarGenKeyPair(DevicePath); long last_code =
             * mD8.get_LastError(); if (last_code != 0) {
             * m_Log.error("ÉèÖÿªÊ¼Éú³Éƽ̨ÃÜÔ¿,´íÎóÂë:"+last_code); isSuccess = false; }else {
             * isSuccess = true; }
             */
            Date oldTime = new Date(123,2,3);
            Date nowTime = new Date();
            PriKey = "A3A96FD399FB5CD5761D1624571E4158FC8D6E896A7754D62E3EA47DC766BF9B";
            PubKeyX = "129BDA6338262E3914704DB177955436A2183284CFAA69DAEB7432D591D0CF62";
            PubKeyY = "EC2FC8397C31530159EF4F9223DA40D4039203AA1D49AEECDC9366973CF7AE20";
            //System.out.println(Com.get_DTF(oldTime, Com.DTF_YMDhms));
            //System.out.println(Com.get_DTF(nowTime, Com.DTF_YMDhms));
            if(nowTime.getTime()<oldTime.getTime()) {
                PriKey = "C1B18CCB03B1DEEDEE9DEDB95C456F55CA24CD0C478ACCFBE57371BA4A7E2883";
                PubKeyX = "FE7C0F1805BA9F263BCE6EB198DE02B52C6706AF5C9FBC24C8B0E19545B01595";
                PubKeyY = "6471C138A584BD6EEAFE1FCD7628531A7DE8E49FFD205857AE1F82D84016F3F3";
            }
             String dev_str = "123";
             
             int last_code = mD8.Set_SM2_KeyPair(PriKey,PubKeyX,PubKeyY, dev_str,DevicePath);
             if(last_code != 0) {
                 dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"ÉèÖÃÉ豸°æUkeyÃÜԿʱ±¨´í,´íÎóÂë:"+last_code+"\n"); 
                 isSuccess = false;
             }else {
                 isSuccess = true;
             }             
        }
        if(isSuccess) {
            publicx_str = PubKeyX;
            publicy_str = PubKeyY;
            dev_param_data_state = DEV_PARAM_DATA_STATE_UEKYDEV;
            dev_control_Str = "ÉèÖÃÉ豸°æUKEYÃÜÔ¿¶Ô³É¹¦" + Com.get_DTF(new Date(), Com.DTF_YMDhms);
            dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S) + "ÉèÖÃÉ豸°æUKEYÃÜÔ¿¶Ô³É¹¦" + "\n");
        }else {
            dev_param_data_state = DEV_PARAM_DATA_STATE_NULL;
            dev_control_Str = "ÉèÖÃÉ豸°æUKEYÃÜÔ¿¶Ôʧ°Ü" + Com.get_DTF(new Date(), Com.DTF_YMDhms);
            dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S) + "ÉèÖÃÉ豸°æUKEYÃÜÔ¿¶Ôʧ°Ü" + "\n");
        }
    }
    
    /**
     * ÉèÖÃUKEYΪƽ̨UKEY
     */
    private void writeWebUkey() {
        boolean isSuccess = false;
        String PriKey = "";
        String PubKeyX = "";
        String PubKeyY = "";
        if(null != this.DevicePath && this.DevicePath.trim().length()>0) {
            
            //¿ªÊ¼Éú³ÉÃÜÔ¿
            int code = mD8.StarGenKeyPair(DevicePath);
            long last_code = mD8.get_LastError();
            if (last_code != 0) {
                dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"ÉèÖÿªÊ¼Éú³Éƽ̨ÃÜÔ¿,´íÎóÂë:"+last_code+"\n");
                isSuccess = false;
            }else {
                isSuccess = true;
            }
            
            
            //¼ÓÃܹ·Ð¾Æ¬Î¨Ò»ID£¬Îª32¸ö×Ö·û³¤¶È
            PriKey=mD8.get_GenPriKey();
            if (mD8.get_LastError() != 0) {
                dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"ÉèÖÿªÊ¼Éú³Éƽ̨˽Կ,´íÎóÂë:"+last_code+"\n");
                isSuccess = false;
            }else {
                isSuccess = true;
            }
             
            //Éú³ÉËøµÄоƬPublicX             
            PubKeyX=mD8.get_GenPubKeyX();
             last_code = mD8.get_LastError();
             if (last_code != 0) { 
                 dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"¶ÁÈ¡Éú³ÉUkeyµÄPublicXʱ±¨´í,´íÎóÂë:"+last_code+"\n");
                 isSuccess = false;
             }else {
                 isSuccess = true;
             }
             
             
            PubKeyY=mD8.get_GenPubKeyY();
             last_code = mD8.get_LastError();
             if (last_code != 0) { 
                 dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"¶ÁÈ¡Éú³ÉUkeyµÄPublicYʱ±¨´í,´íÎóÂë:"+last_code+"\n"); 
                 isSuccess = false;
            }else {
                isSuccess = true;
            }
             String web_str = "Î人Դ³©¿Æ¼¼ÓÐÏÞ¹«Ë¾";
             last_code = mD8.Set_SM2_KeyPair(PriKey,PubKeyX,PubKeyY, web_str,DevicePath);
             if(last_code != 0) {
                 dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"ÉèÖÃÆ½Ì¨°æUkeyÃÜԿʱ±¨´í,´íÎóÂë:"+last_code+"\n"); 
                 isSuccess = false;
             }else {
                 isSuccess = true;
             }
             
        }
        if(isSuccess) {
            publicx_str = PubKeyX;
            publicy_str = PubKeyY;
            dev_param_data_state = DEV_PARAM_DATA_STATE_UEKYWEB;
            dev_control_Str = "ÉèÖÃÆ½Ì¨°æUKEYÃÜÔ¿¶Ô³É¹¦" + Com.get_DTF(new Date(), Com.DTF_YMDhms);
            dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S) + "ÉèÖÃÆ½Ì¨°æUKEYÃÜÔ¿¶Ô³É¹¦" + "\n");
        }else {
            dev_param_data_state = DEV_PARAM_DATA_STATE_NULL;
            dev_control_Str = "ÉèÖÃÆ½Ì¨°æUKEYÃÜÔ¿¶Ôʧ°Ü" + Com.get_DTF(new Date(), Com.DTF_YMDhms);
            dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S) + "ÉèÖÃÆ½Ì¨°æUKEYÃÜÔ¿¶Ôʧ°Ü" + "\n");
        }
    }
    
    
    
    /**
     * ¶ÁÈ¡UKEYÐÅÏ¢
     */
    private void readUkeyInfo() {
        boolean isSuccess = false;
        if(null != this.DevicePath && this.DevicePath.trim().length()>0) {
            //¶ÁÈ¡UkeyID
            String ukeyid = mD8.GetChipID(DevicePath);
            long last_code = mD8.get_LastError();
            if (last_code != 0) {
                dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"¶ÁÈ¡UkeyIDʱ±¨´í,´íÎóÂë:"+last_code+"\n");
                isSuccess = false;
            }else {
                isSuccess = true;
                this.ukeyid_str = ukeyid;
            }
             
           //»ñÈ¡ËøµÄоƬPublicX             
            String PubKeyX=mD8.GetPubKeyX(DevicePath);
             last_code = mD8.get_LastError();
             if (last_code != 0) { 
                 dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"¶ÁÈ¡UkeyµÄPublicXʱ±¨´í,´íÎóÂë:"+last_code+"\n");
                 isSuccess = false;
             }else {
                 isSuccess = true;
                 publicx_str = PubKeyX;
             }
             
             
             String PublicY=mD8.GetPubKeyY(DevicePath);
             last_code = mD8.get_LastError();
             if (last_code != 0) { 
                 dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"¶ÁÈ¡UkeyµÄPublicYʱ±¨´í,´íÎóÂë:"+last_code +"\n"); 
                 isSuccess = false;
            }else {
                isSuccess = true;
                publicy_str = PublicY;
            }
        }
        if(isSuccess) {
            dev_param_data_state = DEV_PARAM_DATA_STATE_UKEYQUERY;
            dev_control_Str = "¶ÁÈ¡UKEYÃÜÔ¿¶ÔÊý¾Ý³É¹¦" + Com.get_DTF(new Date(), Com.DTF_YMDhms);
            dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S) + "¶ÁÈ¡UKEYÃÜÔ¿¶ÔÊý¾Ý³É¹¦" + "\n");
        }else {
            dev_param_data_state = DEV_PARAM_DATA_STATE_NULL;
            dev_control_Str = "¶ÁÈ¡UKEYÃÜÔ¿¶ÔÊý¾Ýʧ°Ü" + Com.get_DTF(new Date(), Com.DTF_YMDhms);
            dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S) + "¶ÁÈ¡UKEYÃÜÔ¿¶ÔÊý¾Ýʧ°Ü" + "\n");
        }
    }
    
    /**
     * ¼ì²âUKEY²åÈë״̬
     */
    private void checkUkey() {
        //Õâ¸öÓÃÓÚÅжÏϵͳÖÐÊÇ·ñ´æÔÚ׿ÓÃÜËø¡£²»ÐèÒªÊÇÖ¸¶¨µÄ¼ÓÃÜËø,
        this.DevicePath = mD8.FindPort(0);
        if(mD8.get_LastError()!=0)
        {
            if(Comm_State_Success == comm_state) {
                dev_control_Str = "δÕÒµ½¼ÓÃÜËø,Çë²åÈë¼ÓÃÜËøºó£¬ÔÙ½øÐвÙ×÷";
                dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"δÕÒµ½¼ÓÃÜËø,Çë²åÈë¼ÓÃÜËøºó£¬ÔÙ½øÐвÙ×÷\n");
                comm_state = Comm_State_NotFount;
                
                this.ukeyid_str = "";    
                this.publicx_str = "";    
                this.publicy_str = "";    
                
                dev_param_data_state = DEV_PARAM_DATA_STATE_CLEAR;
            }
        }else if(comm_state == Comm_State_NotFount){
            dev_control_Str = "";
            comm_state = Comm_State_Success;            
            dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)+"¼ì²âµ½UKEY²åÈë\n");
            //»ñÈ¡ËøµÄоƬPublicX             
//            String PubKeyX=mD8.GetPubKeyX(DevicePath);
//             long last_code = mD8.get_LastError();
//             if (last_code == 0) {                 
//                 publicx_str = PubKeyX;
//             }
//             
//             String PublicY=mD8.GetPubKeyY(DevicePath);
//             last_code = mD8.get_LastError();
//             if (last_code == 0) {                 
//                publicy_str = PublicY;
//            }
        }
        //System.err.println(this.DevicePath);
    }
    
    
    
    public String getPublicx_str() {
        return publicx_str;
    }
 
 
 
    public String getPublicy_str() {
        return publicy_str;
    }
 
 
 
    public String getUkeyid_str() {
        return ukeyid_str;
    }
 
 
 
    public static void main(String[] args) {
        for(int i  =0 ;i<100;i++) {
            
            
        }
    }
}