充放电一体机FGCD通信程序【二期初版】
whyclxw
2021-09-03 cf826529c32d79e78e5fba86d3e4e1483d424d60
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
package com.dev.fgcd.comm;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
 
import com.battmonitor.sql.MysqlConnPool;
import com.battmonitor.sql.Sql_Mysql;
import com.dev.btse.data.ComFn;
import com.dev.fgcd.data.FGCD_Cmd;
import com.dev.fgcd.data.FGCD_ComBase;
import com.dev.fgcd.data.FGCD_ComBuf;
import com.dev.fgcd.data.FGCD_Crc16;
import com.dev.fgcd.data.FGCD_TestFBOFile;
import com.dev.fgcd.data.FGCD_TestFBOFile.FBOFile;
import com.dev.fgcd.fbo.FboData;
import com.dev.fgcd.fbo.FboDataInf;
import com.dev.fgcd.fbo.FboTestTime;
 
 
public class FGCD_TestDataDownLoad {
    
    public static final int DownloadFlag_Fail            = -1;        //µ¼Èëʧ°Ü
    public static final int DownloadFlag_Null             = 0;        //²»ÏÂÔØ
    public static final int DownloadFlag_Start             = 1;        //ÐèÒªµ¼Èë
    public static final int DownloadFlag_Over             = 2;        //ÏÂÔØÍê³É
    
    public static final int FialReason_DeFault             = 0;        //ÔÝÎÞ
    public static final int FialReason_FIleNotFound     = 1;        //ÎļþδÕÒµ½
    public static final int FialReason_ParamError        = 2;        //²ÎÊý´íÎó
    public static final int FialReason_NetWorkError        = 3;        //ÍøÂçÒì³£´íÎó
    public static final int FialReason_UserCancel        = 4;        //Óû§È¡Ïû
    
    
    public static final int DownLoadState_ReadData         = 1;        //ÏÂÔØÎļþ
    public static final int DownLoadState_CreateData    = 2;        //Éú³ÉÎļþ
    public static final int DownLoadState_ExportData    = 3;        //µ¼³öÊý¾Ý
    public static final int DownLoadState_ExportSucc    = 4;        //µ¼Èë³É¹¦
    public static final int DownLoadState_ExportFail    = 5;        //µ¼Èëʧ°Ü
    public static final int DownLoadState_UserCancel    = 6;        //Óû§È¡Ïû
    public static final int DownLoadState_DownLoadCancel    = 7;        //ÏÂÔØÊ§°Ü
    
    
    private ByteBuffer bytebuffer_for_socket_RX = ByteBuffer.allocate(1200);
    
    private FGCD_TestFBOFile fbofile;
    private FGCD_Cmd m_FBS_Cmd = new FGCD_Cmd();
    private boolean ReadTestData = true;
    public byte[] filebyte;
    
    private MysqlConnPool pool;
    private Socket socket;
    private int ErrorCount = 0;            //´íÎó¼ÆÊý;Á¬Ðø3´ÎͨÐÅʧ°Ü¼´ÎªÍøÂçÒì³£½áÊø
    private String fileName;
    private FBOFile nowFbo;
    
    
    public FGCD_TestDataDownLoad(FGCD_TestFBOFile fbofile,Socket socket,MysqlConnPool pool) {
        this.fbofile = fbofile;
        this.socket = socket;
        this.pool = pool;
        
        filebyte = new byte[0];
        downLoadParamCheck();
    }
    
 
    /**
     *     ÏÂÔØµ±Ç°µç³Ø×éÊý¾Ý
     * @param socket
     */
    public void downLoadTestData() {
        int now_download_state = DownLoadState_ReadData;
        fbofile.initDownLoadState();//ÎļþÐÅÏ¢ÏÂÔØ³õʼ»¯
        for(int i=0;i<fbofile.files.length;i++) {
            //µ±Ç°ÏÂÔØÎļþ
            nowFbo = fbofile.files[i];
            int file_downloadNum=i;//ÉèÖõ±Ç°ÏÂÔØÎļþµÄË÷Òý
            if(now_download_state == DownLoadState_DownLoadCancel) {
                fbofile.files[i].setDownload_state(DownLoadState_DownLoadCancel);
                fbofile.files[i].setDownload_flag(DownloadFlag_Fail);
                
                FGCD_Task_Thread_SQL.updateFgcd_Filedownload_TableCmdByDevId(pool,fbofile,file_downloadNum);
                continue;
            }
            if(nowFbo.download_flag != DownloadFlag_Start) {
                continue;
            }
            ReadTestData = true;
            nowFbo.setDownload_state(DownLoadState_ReadData);    
            while(ReadTestData) {
                try {
                    queryDownLoadState(pool, fbofile);
                    if(fbofile.op_cmd == FGCD_ComBase.CMD_DownLoadFBDFile_Over) {
                        now_download_state = FGCD_ComBase.CMD_DownLoadFBDFile_Over;
                        fbofile.setStop_reason(FialReason_UserCancel);
                        //ÊÖ¶¯ÖÕÖ¹ÏÂÔØÃüÁî
                        fbofile.files[file_downloadNum].setDownload_flag(DownloadFlag_Fail);
                        fbofile.files[file_downloadNum].setDownload_state(DownLoadState_DownLoadCancel);
                        fbofile.op_cmd = FGCD_ComBase.CMD_DownLoadFBDFile_Over_ACK;
                        FGCD_Task_Thread_SQL.updateFgcd_Filedownload_TableCmdByDevId(pool, fbofile,file_downloadNum);
                        continue;
                    }                    
                    if(nowFbo.getDownload_state() == DownLoadState_ReadData) {    
                        //System.out.println("¶ÁÈ¡²âÊÔÎļþÖÐ"+file);
                        SocketComm(FGCD_ComBase.CMD_GETFILE,nowFbo.file_index,nowFbo.now_data_block);
                        if(nowFbo.download_state == DownLoadState_CreateData) {
                            //ÏÂÔØÊýÁ¿
                            nowFbo.setNow_data_block(0);
                            nowFbo.setTotal_data_block(0);
                        }
                        
                        updateDownLoadProgressByOne(pool,fbofile,file_downloadNum);        //¸üе±Ç°ÏÂÔØ½ø¶È
                        
                    }
                    if(nowFbo.getDownload_state() == DownLoadState_CreateData) {
                        //Éú³Éµ±Ç°ÏÂÔØµÄÊý¾ÝÎļþ
                        if(createFBOFile(nowFbo)) {
                            //Éú³ÉFBOÎļþ³É¹¦¹ý
                            //System.err.println("Éú³ÉÎļþ³É¹¦");
                            nowFbo.setDownload_state(DownLoadState_ExportData);
                        }else{
                            //Éú³ÉFBOÎļþʧ°Ü
                            //System.err.println("Éú³ÉÎļþʧ°Ü");            
                            nowFbo.setDownload_state(DownLoadState_ExportFail);
                        }            
                    }
                    
                    if(nowFbo.getDownload_state() == DownLoadState_ExportData) {
                        //½âÎö±¾µØÊý¾ÝÎļþ²¢µ¼ÈëÊý¾Ý¿â
                        /*boolean flag = readFBOFileData(file,pool);    
                        if(flag) {
                            nowFbo.setDownload_state(DownLoadState_ExportSucc);
                        }else {
                            nowFbo.setDownload_state(DownLoadState_ExportFail);
                        }*/
                        //¿ªÆôÐÂÏ̵߳¼ÈëÊý¾Ý¿â
                        FGCD_Export_Thread_SQL export_Thread=new FGCD_Export_Thread_SQL(pool, nowFbo.clone(), fbofile.battgroupid,file_downloadNum);
                        new Thread(export_Thread).start();
                        ReadTestData = false;
                    }
                    //System.out.println("nowFbo.getDownload_state():"+nowFbo.getDownload_state());
//                    if(nowFbo.getDownload_state() == DownLoadState_ExportFail
//                        || nowFbo.getDownload_state() == DownLoadState_ExportSucc) {
//                        ReadTestData = false;
//                    }
                    //file.setDownload_state(nowFbo.getDownload_state());
                    //updateDownLoadProgress(pool,fbofile);        //¸üе±Ç°ÏÂÔØ½ø¶È
                    Thread.sleep(50);
                } catch(Exception e) {
                    e.printStackTrace();
                }            
            }
            filebyte = new byte[0];            
            /*{
                if(nowFbo.getDownload_state() == DownLoadState_ExportSucc) {
                    //System.out.println("µ¼³öÀúÊ··ÅµçÊý¾Ý³É¹¦");
                    file.setDownload_flag(DownloadFlag_Over);
                    fbofile.op_cmd = FGCD_ComBase.CMD_DownLoadFBDFile_ACK;
                }else {
                    //System.out.println("µ¼³öÀúÊ··ÅµçÊý¾Ýʧ°Ü");
                    file.setDownload_flag(DownloadFlag_Fail);
                    fbofile.op_cmd = FGCD_ComBase.CMD_DownLoadFBDFile_Over;
                }
            }*/
            //FGCD_Task_Thread_SQL.updateFBOFIleExportFlag(pool,fbofile);        
        }    
        //FGCD_Task_Thread_SQL.updateFgcd_FiledownloadState_TableByDevId(pool, fbofile);
        /******************************** ×îºóÉèÖõ±Ç°µ¼³ö״̬ ********************************************/
    }
    
    /**
     *     ½âÎöFBOÎļþ
     * @param file
     * @param pool
     */
     private boolean readFBOFileData(FBOFile file,MysqlConnPool pool) {
         boolean flag = false;
         FboDataInf data_inf = new FboDataInf();
         ArrayList<FboData> al_fbo_data = new ArrayList<>();
         File f = new File(file.filename);
         if(file.test_timelong > 0) {
             FboData.checkFboFile(f, data_inf, al_fbo_data);
             
             flag = FGCD_Task_Thread_SQL.insertFBODataIntoTable(pool, file, data_inf, al_fbo_data, fbofile.battgroupid);
             flag = true;
         }
         if(f.exists()) {
            //ɾ³ýÏÂÔØµÄFBOÎļþ
            //f.delete();
         }    
         return flag;        
    }
 
 
 
 
 
    /**
      * ÏòÖ¸¶¨µÄsocketͨµÀ·¢ËÍÊý¾Ý½çÃæÍ¬²½ÇëÇó 
      * @param cmd            ¶ÁȡָÁî
      * @param rec_index    ¶ÁÈ¡Ë÷Òý
      * @return
      */
    public boolean SocketComm(int cmd,int file_index,int rec_index)
    {
        boolean res_t = false;
        InputStream in = null;
        OutputStream out = null;
        try
        {
            if(null != this.socket && !this.socket.isClosed())
            {
                in = this.socket.getInputStream();
                out = this.socket.getOutputStream();
                //----------------- clear rx buff for tcp resend packet ----------------//
                byte[] rx_buf_t = new byte[1024];
 
                //----------------------------------------------------------------------//
                bytebuffer_for_socket_RX.order(ByteOrder.LITTLE_ENDIAN);
                bytebuffer_for_socket_RX.clear();
                //--------------------- socket write -----------------------------------//
                //--------------------- socket write -----------------------------------//
                boolean aes_en = false;
                byte[] plain_tx_t = makeCommBuf(cmd,file_index,rec_index);
                Date d1 = new Date();
                int rx_read_time_out = 0;
                //int rx_len = 0;
                //System.out.println("Êý¾Ý³¤¶È" + plain_tx_t.length + "\t·¢ËÍÊý¾Ý:" + ComFn.bytesToHexString(plain_tx_t, plain_tx_t.length));
                out.write(plain_tx_t);
                out.flush();
                while(true) {
                    if(in.available() > 0) {
                        rx_read_time_out = 0;
                        int rx_len_t = in.read(rx_buf_t);
                        if((bytebuffer_for_socket_RX.position()+rx_len_t)
                                < (bytebuffer_for_socket_RX.capacity()-1)) {
                            bytebuffer_for_socket_RX.put(rx_buf_t, 0, rx_len_t);
                        }
                        //bytebuffer_for_socket_RX.put((byte)in.read());
                    } else {
                        rx_read_time_out++;
                        if((bytebuffer_for_socket_RX.position() >= 20) && (rx_read_time_out>10)){
                            //    res = true;
                            break;
                        }
                        if(rx_read_time_out > 300) {
                            break;
                        }
                    }
                    Thread.sleep(10);
                }
                Date d2 = new Date();
                long comm_tms = (d2.getTime() - d1.getTime());
                if(comm_tms < 200) {
                    Thread.sleep(200 - comm_tms);
                }
 
                bytebuffer_for_socket_RX.flip();
 
                byte[] cipher_buf = new byte[bytebuffer_for_socket_RX.limit()];
                bytebuffer_for_socket_RX.get(cipher_buf);
                
                //sysState.makeDevCommDataFlowSum(cipher_buf.length);
                
                //System.out.println("Êý¾Ý³¤¶È"+cipher_buf.length+"\t·µ»ØÊý¾Ý£º"+ ComFn.bytesToHexString(cipher_buf, cipher_buf.length));
                if(true == getDataFromCommBuf(cipher_buf)) {
                    res_t = true; 
                    ErrorCount = 0;
                } else {
                    ErrorCount ++;
                    res_t = false;
                }
            } else {
                ReadTestData = false;
            }
        } catch (IOException | InterruptedException e) {
            ErrorCount ++;
        } finally {
            if(ErrorCount > 5){
                ReadTestData = false;
            }
        }
        return res_t;
    }
    
    public Boolean getDataFromCommBuf(final byte[] bytes)
    {
        boolean isSuccess = false;
        ByteBuffer bf = ByteBuffer.allocate(bytes.length);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.put(bytes);
        bf.flip();
 
        if(true == m_FBS_Cmd.putByteBuffer(bf))
        {
            //---------------------  ÐÄÌø°ü²âÊÔ    ----------------------------------
            if(FGCD_ComBase.CMD_GETFILE == m_FBS_Cmd.CMD) {
                if(FGCD_ComBase.RETURN_SUCCESS == m_FBS_Cmd.RecState) {  
                    this.nowFbo.total_data_block = m_FBS_Cmd.getTotalDownLoadBlock();
                    //System.out.println("Êý¾Ý°ü×ܳ¤¶È£º"+ this.fbofile.total_data_block+ m_FBS_Cmd);
                    if(m_FBS_Cmd.getNowDownLoadIndex() == nowFbo.now_data_block) { 
                        if(putFileData(bf,m_FBS_Cmd.ByteLen-18)) {
                            
                            nowFbo.now_data_block ++;
                            isSuccess = true;
                            System.out.println("¶ÁÈ¡µÚ"+m_FBS_Cmd.getNowDownLoadIndex()+"¸öÊý¾Ý°ü³É¹¦");
                            
                            if(nowFbo.now_data_block == nowFbo.total_data_block) {
                                //System.out.println("ÏÂÔØÀúÊ·Êý¾ÝÎļþÍê³É");
                                nowFbo.setDownload_state(DownLoadState_CreateData);
                            }
                        }                        
                    }
                }
            }         
        }
        return isSuccess;
    }
    
    public byte[] makeCommBuf(final int cmd,int file_index, int rec_index)
    {
        FGCD_Cmd m_cmd = new FGCD_Cmd();
        m_cmd.CMD = cmd;
        m_cmd.Type         = file_index%256;
        m_cmd.RecState     = file_index/256;
        m_cmd.Alarm     = rec_index%256;
        m_cmd.WorkState = rec_index/256;
        
        ByteBuffer bbf = FGCD_ComBuf.makeFGCDTestDataCommBuf(m_cmd);
        byte byte_rest[] = new byte[bbf.limit()];
        bbf.get(byte_rest);
        return byte_rest;
    }
    
    /**
     * 
     * @param bf
     * @param len    µ±Ç°buffµÄÓÐЧ³¤¶È
     * @return
     */
    public boolean putFileData(ByteBuffer bf,int len) {
         if(bf.limit() < 2) {
             return false;
         }
         //System.out.println("ÓÐЧ³¤¶È:"+len+"\t"+ComFn.bytesToHexString(bf.array(), len));
         ByteBuffer tmpbuf = bf;
         tmpbuf.position(0);
         int crc0 = tmpbuf.getShort(len-2) & 0xFFFF;
         //Ö»¼ÆËãǰ1024¸ö×Ö½ÚµÄCRCÊý¾Ý
         int crc1 = FGCD_Crc16.CalCRC16(tmpbuf, len-2);
         if(crc0 != crc1) {
             System.err.println("FGCD_TestDataDownLoad.CRCУÑé:"+crc0+"==="+crc1);
             return false;
         }
         tmpbuf.position(0);
         int last = filebyte.length;
         byte[] tmp = new byte[last+len-2];
         System.arraycopy(filebyte, 0, tmp, 0, last);
         for(int i=0;i<len-2;i++) {
             tmp[last+i] = tmpbuf.get();
         }       
         this.filebyte = tmp;
         return true;
    }
    
    /**
     *     ÀúÊ·ÎļþÏÂÔØ²ÎÊýУÑé
     */
    private void downLoadParamCheck() {
        if(null != this.fbofile) {
            if(fbofile.battgroupid < 0 ||
                fbofile.file_index >= fbofile.file_total) {                
                fbofile.setStop_reason(FialReason_ParamError);    
                fbofile.op_cmd = FGCD_ComBase.CMD_DownLoadFBDFile_Over;        //ÏÂÔØ½áÊø        
                ReadTestData = false;
            }else {
                fbofile.op_cmd = FGCD_ComBase.CMD_DownLoadFBDFile_ACK;                
            }            
        }        
    }
    
    /**
     *     ¸üе±Ç°ÏÂÔØÎļþ״̬
     * @param pool
     * @param fbofile
     */
    public void updateDownLoadState(MysqlConnPool pool,FGCD_TestFBOFile fbofile) {
        String sql_str = " UPDATE " + Sql_Mysql.Tb_Fgcd_Filedownload_Table +
                         " SET op_cmd = " + fbofile.op_cmd +
                         //Ìí¼Óʧ°ÜÔ­Òò×Ö¶ÎÐÞ¸Ä
                         " WHERE dev_id = " + fbofile.dev_id;
        Sql_Mysql sql = null;
        try {
            sql = new Sql_Mysql(pool);
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     *     ¸üе±Ç°É豸µÄÏÂÔØ½ø¶È
     * @param pool
     * @param fbofile
     */
    public void updateDownLoadProgress(MysqlConnPool pool,FGCD_TestFBOFile fbofile) {
        String sql_str = " UPDATE " + Sql_Mysql.Tb_Fgcd_Filedownload_Table +
                         " SET ";
        Sql_Mysql sql = new Sql_Mysql(pool);
        String sql_str_end = " WHERE dev_id =  " + fbofile.dev_id;
        for(int i=0;i<fbofile.files.length;i++) {
            if(i>0) {
                sql_str += ",";
            }
            sql_str += "download_state"+(i+1)+" = "+fbofile.files[i].getDownload_state()
                    + ",now_data_block"+(i+1)+" = "+fbofile.files[i].getNow_data_block()
                    + ",total_data_block"+(i+1)+" = "+fbofile.files[i].getTotal_data_block();
        }
        sql_str += sql_str_end;
        try {
            //System.out.println(sql_str);
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     *     ¸üе±Ç°É豸µÄÏÂÔØ½ø¶È
     * @param pool
     * @param fbofile
     */
    public void updateDownLoadProgressByOne(MysqlConnPool pool,FGCD_TestFBOFile fbofile,int file_downloadNum) {
        String sql_str = " UPDATE " + Sql_Mysql.Tb_Fgcd_Filedownload_Table +
                         " SET ";
        Sql_Mysql sql = new Sql_Mysql(pool);
        String sql_str_end = " WHERE dev_id =  " + fbofile.dev_id;        
        sql_str += "download_state"+(file_downloadNum+1)+" = "+fbofile.files[file_downloadNum].getDownload_state()
                + ",now_data_block"+(file_downloadNum+1)+" = "+fbofile.files[file_downloadNum].getNow_data_block()
                + ",total_data_block"+(file_downloadNum+1)+" = "+fbofile.files[file_downloadNum].getTotal_data_block();
        sql_str += sql_str_end;
        try {
            //System.out.println(sql_str);
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     *     ²éѯµ±Ç°É豸µÄÏÂÔØ½ø¶È,±ÜÃâ³öÏÖÊÖ¶¯Í£Ö¹,¿É¼°Ê±Í£Ö¹´íÎóµÄµ¼Èë
     * @param pool
     * @param fbofile
     */
    public void queryDownLoadState(MysqlConnPool pool,FGCD_TestFBOFile fbofile) {
        String sql_str = " SELECT * FROM " + Sql_Mysql.Tb_Fgcd_Filedownload_Table +
                         " WHERE dev_id = " + fbofile.dev_id;
        Sql_Mysql sql = new Sql_Mysql(pool);
        ResultSet res = null;
        try {
            res = sql.sqlMysqlQuery(sql_str);
            if(res.next()) {
                fbofile.op_cmd = res.getInt("op_cmd");
            }           
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if(null != res) {
                try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            sql.close_con();
        }
    }
    
    
    /**
     *     Éú³ÉFBOÀúÊ·Êý¾ÝÎļþ
     */
    public boolean createFBOFile(FBOFile file){
        boolean flag = true;
        //System.err.println("ÎļþÊý¾Ý£º"+ComFn.bytesToHexString(filebyte, filebyte.length));
        if(filebyte.length <0) {
            file.download_flag = DownloadFlag_Fail;
            return false;
        }
        File root = new File(System.getProperty("user.dir")+File.separator+"fbofiles"+File.separator+fbofile.dev_id);
        if(!root.exists()) {
            root.mkdirs();
        }
        fileName = root.getAbsolutePath()+File.separator+(new Date()).getTime()+".FBO";
        //System.out.println(fileName);
        file.filename = fileName;
        File f = new File(fileName);
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(f);
            fos.write(filebyte);
            fos.flush();
        } catch (IOException e) {
            flag = false;
            e.printStackTrace();
        } finally {
            if(null != fos) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }       
        return flag;
    }
        
    /**
     *     ½âÎöFBOÎļþÏß³Ì
     * @author LiJun
     *
     */
    public class ParseFboThread extends Thread{
        public MysqlConnPool pool; 
        public int port_index;
        public FGCD_TestFBOFile fbofile;
        
        public ParseFboThread(MysqlConnPool pool,int index,FGCD_TestFBOFile fbofile){
            this.pool = pool;
            this.port_index = index;
            this.fbofile = fbofile;
        }
        
        @Override
        public void run() {
            
        }
        
    }
}