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 makeAlarmData(BattDataThread battDataThread, AlarmParam alarmParam){ List 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= 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.max_monvol){ this.max_monvol = this.mon_vols[i]; this.max_monnum = i+1; } if(this.mon_vols[i]