充放电一体机FGCD通信程序【二期初版】
V1.104 2021-08-24 lijun
1.新增远程下载充放电一体机历史数据文件以及转储到数据库
18个文件已修改
26个文件已添加
3151 ■■■■■ 已修改文件
BattMonitor_FGCD-A059NT/.classpath 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/.settings/org.eclipse.core.resources.prefs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/bin/.gitignore 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/bin/poi-3.10.1-20140818.jar 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/error-20210812-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/error-20210818-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/error-20210819-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/error-20210820-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210812-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210813-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210818-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210819-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210820-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210821-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/lib/poi-3.10.1-20140818.jar 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/battmonitor/data/BattStatData.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/battmonitor/data_store/InsertDataToMysql_Task.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/battmonitor/data_store/InsertDataToMysql_Task_SQL.java 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/battmonitor/sql/Com.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/battmonitor/sql/Sql_Mysql.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/batttest/BattResStorePro_Thread.java 169 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_SocketClient_Thread.java 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_SocketClient_Thread_SQL.java 38 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_Task_Thread_SQL.java 209 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_TestDataDownLoad.java 482 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_BattTestParam.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_Cmd.java 129 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_ComBase.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_ComBuf.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_SysState.java 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_TestFBOFile.java 170 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/BattCapFactory.java 171 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/CsvData.java 349 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FBOFileParseState.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboData.java 267 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboDataCrc16.java 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboDataInf.java 265 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboDataType.java 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboDateTime.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboTestTime.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/IdcData.java 158 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/IdcDataInf.java 132 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/IdcTestTime.java 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/src/main/main_Monitor_FGCD_A059NT.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_FGCD-A059NT/.classpath
@@ -18,5 +18,6 @@
    <classpathentry kind="lib" path="lib/sqljdbc4.jar"/>
    <classpathentry kind="lib" path="lib/log4j-api-2.13.3.jar"/>
    <classpathentry kind="lib" path="lib/log4j-core-2.13.3.jar"/>
    <classpathentry kind="lib" path="lib/poi-3.10.1-20140818.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>
BattMonitor_FGCD-A059NT/.settings/org.eclipse.core.resources.prefs
@@ -1,3 +1,5 @@
eclipse.preferences.version=1
encoding//lib/log4j.properties=UTF-8
encoding//src/com/dev/fgcd/fbo/CsvData.java=GBK
encoding//src/com/dev/fgcd/fbo/IdcDataInf.java=GBK
encoding/<project>=GBK
BattMonitor_FGCD-A059NT/bin/.gitignore
@@ -1,2 +1,5 @@
/aopalliance-1.0.jar
/c3p0-0.9.5.jar
/c3p0-oracle-thin-extras-0.9.5.jar
/com/
/main/
BattMonitor_FGCD-A059NT/bin/poi-3.10.1-20140818.jar
Binary files differ
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/error-20210812-1.log.gz
Binary files differ
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/error-20210818-1.log.gz
Binary files differ
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/error-20210819-1.log.gz
Binary files differ
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/error-20210820-1.log.gz
Binary files differ
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210812-1.log.gz
Binary files differ
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210813-1.log.gz
Binary files differ
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210818-1.log.gz
Binary files differ
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210819-1.log.gz
Binary files differ
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210820-1.log.gz
Binary files differ
BattMonitor_FGCD-A059NT/fgcd_battmonitor_logs/info-20210821-1.log.gz
Binary files differ
BattMonitor_FGCD-A059NT/lib/poi-3.10.1-20140818.jar
Binary files differ
BattMonitor_FGCD-A059NT/src/com/battmonitor/data/BattStatData.java
@@ -3,6 +3,7 @@
import com.battmonitor.base.Com;
import com.dev.btse.data.FBS9100_ComBase;
import com.dev.fgcd.data.FGCD_ComBase;
public class BattStatData
{
@@ -229,8 +230,9 @@
        int fbsdev_testtype = this.getDevFBS9100S_TestType();
        //System.out.println("WorkState:"+this.getDevFBS9100S_WorkState()+"\tfbsdev_testtype:"+fbsdev_testtype+"\tLoaderType:"+this.getLoaderType());
        if((FBS9100_ComBase.SYS_STATE_STOPPED != this.getDevFBS9100S_WorkState())
            && ((FBS9100_ComBase.TestType_CAP==fbsdev_testtype)
                || (FBS9100_ComBase.TestType_Charge==fbsdev_testtype))) {
            && ((FGCD_ComBase.TestType_CAP==fbsdev_testtype)
                || (FGCD_ComBase.TestType_Charge==fbsdev_testtype)
                || (FGCD_ComBase.TestType_HuoHua==fbsdev_testtype))) {
            
            //铁塔放电数据误判方法【铁塔需要调用】2021-06-25
            //--------------------- edit by mxpopstar @20201107 ----------------------//
@@ -258,6 +260,14 @@
        return recordNum;
    }
    
    public Date getStartTestTime() {
        return startTestTime;
    }
    public void setStartTestTime(Date startTestTime) {
        this.startTestTime = startTestTime;
    }
    public void setDevFBS9100S_WorkState(int alarm_stat, int test_type, int wks_t) {
        test_stoptype = alarm_stat;
        
BattMonitor_FGCD-A059NT/src/com/battmonitor/data_store/InsertDataToMysql_Task.java
@@ -70,7 +70,11 @@
                                 + " m_batt_rt.MysqlRecordInf_Exist:" + m_batt_rt.MysqlRecordInf_Exist
                                 + " test_stoptype_t:" + test_stoptype_t);
                //------------------------------------------------------------//
                sql_str = InsertDataToMysql_Task_SQL.getInsertOrUpdateBattTestDataInfStr(m_batt_rt, test_stoptype_t);
                /**
                *     注释为原方法,下面的方法为了在记录历史放电放电数据时记录一笔当前电池组的内阻数据
                */
                //sql_str = InsertDataToMysql_Task_SQL.getInsertOrUpdateBattTestDataInfStr(m_batt_rt, test_stoptype_t);
                sql_str = InsertDataToMysql_Task_SQL.getInsertOrUpdateBattTestDataInfStr(m_Conn_Pool,m_batt_rt, test_stoptype_t);
                sql_v.sqlMysqlExecute(sql_str);
                //------------------------------------------------------------//
                sql_v.mysql_con.commit();
BattMonitor_FGCD-A059NT/src/com/battmonitor/data_store/InsertDataToMysql_Task_SQL.java
@@ -9,6 +9,7 @@
import com.battmonitor.data.MonVolData;
import com.battmonitor.sql.MysqlConnPool;
import com.battmonitor.sql.Sql_Mysql;
import com.batttest.BattResStorePro_Thread;
public class InsertDataToMysql_Task_SQL {
    
@@ -404,6 +405,97 @@
        return sql_str;
    }
    
    /**
     *
     *     @lijun 2021-08-16向tb_batttestdata_inf表中添加数据或者更新数据
     * @param rt_data
     * @return
     */
    public static String getInsertOrUpdateBattTestDataInfStr(MysqlConnPool pool,BattData_RT rt_data, int test_stoptype_t)
    {
        String sql_str = " ";
        BattStatData tmp_test_data = rt_data.mTestData.clone();
        tmp_test_data.test_stoptype = test_stoptype_t;
        if(false == rt_data.MysqlRecordInf_Exist)
        {
            sql_str = "INSERT INTO " + Sql_Mysql.BattTestDataInf_Table
                    + " (BattGroupId, "
                    + "test_record_count, "
                    + "test_type, "
                    + "record_time_interval, "
                    + "data_new, "
                    + "data_available, "
                    + "record_num, "
                    + "test_starttime, "
                    + "test_starttype, "
                    + "record_time, "
                    + "test_timelong, "
                    + "test_stoptype, "
                    + "group_vol, "
                    + "test_curr, "
                    + "test_cap, "
                    + "max_monnum, "
                    + "max_monvol, "
                    + "min_monnum, "
                    + "min_monvol) "
                    + " VALUES "
                    + "("+ rt_data.BattGroupId + ", "
                    + tmp_test_data.testRecordCount + ", "
                    + tmp_test_data.battTestType_For_DataSave + ", "
                    + rt_data.mSaveDataTimeInterval + ", "
                    + true + ", "
                    + true + ", "
                    + (tmp_test_data.recordNum + 1) + ", "
                    + "'" + tmp_test_data.getStartTestTimeString() + "', "
                    + tmp_test_data.testLoaderType + ", "
                    + "'" + tmp_test_data.getRecordTimeString() + "', "
                    + tmp_test_data.testTimeLong + ", "
                    + tmp_test_data.test_stoptype + ", "
                    + tmp_test_data.groupVol + ", "
                    + tmp_test_data.testCurr + ", "
                    + tmp_test_data.testCap + ", "
                    + rt_data.mMaxMonNum + ", "
                    + rt_data.mMaxMonVol + ", "
                    + rt_data.mMinMonNum + ", "
                    + rt_data.mMinMonVol + ") ";
            /**
             * 2021-08-16 @lijun    向插入batttestdata_inf表中插入历史数据时记录当前电池组的内阻数据
             *
             */
            BattResStorePro_Thread.insertMonDataToResTable(pool, rt_data, tmp_test_data.getStartTestTime(), BattStatData.BATTDATA_RES);
        }
        else
        {
            sql_str = "UPDATE " + Sql_Mysql.BattTestDataInf_Table
                    + " SET "
                    + "test_type=" + tmp_test_data.battTestType_For_DataSave + ", "
                    + "record_time_interval=" + rt_data.mSaveDataTimeInterval + ", "
                    + "data_new=" + true + ", "
                    + "data_available=" + true + ", "
                    + "record_num=" + (tmp_test_data.recordNum + 1) + ", "
                    + "test_starttime='" + tmp_test_data.getStartTestTimeString() + "', "
                    + "test_starttype=" + tmp_test_data.testLoaderType + ", "
                    + "record_time='" + tmp_test_data.getRecordTimeString() + "', "
                    + "test_timelong=" + tmp_test_data.testTimeLong + ", "
                    + "test_stoptype=" + tmp_test_data.test_stoptype + ", "
                    + "group_vol=" + tmp_test_data.groupVol + ", "
                    + "test_curr=" + tmp_test_data.testCurrAbsMax + ", "
                    + "test_cap=" + tmp_test_data.testCap + ", "
                    + "max_monnum=" + rt_data.mMaxMonNum + ", "
                    + "max_monvol=" + rt_data.mMaxMonVol + ", "
                    + "min_monnum=" + rt_data.mMinMonNum + ", "
                    + "min_monvol=" + rt_data.mMinMonVol + " "
                    + " WHERE "
                    + " BattGroupId=" + rt_data.BattGroupId
                    + " AND "
                    + " test_starttime='" + tmp_test_data.getStartTestTimeString() + "'";
                    //+ " test_record_count=" + tmp_test_data.testRecordCount;
        }
        return sql_str;
    }
    
    /**
     * 根据测试rt_data数据对象构造删除在tb_batttestdata_id,tb_testdatastop_id,tb_batttestdata_inf中的测试记录的SQL语句集合
BattMonitor_FGCD-A059NT/src/com/battmonitor/sql/Com.java
@@ -66,6 +66,18 @@
        else
            return false;
    }
    public static Date get_DT_FromStr(String dt, String format){
        DateFormat dtf = new SimpleDateFormat(format);
        Date date = new Date();
        try {
            date = dtf.parse(dt);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
      
    /**
     * 判断number参数是否是浮点数表示方式
BattMonitor_FGCD-A059NT/src/com/battmonitor/sql/Sql_Mysql.java
@@ -26,6 +26,7 @@
    
    final public static String WEB_Site = "`web_site`";
    final public static String DB_BATT_HISTORY = "`db_batt_history`";
    final public static String DB_FBO_TESTDATA = "`db_fbo_testdata`";                              //FBO历史数据表
    //--------------------------------------------------------------------------------------------//
    public final static String TB_HardDevSmsState = "tb_hard_dev_sms_state";
    //--------------------------------------------------------------------------------------------//
@@ -128,6 +129,9 @@
    
    public final static String Tb_Fgcd_Filedownload_Table = DB_RamDB + ".tb_fgcd_filedownload";                    //充放电一体机文件下载表
    
    public final static String Tb_FboTestData_Inf_Table = DB_FBO_TESTDATA + ".tb_fbotestdata_inf";                //FBO历史数据统计表
    public final static String Tb_FboTestData_Table = DB_FBO_TESTDATA + ".tb_fbotestdata_";                        //FBO历史数据信息表
    //--------------------------------------------------------------------------------------------//
    //--------------------------------------------------------------------------------------------//
    public Connection mysql_con = null;
@@ -648,7 +652,6 @@
                }
                mysql_con.setAutoCommit(true);
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                logger.error(e1.toString(), e1);
            }
        }
BattMonitor_FGCD-A059NT/src/com/batttest/BattResStorePro_Thread.java
@@ -203,6 +203,175 @@
            sql.close_con();
        }
    }
    /**
     *
     *     @lijun  2021-08-18 重写记录单体内阻数据方法,为记录放电数据时记录当前单体的内阻数据
     *
     *     创建及添加数据到tb_battresdata_id表;添加数据,以及更新tb_battresdata_inf数据表,并且向表中添加数据
     * @param conn_pool
     * @param data_rt
     * @param test_type
     */
    public static void insertMonDataToResTable(MysqlConnPool conn_pool, BattData_RT data_rt,Date test_starttime, int test_type)
    {
        int mon_count = data_rt.MonCount;
        if(mon_count < 1)
            return;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        String sql_str = null;
        try {
            sql.sqlMysqlUseDB(Sql_Mysql.DB_BATT_TESTDATA);
            boolean result = true;
            Date rc_time = test_starttime;
            String tb_name = "tb_BattResData_" + data_rt.BattGroupId;
            if(false == sql.sqlMysqlCheckIfTableExist(tb_name))
            {
                sql_str = "CREATE TABLE IF NOT EXISTS " + tb_name + " "
                        + " ( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                        + "`BattGroupId` INT NOT NULL DEFAULT 0, "
                        + "`test_record_count` INT NOT NULL DEFAULT 0, "
                        + "`test_type` INT NOT NULL DEFAULT 0, "
                        + "`data_new` BOOLEAN NOT NULL DEFAULT false, "
                        + "`data_available` BOOLEAN NOT NULL DEFAULT false, "
                        + "`test_starttime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`group_vol` FLOAT NOT NULL DEFAULT 0, "
                        + "`test_curr` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_num` INT NOT NULL DEFAULT 0, "
                        + "`mon_vol` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_tmp` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_res` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_ser` FLOAT NOT NULL DEFAULT 0, "
                        + "`conn_res` FLOAT NOT NULL DEFAULT 0, "
                        + "INDEX index_test_record_count (`test_record_count`), "
                        + "PRIMARY KEY (`num`));";
                //System.out.println(sql_str);
                sql.sqlMysqlExecute(sql_str);
            }
            int mtest_record_count = 0;//sql.getBattTestRecordCountNew(data_rt.BattGroupId, Sql_Mysql.BattResDataInf_Table);
            for(int c=0; c<3; c++)
            {
                try {
                    sql_str = "INSERT INTO " + tb_name + " "
                            + " (BattGroupId, "
                            + "test_record_count, "
                            + "test_type, "
                            + "data_new, "
                            + "data_available, "
                            + "test_starttime, "
                            + "group_vol, "
                            + "test_curr, "
                            + "mon_num, "
                            + "mon_vol,"
                            + "mon_tmp,"
                            + "mon_res,"
                            + "mon_ser,"
                            + "conn_res)"
                            + " VALUES ";
                    try {
                        for(int n=0; n<mon_count; n++) {
                            String tmp_sql_str = "("
                                        + data_rt.BattGroupId + ", "
                                        + mtest_record_count + ", "
                                        + test_type + ", "
                                        + true + ", "
                                        + true + ", "
                                        + "'" + Com.getDateTimeFormat(rc_time, Com.DTF_YMDhms) + "', "
                                        + data_rt.mTestData.groupVol + ", "
                                        + data_rt.mTestData.testCurr + ", "
                                        + ((n+1)*10 + 1) + ", "
                                        + data_rt.al_MonVol.get(n).monVol + ","
                                        + data_rt.al_MonVol.get(n).monTmp + ","
                                        + data_rt.al_MonVol.get(n).monRes + ","
                                        + data_rt.al_MonVol.get(n).monSer + ","
                                        + data_rt.al_MonVol.get(n).connRes
                                        + ")";
                            if(n > 0) {
                                sql_str += ", ";
                            }
                            sql_str += tmp_sql_str;
                        }
                    } catch (Exception e) {
                        sql.logger.error("BattResStorePro_Thread.insertDataToResTable():" + e.toString(), e);
                    }
                    String sql_str2 = "INSERT INTO " + Sql_Mysql.BattResDataInf_Table
                                + " (BattGroupId, "
                                + "test_record_count, "
                                + "test_type, "
                                + "data_new, "
                                + "data_available, "
                                + "test_starttime, "
                                + "test_devtype, "
                                + "record_time, "
                                + "group_vol, "
                                + "test_curr, "
                                + "upload_usr_id) "
                                + " VALUES "
                                + "("+ data_rt.BattGroupId + ", "
                                + mtest_record_count + ", "
                                + test_type + ", "
                                + true + ", "
                                + true + ", "
                                + "'" + Com.getDateTimeFormat(rc_time, Com.DTF_YMDhms) + "', "
                                + 0 + ", "
                                + "'" + Com.getDateTimeFormat(rc_time, Com.DTF_YMDhms) + "', "
                                + 0 + ", "
                                + 0 + ", "
                                + 0 + ") ";
                    if(1 == mtest_record_count) {
                        sql_str2 = "UPDATE " + Sql_Mysql.BattResDataInf_Table + " SET "
                                + "test_type=" + test_type + ", "
                                + "data_new=" + true + ", "
                                + "data_available=" + true + ", "
                                + "test_starttime='" + Com.getDateTimeFormat(rc_time, Com.DTF_YMDhms) + "', "
                                + "test_devtype=" + 0 + ", "
                                + "record_time='" + Com.getDateTimeFormat(rc_time, Com.DTF_YMDhms) + "', "
                                + "group_vol=" + 0 + ", "
                                + "test_curr=" + 0 + ", "
                                + "upload_usr_id=" + 0 + " "
                                + " WHERE BattGroupId=" + data_rt.BattGroupId
                                + " AND test_record_count=" + mtest_record_count;
                    }
                    //System.out.println(sql_str);
                    //System.out.println(sql_str2);
                    sql.mysql_con.setAutoCommit(false);
                    sql.sqlMysqlExecute(sql_str);
                    sql.sqlMysqlExecute(sql_str2);
                    sql.mysql_con.commit();
                } catch (SQLException e) {
                    sql.mysql_con.rollback();
                    //System.out.println(sql_str);
                    sql.logger.error("BattResStorePro_Thread.insertDataToResTable():" + e.toString(), e);
                    result = false;
                } finally {
                    sql.mysql_con.setAutoCommit(true);
                    if(true == result)
                    {
                        break;
                    }
                    else
                    {
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            sql.logger.error("BattResStorePro_Thread.insertDataToResTable():" + e.toString(), e);
                        }
                    }
                }
            }
        } catch (SQLException e) {
            sql.logger.error("BattResStorePro_Thread.insertDataToResTable():" + e.toString(), e);
        } finally {
            sql.close_con();
        }
    }
    //-----------------------------------------------------------------------------//
    @Override
    public void run() {
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_SocketClient_Thread.java
@@ -49,6 +49,7 @@
    private FGCD_SysState sysState;                 //ϵͳ״̬
    private FGCD_Cmd m_FBS_Cmd = new FGCD_Cmd();
    public FGCD_TestFBOFile fboFile;                //历史数据文件
    
    private ByteBuffer bytebuffer_for_socket_RX = ByteBuffer.allocate(1500);
@@ -64,6 +65,10 @@
    private int errcount = 0;
    private int DevReadCount = 0;
    private int m_BattMonCount;
    private boolean readMonData = false;        //是否立即读取单体数据  记录历史数据时立即读取单体数据
    private boolean readCharData = false;        //是否立即读取放电数据  记录历史数据时立即读取放电数据
    
    
    public FGCD_SocketClient_Thread(MysqlConnPool m_ConnPool,BattData_RT_Array m_Data,Socket socket){
@@ -113,15 +118,15 @@
                    }*/
                    
                    if(true == reg_in_st) {
                        logger.trace("devid:" + m_StatAndParam.check_dev_id
                        logger.info("devid:" + m_StatAndParam.check_dev_id
                                + ", 数据库中匹配devid成功!!!!!, IP:" + socket.getInetAddress().getHostAddress());
                    } else {
                        logger.trace("devid:" + m_StatAndParam.check_dev_id
                        logger.info("devid:" + m_StatAndParam.check_dev_id
                                + ", 数据库中未找到匹配的devid, IP:" + socket.getInetAddress().getHostAddress());
                        break;
                    }
                } else {
                    logger.trace(this.getName() + " initFGCD_A059Comm() devid:" + m_StatAndParam.check_dev_id
                    logger.info(this.getName() + " initFGCD_A059Comm() devid:" + m_StatAndParam.check_dev_id
                                + ", 识别FGCD_A059设备失败 ");
                    reg_in_st = false;
                }
@@ -199,16 +204,20 @@
                    if(FGCD_ComBase.CMD_GetDischargeParm == m_StatAndParam.op_cmd) {
                        //读取放电参数
                        SocketComm(FGCD_ComBase.CMD_GETDISCHARGEPARAM, ByteBuffer.allocate(0));
                        logger.warn("DevId:" + m_StatAndParam.dev_id + " 读取放电参数");
                        //logger.info("DevId:" + m_StatAndParam.dev_id + " 读取放电参数");
                    }     
                    
                    if(FGCD_ComBase.CMD_SetDischargeParm == m_StatAndParam.op_cmd) {
                        //设置放电参数
                        FGCD_BattTestParam tmp_set_pm = testParam.clone();
                        FGCD_SocketClient_Thread_SQL.queryFbs9100SetParamBydev_id(m_ConnPool, m_StatAndParam, tmp_set_pm);
                        System.out.println(tmp_set_pm);
                        //System.out.println(tmp_set_pm);
                        logger.warn("DevId:" + m_StatAndParam.dev_id + " 设置放电参数"+tmp_set_pm);
                        SocketComm(FGCD_ComBase.CMD_SETDISCHARGEPARAM, tmp_set_pm.getByteBuffer());
                        if(SocketComm(FGCD_ComBase.CMD_SETDISCHARGEPARAM, tmp_set_pm.getByteBuffer())) {
                            //更新当前活化次数
                            sysState.hhCount = tmp_set_pm.cycleTimes;
                            testParam = tmp_set_pm.clone();
                        }
                        //tmp_set_pm = null;
                    }
                    
@@ -270,15 +279,17 @@
                        SocketComm(fboFile.createCmd(FGCD_ComBase.CMD_GETFILELIST), ByteBuffer.allocate(0));                        
                    }else if(FGCD_ComBase.CMD_DownLoadFBDFile == fboFile.op_cmd) {
                        //开始下载文件
                    }
                        FGCD_TestDataDownLoad download = new FGCD_TestDataDownLoad(fboFile, socket,m_ConnPool);
                        fboFile.initDownLoadState();
                        FGCD_SocketClient_Thread_SQL.updateFgcd_Filedownload_TableCmdByDevId(m_ConnPool, fboFile);
                        download.downLoadTestData();
                    }
                }
                if(DevReadCount %10 == 0) {
                    //logger.info("获取单体数据");
                    SocketComm(FGCD_ComBase.CMD_GETBATTDATA, ByteBuffer.allocate(0));
                    FGCD_Cmd tmp_cmd = new FGCD_Cmd(FGCD_ComBase.CMD_GETBATTDATA);
                    SocketComm(tmp_cmd, ByteBuffer.allocate(0));
                    tmp_cmd = null;
                }
                
                if(DevReadCount %12 == 0) {
@@ -300,7 +311,6 @@
     *     向指定的socket通道发送数据,以及接收数据
     * @return
     */
    public boolean SocketComm(int cmd,ByteBuffer byteBuffer)
    {
        boolean res_t = false;
@@ -651,7 +661,6 @@
        return byte_rest;
    }
    /*********************************************************************************************/
   
    /*********************************************************************************************/
    public Boolean getDataFromCommBuf(final byte[] bytes)
@@ -668,8 +677,6 @@
            if(errcode > 0) {
                logger.error(this.getName(), "FGCD_Cmd.CMD:"+m_FBS_Cmd.CMD+"\t RTN:"+errcode);
            }
            sysState.dev_captest_stop_type = m_FBS_Cmd.Alarm;
            sysState.dev_workstate = m_FBS_Cmd.WorkState;
            //sysState.dev_workstate = 2;
            //---------------------  心跳包测试    ----------------------------------
            if(FGCD_ComBase.CMD_HEARTBEAT == m_FBS_Cmd.CMD) {
@@ -722,12 +729,13 @@
            }
            //---------------------  获取放电参数    ----------------------------------------------
            else if(FGCD_ComBase.CMD_GETDISCHARGEPARAM == m_FBS_Cmd.CMD) {
                //logger.info(TAG, "getDataFromCommBuf: 获取放电参数成功" );
                if(testParam.putByteBuffer(bf)) {
                    m_StatAndParam.op_cmd_ack = FGCD_ComBase.CMD_GetDischargeParmAck;
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamBydev_id(m_ConnPool, m_StatAndParam, testParam);
                    isSuccess = true;
                    sysState.hhCount = testParam.cycleTimes;            //更新当前活化总次数
                    //System.out.println(testParam);
                    logger.trace("getDataFromCommBuf: 获取放电参数成功" + testParam );
                }
            }
            //---------------------- 设置放电参数 --------------------------------------------------
@@ -737,7 +745,7 @@
                    m_StatAndParam.op_cmd_ack = FGCD_ComBase.CMD_SetDischargeParmAck;
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    isSuccess = true;
                    //System.out.println("设置参数成功");
                    logger.warn("getDataFromCommBuf: 设置放电参数成功" + testParam );
                }
            }
            //---------------------  启动放电    ----------------------------------
@@ -748,7 +756,7 @@
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    
                    isSuccess = true;
                    System.err.println("启动放电成功");
                    logger.warn("getDataFromCommBuf: 启动放电成功");
                }
            }
            //---------------------  放电暂停    ----------------------------------
@@ -758,7 +766,7 @@
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    
                    isSuccess = true;
                    //System.out.println("暂停放电成功");
                    logger.warn("dev_id:"+m_StatAndParam.dev_id+"\t getDataFromCommBuf: 暂停放电成功");
                }
            }
            //---------------------  停止放电    ----------------------------------
@@ -767,16 +775,19 @@
                    m_StatAndParam.op_cmd_ack = FGCD_ComBase.CMD_StopDischargeAck;
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    isSuccess = true;
                    //System.out.println("停止放电成功");
                    logger.warn("dev_id:"+m_StatAndParam.dev_id+"\t getDataFromCommBuf: 停止放电成功");
                }
            }
            //---------------------  获取放电数据    ----------------------------------
            else if(FGCD_ComBase.CMD_GETDISCHARGEDATA == m_FBS_Cmd.CMD) {
                if(sysState.putByteBuffer(bf)) {
                    //读取当前设备的停止原因和当前工作状态
                    sysState.dev_captest_stop_type = m_FBS_Cmd.Alarm;
                    sysState.dev_workstate = m_FBS_Cmd.WorkState;
                    sysState.hhstate = m_FBS_Cmd.Db2;        //活化状态
                    for(int i=0;i<sysState.montmps.length;i++) {
                        vc_data.tmp[i] = sysState.montmps[i];
                    }
                    }
                    FGCD_SocketClient_Thread_SQL.updateFbs9100StateOnlyByDev_Id(m_ConnPool, m_StatAndParam);;
                    isSuccess = true;
                }
@@ -789,7 +800,7 @@
                    m_StatAndParam.op_cmd_ack = FGCD_ComBase.CMD_StartCharTestAck;
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    isSuccess = true;
                    //System.out.println("启动充电成功");
                    logger.warn("dev_id:"+m_StatAndParam.dev_id+"\t getDataFromCommBuf: 启动充电成功");
                }
            }
            //---------------------  暂停充电    ----------------------------------
@@ -798,7 +809,7 @@
                    m_StatAndParam.op_cmd_ack = FGCD_ComBase.CMD_PauseCharTestAck;
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    isSuccess = true;
                    //System.out.println("暂停充电成功");
                    logger.warn("dev_id:"+m_StatAndParam.dev_id+"\t getDataFromCommBuf: 暂停充电成功");
                }
            }
            //---------------------  停止充电    ----------------------------------
@@ -807,7 +818,7 @@
                    m_StatAndParam.op_cmd_ack = FGCD_ComBase.CMD_StopCharTestAck;
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    isSuccess = true;
                    //System.out.println("停止充电成功");
                    logger.warn("dev_id:"+m_StatAndParam.dev_id+"\t getDataFromCommBuf: 停止充电成功");
                }
            }
@@ -826,7 +837,7 @@
                    //FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    FGCD_SocketClient_Thread_SQL.updateClearAlarmState(m_ConnPool, m_StatAndParam, FGCD_ComBase.CMD_ClearSysAlarm_ACK);
                    isSuccess = true;
                    System.out.println("清除告警成功");
                    logger.warn("dev_id:"+m_StatAndParam.dev_id+"\t 清除告警成功");
                }
            }
            //---------------------  进入 Android控制   ----------------------------------
@@ -863,7 +874,7 @@
                    m_StatAndParam.op_cmd_ack = FGCD_ComBase.CMD_StartHUOHUATestACK;
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    isSuccess = true;
                    //System.out.println("启动活化测试成功");
                    logger.warn("dev_id:"+m_StatAndParam.dev_id+"\t 启动活化测试成功");
                }
            }else if(FGCD_ComBase.CMD_PAUSEHHTEST == m_FBS_Cmd.CMD) {
                //暂停活化测试
@@ -871,7 +882,7 @@
                    m_StatAndParam.op_cmd_ack = FGCD_ComBase.CMD_PauseHUOHUATestACK;
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    isSuccess = true;
                    //System.out.println("暂停活化测试成功");
                    logger.warn("dev_id:"+m_StatAndParam.dev_id+"\t 暂停活化测试成功");
                }                
            }else if(FGCD_ComBase.CMD_STOPHHTEST == m_FBS_Cmd.CMD) {
                //停止活化测试
@@ -879,7 +890,7 @@
                    m_StatAndParam.op_cmd_ack = FGCD_ComBase.CMD_StopHUOHUATestACK;
                    FGCD_SocketClient_Thread_SQL.updateFbs9100SetParamCmdAckBydev_id(m_ConnPool,m_StatAndParam);
                    isSuccess = true;
                    //System.out.println("停止活化测试成功");
                    logger.warn("dev_id:"+m_StatAndParam.dev_id+"\t 停止活化测试成功");
                }
            }else if(FGCD_ComBase.CMD_GETFILELIST == m_FBS_Cmd.CMD) {
                //获取文件列表
@@ -918,7 +929,13 @@
                    logger.error(e.toString(), e);
                }
                int now_test_type = FGCD_ComBase.TestType_NULL;
                m_RTData[n].mTestData.test_stoptype = sys_state.dev_captest_stop_type;        //更新当前的停止原因
                //记录停止原因时数据处理
                if(sys_state.dev_captest_stop_type > 0x80) {
                    m_RTData[n].mTestData.test_stoptype = sys_state.dev_captest_stop_type - 0x80;        //更新当前的停止原因
                }else {
                    m_RTData[n].mTestData.test_stoptype = sys_state.dev_captest_stop_type;
                }
                int now_dev_workstate = 0;
                if(FGCD_ComBase.WORK_STATE_DISTEST == sys_state.dev_workstate ||
                    (FGCD_ComBase.WORK_STATE_STOPDIS == sys_state.dev_workstate)){
                    vc_data.battcurr[n] = (-1)*Math.abs(vc_data.battcurr[n]);
@@ -930,6 +947,12 @@
                    //System.out.println("vc_data.battcurr[n]:"+vc_data.battcurr[n]);
                    now_test_type = FGCD_ComBase.TestType_Charge;
                }
                now_dev_workstate = sys_state.dev_workstate;
                if(sys_state.hhstate > 0) {
                    //设备当前状态为活化状态
                    now_dev_workstate = FGCD_ComBase.WORK_STATE_HUOHUA;
                    now_test_type = FGCD_ComBase.TestType_HuoHua;
                }
                //--------------------- 再读取系统状态 ---------------------------------------//
//                if(((FBS9100_ComBase.SYS_STATE_STOPPED!=sys_state.dev_workstate) && ((n+1)==sys_state.TestGroupNum))
//                    || (FGCD_ComBase.WORK_STATE_STOPPED == sys_state.dev_workstate)) {
@@ -939,7 +962,7 @@
                    //--------------------------------------------------------------------------//
                    m_RTData[n].mTestData.setDevFBS9100S_WorkState(sys_state.dev_captest_stop_type, 
                                                                    now_test_type,
                                                                    sys_state.dev_workstate);
                                                                    now_dev_workstate);
//                }
                
                //--------------------- 再读取端电压 -----------------------------------------//
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_SocketClient_Thread_SQL.java
@@ -168,11 +168,12 @@
     */
    public static void updateTb_Fgcd_Filedownload_Table(MysqlConnPool pool,FGCD_TestFBOFile fbo) {
        String sql_str = " UPDATE " + Sql_Mysql.Tb_Fgcd_Filedownload_Table +
                " SET op_cmd = "+fbo.op_cmd+"," +
                " file_count = " + fbo.file_total;
                " SET op_cmd = "+fbo.op_cmd +
                " ,file_count = " + fbo.file_count +
                " ,file_total = " + fbo.file_total;
        if(fbo.file_count > 0) {
            //当前文件数大于0
            for(int i=0;i<fbo.file_count;i++) {
            for(int i=0;i<fbo.files.length;i++) {
                FBOFile file = fbo.files[i];
                sql_str += ",file_name"+(i+1)+"='"+file.filename+"'"
                         + ",file_index"+(i+1)+"="+file.file_index
@@ -214,6 +215,9 @@
                file.battgroupid = res.getInt("BattGroupId");
                file.file_index = res.getInt("file_index");
                file.op_cmd = res.getInt("op_cmd");
                for(int i=0;i<file.files.length;i++) {
                    file.files[i].setDownload_flag(res.getInt("download_flag"+(i+1)));;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
@@ -225,6 +229,26 @@
                    e.printStackTrace();
                }
            }
            sql.close_con();
        }
    }
    /**
     *     更新当前下载状态,以及异常结束原因
     * @param pool
     * @param file
     */
    public static void updateFgcd_Filedownload_TableCmdByDevId(MysqlConnPool pool,FGCD_TestFBOFile file) {
        String sql_str = " UPDATE " + Sql_Mysql.Tb_Fgcd_Filedownload_Table +
                         " SET op_cmd =  " + file.op_cmd +
                         " ,stop_reason =  " + file.getStop_reason() +
                         " WHERE dev_id =  " + file.dev_id;
        Sql_Mysql sql = new Sql_Mysql(pool);
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
@@ -1186,9 +1210,15 @@
                    + "batt_online_state=" + m_pm.sysState.diode_state+ ", "
                    + "dev_temp=" + m_pm.sysState.devtmp + ", "
                    + "dev_res_test_state=" + m_pm.sysState.tmp_alm_lock + ", "
                    + "dev_testgroupnum=" + m_pm.sysState.hhProgress + ", "
                    + "dev_workstate=" + m_pm.sysState.dev_workstate + ", "
                    + "dev_captest_curr=" + m_pm.sysState.chargeCurr + ", "
                    + "dev_restest_monindex=" + m_pm.sysState.hhProgress + ", "            //活化进度
                    + "dev_restest_moncount=" + m_pm.sysState.hhCount + ", "            //活化次数
                    + "dev_batt_xuhang_tlong=" + m_pm.sysState.hhstate + ", "            //活化状态
                    + "dev_captest_timelong=" + m_pm.sysState.test_timelong + ", "        //显示屏测试时长
                    + "dev_eachgroup_battsum=" + m_pm.sysState.char_phase + ", "        //充电阶段数
                    + "dev_last_captest_stop_type=" + m_pm.sysState.dev_captest_stop_type + ", "
                    + "dev_captest_cap=" + m_pm.sysState.testCap + ", "
                    + "dev_data_flowsum=" + m_pm.sysState.dev_data_flowsum+ ", "
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_Task_Thread_SQL.java
New file
@@ -0,0 +1,209 @@
package com.dev.fgcd.comm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.battmonitor.sql.Com;
import com.battmonitor.sql.MysqlConnPool;
import com.battmonitor.sql.Sql_Mysql;
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.mchange.v2.resourcepool.ResourcePoolListener;
public class FGCD_Task_Thread_SQL {
    /**
     *     插入FBO历史数据
     * @param pool
     * @param file
     * @param fbo
     * @param datas
     * @return
     */
    public static boolean insertFBODataIntoTable(MysqlConnPool pool,FBOFile file,FboDataInf fbo,List<FboData> datas,int BattGoupId) {
        boolean success = false;
        if(fbo.getTestTimeLong() > 0) {
            createTb_FboTestData_Table(pool, BattGoupId);
            int max_test_record_count = quereyBattMaxTestRecordCount(pool, BattGoupId);
            ArrayList<String> sql_strs = new ArrayList<>();
            sql_strs.add("INSERT INTO " + Sql_Mysql.Tb_FboTestData_Inf_Table +
                    "(BattGroupId,test_record_count,test_starttime,test_timelong,device,test_type,hourrate,save_interval,monomervol,moncapstd,test_curr,test_cap,monvol_limit,gourpvol_limit,mon_count,monvol_limitcount,stop_type,download_time) " +
                    " VALUES(" + BattGoupId
                    + "," +max_test_record_count
                    + ",'" + Com.getDateTimeFormat(fbo.TestStartTime.getFBODateTime(), Com.DTF_YMDhms)
                    + "'," + fbo.getTestTimeLong()
                    + "," + fbo.Device
                    + "," + fbo.DataType
                    + "," + fbo.HourRate
                     + "," + fbo.SaveInterval
                    + "," + fbo.MonomerVol
                    + "," + fbo.STDCap
                    + "," + fbo.TestCur
                    + "," + fbo.TestCap
                    + "," + fbo.MVLLimit
                     + "," + fbo.SumVLLimit
                    + "," + fbo.BattSum
                    + "," + fbo.MVLLimitCount
                    + "," + fbo.StopType
                    + ",'" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)
                    + "')");
            for(int i = 0;i<datas.size();i++) {
                FboData data = datas.get(i);
                //System.out.println("测试时长"+data.m_TestTime.getTestTimeString());
                String sql_str = "INSERT INTO "+Sql_Mysql.Tb_FboTestData_Table+BattGoupId+"(BattGroupId,test_record_count,test_starttime,test_timelong,record_time,record_num,online_vol,sum_vol,test_curr,test_cap,mon_num,mon_vol) " +
                                 " VALUES";
                Date record_time = new Date(fbo.TestStartTime.getFBODateTime().getTime()+data.m_TestTime.getTestTimeLong()*1000);
                if(data.BattSum > 0) {
                    //有单体时
                    for(int k=0;k<data.BattSum && k<data.SingleVol.length;k++) {
                        sql_strs.add(sql_str + "("
                                + "" + BattGoupId
                                + "," + max_test_record_count
                                + ",'" + Com.getDateTimeFormat(fbo.TestStartTime.getFBODateTime(), Com.DTF_YMDhms)
                                + "'," + data.m_TestTime.getTestTimeLong()
                                + ",'" + Com.getDateTimeFormat(record_time, Com.DTF_YMDhms)
                                + "'," + (i+1)
                                + "," + data.OnlineVol
                                + "," + data.SumVoltage
                                + "," + data.SumCurrent
                                + "," + data.AllCap
                                + "," + (k+1)
                                + "," + data.SingleVol[k]
                                + ")");
                    }
                }else {
                    //没有单体数据时
                    sql_strs.add(sql_str + "("
                            + "" + BattGoupId
                            + "," + max_test_record_count
                            + ",'" + Com.getDateTimeFormat(fbo.TestStartTime.getFBODateTime(), Com.DTF_YMDhms)
                            + "'," + data.m_TestTime.getTestTimeLong()
                            + ",'" + Com.getDateTimeFormat(record_time, Com.DTF_YMDhms)
                            + "'," + (i+1)
                            + "," + data.OnlineVol
                            + "," + data.SumVoltage
                            + "," + data.SumCurrent
                            + "," + data.AllCap
                            + "," + 0
                            + "," + 0
                            + ")");
                }
            }
            Sql_Mysql sql = new Sql_Mysql(pool);
            ResultSet res = null;
            try {
                res = sql.sqlMysqlQuery(" SELECT * " +
                        " FROM " + Sql_Mysql.Tb_FboTestData_Inf_Table +
                        " WHERE BattGroupId = "+BattGoupId+" AND test_starttime = '"+Com.getDateTimeFormat(fbo.TestStartTime.getFBODateTime(), Com.DTF_YMDhms)+"'");
                if(!res.next()) {
                    success = sql.makeManualCommit(sql_strs);
                }else {
                    //System.out.println("已存在当前测试数据");
                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                if(null != res) {
                    try {
                        res.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
                sql.close_con();
            }
        }
        return success;
    }
    /**
     *     创建FBO历史数据_ID表
     * @param pool
     * @param BattGroupId
     */
    public static void createTb_FboTestData_Table(MysqlConnPool pool,int BattGroupId) {
        String sql_str = " CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_FboTestData_Table+BattGroupId+" (" +
                "  `num` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键'," +
                "  `BattGroupId` int(11) NOT NULL DEFAULT '0' COMMENT '电池组ID'," +
                "  `test_record_count` int(11) NOT NULL DEFAULT '1' COMMENT '测试笔数'," +
                "  `test_starttime` datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '测试开始时间'," +
                "  `test_timelong` int(11) NOT NULL," +
                "  `record_time` datetime NOT NULL," +
                "  `record_num` int(11) NOT NULL DEFAULT '1' COMMENT '记录笔数'," +
                "  `online_vol` float NOT NULL DEFAULT '0' COMMENT '在线电压'," +
                "  `sum_vol` float NOT NULL DEFAULT '0' COMMENT '总电压'," +
                "  `test_curr` float NOT NULL DEFAULT '0' COMMENT '测试电流'," +
                "  `test_cap` float NOT NULL DEFAULT '0' COMMENT '测试容量'," +
                "  `mon_num` int(11) NOT NULL DEFAULT '0' COMMENT '单体编号'," +
                "  `mon_vol` float NOT NULL DEFAULT '0' COMMENT '单体电压'," +
                "  PRIMARY KEY (`num`)" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8; ";
        Sql_Mysql sql = new Sql_Mysql(pool);
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     *     查询当前电池组当前最大的记录笔数+1
     * @param pool
     * @param BattGroupId
     * @return
     */
    public static int quereyBattMaxTestRecordCount(MysqlConnPool pool,int BattGroupId) {
        int test_record_count = 0;
        String sql_str = " SELECT MAX(test_record_count) as test_record_count " +
                         " FROM " + Sql_Mysql.Tb_FboTestData_Inf_Table +
                         " WHERE BattGroupId = " + BattGroupId;
        Sql_Mysql sql = new Sql_Mysql(pool);
        ResultSet res = null;
        try {
            res = sql.sqlMysqlQuery(sql_str);
            if(res.next()) {
                test_record_count = res.getInt("test_record_count");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(null != res) {
                try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            sql.close_con();
        }
        return (test_record_count+1);
    }
    public static void updateFBOFIleExportFlag(MysqlConnPool pool, FGCD_TestFBOFile fbofile) {
        String sql_str = " Update  " + Sql_Mysql.Tb_Fgcd_Filedownload_Table +
                         " Set download_state = " + fbofile.getDownload_state();
        for(int i=0;i<fbofile.files.length;i++) {
            sql_str += " ,download_flag"+(i+1)+" = "+fbofile.files[i].download_flag+""
                     + " ,download_state"+(i+1)+" =" +fbofile.files[i].download_state;
        }
        sql_str += " WHERE dev_id = " + fbofile.dev_id;
        Sql_Mysql sql = new Sql_Mysql(pool);
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/comm/FGCD_TestDataDownLoad.java
New file
@@ -0,0 +1,482 @@
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 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;        //导入失败
    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;
    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() {
        for(int i=0;i<fbofile.files.length;i++) {
            //当前下载文件
            FBOFile file = fbofile.files[i];
            if(file.download_flag != DownloadFlag_Start) {
                continue;
            }
            ReadTestData = true;
            fbofile.initDownLoadState();
            fbofile.setDownload_state(DownLoadState_ReadData);
            while(ReadTestData) {
                try {
                    queryDownLoadState(pool, fbofile);
                    if(fbofile.op_cmd != FGCD_ComBase.CMD_DownLoadFBDFile_Over) {
                        //手动终止下载命令
                        return;
                    }
                    if(fbofile.getDownload_state() == DownLoadState_ReadData) {
                        //System.out.println("读取测试文件中"+file);
                        SocketComm(FGCD_ComBase.CMD_GETFILE,file.file_index,fbofile.now_data_block);
                    }
                    if(fbofile.getDownload_state() == DownLoadState_CreateData) {
                        //生成当前下载的数据文件
                        if(createFBOFile(file)) {
                            //生成FBO文件成功过
                            //System.err.println("生成文件成功");
                            fbofile.setDownload_state(DownLoadState_ExportData);
                        }else{
                            //生成FBO文件失败
                            //System.err.println("生成文件失败");
                            fbofile.setDownload_state(DownLoadState_ExportFail);
                        }
                    }
                    if(fbofile.getDownload_state() == DownLoadState_ExportData) {
                        //解析本地数据文件并导入数据库
                        boolean flag = readFBOFileData(file,pool);
                        if(flag) {
                            fbofile.setDownload_state(DownLoadState_ExportSucc);
                        }else {
                            fbofile.setDownload_state(DownLoadState_ExportFail);
                        }
                    }
                    if(fbofile.getDownload_state() == DownLoadState_ExportFail
                        || fbofile.getDownload_state() == DownLoadState_ExportSucc) {
                        ReadTestData = false;
                    }
                    file.setDownload_state(fbofile.getDownload_state());
                    updateDownLoadProgress(pool,fbofile);        //更新当前下载进度
                    Thread.sleep(50);
                } catch(Exception e) {
                    e.printStackTrace();
                }
            }
            filebyte = new byte[0];
            {
                if(fbofile.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);
        }
        /******************************** 最后设置当前导出状态 ********************************************/
    }
    /**
     *     解析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.fbofile.total_data_block = m_FBS_Cmd.getTotalDownLoadBlock();
                    //System.out.println("数据包总长度:"+ this.fbofile.total_data_block+ m_FBS_Cmd);
                    if(m_FBS_Cmd.getNowDownLoadIndex() == fbofile.now_data_block) {
                        if(putFileData(bf,m_FBS_Cmd.ByteLen-18)) {
                            fbofile.now_data_block ++;
                            isSuccess = true;
                            //System.out.println("读取第"+m_FBS_Cmd.getNowDownLoadIndex()+"个数据包成功");
                            if(fbofile.now_data_block == fbofile.total_data_block) {
                                //System.out.println("下载历史数据文件完成");
                                fbofile.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 download_state = " + fbofile.getDownload_state() +
                         " ,now_data_block = " + fbofile.now_data_block +
                         " ,total_data_block = " + fbofile.total_data_block;
        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++) {
            sql_str += ",download_state"+(i+1)+" = "+fbofile.files[i].getDownload_state();
        }
        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;
    }
//    public static void main(String[] args) {
//        File root = new File(System.getProperty("user.dir")+File.separator+"88888"+File.separator+123456);
//        if(!root.exists()) {
//            root.mkdirs();
//        }
//    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_BattTestParam.java
@@ -36,7 +36,7 @@
    public int monVolLowCount;            //单体下限数量(0~240)
    //public int saveInterval;            //数据保存间隔min
    //public double dcVolHighLimit;        //升压上限(0.1V)
    public double mon_vol;              //单体电压
    public double mon_vol;              //单体电压(0.1V 0~20V)
    //public double chargeCurr;            //充电电压(在线阈值)A
    public int testType;                //测试类型(0:恒电流    1:恒功率      2:恒电阻)
    public double dischargePower;        //预放功率(0.1kw)
@@ -63,9 +63,7 @@
    public int FlowOver_Count;             //恒流总阶段数             1-3
    public int C_Curr_Num;                  //当前设置阶段index       0-2
    public float FlowOver_CharCurr[] = new float[3];    //恒流阶段充电电流         1-100A
    public int FlowOver_CharTime[] = new int[3];      //恒流阶段充电时间
    public int FlowOver_CharTime[] = new int[3];          //恒流阶段充电时间
    
    public int[] backup = new int[3];                
@@ -146,7 +144,7 @@
        monVolLowCount = FGCD_ComBase.changeShortToInt(bf.getShort());                //单体下限数量
        //dcVolHighLimit = FGCD_ComBase.changeShortToDouble(bf.getShort())/10;        //升压上限
        mon_vol = (double)FGCD_ComBase.changeShortToDouble(bf.getShort())/10;               //单体电压
        System.err.println(mon_vol);
        //System.err.println(mon_vol);
        testType = FGCD_ComBase.changeShortToInt(bf.getShort());                    //测试类型
        dischargePower = FGCD_ComBase.changeShortToDouble(bf.getShort())/10;        //预放功率
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_Cmd.java
@@ -2,6 +2,7 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
public class FGCD_Cmd {
@@ -20,6 +21,13 @@
    public int Db4;                                                //预留4
    private int CRC;
    public FGCD_Cmd() {
        // TODO Auto-generated constructor stub
    }
    public FGCD_Cmd(int CMD) {
        this.CMD = CMD;
    }
    public void makeCmd(int cmd, int byteLen)
    {
@@ -60,6 +68,24 @@
        tmpbuf.flip();
        return true;
    }
    /**
     *     读取当前下载成功数据块号
     * @return
     */
    public int getNowDownLoadIndex() {
        return this.Db3*256 + Db4;
    }
    /**
     *     读取当前总的数据块数目
     * @return
     */
    public int getTotalDownLoadBlock() {
        int total = this.Db1*256 + this.Db2;
        System.err.println(total);
        return total;
    }
    public int createCrc16(ByteBuffer bf) {
@@ -115,4 +141,107 @@
        int check_dev_id = 8059*100000 + (this.Db1<<8) +(this.Db2);
        return check_dev_id;
    }
    public int getBYTE_LEN() {
        return BYTE_LEN;
    }
    public int[] getSYNCode() {
        return SYNCode;
    }
    public int getByteLen() {
        return ByteLen;
    }
    public int getCMD() {
        return CMD;
    }
    public int getRecState() {
        return RecState;
    }
    public int getType() {
        return Type;
    }
    public int getWorkState() {
        return WorkState;
    }
    public int getAlarm() {
        return Alarm;
    }
    public int getDb1() {
        return Db1;
    }
    public int getDb2() {
        return Db2;
    }
    public int getDb3() {
        return Db3;
    }
    public int getDb4() {
        return Db4;
    }
    public int getCRC() {
        return CRC;
    }
    public void setSYNCode(int[] sYNCode) {
        SYNCode = sYNCode;
    }
    public void setCMD(int cMD) {
        CMD = cMD;
    }
    public void setRecState(int recState) {
        RecState = recState;
    }
    public void setType(int type) {
        Type = type;
    }
    public void setWorkState(int workState) {
        WorkState = workState;
    }
    public void setAlarm(int alarm) {
        Alarm = alarm;
    }
    public void setDb1(int db1) {
        Db1 = db1;
    }
    public void setDb2(int db2) {
        Db2 = db2;
    }
    public void setDb3(int db3) {
        Db3 = db3;
    }
    public void setDb4(int db4) {
        Db4 = db4;
    }
    public void setCRC(int cRC) {
        CRC = cRC;
    }
    @Override
    public String toString() {
        return "FGCD_Cmd [BYTE_LEN=" + BYTE_LEN + ", SYNCode=" + Arrays.toString(SYNCode) + ", ByteLen=" + ByteLen
                + ", CMD=" + CMD + ", RecState=" + RecState + ", Type=" + Type + ", WorkState=" + WorkState + ", Alarm="
                + Alarm + ", Db1=" + Db1 + ", Db2=" + Db2 + ", Db3=" + Db3 + ", Db4=" + Db4 + ", CRC=" + CRC + "]";
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_ComBase.java
@@ -49,6 +49,9 @@
    public static final int     CMD_DownLoadFBDFile_ACK            =    0xA4;            //下载成功
    
    
    public static final int     CMD_DownLoadFBDFile_Over        =    0xA4;            //手动结束
    //----------------------------------------------------------------------------
    //------------ 读取电压电流、充放电测试、内阻测试数据 ---------------------------
    public static final int     CMD_GetVIData                    =    0x60;
@@ -98,6 +101,7 @@
    public static final int        TestType_Charge_HELUQI            =    0xBC;
    public static final int        TestType_CAP_HELUQI                =    0xBD;    //升压续航放电测试类型
    public static final int        TestType_SwitchDiode            =     0xD1;    //KD测试
    public static final int     TestType_HuoHua                    =     0xD2;    //活化测试
    //------------------------------------------------------------------------------
    //------------ 电池状态 ---------------------------------------------------------
    public static final int        BattState_Float                    =    0x00;            //浮充
@@ -127,6 +131,8 @@
    public static final int WORK_STATE_DISTEST                     = 2;    //放电测试
    public static final int WORK_STATE_STOPCHAR                 = 3;    //暂停充电
    public static final int WORK_STATE_CHARTEST                 = 4;    //正在充电
    public static final int WORK_STATE_HUOHUA                    = 5;    //设备无对应,通信程序添加
    
    //------------------------------------------------------------------------------
    //------------ FGCD_A059 设备相关命令   ------------------------------------------------------
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_ComBuf.java
@@ -63,4 +63,19 @@
        buffer.flip();
        return buffer;
    }
    public static ByteBuffer makeFGCDTestDataCommBuf(FGCD_Cmd m_CMD)
    {
        //System.err.println(bf.limit()+"$$$$$$$$$$");
        ByteBuffer bf = ByteBuffer.allocate(0);
        ByteBuffer buffer = ByteBuffer.allocate(m_CMD.BYTE_LEN + bf.limit() + 32);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        m_CMD.makeCmd(m_CMD.CMD, bf.limit());
        buffer.put(m_CMD.getByteBuffer(bf));
        buffer.flip();
        return buffer;
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_SysState.java
@@ -13,6 +13,7 @@
    public double tatalVol;                            //总电压(0.1V)
    public Date nowDate;                            //标准时间
    public String chageDate;                        //充电时间(时:分:秒)
    public int test_timelong;                        //测试时长(分钟)
    public int btnState;                            //按键状态(0:停止  1:暂停放电  2:放电   3:暂停充电   4:充电  5:等待充电   6:等待放电)
    public int lowerCount;                            //已到下限单体数量
    public double chargeCurr;                        //充电电流(0.1A)
@@ -22,6 +23,9 @@
    public int minVolNum;                            //最低单体号
    public double minVol;                            //最低单体电压(0.001V)
    public int hhProgress;                          //当前活化次数
    public int hhCount;                                //活化测试总数
    public int hhstate;                                //活化状态
    
    public float montmps[];                            //单体温度[有符号整数]
    public float devtmp;                            //烟雾报警器温度[有符号整数]
@@ -33,8 +37,9 @@
    public double on_online_vol;                    //在线模块在线电压(0.1)
    public double on_group_vol;                        //在线模块组端电压(0.1)
    public int diode_state;                            //二极管状态
    public int char_phase;                            //当前充电阶段
    
    public int[] backup;                            //预留5个字节
    public int[] backup;                            //预留4个字节
    
    public int dev_captest_stop_type;                //停止原因
    public long dev_data_flowsum;                    //流量byte
@@ -58,7 +63,7 @@
        hhProgress = 0;                          //当前活化次数
        montmps = new float[3];
        devtmp  = 0;
        backup = new int[5];                    //预留5个字节
        backup = new int[4];                    //预留5个字节
    }
    
    public void makeDevCommDataFlowSum (int dat_len) {
@@ -115,6 +120,10 @@
        int hour1 = FGCD_ComBase.changeByteToInt(bf.get());
        int min1 = FGCD_ComBase.changeByteToInt(bf.get());
        int sec1 = FGCD_ComBase.changeByteToInt(bf.get());
        test_timelong = hour1*60 + min1;        //(分钟)----为了计算当前充电阶段
        chageDate = hour1+":"+min1+":"+sec1;                                        //充电时间(时:分:秒)
        btnState = FGCD_ComBase.changeByteToInt(bf.get());                            //按键状态(0:停止  1:暂停放电  2:放电   3:暂停充电   4:充电  5:等待充电   6:等待放电)
        lowerCount = FGCD_ComBase.changeShortToInt(bf.getShort());                    //已到下限单体数量
@@ -136,7 +145,16 @@
        on_online_vol = FGCD_ComBase.changeShortToDouble(bf.getShort())/10;            //在线模块在线电压
        on_group_vol = FGCD_ComBase.changeShortToDouble(bf.getShort())/10;            //在线模块组端电压
        diode_state = FGCD_ComBase.changeByteToInt(bf.get());                        //二极管状态
        char_phase = FGCD_ComBase.changeByteToInt(bf.get());                        //充电阶段数目
        {
            //设置当前阶段数目
            int char_phase_high = char_phase>>4;
            if(char_phase_high > 0) {
                char_phase = char_phase_high<<4;
            }
        }
        for(int i = 0;i<backup.length;i++) {
            backup[i] = FGCD_ComBase.changeByteToInt(bf.get());
        }
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/data/FGCD_TestFBOFile.java
@@ -3,6 +3,7 @@
import java.nio.ByteBuffer;
import com.battmonitor.base.ComBase;
import com.dev.fgcd.comm.FGCD_TestDataDownLoad;
import com.mchange.v3.hocon.HoconUtils;
public class FGCD_TestFBOFile {
@@ -15,6 +16,11 @@
    public int file_count;                        //当前文件数
    public int file_total;                        //数据文件总数
    
    public int total_data_block;                //总的数据块数
    public int now_data_block;                    //当前数据块数目
    private int download_state;                    //当前下载状态
    private int stop_reason;                    //结束原因
    public FBOFile[] files = new FBOFile[8];    //读取的历史文件
    
    public FGCD_TestFBOFile(int dev_id) {
@@ -22,6 +28,12 @@
        for(int i=0;i<files.length;i++) {
            files[i] = new FBOFile();
        }
    }
    public void initDownLoadState() {
        total_data_block = 0;                                                //总的数据块数
        now_data_block = 0;                                                    //当前数据块数目
        download_state = FGCD_TestDataDownLoad.DownLoadState_ReadData;        //当前下载状态
    }
    
    public FGCD_Cmd createCmd(int cmd) {
@@ -32,46 +44,81 @@
    }
    
    
    public int getDownload_state() {
        return download_state;
    }
    public int getStop_reason() {
        return stop_reason;
    }
    public void setDownload_state(int download_state) {
        this.download_state = download_state;
    }
    public void setStop_reason(int stop_reason) {
        this.stop_reason = stop_reason;
    }
    public boolean putByteBuffer(ByteBuffer bf,int file_count) {
        this.file_count = (int)Math.floor((double)bf.limit()/BYTE_LEN);
        if(bf.limit() < BYTE_LEN) {
            return false;
        }
        ByteBuffer tmpbuf = bf;
        tmpbuf.position(0);
        for(int i=0;i<this.file_count;i++) {
            FBOFile fbo = files[i];
            fbo.file_count = ComBase.changeByteToInt(bf.get());
            this.file_total = fbo.file_count;
            fbo.file_index = ComBase.changeByteToInt(bf.get());
            fbo.year = ComBase.changeByteToInt(bf.get());                            //年
            fbo.month = ComBase.changeByteToInt(bf.get());                            //月
            fbo.day = ComBase.changeByteToInt(bf.get());                            //天
            fbo.hour = ComBase.changeByteToInt(bf.get());                            //ʱ
            fbo.minte = ComBase.changeByteToInt(bf.get());                            //分
            fbo.second = ComBase.changeByteToInt(bf.get());                            //秒
            //System.out.println(fbo.year+"-"+fbo.month+"-"+fbo.day+" "+fbo.hour+":"+fbo.minte+":"+fbo.second);
            fbo.setFileName();
            //System.out.println(fbo.filename);
            //fbo.filename;        //文件名
            int hour =  ComBase.changeByteToInt(bf.get());
            int minte =  ComBase.changeByteToInt(bf.get());
            int second =  ComBase.changeByteToInt(bf.get());
            fbo.test_timelong = hour*60*60+minte*60+second;                            //测试时长
            fbo.data_type = ComBase.changeByteToInt(bf.get());                        //数据类型
            fbo.test_curr = (float)ComBase.changeShortToInt(bf.getShort())/10;        //测试电流(0.1A)
            fbo.test_cap = ComBase.changeShortToInt(bf.getShort());                    //测试容量(1AH)
            fbo.cap_std = ComBase.changeShortToInt(bf.getShort());                    //标称容量(1AH)
            fbo.monvol_low = ComBase.changeShortToInt(bf.getShort())/100;            //单体下限(0.01V)
            fbo.groupvol_low = ComBase.changeShortToInt(bf.getShort());                //组端下限
            fbo.mon_count = ComBase.changeShortToInt(bf.getShort());                //单体个数
            fbo.testgroup_count = ComBase.changeShortToInt(bf.getShort());            //测试第几组得到的数据
            fbo.teststop_reason = ComBase.changeByteToInt(bf.get());                //停止原因
            fbo.monvol_type = getMonVolType(ComBase.changeByteToInt(bf.get()));                    //单体电压类型
        tmpbuf.position(0);
        for(int i=0;i<files.length;i++) {
            if(i< this.file_count) {
                FBOFile fbo = files[i];
                fbo.file_count = ComBase.changeByteToInt(bf.get());
                this.file_total = fbo.file_count;
                fbo.file_index = ComBase.changeByteToInt(bf.get());
                fbo.year = ComBase.changeByteToInt(bf.get());                            //年
                fbo.month = ComBase.changeByteToInt(bf.get());                            //月
                fbo.day = ComBase.changeByteToInt(bf.get());                            //天
                fbo.hour = ComBase.changeByteToInt(bf.get());                            //ʱ
                fbo.minte = ComBase.changeByteToInt(bf.get());                            //分
                fbo.second = ComBase.changeByteToInt(bf.get());                            //秒
                //System.out.println(fbo.year+"-"+fbo.month+"-"+fbo.day+" "+fbo.hour+":"+fbo.minte+":"+fbo.second);
                fbo.setFileName();
                //System.out.println(fbo.filename);
                //fbo.filename;        //文件名
                int hour =  ComBase.changeByteToInt(bf.get());
                int minte =  ComBase.changeByteToInt(bf.get());
                int second =  ComBase.changeByteToInt(bf.get());
                fbo.test_timelong = hour*60*60+minte*60+second;                            //测试时长
                fbo.data_type = getFBSDevType(ComBase.changeByteToInt(bf.get()));        //数据类型
                fbo.test_curr = (float)ComBase.changeShortToInt(bf.getShort())/10;        //测试电流(0.1A)
                fbo.test_cap = ComBase.changeShortToInt(bf.getShort());                    //测试容量(1AH)
                fbo.cap_std = ComBase.changeShortToInt(bf.getShort());                    //标称容量(1AH)
                fbo.monvol_low = ComBase.changeShortToInt(bf.getShort())/100;            //单体下限(0.01V)
                fbo.groupvol_low = ComBase.changeShortToInt(bf.getShort());                //组端下限
                fbo.mon_count = ComBase.changeShortToInt(bf.getShort());                //单体个数
                fbo.testgroup_count = ComBase.changeShortToInt(bf.getShort());            //测试第几组得到的数据
                fbo.teststop_reason = ComBase.changeByteToInt(bf.get());                //停止原因
                fbo.monvol_type = getMonVolType(ComBase.changeByteToInt(bf.get()));                //单体电压类型
            }else {
                files[i].clear();
            }
        }
        return true;
    }
    /**
     *     转化当前测试类型
     * @param dev_type
     * @return
     */
    public static int getFBSDevType(int dev_type) {
        switch(dev_type) {
            case 0xFD:dev_type = 3;break;            //放电
            case 0xFC:dev_type = 2;break;            //充电
            case 0xFE:dev_type = 4;break;            //活化
        }
        return dev_type;
    }
    
    /**
@@ -114,7 +161,28 @@
        public int mon_count;        //单体个数
        public int testgroup_count;    //测试第几组得到的数据
        public int teststop_reason;    //停止原因
        public float monvol_type;        //单体电压类型
        public float monvol_type;    //单体电压类型
        public int download_flag;    //下载标识
        public int download_state;    //下载状态
        public void clear() {
            file_count = 0;        //数据文件总数
            file_index = 0;        //当前文件索引
            filename = "";        //文件名
            test_timelong = 0;    //测试时长
            data_type = 0;        //数据类型
            test_curr = 0;        //测试电流(0.1A)
            test_cap = 0;        //测试容量(1AH)
            cap_std = 0;            //标称容量(1AH)
            monvol_low = 0;    //单体下限(0.01V)
            groupvol_low = 0;    //组端下限
            mon_count = 0;        //单体个数
            testgroup_count = 0;    //测试第几组得到的数据
            teststop_reason = 0;    //停止原因
            monvol_type = 0;    //单体电压类型
            download_flag = 0;    //下载标识
            download_state = 0;    //下载状态
        }
        
        public int getFile_count() {
            return file_count;
@@ -215,6 +283,21 @@
        public void setCap_std(int cap_std) {
            this.cap_std = cap_std;
        }
        public int getDownload_flag() {
            return download_flag;
        }
        public int getDownload_state() {
            return download_state;
        }
        public void setDownload_flag(int download_flag) {
            this.download_flag = download_flag;
            if(this.download_flag == FGCD_TestDataDownLoad.DownloadFlag_Start) {
                this.download_state = FGCD_TestDataDownLoad.DownLoadState_ReadData;
            }
        }
        public void setDownload_state(int download_state) {
            this.download_state = download_state;
        }
        public void setMonvol_low(float monvol_low) {
            this.monvol_low = monvol_low;
        }
@@ -239,22 +322,27 @@
        
        public void setFileName() {
            filename = "F"+(2000+year);
            if(month>10) {
            if(month>=10) {
                filename += "-"+month;
            }else {
                filename += "-0"+month;                
            }
            if(day>10) {
            if(day>=10) {
                filename += "-"+day;
            }else {
                filename += "-0"+day;    
            }
            if(hour>10) {
            if(hour>=10) {
                filename += " "+hour;
            }else {
                filename += " 0"+hour;
            }
            if(second > 10) {
            if(minte >= 10) {
                filename += ":"+minte;
            }else {
                filename += ":0"+minte;
            }
            if(second >= 10) {
                filename += ":"+second;
            }else {
                filename += ":0"+second;
@@ -264,4 +352,12 @@
        
    }
    @Override
    public String toString() {
        return "FGCD_TestFBOFile [dev_id=" + dev_id + ", op_cmd=" + op_cmd + ", battgroupid=" + battgroupid
                + ", file_index=" + file_index + ", file_count=" + file_count + ", file_total=" + file_total
                + ", total_data_block=" + total_data_block + ", now_data_block=" + now_data_block + ", download_state="
                + download_state + ", stop_reason=" + stop_reason + "]";
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/BattCapFactory.java
New file
@@ -0,0 +1,171 @@
package com.dev.fgcd.fbo;
public class BattCapFactory {
    public static int  CapType_Rest = 0;                    //当查询剩余容量时传递
    public static int  CapType_Real = 1;                    //当查询实际容量时传递
    public static final int Alarm_CapAlarm = 119010;          //--容量告警告警
    public static final int Alarm_CapChange = 119011;          //--容量更换告警
    public static int  CapType_type = 2;       //容量
    public static int  CapType_name = 1;       //次低
    public static int  CapType_method = 0;     //标称
    // 获取标纯电流
    public static double GetFDCurrent(double stdcap, int hourrate)
    {
        double res = 0.055;
        switch(hourrate)
        {
            case 1: res = 0.514; break;
            case 2: res = 0.306; break;
            case 3: res = 0.250; break;
            case 4: res = 0.200; break;
            case 5: res = 0.166; break;
            case 6: res = 0.146; break;
            case 7: res = 0.131; break;
            case 8: res = 0.118; break;
            case 9: res = 0.108; break;
            case 10: res = 0.100; break;
            case 20: res = 0.055; break;
            default: res = 0.055; break;
        }
        return (stdcap * res);
    }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    // 获取放电小时率        stdah:标纯容量          current:当前电流
    public static int GetHourRate(int stdah, int current)
    {
        int index = 0;
        int value[]={514, 306, 250, 200, 166, 146, 131, 118, 108, 100, 55};
        int res;
        res = (current*100)/(stdah/10);
        if(res>=514) return 1;
        else if(res<=55) return 20;
        else
        {
            for(index=0; index<10; index++)
            {
                if((res<=value[index]) && (res>value[index+1]))    break;
                else continue;
            }
            if((value[index]-res) < (res-value[index+1]))
            {
                return (index+1);
            }
            else
            {
                if(index+2 > 10) return (20);
                else return (index+2);
            }
        }
    }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    public static double N_TO_10H(int n_H)
    {
        switch(n_H)
        {
            case  1 : return(1/0.55);
            case  2 : return(1/0.61);
            case  3 : return(1/0.75);
            case  4 : return(1/0.79);
            case  5 : return(1/0.833);
            case  6 : return(1/0.876);
            case  7 : return(1/0.917);
            case  8 : return(1/0.944);
            case  9 : return(1/0.974);
            case  10: return(1/1);
            case  20: return(1/1.1);
        }
        return 1.0;
    }
    //-------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------
    //获取剩余容量    STDAH:标称容量        HourRate:放电小时率    SumAH:测试容量        MaxMonomerVol:最大电池电压        MonomerVol:当前电池组的最低单体电压
    //MonomerVolType:电池电压类型    2v,6v,12v    CapType:容量类型(定值是常量)
                                                         //小时率        已测试容量            最容量
    public static double GetMonomerCap(double STDAH, int HourRate, double SumAH, double MaxMonomerVol,
                                        double MonomerVol, double MonomerVolType, int CapType)
    {
        //System.out.println("STDAH:"+STDAH+"\tHourRate:"+HourRate+"\tTestCap:"+SumAH+"\tMaxMonomerVol:"+MaxMonomerVol+"\tMonomerVol:"+MonomerVol+"\tMonomerVolType:"+MonomerVolType);
        if((MaxMonomerVol - MonomerVolType*0.9) <= 0)
            return 0;
        if(SumAH < 0)
            SumAH *= (-1);
        double tmp_cap;
        tmp_cap = MonomerVol - MonomerVolType * 0.9;
        tmp_cap *= (STDAH - SumAH * N_TO_10H(HourRate));
        double dt_vol = MaxMonomerVol - MonomerVolType*0.9;
        if(dt_vol < 0.01)
            dt_vol = 0.01;
        tmp_cap = tmp_cap/dt_vol;
        if(tmp_cap < 0)
            tmp_cap = 0;
        if(CapType == CapType_Rest)
            return tmp_cap;
        else if(CapType == CapType_Real)
            return (tmp_cap + SumAH * N_TO_10H(HourRate));
        else
            return ((tmp_cap + SumAH * N_TO_10H(HourRate))*100 / STDAH);
    }
    //----------------------------------------------------------------------------------
    //----------------------------------------------------------------------------------
    //获取后备时间
    public static int GetRestTimeSecond(double restcap, double curr)
    {
        double tmp_curr = Math.abs(curr);
        if(tmp_curr < 0.1)
            tmp_curr = 0.1;
        int rest_time = (int)((restcap / tmp_curr) * 3600);
        if(rest_time > (99*3600))
            rest_time = (99*3600);
        return rest_time;
    }
    //判断通过实际容量判断某次放电测试是否有效
    /*
     * STDAH:标存容量
     * param:容量有效参数
     *
     * */
    public static  int Judge(double realCap,float param,double STDAH){
        int flag=0;
        if(Math.abs(realCap)>(param*STDAH)){
            flag=1;
        }else{
            flag=0;
        }
        return flag;
    }
    //判断通过实际容量判断某次放电测试是否有效
    /*
     * STDAH:标存容量
     * param:容量告警参数
     *
     */
    public static  int JudgeAlarm(double realCap,float param,float Cparam,double STDAH){
        int flag=0;
        if(realCap > (param*STDAH)){
            flag=1;
        }else{
            if(realCap < (Cparam*STDAH)){
                flag = Alarm_CapChange;
            }else{
                flag = Alarm_CapAlarm;
            }
        }
        return flag;
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/CsvData.java
New file
@@ -0,0 +1,349 @@
package com.dev.fgcd.fbo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.battmonitor.base.BattTestData;
import com.battmonitor.sql.Com;
import com.dev.fgcd.data.FGCD_ComBase;
import org.dom4j.DocumentException;
public class CsvData {
    public static final int DevType_Csv = 0x45;
    public static final int DevType_FBR = 0x46;
    public boolean m_DataOk = true;
    public String m_BattGroupNameFull = "";
    public int m_STDAH;                        //标称容量。
    public int m_BattSum;                      //电池个数。
    public float m_MonomerVol = 2;
    public int m_DevType = 0;
    public int m_TestType = 0;
    public Date m_TestTime = new Date();
    public float m_GroupVol;
    public float m_TestCurr;
    public int m_MinNum = 0;
    public float m_MinValue = 0;
    public int BATT_MON_COUNT_MAX = FGCD_ComBase.MonomerCountMax;
    public float[] MonomerVol = new float[BATT_MON_COUNT_MAX];
    public float[] MonomerRes = new float[BATT_MON_COUNT_MAX];
    public float[] MonomerSer = new float[BATT_MON_COUNT_MAX];
    public float[] MonomerTmp = new float[BATT_MON_COUNT_MAX];
    public float[] MonomerConn = new float[BATT_MON_COUNT_MAX];
    public void setData(File file)
    {
        //System.out.println(111111111);
        m_DataOk = true;
        BufferedReader reader = null;
        try {
            m_TestType = BattTestData.BATTDATA_SER;
            m_DevType = DevType_Csv;
            reader = new BufferedReader(new FileReader(file));
            //-------------------------------------------------------------------//
            //-------------------------------------------------------------------//
            String tmpstr = reader.readLine();
            //-------------------------------------------------------------------//
            //-------------------------------------------------------------------//
            tmpstr = reader.readLine();
            for(int n=0; n<4; n++) {
                tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
            }
            if(tmpstr.contains(",")) {
                tmpstr = tmpstr.substring(0, tmpstr.indexOf(","));
            } else if(tmpstr.contains("\r\n")) {
                tmpstr = tmpstr.substring(0, tmpstr.indexOf("\r\n"));
            }
            //System.out.println(tmpstr);
            m_BattSum = Integer.parseInt(tmpstr.trim());
            //-------------------------------------------------------------------//
            //-------------------------------------------------------------------//
            tmpstr = reader.readLine();
            for(int n=0; n<4; n++) {
                tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
            }
            tmpstr = tmpstr.substring(0, tmpstr.indexOf(","));
            m_MonomerVol = Float.parseFloat(tmpstr.trim());
            if((m_MonomerVol>10.1) && (m_MonomerVol<20)) {
                m_MonomerVol = 12;
            } else if((m_MonomerVol>5.4) && (m_MonomerVol<7.8)) {
                m_MonomerVol = 6;
            } else if((m_MonomerVol>2.7) && (m_MonomerVol<4.0)) {
                m_MonomerVol = 4;
            } else {
                m_MonomerVol = 2;
            }
            //-------------------------------------------------------------------//
            //-------------------------------------------------------------------//
            tmpstr = reader.readLine();
            for(int n=0; n<4; n++) {
                tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
            }
            int month = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf("/")).trim());
            tmpstr = tmpstr.substring(tmpstr.indexOf("/")+1, tmpstr.length());
            int day = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf("/")).trim());
            tmpstr = tmpstr.substring(tmpstr.indexOf("/")+1, tmpstr.length());
            int year = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf(",")).trim());
            tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
            int hour = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf(":")).trim());
            tmpstr = tmpstr.substring(tmpstr.indexOf(":")+1, tmpstr.length());
            int minute = Integer.parseInt(tmpstr.substring(0, 2).trim());
            tmpstr = tmpstr.substring(3, tmpstr.length());
            if(tmpstr.substring(0, tmpstr.indexOf(",")).trim().equals("PM"))
            {
                hour += 12;
            }
            GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
            gc.set(GregorianCalendar.YEAR, year);
            gc.set(GregorianCalendar.MONTH, month-1);
            gc.set(GregorianCalendar.DATE, day);
            gc.set(GregorianCalendar.HOUR_OF_DAY, hour);
            gc.set(GregorianCalendar.MINUTE, minute);
            gc.set(GregorianCalendar.SECOND, 0);
            m_TestTime = gc.getTime();
            //-------------------------------------------------------------------//
            //-------------------------------------------------------------------//
            tmpstr = reader.readLine();
            reader.mark(0);
            //-------------------------------------------------------------------//
            //-------------------------------------------------------------------//
            tmpstr = reader.readLine() + reader.readLine() + reader.readLine() + reader.readLine();
            int sub_con_count = 1;
            if (tmpstr.contains("J1D")) {
                sub_con_count = 4;
            } else if (tmpstr.contains("J1C")) {
                sub_con_count = 3;
            } else if (tmpstr.contains("J1B")) {
                sub_con_count = 2;
            }
            m_BattSum /= sub_con_count;
            //-------------------------------------------------------------------//
            reader.reset();
            //-------------------------------------------------------------------//
            m_MinValue = 900000;
            for(int n=0; n<m_BattSum; n++) {
                float tmpser = 0;
                float tmpvol = 0;
                for(int cnt=0; cnt<sub_con_count; cnt++) {
                    tmpstr = reader.readLine();
                    if(null != tmpstr) {
                        tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
                        tmpser += Float.parseFloat(tmpstr.substring(0, tmpstr.indexOf(",")));
                        tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
                        tmpvol += Float.parseFloat(tmpstr.substring(0, tmpstr.indexOf(",")));
                    } else {
                        m_DataOk = false;
                        break;
                    }
                }
                if(false == m_DataOk) {
                    break;
                }
                MonomerSer[n] = tmpser / sub_con_count;
                MonomerVol[n] = tmpvol / sub_con_count ;
                MonomerRes[n] = 0;
                if(MonomerSer[n] > 1) {
                    MonomerRes[n] = 1000 / (MonomerSer[n] / (m_MonomerVol/2));
                }
                if(MonomerSer[n] < m_MinValue) {
                    m_MinValue = MonomerSer[n];
                    m_MinNum = n+1;
                }
            }
            //-------------------------------------------------------------------//
        } catch (Exception e) {
            m_DataOk = false;
            System.err.println("Class 'CsvData' function setData(): " + e.getMessage());
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    public void checkCsvFile(File file)
    {
        setData(file);
    }
    private String getNodeTextEx(Object ob, Element rootnode, String node_name) {
        String text = String.valueOf(ob);
        try
        {
            Element node = rootnode.element(node_name);
            text = node.getTextTrim();
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
        return text;
    }
    public void checkXmlFile(File file)
    {
        m_DataOk = false;
        try {
            SAXReader reader = new SAXReader();
            Document document = reader.read(file);
            Element rootnode = document.getRootElement();
            m_TestType = BattTestData.BATTDATA_RES;
            m_DevType = DevType_FBR;
            String test_time = getNodeTextEx("1990-01-01_00:00:00", rootnode, "TEST_TIME");
            if(test_time.contains("1990-01-01")) {
                m_DataOk = false;
                return;
            }
            m_TestTime = Com.get_DT_FromStr(test_time.replace("_", " ").trim(), Com.DTF_YMDhms);
            //String data_version = Config.getNodeTextEx("V1.0", rootnode, "VERSION");
            Element sub_node = rootnode.element("BATT_PARAM");
            m_BattSum = Integer.parseInt(getNodeTextEx("0", sub_node, "batt_count"));
            m_MonomerVol = Float.parseFloat(getNodeTextEx("0.0", sub_node, "batt_vol"));
            m_STDAH = Integer.parseInt(getNodeTextEx("0", sub_node, "batt_cap"));
            int concount_pb = Integer.parseInt(getNodeTextEx("1", sub_node, "concount_pb"));
            m_MinValue = 900000;
            for(int n=0; n<m_BattSum; n++) {
                @SuppressWarnings("unchecked")
                List<Element> childElements = rootnode.elements();
                int cnt = 0;
                for(cnt=0; cnt<childElements.size(); cnt++) {
                    Element child = childElements.get(cnt);
                    if(null == child.attributeValue("batt_num")) {
                        continue;
                    }
                    if(Integer.parseInt(child.attributeValue("batt_num").trim()) == (n+1)) {
                        float tmp_var_res = 0;
                        float tmp_var_vol = 0;
                        float tmp_var_ser = 0;
                        float tmp_var_con = 0;
                        for(int c=0; c<concount_pb; c++) {
                            tmp_var_res += Float.parseFloat(getNodeTextEx("0.0", child, "br_" + (c+1)));
                            tmp_var_vol += Float.parseFloat(getNodeTextEx("0.0", child, "bv_" + (c+1)));
                            tmp_var_ser += Float.parseFloat(getNodeTextEx("0.0", child, "bs_" + (c+1)));
                            tmp_var_con += Float.parseFloat(getNodeTextEx("0.0", child, "cr_" + (c+1)));
                        }
                        tmp_var_res /= concount_pb;
                        tmp_var_vol /= concount_pb;
                        tmp_var_ser /= concount_pb;
                        tmp_var_con /= concount_pb;
                        MonomerRes[n] = tmp_var_res;
                        MonomerVol[n] = tmp_var_vol;
                        MonomerSer[n] = tmp_var_ser;
                        MonomerConn[n] = tmp_var_con;
                        break;
                    }
                }
                if(cnt < childElements.size()) {
                    m_DataOk = true;
                }
                if(MonomerSer[n] < m_MinValue) {
                    m_MinValue = MonomerSer[n];
                    m_MinNum = n+1;
                }
            }
        } catch (NumberFormatException e) {
            m_DataOk = false;
            e.printStackTrace();
        } catch (DocumentException e) {
            m_DataOk = false;
            e.printStackTrace();
        }
    }
    public void checkFgxlsFile(File file)
    {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(file);
            HSSFWorkbook workbook = new HSSFWorkbook(fis);
            HSSFSheet rs = workbook.getSheetAt(0);
            m_BattGroupNameFull=rs.getRow(0).getCell(0).getStringCellValue().trim().replace("---", "-");
            String bg_inf = rs.getRow(0).getCell(1).getStringCellValue().trim().replace("---", "-");
            //m_BattGroupNameFull = rs.getCell(0, 0).getContents().trim().replace("---", "-");
            //System.out.println(m_BattGroupNameFull);
            //String bg_inf = rs.getCell(0, 1).getContents().trim();
            //System.out.println(bg_inf);
            m_TestType = DevType_Csv;
            m_DevType = DevType_Csv;
            m_MonomerVol = Float.parseFloat(bg_inf.substring(bg_inf.indexOf("单体电压:")+5,
                                                bg_inf.indexOf("参考电导值")-1).trim());
            m_BattSum = Integer.parseInt(bg_inf.substring(bg_inf.indexOf("单体数:")+4,
                                                            bg_inf.indexOf("测试时间:")-1).trim());
            m_TestTime = Com.get_DT_FromStr(bg_inf.substring(bg_inf.indexOf("测试时间:")+5,
                                                bg_inf.length()).trim(), Com.DTF_YMDhms);
            if(m_BattSum > 500) {
                m_BattSum = 500;
            }
            m_MinValue = 900000;
            for(int n=0; n<m_BattSum; n++) {
                MonomerSer[n] = Float.parseFloat(rs.getRow(1).getCell(n+3).getStringCellValue().trim());
                MonomerSer[n] = Float.parseFloat(rs.getRow(2).getCell(n+3).getStringCellValue().trim());
                //MonomerSer[n] = Float.parseFloat(rs.getCell(1, n+3).getContents().trim());
                //MonomerVol[n] = Float.parseFloat(rs.getCell(2, n+3).getContents().trim());
                MonomerRes[n] = 0;
                if(MonomerSer[n] > 1) {
                    MonomerRes[n] = 1000 / (MonomerSer[n] / (m_MonomerVol/2));
                }
                if(MonomerSer[n] < m_MinValue) {
                    m_MinValue = MonomerSer[n];
                    m_MinNum = n+1;
                }
            }
        } catch (IOException  e) {
            e.printStackTrace();
        } finally {
            if(null != fis)
            {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FBOFileParseState.java
New file
@@ -0,0 +1,74 @@
package com.dev.fgcd.fbo;
import java.util.Date;
public class FBOFileParseState {
    public static final int ParseType_Null         = 0;
    public static final int ParseType_Start     = 1;
    public static final int ParseType_Success    = 2;
    public static final int ParseType_Fail         = 3;
    public int fbo_id;
    public String fbo_filepath;                        //'fbo文件目录[绝对路径]',
    public int parse_type;                            //'瑙f瀽绫诲瀷0:鏆備笉瑙f瀽锛?1:寮?濮嬭В鏋愶紱2锛氳В鏋愬畬鎴愶紱3:瑙f瀽澶辫触',
    public Date parse_starttime;                    //'寮?濮嬭В鏋愭椂闂?',
    public Date parse_endtime;                        //'解析结束时间',
    public int faile_reason;                        //'瑙f瀽澶辫触鍘熷洜:0:鏃?;1:鏂囦欢鏈壘鍒?;2:鏂囦欢鏍煎紡閿欒;3鏂囦欢瑙f瀽閿欒',
    public FboDataInf fboinf;                        //历史数据解析
    public FBOFileParseState(int fbo_id){
        this.fbo_id = fbo_id;
        fboinf = new FboDataInf();
    }
    public int getFbo_id() {
        return fbo_id;
    }
    public String getFbo_filepath() {
        return fbo_filepath;
    }
    public int getParse_type() {
        return parse_type;
    }
    public Date getParse_starttime() {
        return parse_starttime;
    }
    public Date getParse_endtime() {
        return parse_endtime;
    }
    public int getFaile_reason() {
        return faile_reason;
    }
    public FboDataInf getFboinf() {
        return fboinf;
    }
    public void setFbo_id(int fbo_id) {
        this.fbo_id = fbo_id;
    }
    public void setFbo_filepath(String fbo_filepath) {
        this.fbo_filepath = fbo_filepath;
    }
    public void setParse_type(int parse_type) {
        this.parse_type = parse_type;
    }
    public void setParse_starttime(Date parse_starttime) {
        this.parse_starttime = parse_starttime;
    }
    public void setParse_endtime(Date parse_endtime) {
        this.parse_endtime = parse_endtime;
    }
    public void setFaile_reason(int faile_reason) {
        this.faile_reason = faile_reason;
    }
    public void setFboinf(FboDataInf fboinf) {
        this.fboinf = fboinf;
    }
    @Override
    public String toString() {
        return "FBOFileParseState [fbo_id=" + fbo_id + ", fbo_filepath=" + fbo_filepath + ", parse_type=" + parse_type
                + ", parse_starttime=" + parse_starttime + ", parse_endtime=" + parse_endtime + ", faile_reason="
                + faile_reason + ", fboinf=" + fboinf + "]";
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboData.java
New file
@@ -0,0 +1,267 @@
package com.dev.fgcd.fbo;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
public class FboData {
    public FboDataType m_DataType = new FboDataType();
    public short CRC16;
    public FboTestTime m_TestTime = new FboTestTime();
    public int BattGroup;
    public int BattSum;
    public float OnlineVol;
    public float SumVoltage;
    public float SumCurrent;
    public float[] SubCurrent = new float[4];
    public float AllCap;
    public float[] SubCap = new float[4];
    public float[] SingleVol = new float[500];
    public float maxMonVol;
    public float minMonVol;
    public void setData(byte[] buf)
    {
        ByteBuffer bf = ByteBuffer.allocate(2048);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.put(buf);
        bf.position(0);
        CRC16 = (short) (bf.getShort()&0xFFFF);
        m_TestTime.hour = (int) (bf.get()&0xFF);
        m_TestTime.minute = (int) (bf.get()&0xFF);
        m_TestTime.second = (int) (bf.get()&0xFF);
        BattGroup = (int) (bf.get()&0xFF);
        BattSum = (int) (bf.getShort()&0xFFFF);
        if(BattSum > 500)
            BattSum = 500;
        else if (BattSum < 0) {
            BattSum = 0;
        }
        OnlineVol = ((float) (bf.getShort()&0xFFFF)) / 100;
        SumVoltage = ((float) (bf.getShort()&0xFFFF)) / 100;
        SumCurrent = ((float) (bf.getShort()&0xFFFF)) / 100;
        if(0xFD == m_DataType.TypeTag0) {
            SumCurrent *= -1;
        }
        for(int n=0; n<4; n++)
        {
            SubCurrent[n] = ((float) (bf.getShort()&0xFFFF)) / 10;
            if(0xFD == m_DataType.TypeTag0) {
                SubCurrent[n] *= -1;
            }
        }
        AllCap = ((float) (bf.getShort()&0xFFFF));
        if(0xFD == m_DataType.TypeTag0) {
            AllCap *= -1;
        }
        for(int n=0; n<4; n++)
        {
            SubCap[n] = ((float) (bf.getShort()&0xFFFF));
            if(0xFD == m_DataType.TypeTag0) {
                SubCap[n] *= -1;
            }
        }
        for(int n=0; n<BattSum; n++)
        {
            SingleVol[n] = ((float) (bf.getShort()&0xFFFF)) / 1000;
        }
        maxMonVol = SingleVol[0];
        minMonVol = SingleVol[0];
        for(int n=0;n<BattSum;n++) {
            if(SingleVol[n] > maxMonVol) {
                maxMonVol = SingleVol[n];
            }
            if(SingleVol[n] < minMonVol) {
                minMonVol = SingleVol[n];
            }
        }
    }
    public static void checkFboFile(File file, FboDataInf data_inf, ArrayList<FboData> al_fbo_data)
    {
        File f = file;
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(f);
            byte[] buf = new byte[256];
            if(fis.read(buf, 0, buf.length) == 256)
            {
                data_inf.setDataInf(buf);
                while(true)
                {
                    FboDataType mType = new FboDataType();
                    int tag = mType.checkDataHead(fis);
                    if((0xFD == tag) || (0xFC == tag))
                    {
                        byte[] databuf = new byte[data_inf.BattSum*2 + 32];
                        if(fis.read(databuf) == databuf.length)
                        {
                            FboData m_FboData = new FboData();
                            m_FboData.m_DataType = mType;
                            m_FboData.setData(databuf);
                            al_fbo_data.add(m_FboData);
                        }
                    }
                    if(tag == 1)
                        break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(null != fis)
            {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public void setData(IdcData i_data)
    {
        m_DataType.TypeTag0 = i_data.DataType;
        m_DataType.TypeTag1 = i_data.DataType;
        m_DataType.TypeTag2 = i_data.DataType;
        m_DataType.TypeTag3 = i_data.DataType;
        OnlineVol = 0;
        SumVoltage = i_data.SumVol;
        SumCurrent = i_data.SumCur;
        SubCurrent[0] = SumCurrent;
        AllCap = i_data.SumAH;
        SubCap[0] = AllCap;
        int param = (-1);
        if(0xFC == m_DataType.TypeTag0) {
            param = 1;
        }
        SumCurrent = Math.abs(SumCurrent) * param;
        SubCurrent[0] = Math.abs(SubCurrent[0]) * param;
        AllCap = Math.abs(AllCap) * param;
        SubCap[0] = Math.abs(SubCap[0]) * param;
        for(int n=0; n<400; n++)
        {
            SingleVol[n] = i_data.MonomerVol[n];
        }
    }
    public int getMinIndex()
    {
        int num = 0;
        float min = 800000;
        for(int n=0; n<SingleVol.length; n++)
        {
            if((SingleVol[n] > 0.1) && (SingleVol[n] < min))
            {
                min = SingleVol[n];
                num = n;
            }
        }
        return num;
    }
    public int getMaxIndex()
    {
        int num = 0;
        float max = 0;
        for(int n=0; n<SingleVol.length; n++)
        {
            if((SingleVol[n] > 0.1) && (max < SingleVol[n]))
            {
                max = SingleVol[n];
                num = n;
            }
        }
        return num;
    }
    public float getMinVol()
    {
        float min = 800000;
        for(int n=0; n<SingleVol.length; n++)
        {
            if((SingleVol[n] > 0.1) && (SingleVol[n] < min))
            {
                min = SingleVol[n];
            }
        }
        return min;
    }
    public float getMaxVol()
    {
        float max = 0;
        for(int n=0; n<SingleVol.length; n++)
        {
            if((SingleVol[n] > 0.1) && (max < SingleVol[n]))
            {
                max = SingleVol[n];
            }
        }
        return max;
    }
    public static void countLowBatt(FboDataInf data_inf,ArrayList<FboData> al_fbo_data) {
        if(null != data_inf && null != al_fbo_data && al_fbo_data.size() > 0) {
            data_inf.monRealCap = new double[data_inf.BattSum];
            for(int i=0;(i<data_inf.BattSum) && (i < al_fbo_data.get(al_fbo_data.size()-1).SingleVol.length-1);i++) {
                float[] single = al_fbo_data.get(al_fbo_data.size()-2).SingleVol;
                FboData fbodata = al_fbo_data.get(al_fbo_data.size()-2);
                //System.out.println("monvol:"+single[i]+"\t"+al_fbo_data.get(al_fbo_data.size()-1));
                //data_inf.monRealCap[i] = BattCapFactory.GetMonomerCap(data_inf.STDCap,data_inf.HourRate, data_inf.TestCap, fbodata.maxMonVol, single[i], data_inf.MonomerVol, BattCapFactory.CapType_Real);
                //data_inf.monRealCap[i] = BattCapFactory.GetMonomerCap(data_inf.STDCap,data_inf.HourRate, data_inf.TestCap, fbodata.maxMonVol, single[i], data_inf.MonomerVol, BattCapFactory.CapType_Real);
                data_inf.monRealCap[i] = BattCapFactory.GetMonomerCap(data_inf.STDCap,data_inf.HourRate, fbodata.SubCap[0], fbodata.maxMonVol, single[i], data_inf.MonomerVol, BattCapFactory.CapType_Real);
                if(data_inf.monRealCap[i]<data_inf.STDCap*0.8) {
                    if(data_inf.lowMonCount >0) {
                        data_inf.lowMonNum += ",";
                    }
                    data_inf.lowMonNum = data_inf.lowMonNum+(i+1) + "#";
                    data_inf.lowMonCount ++;
                }
            }
            System.out.println(Arrays.toString(data_inf.monRealCap));
            if(data_inf.lowMonCount > FboDataInf.MaxLowMonCount) {
                data_inf.batt_qualified = 0;
            }else {
                data_inf.batt_qualified = 1;
            }
            //System.out.println(Arrays.toString(data_inf.monRealCap));
        }
    }
    public static void main(String[] args) {
        File file = new File("4鏈?5鏃?2-1鏀剧數.FBO");
        file = new File("F2013-01-12 14.34.35.FBO");
        FboData data = new FboData();
        FboDataInf data_inf = new FboDataInf();
        ArrayList<FboData> al_fbo_data = new ArrayList<>();
        data.checkFboFile(file, data_inf, al_fbo_data);
        System.out.println(data_inf);
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboDataCrc16.java
New file
@@ -0,0 +1,56 @@
package com.dev.fgcd.fbo;
public class FboDataCrc16 {
    private static final int[] CRC16Table =
    {
            0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
            0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
            0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
            0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
            0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
            0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
            0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
            0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
            0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
            0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
            0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
            0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
            0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
            0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
            0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
            0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
            0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
            0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
            0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
            0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
            0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
            0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
            0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
            0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
            0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
            0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
            0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
            0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
            0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
            0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
            0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
            0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
    };
    //-------------------------------------------------------------------------------//
    public static short CalCRC16(byte[] pdata, int count)
    {
        short crc = 0x00;
        short i, tmp1;
        for (i=0; i<count; i++)
        {
            tmp1 = crc;
            crc = (short) CRC16Table[(tmp1>>8) ^ (pdata[i])];
            crc = (short) (crc ^ (tmp1<<8));
        }
        return(crc);
    }
    //-------------------------------------------------------------------------------//
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboDataInf.java
New file
@@ -0,0 +1,265 @@
package com.dev.fgcd.fbo;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.GregorianCalendar;
import com.battmonitor.sql.Com;
import com.dev.fgcd.data.FGCD_TestFBOFile;
public class FboDataInf {
    public static final int MaxLowMonCount = 6;                    //最低落后单体数量
    public FboDateTime TestStartTime = new FboDateTime();        //放电开始的时间
    public int Device;                      //仪表类型
    public int DataVersion;                //数据版本
    public int DataType;                   //数据类型;0xFD表示放电,0xFC表示充电
    public int HourRate;                   //小时率
    public int SaveInterval;               //采集间隔
    public float MonomerVol;             //单体电压类型
    public int  STDCap;                   //标称容量
    public float  TestCur;              //测试电流
    public float  MVLLimit;             //单体下限
    public float  SumVLLimit;           //组端下限
    public int  BattSum;                  //单体数量
    public int  BattGroup;                //电池组数
    public float  MVLLimitCount;        //单体下限个数
    public FboTestTime TestTimeLong = new FboTestTime();               //测试时长
    public int StopType;                       //结束方式
    public int BlockSum;                      //保存数据的总块数
    public int StandBy;                          //保留备用
    public int[] SMaxIndex = new int[4];       //最高单体索引
    public int[] SMinIndex = new int[4];       //最低单体索引
    public float[]  SMaxVol = new float[4]; //最高单体
    public float[]  SMinVol = new float[4]; //最低单体
    public double    realcap;                //预估实际容量
    public float  TestCap;                    //测试容量
    public float avg_curr;                    //平均电流
    public double[] monRealCap;
    public String lowMonNum="";                //落后单体编号
    public int lowMonCount;                    //落后单体数量
    public int batt_qualified;                //0:不合格      1:合格
    public void setDataInf(byte[] inf_data)
    {
        ByteBuffer bf = ByteBuffer.allocate(2048);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.put(inf_data);
        bf.position(0);
        TestStartTime.year = (int) (bf.get()&0xFF);
        TestStartTime.month = (int) (bf.get()&0xFF)-1;
        //System.out.println(TestStartTime.month+"  setDataInf(byte[] inf_data)");
        TestStartTime.day = (int) (bf.get()&0xFF);
        TestStartTime.hour = (int) (bf.get()&0xFF);
        TestStartTime.minute = (int) (bf.get()&0xFF);
        TestStartTime.second = (int) (bf.get()&0xFF);
        //System.out.println(Com.getDateTimeFormat(TestStartTime.getFBODateTime(), Com.DTF_YMDhms));
        Device = (int) (bf.get()&0xFF);
        DataVersion = (int) (bf.get()&0xFF);                                    //数据版本
        DataType = FGCD_TestFBOFile.getFBSDevType((int) (bf.get()&0xFF));       //数据类型;0xFD表示放电,0xFC表示充电
        HourRate = (int) (bf.get()&0xFF);                                       //小时率
        SaveInterval = (int) (bf.get()&0xFF);                                   //采集间隔
        MonomerVol = (float) (bf.get()&0xFF)/10;                                 //单体电压类型
        STDCap = (int) (bf.getShort()&0xFFFF);                                   //标称容量
        TestCur = (float) (bf.getShort()&0xFFFF)/10;                              //测试电流
        MVLLimit = ((float) (bf.getShort()&0xFFFF)) / 1000;                     //单体下限
        SumVLLimit = ((float) (bf.getShort()&0xFFFF)) / 10;                       //组端下限
        BattSum = (int) (bf.getShort()&0xFFFF);                                 //单体数量
        BattGroup = (int) (bf.getShort()&0xFFFF);                               //电池组数
        MVLLimitCount = (int) (bf.getShort()&0xFFFF);                            //单体下限个数
        TestTimeLong.hour = (int) (bf.get()&0xFF);
        TestTimeLong.minute = (int) (bf.get()&0xFF);
        TestTimeLong.second = (int) (bf.get()&0xFF);
        StopType = (int) (bf.get()&0xFF);
        //当放电结束后计算当前停止原因
        if(StopType > 0x80) {
            StopType = StopType - 0x80;
        }
        BlockSum = (int) (bf.get()&0xFF);
        StandBy = (int) (bf.get()&0xFF);
        for(int n=0; n<4; n++)
        {
            SMaxIndex[n] = (int) (bf.getShort()&0xFFFF);
        }
        for(int n=0; n<4; n++)
        {
            SMinIndex[n] = (int) (bf.getShort()&0xFFFF);
        }
        for(int n=0; n<4; n++)
        {
            SMaxVol[n] = ((float) (bf.getShort()&0xFFFF)) / 1000;
        }
        for(int n=0; n<4; n++)
        {
            SMinVol[n] = ((float) (bf.getShort()&0xFFFF)) / 1000;
        }
        TestCap = (float) (bf.getShort()&0xFFFF)/10;
        avg_curr = TestCap*3600/TestTimeLong.getTestTimeLong();
        //System.out.println("avg_curr:"+avg_curr);
        realcap = BattCapFactory.GetMonomerCap(STDCap,HourRate, TestCap, SMaxVol[0], MonomerVol, SMinVol[0], BattCapFactory.CapType_Real);
    }
    public int getTestTimeLong() {
        return TestTimeLong.hour*60*60+TestTimeLong.minute*60+TestTimeLong.second;
    }
    public void setDataInf(IdcDataInf d_inf)
    {
        GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
        gc.setTime(d_inf.m_TestTime);
        TestStartTime.year = gc.get(GregorianCalendar.YEAR);
        TestStartTime.month = gc.get(GregorianCalendar.MONTH)-1;
        //System.out.println(TestStartTime.month+"  IdcDataInf d_inf ");
        TestStartTime.day = gc.get(GregorianCalendar.DATE);
        TestStartTime.hour = gc.get(GregorianCalendar.HOUR);
        TestStartTime.minute = gc.get(GregorianCalendar.MINUTE);
        TestStartTime.second = gc.get(GregorianCalendar.SECOND);
        Device = IdcDataInf.DevType_Idc;
        DataVersion = 0;                                        //数据版本
        DataType = d_inf.m_TestType;                               //数据类型;0xFD表示放电,0xFC表示充电
        HourRate = d_inf.m_HourRate;                               //小时率
        SaveInterval = 0;                                       //采集间隔
        MonomerVol = (int) d_inf.m_MonomerVol;                     //单体电压类型
        STDCap = d_inf.m_STDAH;                                   //标称容量
        TestCur = 0;                                              //测试电流
        MVLLimit = d_inf.m_MonomerVolLL;                         //单体下限
        SumVLLimit = d_inf.m_SumVolLL;                           //组端下限
        BattSum = d_inf.m_EachBattSum * d_inf.m_BattGroup;         //单体数量
        BattGroup = d_inf.m_BattGroup;                           //电池组数
        MVLLimitCount = 1;                                        //单体下限个数
        TestTimeLong.hour = 0;
        TestTimeLong.minute = 0;
        TestTimeLong.second = 0;
        StopType = 0;
        BlockSum = 0;
        StandBy = 0;
        for(int n=0; n<4; n++)
        {
            SMaxIndex[n] = 0;
        }
        for(int n=0; n<4; n++)
        {
            SMinIndex[n] = 0;
        }
        for(int n=0; n<4; n++)
        {
            SMaxVol[n] = 0;
        }
        for(int n=0; n<4; n++)
        {
            SMinVol[n] = 0;
        }
        TestCap = 0;
    }
    public static String getDeviceType(int type)
    {
        String dev_type = "δ֪";
        switch(type)                       //测试仪表类型
        {
             case 0xFB : dev_type = "FBO4815-CT"; break;
             case 0xDC : dev_type = "IDCE4815-CT";break;
             case 0x2F : dev_type = "FBO2205-CT"; break;
             case 0x2E : dev_type = "IDCE2205-CT";break;
             case 0x26 : dev_type = "FBO2206-CT"; break;
             case 0x25 : dev_type = "IDCE2206-CT";break;
             case 0x3F : dev_type = "FBO4830-CT"; break;
             case 0x3E : dev_type = "IDCE4830-CT";break;
             case 0x6F : dev_type = "FBO6003-CT"; break;
             case 0x6E : dev_type = "IDCE6003-CT";break;
             case 0x66 : dev_type = "FBO6006-CT"; break;
             case 0x67 : dev_type = "IDCE6006-CT";break;
             case 0x60 : dev_type = "FBO60010-CT";break;
             case 0x61 : dev_type = "IDCE60010-CT";break;
             case 0x0F : dev_type = "FBO1101-CT"; break;
             case 0x0E : dev_type = "IDCE1101-CT";break;
             case 0x1F : dev_type = "FBO1110-CT"; break;
             case 0x1E : dev_type = "IDCE1110-CT";break;
             case 0xF2 : dev_type = "FBI-4548CT";break;
             case 0xF3 : dev_type = "FBI-3048CT";break;
             case 0xF1 : dev_type = "FBI-3015CT";break;
             case 0xF4 : dev_type = "FBI-10480CT";break;
             case 0xF5 : dev_type = "FBI-05480CT";break;
             case 0xF6 : dev_type = "FBI-15480CT";break;
             case 0xF7 : dev_type = "FBI-20480CT";break;
             case 0xE1 : dev_type = "FBI-05240CT";break;
             case 0xE2 : dev_type = "FBI-10240CT";break;
             case 0xE3 : dev_type = "FBI-15240CT";break;
             case 0xE4 : dev_type = "FBI-20240CT";break;
             case 0x22 : dev_type = "FBO2210-CT"; break;
             case 0x21 : dev_type = "IDCE2210-CT";break;
             case 0x15 : dev_type = "FBO2415-CT"; break;
             case 0x16 : dev_type = "IDCE2415-CT";break;
             case 0x12 : dev_type = "FBO1230-CT";break;
             case 0x11 : dev_type = "IDCE1230-CT";break;
             case 0x84 : dev_type = "FBO840-CT";break;
             case 0x85 : dev_type = "IDCE840-CT";break;
             case 0x13 : dev_type = "IDC_DEV";break;
             case 0x45 : dev_type = "Ser_DEV";break;
             case 0x46 : dev_type="DevType_FBR";break;
        }
        return dev_type;
    }
    public static String getTestType(int type)
    {
        String test_type = "δ֪";
        switch(type)
        {
             case 0xFD : test_type = "放电"; break;
             case 0xFC : test_type = "充电"; break;
             case 0xCD : test_type = "充放电"; break;
             case CsvData.DevType_Csv : test_type = "电导"; break;
             case CsvData.DevType_FBR :    test_type = "内阻"; break;
        }
        return test_type;
    }
    public static String getStopType(int type)
    {
        String stop_type = "δ֪";
        switch(type)
        {
             case 0 : stop_type = "手动停止"; break;
             case 1 : stop_type = "放电时间到"; break;
             case 2 : stop_type = "放电容量到"; break;
             case 3 : stop_type = "单体下限到"; break;
             case 4 : stop_type = "组端下限到"; break;
             case 5 : stop_type = "市电中断"; break;
             case 6 : stop_type = "内存不足"; break;
             case 7 : stop_type = "温度异常"; break;
        }
        return stop_type;
    }
    @Override
    public String toString() {
        return "FboDataInf [TestStartTime=" + TestStartTime + ", Device=" + Device + ", DataVersion=" + DataVersion
                + ", DataType=" + DataType + ", HourRate=" + HourRate + ", SaveInterval=" + SaveInterval
                + ", MonomerVol=" + MonomerVol + ", STDCap=" + STDCap + ", TestCur=" + TestCur + ", MVLLimit="
                + MVLLimit + ", SumVLLimit=" + SumVLLimit + ", BattSum=" + BattSum + ", BattGroup=" + BattGroup
                + ", MVLLimitCount=" + MVLLimitCount + ", TestTimeLong=" + TestTimeLong + ", StopType=" + StopType
                + ", BlockSum=" + BlockSum + ", StandBy=" + StandBy + ", SMaxIndex=" + Arrays.toString(SMaxIndex)
                + ", SMinIndex=" + Arrays.toString(SMinIndex) + ", SMaxVol=" + Arrays.toString(SMaxVol) + ", SMinVol="
                + Arrays.toString(SMinVol) + ", realcap=" + realcap + ", TestCap=" + TestCap + "]";
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboDataType.java
New file
@@ -0,0 +1,64 @@
package com.dev.fgcd.fbo;
import java.io.FileInputStream;
import java.io.IOException;
public class FboDataType {
    public int TypeTag0;
    public int TypeTag1;
    public int TypeTag2;
    public int TypeTag3;
    public void setType(int type)
    {
        TypeTag0 = type;
        TypeTag1 = type;
        TypeTag2 = type;
        TypeTag3 = type;
    }
    public int checkDataHead(FileInputStream fis)
    {
        boolean file_end = false;
        byte type_tag = 0;
        byte[] tag = new byte[1];
        try {
            while(true)
            {
                type_tag = 0;
                int n = 0;
                for(n=0; n<4; n++)
                {
                    if(1 != fis.read(tag, 0, 1))
                    {
                        file_end = true;
                        break;
                    }
                    if((0xFD != (tag[0]&0xFF)) && (0xFC != (tag[0]&0xFF)))
                    {
                        break;
                    }
                }
                if(n >= 4)
                {
                    type_tag = tag[0];
                    break;
                }
                if(true == file_end)
                {
                    type_tag = 1;
                    break;
                }
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
        }
        setType(type_tag&0xFF);
        return (TypeTag0);
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboDateTime.java
New file
@@ -0,0 +1,21 @@
package com.dev.fgcd.fbo;
import java.util.Calendar;
import java.util.Date;
public class FboDateTime {
    public int year;
    public int month;
    public int day;
    public int hour;
    public int minute;
    public int second;
    public Date getFBODateTime() {
        Calendar c = Calendar.getInstance();
        c.set(2000+year, month, day, hour, minute, second);
        return c.getTime();
        //return Com.get_DT_FromStr(year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second, Com.DTF_YMDhms);
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/FboTestTime.java
New file
@@ -0,0 +1,17 @@
package com.dev.fgcd.fbo;
public class FboTestTime {
    public int hour;
    public int minute;
    public int second;
    public int getTestTimeLong() {
        return (hour*60*60+minute*60+second);
    }
    public String getTestTimeString() {
        return hour+":"+minute+":"+second;
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/IdcData.java
New file
@@ -0,0 +1,158 @@
package com.dev.fgcd.fbo;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
public class IdcData {
    public static final int Data400_Len = 1632;
    public static final int Data24_Len = 128;
    public static final int DataVer_YC = 0;
    public static final int DataVer_MR = 1;
    public int DataVersion = DataVer_YC;
    public int DataType;
    public IdcTestTime DateTime = new IdcTestTime();
    public float SumVol;
    public float SumCur;
    public float SumAH;
    public float[] MonomerVol = new float[400];
    public void setData(byte[] buf)
    {
        ByteBuffer bf = ByteBuffer.allocate(2048);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.put(buf);
        bf.position(0);
        DataVersion = DataVer_YC;
        DataType = (bf.getInt()&0xFFFF);
        DateTime.year = (int) (bf.getShort()&0xFFFF);
        DateTime.month = (int) (bf.getShort()&0xFFFF);
        DateTime.dayofweek = (int) (bf.getShort()&0xFFFF);
        DateTime.day = (int) (bf.getShort()&0xFFFF);
        DateTime.hour = (int) (bf.getShort()&0xFFFF);
        DateTime.minute = (int) (bf.getShort()&0xFFFF);
        DateTime.second = (int) (bf.getShort()&0xFFFF);
        DateTime.millsecond = (int) (bf.getShort()&0xFFFF);
        SumVol = bf.getFloat();
        SumCur = bf.getFloat();
        SumAH = bf.getFloat();
        for(int n=0; n<400; n++)
        {
            MonomerVol[n] = bf.getFloat();
            if(n > 30) {
                if(MonomerVol[n] > 0.1) {
                    DataVersion = DataVer_MR;
                }
            }
        }
    }
    public static void checkIdcFile(File file, FboDataInf data_inf, ArrayList<FboData> al_fbo_data)
    {
        File f = file;
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(f);
            byte[] buf = new byte[1024];
            if(fis.read(buf, 0, buf.length) == 1024)
            {
                IdcDataInf idc_inf = new IdcDataInf();
                idc_inf.setDataInf(buf);
                data_inf.setDataInf(idc_inf);
                data_inf.DataType = 0xFD;
                int data_count = 0;
                int data_len = IdcData.Data400_Len;
                IdcData idc_data_begin = new IdcData();
                IdcData idc_data_tmp = new IdcData();
                byte[] databuf = new byte[IdcData.Data400_Len];
                FboData fbo_data = new FboData();
                if(fis.read(databuf , 0 , data_len) == data_len)
                {
                    idc_data_tmp.setData(databuf);
                    if(IdcData.DataVer_MR == idc_data_tmp.DataVersion) {
                        data_len = IdcData.Data24_Len;
                    }
                }
                fis.skip(IdcData.Data400_Len * (-1));
                while(true)
                {
                    if(fis.read(databuf, 0, data_len) == data_len)
                    {
                        IdcData idc_data = new IdcData();
                        idc_data.setData(databuf);
                        if(0 == data_count) {
                            idc_data_begin = idc_data;
                            idc_data_tmp = idc_data;
                            if(0xCC == idc_data.DataType) {
                                data_inf.DataType = 0xFC;
                            }
                        }
                        idc_data.DataType = data_inf.DataType;
                        fbo_data = new FboData();
                        fbo_data.setData(idc_data);
                        fbo_data.m_TestTime = IdcTestTime.getFboTestTime(idc_data.DateTime, idc_data_begin.DateTime);
                        int second_count = (int) (idc_data.DateTime.getTimeInSecond() - idc_data_tmp.DateTime.getTimeInSecond());
                        if(second_count > 56) {
                            data_inf.SaveInterval = second_count / 60;
                            if((second_count % 60) > 0) {
                                data_inf.SaveInterval += 1;
                            }
                        }
                        float tmp_cap = (fbo_data.SubCurrent[0] * second_count) / 3600;
                        if(al_fbo_data.size() > 0) {
                            fbo_data.SubCap[0] = al_fbo_data.get(al_fbo_data.size()-1).SubCap[0] + tmp_cap;
                        } else {
                            fbo_data.SubCap[0] = tmp_cap;
                        }
                        fbo_data.AllCap = fbo_data.SubCap[0];
                        al_fbo_data.add(fbo_data);
                        idc_data_tmp = idc_data;
                        data_count += 1;
                    } else {
                        break;
                    }
                }
                data_inf.TestTimeLong.hour = fbo_data.m_TestTime.hour;
                data_inf.TestTimeLong.minute = fbo_data.m_TestTime.minute;
                data_inf.TestTimeLong.second = fbo_data.m_TestTime.second;
                data_inf.TestCur = fbo_data.SubCurrent[0];
                data_inf.TestCap = fbo_data.SubCap[0];
                data_inf.SMaxIndex[0] = fbo_data.getMaxIndex();
                data_inf.SMaxVol[0] = fbo_data.getMaxVol();
                data_inf.SMinIndex[0] = fbo_data.getMinIndex();
                data_inf.SMinVol[0] = fbo_data.getMinVol();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if(null != fis)
            {
                try {
                    fis.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/IdcDataInf.java
New file
@@ -0,0 +1,132 @@
package com.dev.fgcd.fbo;
import java.util.Date;
import com.battmonitor.sql.Com;
public class IdcDataInf {
    public static final int DevType_Idc = 0x13;
    public int m_STDAH;                    //标称容量。
    public int m_EachBattSum;            //电池个数。
    public int m_HourRate;               //小时率。
    public int m_BattGroup;
    public float m_MonomerVol;
    public float m_MonomerType;
    public float m_SumVolLL;
    public float m_MonomerVolLL;
    public int m_MonomerLLCount;
    public int m_TestCap;
    public int m_TestType;
    public String m_TestTimeLong;
    public String m_MasterCorp;
    public String m_Filiale;
    public String m_Subarea;
    public String m_BureauNO;
    public String m_BattGroupName;
    public String m_BattProducer;
    public Date m_BattProducedTime;
    public Date m_BattFirstUsedTime;
    public String m_VictorMan;
    public Date m_TestTime;
    public String m_ContactPhone;
    public String m_StopType;
    public String m_TestDevice;
    public String m_Remark;
    private int StrToInt(String str)
    {
        return Integer.parseInt(str);
    }
    public void setDataInf(byte[] inf_data)
    {
        int IDCtype = 0;
        String tmpstr = new String(inf_data);
        //System.out.println(tmpstr);
        for (int i=0; i<17; i++)
        {
            int j = tmpstr.indexOf(",");
            if(i == 6)   //--------标称容量
            {
                String text = tmpstr.substring(0,j).trim();
                if(text != "")
                     m_STDAH = StrToInt(text);
                else m_STDAH = 1000;
            }
            if(i == 7)  //--------单体电压
            {
                String text = tmpstr.substring(0,j).trim();
                if(text != "")
                     m_MonomerVol = StrToInt(text);
                else m_MonomerVol = 2;
            }
            if(i == 8)  //--------小时率
            {
                String text = tmpstr.substring(0,j).trim();
                if(text != "")
                      m_HourRate = StrToInt(text);
                else  m_HourRate = 10;
            }
            if(i == 11)  //--------电池组数
            {
                String text = tmpstr.substring(0,j).trim();
                if(text != "")
                    m_BattGroup = StrToInt(text);
            }
            if(i == 12) //--------单体数量
            {
                String text = tmpstr.substring(0,j).trim();
                if(text != "") m_EachBattSum = StrToInt(text);
                else m_EachBattSum = 24;
                if(IDCtype == 0)
                {
                    if(m_EachBattSum > 250) m_EachBattSum = 24;
                }
                else if(m_EachBattSum > 24) m_EachBattSum = 24;
            }
            if (i == 0) m_Filiale = tmpstr.substring(0,j).trim();        //分公司
            if (i == 1) m_Subarea = tmpstr.substring(0,j).trim();        //分区
            if (i == 2) m_BattGroupName = tmpstr.substring(0,j).trim();  //电池组名称
            if (i == 3)
            {
                String testtime = tmpstr.substring(0,j).trim();
                if(testtime.contains("  ")) {
                    testtime.replace("  ", " ");
                }
                m_TestTime = IdcTestTime.getDateFromStr(testtime);        //测试时间
            }
            if (i == 4) m_BattProducer = tmpstr.substring(0,j).trim();    //电池品牌
            //if (i == 5) m_BattType = tmpstr.SubString(1,j).Trim();     //电池型号
            if (i == 9) m_VictorMan = tmpstr.substring(0,j).trim();        //维护人员
            //System.out.println(tmpstr);
            if (i == 10) m_ContactPhone = tmpstr.substring(0,j).trim();    //联系电话
            if (i == 13) m_BureauNO = tmpstr.substring(0,j).trim();        //局站编号
            if (i == 14)
            {
                if(tmpstr.substring(0,j).trim() != "")                    //电池生产日期
                    m_BattProducedTime = Com.get_DT_FromStr(tmpstr.substring(0,j).trim(), Com.DTF_YMD);
            }
            if (i == 15)
            {
                if(tmpstr.substring(0,j).trim() != "")                    //电池投入使用日期
                    m_BattFirstUsedTime = Com.get_DT_FromStr(tmpstr.substring(0,j).trim(), Com.DTF_YMD);
            }
            if (i == 16)
            {
                m_Remark = tmpstr.substring(0,j).trim();//备注
            }
            if(i>10)
                tmpstr += "  , ";
            tmpstr = tmpstr.substring(j+1, tmpstr.length()).trim();
        }
    }
}
BattMonitor_FGCD-A059NT/src/com/dev/fgcd/fbo/IdcTestTime.java
New file
@@ -0,0 +1,103 @@
package com.dev.fgcd.fbo;
import java.util.Date;
import java.util.GregorianCalendar;
public class IdcTestTime {
    public int year;
    public int month;
    public int dayofweek;
    public int day;
    public int hour;
    public int minute;
    public int second;
    public int millsecond;
    public long getTimeInSecond()
    {
        GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
        gc.set(GregorianCalendar.YEAR, year);
        gc.set(GregorianCalendar.MONTH, month-1);
        gc.set(GregorianCalendar.DATE, day);
        gc.set(GregorianCalendar.HOUR_OF_DAY, hour);
        gc.set(GregorianCalendar.MINUTE, minute);
        gc.set(GregorianCalendar.SECOND, second);
        return (gc.getTimeInMillis()/1000);
    }
    public static Date getDateFromStr(String str_time)
    {
        GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
        int year = 1, month = 1, day = 1, hour = 0, minute = 0, second = 0;
        String str = str_time;
        if(str.indexOf("-") >= 0) {
            year = Integer.parseInt(str.substring(0, str.indexOf("-")).trim());
            str = str.substring(str.indexOf("-")+1, str.length());
            month = Integer.parseInt(str.substring(0, str.indexOf("-")).trim());
            str = str.substring(str.indexOf("-")+1, str.length());
        } else if(str.indexOf("/") >= 0) {
            year = Integer.parseInt(str.substring(0, str.indexOf("/")).trim());
            str = str.substring(str.indexOf("/")+1, str.length());
            month = Integer.parseInt(str.substring(0, str.indexOf("/")).trim());
            str = str.substring(str.indexOf("/")+1, str.length());
        }
        if(str.indexOf(" ") >= 0) {
            day = Integer.parseInt(str.substring(0, str.indexOf(" ")).trim());
            str = str.substring(str.indexOf(" ")+1, str.length()).trim();
        } else {
            day = Integer.parseInt(str.trim());
            str = str.trim();
        }
        if(year < day) {
            int tmp = year;
            year = day;
            day = tmp;
        }
        if(str.indexOf(" ") >= 0) {
            str = str.substring(str.indexOf(" ")+1, str.length());
        }
        if(str.indexOf(":") >= 0) {
            hour = Integer.parseInt(str.substring(0, str.indexOf(":")).trim());
            if(str_time.contains("����")) {
                if(hour < 12) {
                    hour += 12;
                }
            }
            str = str.substring(str.indexOf(":")+1, str.length());
            minute = Integer.parseInt(str.substring(0, str.indexOf(":")).trim());
            str = str.substring(str.indexOf(":")+1, str.length());
            second = Integer.parseInt(str.trim());
        }
        gc.set(GregorianCalendar.YEAR, year-2000);
        gc.set(GregorianCalendar.MONTH, month);
        gc.set(GregorianCalendar.DATE, day);
        gc.set(GregorianCalendar.HOUR_OF_DAY, hour);
        gc.set(GregorianCalendar.MINUTE, minute);
        gc.set(GregorianCalendar.SECOND, second);
        return gc.getTime();
    }
    public static FboTestTime getFboTestTime(IdcTestTime t_end, IdcTestTime t_begin)
    {
        FboTestTime fbo_time = new FboTestTime();
        long seconds = t_end.getTimeInSecond() - t_begin.getTimeInSecond();
        fbo_time.hour = (int) (seconds / 3600);
        fbo_time.minute = (int) ((seconds % 3600) / 60);
        fbo_time.second = (int) (seconds % 60);
        return fbo_time;
    }
}
BattMonitor_FGCD-A059NT/src/main/main_Monitor_FGCD_A059NT.java
@@ -17,7 +17,7 @@
public class main_Monitor_FGCD_A059NT {
    public final static double m_VersionNum = 1.103;
    public final static double m_VersionNum = 1.104;
    public final static String m_Version = "Welcome To Use main_Monitor_FGCD_A059NT PRO 20210714 V" 
                                            + m_VersionNum ;
    /**************************************************************************/