充放电一体机FGCD通信程序【二期初版】
whyclxw
2021-09-03 fd38ca665f1139baa74206c6e08b49f06db4e441
去掉停止时的ACK
4个文件已修改
69 ■■■■■ 已修改文件
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_Export_Thread_SQL.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_Task_Thread_SQL.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_TestDataDownLoad.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboData.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_Export_Thread_SQL.java
@@ -23,12 +23,12 @@
    public int file_downloadNum=0;
    
    public FGCD_Export_Thread_SQL(MysqlConnPool m_ConnPool, FBOFile nowFbo,FGCD_TestFBOFile fbofile,int file_downloadNum) {
    public FGCD_Export_Thread_SQL(MysqlConnPool m_ConnPool, FBOFile nowFbo,int battgroupid,int file_downloadNum) {
        super();
        this.m_ConnPool = m_ConnPool;
        this.nowFbo = nowFbo;
        //this.battgroupid=battgroupid;
        this.fbofile=fbofile;
        this.battgroupid=battgroupid;
        //this.fbofile=fbofile;
        this.file_downloadNum=file_downloadNum;
        this.logger = LogManager.getLogger(this);
    }
@@ -49,7 +49,7 @@
     private void readFBOFileData(FBOFile nowFbo,MysqlConnPool pool) {
         File file = new File(nowFbo.filename);
         if(nowFbo.test_timelong > 0) {
             FboData.checkFboFileByOneSql(m_ConnPool,file,fbofile,file_downloadNum);
             FboData.checkFboFileByOneSql(m_ConnPool,file,battgroupid,file_downloadNum);
         }
         if(file.exists()) {
            //删除下载的FBO文件
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_Task_Thread_SQL.java
@@ -324,10 +324,10 @@
    }
    //文件导入进度修改
    public static void updateFBOGressByOneSql(MysqlConnPool pool,int file_sum,int file_block,FGCD_TestFBOFile fbofile,int file_downloadNum) {
    public static void updateFBOGressByOneSql(MysqlConnPool pool,int file_sum,int file_block,int battgroupid,int file_downloadNum) {
        //System.out.println("file_downloadNum:"+file_downloadNum);
        String sql_str = " update " + Sql_Mysql.Tb_Fgcd_Filedownload_Table +
                         " set now_data_block"+(file_downloadNum+1)+"="+file_block+",total_data_block"+(file_downloadNum+1)+"="+file_sum+" WHERE BattGroupId = " + fbofile.battgroupid+" and dev_id="+fbofile.dev_id;
                         " set now_data_block"+(file_downloadNum+1)+"="+file_block+",total_data_block"+(file_downloadNum+1)+"="+file_sum+" WHERE BattGroupId = " + battgroupid;
        Sql_Mysql sql = new Sql_Mysql(pool);
        try {
            sql.sqlMysqlExecute(sql_str);
@@ -337,10 +337,10 @@
            sql.close_con();
        }
    }
    //文件导入状态
    public static void updateFBOStateByOneSql(MysqlConnPool pool,int download_flag,int download_state,FGCD_TestFBOFile fbofile,int file_downloadNum) {
    //文件导入状态   op_cmd="+FGCD_ComBase.CMD_DownLoadFBDFile_Over_ACK+",
    public static void updateFBOStateByOneSql(MysqlConnPool pool,int download_flag,int download_state,int battgroupid,int file_downloadNum) {
        String sql_str = " update " + Sql_Mysql.Tb_Fgcd_Filedownload_Table +
                         " set op_cmd="+FGCD_ComBase.CMD_DownLoadFBDFile_Over_ACK+",download_flag"+(file_downloadNum+1)+"="+download_flag+",download_state"+(file_downloadNum+1)+"="+download_state+" WHERE BattGroupId = " + fbofile.battgroupid+" and dev_id="+fbofile.dev_id;
                         " set download_flag"+(file_downloadNum+1)+"="+download_flag+",download_state"+(file_downloadNum+1)+"="+download_state+" WHERE BattGroupId = " + battgroupid;
        Sql_Mysql sql = new Sql_Mysql(pool);
        try {
            sql.sqlMysqlExecute(sql_str);
@@ -374,12 +374,12 @@
    /**
     *     更新当前下载状态,以及异常结束原因
     * @param pool
     * @param file
     * @param file
     * op_cmd =  " + file.op_cmd + " ,
     */
    public static void updateFgcd_Filedownload_TableCmdByDevId(MysqlConnPool pool,FGCD_TestFBOFile file,int file_downloadNum) {
        String sql_str = " UPDATE " + Sql_Mysql.Tb_Fgcd_Filedownload_Table +
                         " SET op_cmd =  " + file.op_cmd +
                         " ,stop_reason =  " + file.getStop_reason() +
                         " SET stop_reason =  " + file.getStop_reason() +
                         " ,download_flag"+(file_downloadNum+1)+" =  " + file.files[file_downloadNum].download_flag +
                         " ,download_state"+(file_downloadNum+1)+" =  " + file.files[file_downloadNum].download_state +
                         " WHERE dev_id =  " + file.dev_id;
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_TestDataDownLoad.java
@@ -111,12 +111,14 @@
                    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) {
                        /*if(nowFbo.download_state == DownLoadState_CreateData) {
                            //下载数量
                            nowFbo.setNow_data_block(0);
                            nowFbo.setTotal_data_block(0);
                        }
                        updateDownLoadProgress(pool,fbofile);        //更新当前下载进度
                        */
                        updateDownLoadProgressByOne(pool,fbofile,file_downloadNum);        //更新当前下载进度
                    }
                    if(nowFbo.getDownload_state() == DownLoadState_CreateData) {
                        //生成当前下载的数据文件
@@ -140,7 +142,7 @@
                            nowFbo.setDownload_state(DownLoadState_ExportFail);
                        }*/
                        //开启新线程导入数据库
                        FGCD_Export_Thread_SQL export_Thread=new FGCD_Export_Thread_SQL(pool, nowFbo.clone(), fbofile,file_downloadNum);
                        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;
                    }
@@ -434,6 +436,29 @@
            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();
        }
    }
    
    /**
     *     查询当前设备的下载进度,避免出现手动停止,可及时停止错误的导入
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboData.java
@@ -154,7 +154,7 @@
    }
    
    //按照每读取一笔数据插入数据库的方式
    public static void checkFboFileByOneSql(MysqlConnPool m_ConnPool,File file,FGCD_TestFBOFile fbofile,int file_downloadNum)
    public static void checkFboFileByOneSql(MysqlConnPool m_ConnPool,File file,int battgroupid,int file_downloadNum)
    {
        File f = file;
        int file_sum=0; //需要导入文件的文件大小字节(导入数据库进度)
@@ -172,12 +172,12 @@
            if(fis.read(buf, 0, buf.length) == 256)
            {
                data_inf.setDataInf(buf);
                int max_test_record_count =FGCD_Task_Thread_SQL.quereyBattMaxTestRecordCount(m_ConnPool, fbofile.battgroupid);
                int max_test_record_count =FGCD_Task_Thread_SQL.quereyBattMaxTestRecordCount(m_ConnPool, battgroupid);
                //添加inf表记录
                boolean flag=FGCD_Task_Thread_SQL.insertFBOInfIntoTable(m_ConnPool, data_inf, fbofile.battgroupid,max_test_record_count);
                boolean flag=FGCD_Task_Thread_SQL.insertFBOInfIntoTable(m_ConnPool, data_inf, battgroupid,max_test_record_count);
                while(true&&flag)
                {   
                    int nowFbo_download_state=FGCD_Task_Thread_SQL.quereyDownLoadState_UserCancel(m_ConnPool,fbofile.battgroupid);
                    int nowFbo_download_state=FGCD_Task_Thread_SQL.quereyDownLoadState_UserCancel(m_ConnPool,battgroupid);
                    if(nowFbo_download_state==FGCD_ComBase.CMD_DownLoadFBDFile_Over) {
                        sucess=false;
                        break;
@@ -194,10 +194,10 @@
                            m_FboData.setData(databuf);
                            //al_fbo_data.add(m_FboData);
                            //System.err.println(m_FboData.toString());
                            boolean bl=FGCD_Task_Thread_SQL.insertFBODataIntoTableByOneSql(m_ConnPool,data_inf,m_FboData,fbofile.battgroupid,record_num,max_test_record_count);
                            boolean bl=FGCD_Task_Thread_SQL.insertFBODataIntoTableByOneSql(m_ConnPool,data_inf,m_FboData,battgroupid,record_num,max_test_record_count);
                            sucess=sucess&bl;
                            file_block=record_num*(data_inf.BattSum*2 + 32)+256;
                            FGCD_Task_Thread_SQL.updateFBOGressByOneSql(m_ConnPool,file_sum,file_block,fbofile,file_downloadNum);//插入文件的进度
                            FGCD_Task_Thread_SQL.updateFBOGressByOneSql(m_ConnPool,file_sum,file_block,battgroupid,file_downloadNum);//插入文件的进度
                            System.err.println("总数:"+file_sum+"  导入数据:"+file_block);
                            record_num++;
                        }
@@ -212,7 +212,7 @@
                    download_flag=FGCD_TestDataDownLoad.DownloadFlag_Fail;
                    download_state=FGCD_TestDataDownLoad.DownLoadState_ExportFail;
                }
                FGCD_Task_Thread_SQL.updateFBOStateByOneSql(m_ConnPool,download_flag,download_state,fbofile,file_downloadNum);
                FGCD_Task_Thread_SQL.updateFBOStateByOneSql(m_ConnPool,download_flag,download_state,battgroupid,file_downloadNum);
            }
                
        } catch (IOException e) {