编辑电池组信息时改变当前电池组线程状态,并且添加电池组充放电线程记录
6个文件已修改
188 ■■■■ 已修改文件
platforms/android/app/src/main/java/com/concentrator/Concentrator_State.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platforms/android/app/src/main/java/com/fgkj/service/BattinfService.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
platforms/android/app/src/main/java/com/socket/BattDataThread.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platforms/android/app/src/main/java/com/socket/BattTestDataRecordThread.java 116 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platforms/android/app/src/main/java/com/socket/CommSockClientThread.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platforms/android/app/src/main/java/com/socket/FBS9600S_DeviceService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platforms/android/app/src/main/java/com/concentrator/Concentrator_State.java
@@ -24,8 +24,11 @@
    public long testTimelong = 0;                            //测试时长
    public Date testStartTime = new Date();                    //测试开始时间
    public Date record_time = new Date();                    //记录时间
    public int test_type;                                    //测试类型
    public int test_record_count;                            //当前测试次数(包括充放电)
    public Integer record_num;                                //记录笔数
    public int monCount = 24;                                //单体数量
@@ -33,7 +36,7 @@
    private int sysstate;                                    //系统状态         0-常规模式    1-内阻模式    2-编址模式
    private double groupvol;                                //组端电压(0.1)
    private double groupcurr;                                //组端电流(0.1)
    private int battstate;                                    //电池状态    0-浮充     1-放电        2-充电
    public int battstate;                                    //电池状态    0-浮充     1-放电        2-充电
    private int currdirection;                                //电流方向    0-充电       1-放电
    private int backup1;
platforms/android/app/src/main/java/com/fgkj/service/BattinfService.java
@@ -16,6 +16,7 @@
import com.fgkj.dao.DBHelper;
import com.fgkj.dto.Battinf;
import com.google.gson.Gson;
import com.socket.FBS9600S_DeviceService;
import com.sqlite_DaoHelper.DAOHelper;
import java.text.SimpleDateFormat;
@@ -75,8 +76,9 @@
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        Battinf binf=ActionUtil.getGson("yyyy-MM-dd").fromJson(obj,Battinf.class);
        //List<App_Param> params = getGson().fromJson(json, new TypeToken<List<App_Param>>(){}.getType());
       boolean bl=dao.update(db,binf);
        boolean bl=dao.update(db,binf);
        if(bl){
            FBS9600S_DeviceService.allBattDatt.get(binf.getBattGroupId()-1).isInstall = binf.getStation_install()==1;
            model.code=1;
            model.msg="修改成功";
        }else{
platforms/android/app/src/main/java/com/socket/BattDataThread.java
@@ -22,6 +22,7 @@
 *     电池组组操作相关类
 */
public class BattDataThread extends Thread{
    public static final int TESTTYPE_NULL    = 0;               //
    public static final int TESTTYPE_CHRTEST = 2;               //充电测试
    public static final int TESTTYPE_DISTEST = 3;               //放电测试
    public static final int TESTTYPE_RESTEST = 5;               //内阻测试
@@ -33,17 +34,17 @@
    public Handler mSocketHandler = null;
    private CommSockClientThread clientThread = null;
    public boolean isInstall = false;                                   //是否安装
    public int battIndex = 1;                                           //电池组ID                   默认电池组ID
    public Concentrator_Param param;                                    //汇集器参数
    public Concentrator_State state;                                    //汇集器状态
    public boolean isInstall = false;                                               //是否安装
    public int battIndex = 1;                                                       //电池组ID                   默认电池组ID
    public Concentrator_Param param;                                                //汇集器参数
    public Concentrator_State state;                                                //汇集器状态
    public DBHelper dbHelper;
    public WebView webView;
    public Date lastUpdateTime = new Date();                                         //上一次获取数据时间
    public boolean isOutTime = true;                                    //通讯是否超时               超时重连时会重新获取设备的系统参数
    public boolean isOutTime = true;                                                //通讯是否超时               超时重连时会重新获取设备的系统参数
    public long loseTimeLong = 0;                                                   //断开连接时长
    public BattDataThread(int battIndex, DBHelper dbHelper,WebView webView){
        this.webView = webView;
@@ -52,6 +53,7 @@
        param = new Concentrator_Param();
        state = new Concentrator_State();
        clientThread = CommSockClientThread.createClientThread();      //串口通讯线程                     //每个电池组通用同一个串口线程
        BattResDataRecordThread battResDataRecordThread = new BattResDataRecordThread(this,dbHelper);
        battResDataRecordThread.start();
@@ -125,19 +127,21 @@
        while(true){
            try {
                //Log.e(TAG, "run: &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&install" + isInstall+"\tOutTime"+isOutTime);
                //Log.e(TAG, "run: &&&&&&&&&&&&&&&&"+battIndex+"&&&&&&&&&&&&&&&&&&&&&&&&&&&install" + isInstall+"\tOutTime"+isOutTime);
                if(isInstall){
                    //如果当前电池组已安装则实时获取当前电池组的单体信息
                    if( isOutTime ){
                        //超时之后只获取当前的系统参数
                        readSystemParam("");                                                          //读取系统参数
                        if(runCount %15 == 0) {
                            //超时之后只获取当前的系统参数
                            readSystemParam("");                                                          //读取系统参数
                        }
                    }else{
                        if(runCount %15 == 0){
                            //读取系统状态
                            readSystemState("");
                        }
                        if(runCount % 15 == 0){
                        if(runCount % 20 == 0){
                            int maxCount = (int)Math.ceil((double)state.monCount/100);              //最多需要读取次数
                            int monindex = monRCount % maxCount;                                     //单体索引
                            //读取单体电压
@@ -155,14 +159,12 @@
                }
                runCount ++;
                nowTime = new Date();
                long timeCount =  (nowTime.getTime() - lastUpdateTime.getTime())/1000;
                if(timeCount > 60){
                loseTimeLong =  (nowTime.getTime() - lastUpdateTime.getTime())/1000;
                if(loseTimeLong > 60){
                    isOutTime = true;                                                               //60秒未通讯判定为通讯超时
                }else{
                    isOutTime = false;
                }
                sleep(200);
            } catch (Exception e) {
@@ -170,6 +172,7 @@
            }
        }
    }
    //获取系统参数
    public void readSystemParam(String method){
@@ -235,6 +238,8 @@
        Message childMsg = clientThread.mHandler.obtainMessage();
        childMsg.obj = model;
        childMsg.what = isInstall?1:0;
        Log.e(TAG, battIndex+"sendMessageToSocketClient: isStall"+ isInstall);
        return (clientThread.mHandler.sendMessage(childMsg));
    }
platforms/android/app/src/main/java/com/socket/BattTestDataRecordThread.java
@@ -7,6 +7,7 @@
import com.concentrator.Concentrator_State;
import com.fgkj.dao.DBHelper;
import com.sqlite_DaoHelper.SqliteHelper;
import com.util.Com;
import java.util.Date;
@@ -39,24 +40,67 @@
        Log.e(TAG,"run:BattTestDataRecordThread start at " + Com.getDateTimeFormat(new Date(),Com.DTF_YMDhms));
        int nowTestType = Concentrator_State.WORKSTATE_FLOAT;           //当前记录的测试类型(当前电池状态)
        int nowTestType = BattDataThread.TESTTYPE_NULL;                 //当前记录的测试类型
        int nowworkState = Concentrator_State.WORKSTATE_FLOAT;          //当前电池组的状态
        Date lastRecordTime = new Date();                               //上一次记录的时间
        boolean isStartRecord = false;                                  //是否是新的放电记录
        int record_num = 0;                                             //记录笔数
        while(true){
            try {
                if(isRecording){
                    //正在记录历史充放电数据
                    battData.state.record_time = new Date();
                    if(isStartRecord){
                        battData.state.testStartTime = new Date();                                                  //测试开始时间
                        battData.state.test_type = nowTestType;                                                     //设置当前的测试类型
                        battData.state.testTimelong = 0;
                        battData.state.test_record_count = queryMaxTestRecordCount(battData.battIndex,dbHelper);
                        battData.state.record_num = 1;
                        //刚开始记录的线程
                        insertBattTestDatainf(dbHelper,battData);
                        lastRecordTime = new Date();
                        isStartRecord = false;
                    }
                    int testTimelong = (int)((battData.state.record_time.getTime() - battData.state.testStartTime.getTime())/1000);             //测试时长
                    battData.state.testTimelong = testTimelong;
                    if(battData.state.battstate != nowworkState || !battData.isInstall || battData.loseTimeLong > 60*60){
                        //当前电池组的状态变化//当前电池组变成未安装//通讯超时(1小时)
                        isRecording = false;
                    }
                    int recordInterver = (int)Math.abs(new Date().getTime()-lastRecordTime.getTime())/1000;                     //距离上次记录数据的时长
                    if(recordInterver >= saveDataIntever || !isStartRecord){
                        lastRecordTime = new Date();
                        //放电结束或者记录时间到
                        //记录当前的充放电记录
                        insertBattTestData(dbHelper,battData);
                    }
                    battData.state.record_num++;
                }else{
                    //暂无记录充放电数据
                    if(battData.state.battstate == Concentrator_State.WORKSTATE_DISCH && battData.isInstall && battData.loseTimeLong <= 60*60){
                        //正在放电
                        isRecording = true;
                        isStartRecord = true;
                        nowTestType = BattDataThread.TESTTYPE_DISTEST;
                        nowworkState = Concentrator_State.WORKSTATE_DISCH;
                    }else if(battData.state.battstate == Concentrator_State.WORKSTATE_CHARG && battData.isInstall && battData.loseTimeLong <= 60*60){
                        //正在充电
                        isRecording = true;
                        isStartRecord = true;
                        nowTestType = BattDataThread.TESTTYPE_CHRTEST;
                        nowworkState = Concentrator_State.WORKSTATE_CHARG;
                    }else{
                        nowTestType = BattDataThread.TESTTYPE_NULL;
                        nowworkState = Concentrator_State.WORKSTATE_FLOAT;
                        isRecording = false;
                    }
                }
                sleep(2000);
                sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -90,10 +134,72 @@
    }
    //插入历史数据
    public static void insertBattTestDatainf(DBHelper dbHelper,Concentrator_State state){
        String sql_str = "";
    public static void insertBattTestDatainf(DBHelper dbHelper,BattDataThread battData){
        Concentrator_State state = battData.state;
        String batt_inf_sql_str = "INSERT INTO tb_batttestdata_inf" +
                         "(BattGroupId,test_record_count,test_type,record_time_interval,record_num,test_starttime,record_time,test_timelong,group_vol,test_curr,test_cap,max_monnum,max_monvol,min_monnum,min_monvol) " +
                         " VALUES("+battData.battIndex+","+state.test_record_count+","+state.test_type+","+saveDataIntever+","+state.record_num+",'"+Com.getDateTimeFormat(state.testStartTime,Com.DTF_YMDhms)+"','"+Com.getDateTimeFormat(state.record_time,Com.DTF_YMDhms)+"',"+state.testTimelong+","+state.getGroupvol()+","+state.getGroupcurr()+","+0+","+state.max_monnum+","+state.max_monvol+","+state.min_monnum+","+state.min_monvol+") ";
        String batt_id_sql_str="INSERT INTO tb_batttestdata_"+battData.battIndex+"(BattGroupId,test_record_count,test_type,test_starttime,record_time,test_timelong,group_vol,test_curr,test_cap,mon_num,mon_vol,mon_tmp,mon_res) " +
                "VALUES";
        for(int i=0;i<state.monCount;i++){
            if(i != 0){
                batt_id_sql_str += ",";
            }
            batt_id_sql_str += "("+battData.battIndex+","+state.test_record_count+","+state.test_type+",'"+Com.getDateTimeFormat(state.testStartTime,Com.DTF_YMDhms)+"','"+Com.getDateTimeFormat(state.record_time,Com.DTF_YMDhms)+"',"+state.testTimelong+","+state.getGroupvol()+","+state.getGroupcurr()+","+0+","+(i+1)+","+state.mon_vols[i]+","+state.mon_tmps[i]+","+state.mon_ress[i]+")";
        }
        SQLiteDatabase db = null;
        try {
            db = dbHelper.getWritableDatabase();
            db.beginTransaction();
            db.execSQL(batt_inf_sql_str);
            db.execSQL(batt_id_sql_str);
            db.setTransactionSuccessful();
            db.endTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if(db != null){
                try {
                    db.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    //插入历史数据
    public static void insertBattTestData(DBHelper dbHelper,BattDataThread battData){
        Concentrator_State state = battData.state;
        String batt_inf_sql_str = " UPDATE tb_batttestdata_inf SET record_num ="+state.record_num+" ,record_time='"+Com.getDateTimeFormat(state.record_time,Com.DTF_YMDhms)+"',test_timelong="+state.testTimelong+",group_vol="+state.getGroupvol()+",test_curr="+state.getGroupcurr()+",test_cap=0,max_monnum="+state.max_monnum+",max_monvol="+state.max_monvol+",min_monnum="+state.min_monnum+",min_monvol="+state.min_monvol+" WHERE BattGroupId = "+battData.battIndex+" AND test_record_count = "+state.test_record_count;
        String batt_id_sql_str="INSERT INTO tb_batttestdata_"+battData.battIndex+"(BattGroupId,test_record_count,test_type,test_starttime,record_time,test_timelong,group_vol,test_curr,test_cap,mon_num,mon_vol,mon_tmp,mon_res) " +
                "VALUES";
        for(int i=0;i<state.monCount;i++){
            if(i != 0){
                batt_id_sql_str += ",";
            }
            batt_id_sql_str += "("+battData.battIndex+","+state.test_record_count+","+state.test_type+",'"+Com.getDateTimeFormat(state.testStartTime,Com.DTF_YMDhms)+"','"+Com.getDateTimeFormat(state.record_time,Com.DTF_YMDhms)+"',"+state.testTimelong+","+state.getGroupvol()+","+state.getGroupcurr()+","+0+","+(i+1)+","+state.mon_vols[i]+","+state.mon_tmps[i]+","+state.mon_ress[i]+")";
        }
        SQLiteDatabase db = null;
        try {
            db = dbHelper.getWritableDatabase();
            db.beginTransaction();
            db.execSQL(batt_inf_sql_str);
            db.execSQL(batt_id_sql_str);
            db.setTransactionSuccessful();
            db.endTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if(db != null){
                try {
                    db.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
platforms/android/app/src/main/java/com/socket/CommSockClientThread.java
@@ -21,7 +21,9 @@
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * 底层和汇集器通讯线程
@@ -77,7 +79,13 @@
            public void handleMessage(Message msg)
            {
                ServiceModel model = (ServiceModel) (msg.obj);
                //Log.e(TAG, "handleMessage: " + model);
//                int what = msg.what;
//                List<BattDataThread> battData = FBS9600S_DeviceService.allBattDatt;
//                if(model.battindex>0 && model.battindex<FBS9600S_DeviceService.MAXCONCENTRATORCOUNT){
//                    if(!battData.get(model.battindex-1).isInstall){
//                        return;
//                    }
//                }
                try
                {
                    if(null != model.mhandler)
@@ -108,7 +116,7 @@
                        Message toMain = handler.obtainMessage();
                        toMain.obj = remodel;
                        handler.sendMessage(toMain);
                        sleep(200);
                        sleep(5);
                    }
                }
                catch (InterruptedException e)
@@ -200,7 +208,7 @@
                            //    res = true;
                            break;
                        }
                        if(rx_read_time_out > 40) {
                        if(rx_read_time_out > 30) {
                            break;
                        }
                    }
@@ -209,11 +217,11 @@
                bytebuffer_for_socket_RX.flip();
                Date d2 = new Date();
                long comm_tms = (d2.getTime() - d1.getTime());
                if(comm_tms < 200) {
                    Thread.sleep(200 - comm_tms);
                }
//                Date d2 = new Date();
//                long comm_tms = (d2.getTime() - d1.getTime());
//                if(comm_tms < 200) {
//                    Thread.sleep(200 - comm_tms);
//                }
                /*
                System.out.println(this.getName()
                                    + "  dev_id: " + m_StatAndParam.dev_id
@@ -228,7 +236,7 @@
                bytebuffer_for_socket_RX.get(cipher_buf);
                Log.e(TAG, "接收数据: "+ ComFn.bytesToHexString(cipher_buf, cipher_buf.length));
                //Log.e(TAG, "接收数据: "+ ComFn.bytesToHexString(cipher_buf, cipher_buf.length));
                if(true == getDataFromCommBuf(cipher_buf,remodel)) {
                    rx_errcount_for_live_of_thread = 0;
                    res_t = true;
platforms/android/app/src/main/java/com/socket/FBS9600S_DeviceService.java
@@ -19,10 +19,10 @@
import java.util.List;
public class FBS9600S_DeviceService {
    public static final int MAXCONCENTRATORCOUNT = 16;                                  //最多连接的汇集器数量
    public static final int MAXCONCENTRATORCOUNT = 2;                                  //最多连接的汇集器数量
    public static final String JS_INTERFACE_NAME = "DeviceService";            //JS调用类名
    public List<BattDataThread> allBattDatt;
    public static List<BattDataThread> allBattDatt;
    public DBHelper dbHelper;
    public WebView webView;
    public FBS9600S_DeviceService(WebView webView,DBHelper dbHelper){