充放电一体机FGCD通信程序【二期初版】
11
whyclxw
2021-09-02 5c3e9ca324155efb5461ee48ad591a1070d6ae5e
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_TestDataDownLoad.java
@@ -47,7 +47,7 @@
   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);
@@ -80,22 +80,21 @@
    */
   public void downLoadTestData() {
      int now_download_state = DownLoadState_ReadData;
      fbofile.initDownLoadState();//文件信息下载初始化
      for(int i=0;i<fbofile.files.length;i++) {
         //当前下载文件
         FBOFile file = fbofile.files[i];
         nowFbo = fbofile.files[i];
         int file_downloadNum=i;//设置当前下载文件的索引
         if(now_download_state == DownLoadState_UserCancel) {
            file.setDownload_state(DownLoadState_UserCancel);
            file.setDownload_flag(DownloadFlag_Fail);
         if(now_download_state == DownLoadState_DownLoadCancel) {
            nowFbo.setDownload_state(DownLoadState_DownLoadCancel);
            nowFbo.setDownload_flag(DownloadFlag_Fail);
            continue;
         }
         if(file.download_flag != DownloadFlag_Start) {
         if(nowFbo.download_flag != DownloadFlag_Start) {
            continue;
         }
         nowFbo = file;
         ReadTestData = true;
         fbofile.initDownLoadState();//文件信息下载初始化
         file.setDownload_state(DownLoadState_ReadData);
         nowFbo.setDownload_state(DownLoadState_ReadData);
         while(ReadTestData) {
            try {
               queryDownLoadState(pool, fbofile);
@@ -103,19 +102,25 @@
                  now_download_state = FGCD_ComBase.CMD_DownLoadFBDFile_Over;
                  fbofile.setStop_reason(FialReason_UserCancel);
                  //手动终止下载命令
                  file.setDownload_flag(DownloadFlag_Fail);
                  nowFbo.setDownload_flag(DownloadFlag_Fail);
                  nowFbo.setDownload_state(DownLoadState_DownLoadCancel);
                  fbofile.op_cmd = FGCD_ComBase.CMD_DownLoadFBDFile_Over_ACK;
                  FGCD_Task_Thread_SQL.updateFgcd_Filedownload_TableCmdByDevId(pool, fbofile);
                  file.setDownload_state(DownLoadState_UserCancel);
                  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,file.file_index,nowFbo.now_data_block);
                  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);
                  }
                  updateDownLoadProgress(pool,fbofile);      //更新当前下载进度
               }
               if(nowFbo.getDownload_state() == DownLoadState_CreateData) {
                  //生成当前下载的数据文件
                  if(createFBOFile(file)) {
                  if(createFBOFile(nowFbo)) {
                     //生成FBO文件成功过
                     //System.err.println("生成文件成功");
                     nowFbo.setDownload_state(DownLoadState_ExportData);
@@ -135,17 +140,17 @@
                     nowFbo.setDownload_state(DownLoadState_ExportFail);
                  }*/
                  //开启新线程导入数据库
                  FGCD_Export_Thread_SQL export_Thread=new FGCD_Export_Thread_SQL(pool, nowFbo, fbofile,file_downloadNum);
                  FGCD_Export_Thread_SQL export_Thread=new FGCD_Export_Thread_SQL(pool, nowFbo.clone(), fbofile,file_downloadNum);
                  new Thread(export_Thread).start();
               }
               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);      //更新当前下载进度
               */
               //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();
@@ -165,7 +170,7 @@
         }*/
         //FGCD_Task_Thread_SQL.updateFBOFIleExportFlag(pool,fbofile);      
      }   
      FGCD_Task_Thread_SQL.updateFgcd_FiledownloadState_TableByDevId(pool, fbofile);
      //FGCD_Task_Thread_SQL.updateFgcd_FiledownloadState_TableByDevId(pool, fbofile);
      /******************************** 最后设置当前导出状态 ********************************************/
   }