package com.concentrator;
|
|
import android.util.Log;
|
|
import com.alarms.*;
|
import com.alarms.BattAlarmData;
|
import com.socket.BattDataThread;
|
import com.util.ComBase;
|
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
|
public class Concentrator_State {
|
public static final String TAG = "Concentrator_State";
|
|
public static final int WORKSTATE_FLOAT = 0; //浮充
|
public static final int WORKSTATE_DISCH = 1; //放电
|
public static final int WORKSTATE_CHARG = 2; //充电
|
|
|
public static final int BYTE_LEN = 30;
|
public static final int REG_LEN = 30;
|
|
public static final int MON_REG_COUNT = 100; //单体数据一次最多的汇集器数量
|
public static final int SYS_REG_COUNT = 15; //系统状态的汇集器数量
|
|
|
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; //单体数量
|
|
|
private double sysversion; //系统版本(0.1)
|
private int sysstate; //系统状态 0-常规模式 1-内阻模式 2-编址模式
|
private float groupvol; //组端电压(0.1)
|
private float groupcurr; //组端电流(0.1)
|
public int battstate; //电池状态 0-浮充 1-放电 2-充电
|
private int currdirection; //电流方向 0-充电 1-放电
|
|
private int backup1;
|
private int backup2;
|
private int backup3;
|
private int backup4;
|
private int backup5;
|
private int backup6;
|
private int backup7;
|
private int backup8;
|
private int restestcount; //内阻测试次数
|
|
public BattAlarmData groupVol_AlarmData; //组端电压告警
|
public BattAlarmData battCurr_AlarmData; //电池电流告警
|
public BattAlarmData[] monVol_AlarmData = new BattAlarmData[Concentrator_ComBase.MonomerCountMax]; //单体电压告警
|
public BattAlarmData[] monTmp_AlarmData = new BattAlarmData[Concentrator_ComBase.MonomerCountMax]; //单体温度告警
|
public BattAlarmData[] monRes_AlarmData = new BattAlarmData[Concentrator_ComBase.MonomerCountMax]; //单体内阻告警
|
|
|
public double[] mon_vols = new double[Concentrator_ComBase.MonomerCountMax]; //单体电压
|
public double[] mon_tmps = new double[Concentrator_ComBase.MonomerCountMax]; //单体温度
|
public double[] mon_ress = new double[Concentrator_ComBase.MonomerCountMax]; //单体内阻
|
public int max_monnum; //最大单体电压编号
|
public double max_monvol; //最大单体电压
|
public int min_monnum; //最小单体电压编号
|
public double min_monvol; //最小单体电压
|
|
public int isOutTime = 0; //是否超时
|
|
//复制设备状态
|
public void cloneSystemState(Concentrator_State state){
|
this.sysversion = state.sysversion; //系统版本(0.1)
|
this.sysstate = state.sysstate; //系统状态 0-常规模式 1-内阻模式 2-编址模式
|
this.groupvol = state.groupvol; //组端电压(0.1)
|
this.groupcurr = state.groupcurr; //组端电流(0.1)
|
this.battstate = state.battstate; //电池状态 0-浮充 1-放电 2-充电
|
this.currdirection = state.currdirection; //电流方向 0-充电 1-放电
|
|
this.backup1 = state.backup1;
|
this.backup2 = state.backup2;
|
this.backup3 = state.backup3;
|
this.backup4 = state.backup4;
|
this.backup5 = state.backup5;
|
this.backup6 = state.backup6;
|
this.backup7 = state.backup7;
|
this.backup8 = state.backup8;
|
this.restestcount = state.restestcount; //内阻测试次数
|
|
this.groupvol = groupvol+(float)Math.random()*10; //随机组端电压
|
this.groupvol = (float)Math.round(groupvol*100)/100;
|
this.groupcurr = groupcurr+(float)Math.random()*5; //随机组端电流
|
this.groupcurr = (float)Math.round(groupcurr*100)/100;
|
}
|
|
//复制单体电压
|
public void cloneMonVol(Concentrator_State state,int index){
|
for(int i=index;i<(index+100) && i<300;i++){
|
this.mon_vols[i] = state.mon_vols[i]; //单体电压
|
}
|
initmonvols();
|
}
|
|
//复制单体单体温度
|
public void cloneMonTmp(Concentrator_State state,int index){
|
for(int i=index;i<(index+100);i++){
|
this.mon_tmps[i] = state.mon_tmps[i]; //单体温度
|
}
|
}
|
|
//复制单体单体内阻
|
public void cloneMonRes(Concentrator_State state,int index){
|
for(int i=index;i<(index +100);i++){
|
this.mon_ress[i] = state.mon_ress[i]; //单体内阻
|
}
|
}
|
|
public ByteBuffer getReadBuffer() {
|
ByteBuffer tmp = ByteBuffer.allocate(2);
|
tmp.order(ByteOrder.BIG_ENDIAN);
|
tmp.putShort(ComBase.changeIntToShort(REG_LEN));
|
tmp.flip();
|
return tmp;
|
}
|
|
public boolean putByteBuffer(ByteBuffer bf) {
|
if(bf.limit() < BYTE_LEN) {
|
return false;
|
}
|
ByteBuffer tmpbuf = bf;
|
tmpbuf.position(0);
|
|
sysversion = ComBase.changeShortToDouble(tmpbuf.getShort())/10; //系统版本
|
sysstate = ComBase.changeShortToInt(tmpbuf.getShort()); //系统状态
|
groupvol = (float)ComBase.changeShortToDouble(tmpbuf.getShort())/10; //组端电压
|
groupcurr = (float)ComBase.changeShortToDouble(tmpbuf.getShort())/10; //组端电流
|
battstate = ComBase.changeShortToInt(tmpbuf.getShort()); //电池状态
|
currdirection = ComBase.changeShortToInt(tmpbuf.getShort()); //电流方向
|
this.currdirection=0;
|
this.battstate = 2;
|
if(currdirection == 1){
|
groupcurr = groupcurr *(-1); //改变当前电流方向
|
}
|
|
backup1 = ComBase.changeShortToInt(tmpbuf.getShort());
|
backup2 = ComBase.changeShortToInt(tmpbuf.getShort());
|
backup3 = ComBase.changeShortToInt(tmpbuf.getShort());
|
backup4 = ComBase.changeShortToInt(tmpbuf.getShort());
|
backup5 = ComBase.changeShortToInt(tmpbuf.getShort());
|
backup6 = ComBase.changeShortToInt(tmpbuf.getShort());
|
backup7 = ComBase.changeShortToInt(tmpbuf.getShort());
|
backup8 = ComBase.changeShortToInt(tmpbuf.getShort());
|
restestcount = ComBase.changeShortToInt(tmpbuf.getShort()); //内阻测试次数
|
|
return true;
|
}
|
|
public List<BattAlarmData> makeAlarmData(BattDataThread battDataThread, AlarmParam alarmParam){
|
List<BattAlarmData> alarmDatas = new ArrayList<>();
|
Concentrator_State state = battDataThread.state;
|
|
//判断组端电压告警
|
AlarmParam.AlarmParamCell groupVol_param = alarmParam.alm_GroupVol.CreateAlarmParamCell(battDataThread.battinf);
|
state.groupVol_AlarmData.makeAlarmData(alarmDatas,groupVol_param,state.groupvol);
|
|
//判断电池电流告警
|
AlarmParam.AlarmParamCell battCurr_param = alarmParam.alm_BattCurr.CreateAlarmParamCell(battDataThread.battinf);
|
state.battCurr_AlarmData.makeAlarmData(alarmDatas,battCurr_param,state.groupcurr);
|
|
//判断单体告警
|
for(int i=0;i<monCount;i++){
|
//判断单体电压告警
|
AlarmParam.AlarmParamCell monVol_param = alarmParam.alm_MonVol.CreateAlarmParamCell(battDataThread.battinf);
|
//Log.e(TAG, "makeAlarmData: monvol 告警值hig"+monVol_param.alm_high_coe+"\tlow"+monVol_param.alm_low_coe );
|
state.monVol_AlarmData[i].makeAlarmData(alarmDatas,monVol_param,state.mon_vols[i]);
|
|
//判断单体温度告警
|
AlarmParam.AlarmParamCell monTmp_param = alarmParam.alm_MonTmp.CreateAlarmParamCell(battDataThread.battinf);
|
state.monTmp_AlarmData[i].makeAlarmData(alarmDatas,monTmp_param,state.mon_tmps[i]);
|
|
//判断单体内阻告警
|
AlarmParam.AlarmParamCell monRes_param = alarmParam.alm_MonRes.CreateAlarmParamCell(battDataThread.battinf);
|
state.monRes_AlarmData[i].makeAlarmData(alarmDatas,monRes_param,state.mon_ress[i]);
|
|
}
|
return alarmDatas;
|
}
|
|
public boolean putMonDataBuffer(ByteBuffer bf,int reg_addr){
|
if(bf.limit() < BYTE_LEN) {
|
return false;
|
}
|
bf.position(0);
|
int index = 0;
|
int dataType = 1;
|
int range = 1000;
|
|
//Log.e("Concentrator_State", "putMonDataBuffer:3########################## "+reg_addr);
|
if(reg_addr >= 0x201B && reg_addr <= 0x2146){
|
//单体电压
|
dataType = 1;
|
index = (reg_addr - 0x201B)/100; //设置当前索引
|
}else if(reg_addr >= 0x2147 && reg_addr<= 0x2272){
|
//单体温度
|
dataType = 2;
|
index = (reg_addr - 0x2147)/100;
|
}else if(reg_addr >= 0x2273 && reg_addr <= 0x239E){
|
//单体内阻
|
dataType = 3;
|
index = (reg_addr - 0x2273)/100;
|
}
|
for(int i=0;i<100;i++){
|
switch (dataType){
|
case 1:{
|
mon_vols[index*100+i] = ComBase.changeShortToDouble(bf.getShort())/1000;
|
}break;
|
case 2:{
|
mon_tmps[index*100+i] = ComBase.changeShortToDouble(bf.getShort())/10;
|
}break;
|
case 3:{
|
mon_ress[index*100+i] = ComBase.changeShortToDouble(bf.getShort())/1000;
|
}break;
|
}
|
}
|
if(dataType == 1){
|
initmonvols();
|
}
|
return true;
|
}
|
|
//统计当前电池组的最值
|
public void initmonvols(){
|
this.max_monnum = 1;
|
this.max_monvol = this.mon_vols[0];
|
this.min_monnum = 1;
|
this.min_monvol = this.mon_vols[0];
|
for (int i=0;i<this.monCount;i++){
|
if(this.mon_vols[i] > this.max_monvol){
|
this.max_monvol = this.mon_vols[i];
|
this.max_monnum = i+1;
|
}
|
if(this.mon_vols[i]<this.min_monvol){
|
this.min_monvol = this.mon_vols[i];
|
this.min_monnum = i+1;
|
}
|
}
|
//Log.e(TAG, "initmonvols: 初始化最大最小值maxmonvol:"+max_monvol+"\tminmonvol:"+min_monvol);
|
}
|
|
public int getBYTE_LEN() {
|
return BYTE_LEN;
|
}
|
|
|
public double getSysversion() {
|
return sysversion;
|
}
|
|
public int getSysstate() {
|
return sysstate;
|
}
|
|
public double getGroupvol() {
|
return groupvol;
|
}
|
|
public double getGroupcurr() {
|
return groupcurr;
|
}
|
|
public int getBattstate() {
|
return battstate;
|
}
|
|
public int getCurrdirection() {
|
return currdirection;
|
}
|
|
public int getBackup1() {
|
return backup1;
|
}
|
|
public int getBackup2() {
|
return backup2;
|
}
|
|
public int getBackup3() {
|
return backup3;
|
}
|
|
public int getBackup4() {
|
return backup4;
|
}
|
|
public int getBackup5() {
|
return backup5;
|
}
|
|
public int getBackup6() {
|
return backup6;
|
}
|
|
public int getBackup7() {
|
return backup7;
|
}
|
|
public int getBackup8() {
|
return backup8;
|
}
|
|
public int getRestestcount() {
|
return restestcount;
|
}
|
|
|
public void setSysversion(double sysversion) {
|
this.sysversion = sysversion;
|
}
|
|
public void setSysstate(int sysstate) {
|
this.sysstate = sysstate;
|
}
|
|
public void setGroupvol(float groupvol) {
|
this.groupvol = groupvol;
|
}
|
|
public void setGroupcurr(float groupcurr) {
|
this.groupcurr = groupcurr;
|
}
|
|
public void setBattstate(int battstate) {
|
this.battstate = battstate;
|
}
|
|
public void setCurrdirection(int currdirection) {
|
this.currdirection = currdirection;
|
}
|
|
public void setBackup1(int backup1) {
|
this.backup1 = backup1;
|
}
|
|
public void setBackup2(int backup2) {
|
this.backup2 = backup2;
|
}
|
|
public void setBackup3(int backup3) {
|
this.backup3 = backup3;
|
}
|
|
public void setBackup4(int backup4) {
|
this.backup4 = backup4;
|
}
|
|
public void setBackup5(int backup5) {
|
this.backup5 = backup5;
|
}
|
|
public void setBackup6(int backup6) {
|
this.backup6 = backup6;
|
}
|
|
public void setBackup7(int backup7) {
|
this.backup7 = backup7;
|
}
|
|
public void setBackup8(int backup8) {
|
this.backup8 = backup8;
|
}
|
|
public void setRestestcount(int restestcount) {
|
this.restestcount = restestcount;
|
}
|
|
@Override
|
public String toString() {
|
return "Concentrator_State [sysversion=" + sysversion + ", sysstate=" + sysstate
|
+ ", groupvol=" + groupvol + ", groupcurr=" + groupcurr + ", battstate=" + battstate
|
+ ", currdirection=" + currdirection + ", backup1=" + backup1 + ", backup2=" + backup2 + ", backup3="
|
+ backup3 + ", backup4=" + backup4 + ", backup5=" + backup5 + ", backup6=" + backup6 + ", backup7="
|
+ backup7 + ", backup8=" + backup8 + ", restestcount=" + restestcount + "]";
|
}
|
}
|