package com.dev.fbs9600;
|
|
import java.util.Date;
|
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
import com.battdata_rt.BattData_RT;
|
import com.dev.modbus4j.MyModbusMaster;
|
import com.dev.modbus4j.MyModbusUtils;
|
import com.serotonin.modbus4j.BatchRead;
|
import com.serotonin.modbus4j.BatchResults;
|
import com.serotonin.modbus4j.code.DataType;
|
|
public class FBS9600_State {
|
private static final int BATT_MAXGOROUP_COUNT = 16;
|
static final int UsrCmdNull = 0;
|
static final int UsrCmdTestRes = 81;
|
static final int UsrCmdTestResSuc = 82;
|
static final int WorkStateNull = 0;
|
static final int WorkStateRes = 1;
|
public String ip_addr;
|
public int dev_id;
|
public int check_dev_id; //校验设备id
|
private int op_cmd;
|
public int BattGroupNum; //当前电池组号启动或停止时判断要启动和停止的组号
|
private boolean op_cmd_ack_fromdev = false;
|
int work_state;
|
|
public int com_count; //通信计数
|
public int com_err_count; //连续错误计数
|
|
|
public int com_totalcount; //总的错误计数
|
public int com_err_totalcount; //总的错误计数
|
|
long alm_rec_id = 0L;
|
public int[] dev_works = new int[BATT_MAXGOROUP_COUNT];
|
public float[] dev_currs = new float[BATT_MAXGOROUP_COUNT];
|
public float[] dev_groupvols = new float[BATT_MAXGOROUP_COUNT];
|
public int[] batt_type = new int[BATT_MAXGOROUP_COUNT]; //电池类型0铅酸;1锂电池
|
public FBS9600_Lithium_Data[] lidata = new FBS9600_Lithium_Data[BATT_MAXGOROUP_COUNT];
|
|
private Logger logger;
|
public FBS9600_State(String ipaddr, int id) {
|
this.ip_addr = ipaddr;
|
this.dev_id = id;
|
|
this.logger = LogManager.getLogger(this);
|
}
|
|
public void setWorkState(int work_state) {
|
this.work_state = work_state;
|
}
|
|
public void clearWorkState() {
|
this.work_state = 0;
|
}
|
|
public int getWorkState() {
|
return this.work_state;
|
}
|
|
public void setFBS9600CmdAckFromDev(boolean stat) {
|
this.op_cmd_ack_fromdev = stat;
|
}
|
|
public boolean getFBS9600CmdAckFromDev() {
|
return this.op_cmd_ack_fromdev;
|
}
|
|
public void setFBS9600Cmd(int cmd) {
|
this.op_cmd = cmd;
|
}
|
|
public int getFBS9600Cmd() {
|
return this.op_cmd;
|
}
|
|
public void setComCountInc() {
|
this.com_err_count = 0;
|
this.com_count += 1;
|
if (this.com_count >= 90000000)
|
this.com_count = 1;
|
}
|
|
public int getOp_cmd() {
|
return op_cmd;
|
}
|
|
public int getBattGroupNum() {
|
return BattGroupNum;
|
}
|
|
public void setOp_cmd(int op_cmd) {
|
this.op_cmd = op_cmd;
|
}
|
|
public void setBattGroupNum(int battGroupNum) {
|
BattGroupNum = battGroupNum;
|
}
|
|
public void setComErrCountInc() {
|
this.com_err_count += 1;
|
this.com_err_totalcount += 1;
|
if (this.com_err_totalcount >= 90000000)
|
this.com_err_totalcount = 20;
|
this.com_err_count = 20;
|
}
|
|
public int getTotalCommCount() {
|
int totalCommCount = (this.com_count + this.com_totalcount);
|
if(totalCommCount > 90000000) {
|
this.com_totalcount = 20;
|
}
|
|
return (this.com_count + this.com_totalcount);
|
}
|
|
public int getTotalErrCommCount() {
|
int totalCommErrCount = (this.com_err_count + this.com_err_totalcount);
|
if(totalCommErrCount > 90000000) {
|
this.com_err_totalcount = 20;
|
}
|
return (this.com_err_count + this.com_err_totalcount);
|
}
|
/**
|
* 构造State 的设备ID读取集合
|
* @param master
|
* @return
|
*/
|
public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
batch.addLocator(0,MyModbusUtils.createBaseLocator(0xF001,DataType.TWO_BYTE_INT_UNSIGNED, master)); //机箱跳闸输出
|
batch.addLocator(1,MyModbusUtils.createBaseLocator(0xF002, DataType.TWO_BYTE_INT_UNSIGNED, master)); //故障复位信号
|
|
return batch;
|
}
|
|
/**
|
* 解析State 的设备ID读取集合
|
* @param res
|
*/
|
public boolean putBatchResult(BatchResults<Integer> res) {
|
if(res != null) {
|
int dev_head = res.getIntValue(0);
|
int dev_food = res.getIntValue(1);
|
|
this.check_dev_id = dev_head*100000+dev_food;
|
|
logger.debug("check_dev_id:"+this.check_dev_id+"\t 0xF001:"+dev_head+"\t 0xF002:"+dev_food);
|
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 读取电池组组端数据信息
|
* @param master
|
* @return
|
*/
|
public BatchRead<Integer> createGruopBatchRead(MyModbusMaster master,int index) {
|
int offset = index*0x1000;
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
batch.addLocator(0,MyModbusUtils.createBaseLocator(0x0003+offset,DataType.TWO_BYTE_INT_UNSIGNED, master)); //模块状态:0-正常采集 1-内阻测试 2-单体编号
|
batch.addLocator(1,MyModbusUtils.createBaseLocator(0x0004+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //组端电压
|
batch.addLocator(2,MyModbusUtils.createBaseLocator(0x0006+offset, DataType.TWO_BYTE_INT_SIGNED, master)); //组端电流
|
batch.addLocator(3,MyModbusUtils.createBaseLocator(0x0007+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //蓄电池状态
|
batch.addLocator(4,MyModbusUtils.createBaseLocator(0x000A+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //纹波电流均值
|
batch.addLocator(5,MyModbusUtils.createBaseLocator(0x000B+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //纹波电流峰值
|
batch.addLocator(6,MyModbusUtils.createBaseLocator(0x0ABD+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //电池类型
|
|
return batch;
|
}
|
|
|
|
public boolean putGroupBatchResult(BatchResults<Integer> res,int index,BattData_RT battData_RT) {
|
if(res != null) {
|
dev_works[index] = res.getIntValue(0);
|
//System.out.println("work_state"+(index+1)+":"+dev_works[index]);
|
dev_groupvols[index] = ((float)res.getIntValue(1))/10;
|
battData_RT.mTestData.updateGroupVolFrom_FBSDev(dev_groupvols[index]);
|
battData_RT.mTestData.newDataRecordTime = new Date();
|
|
//内阻测试过程中处理
|
if(dev_works[index] == FBS9600_CommData.DevWorkstate_ResTest) {
|
battData_RT.mTestData.setBatt_res_test_state(1);
|
}else {
|
battData_RT.mTestData.setBatt_res_test_state(0);
|
}
|
|
float battcurr = ((float)((short)res.getValue(2)))/10;
|
//float battcurr = 10;
|
int battstate = res.getIntValue(3);
|
if (1 == battstate) {
|
battcurr = Math.abs(battcurr)* -1.0F;
|
}
|
dev_currs[index] = battcurr;
|
battData_RT.mTestData.updateCurrFrom_FBSDev(battcurr);
|
float curr_avg = ((float)res.getIntValue(4))/10;
|
float curr_top = ((float)res.getIntValue(5))/10;
|
//System.out.println(res);
|
batt_type[index] = res.getIntValue(6); //电池型号
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 读取单体电压
|
* @param master
|
* @param index
|
* @param monCount
|
* @return
|
*/
|
public BatchRead<Integer> createMonVolBatchRead(MyModbusMaster master, int index,int monCount) {
|
int offset = index*0x1000;
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
for(int i=0;i<monCount;i++) {
|
batch.addLocator(i,MyModbusUtils.createBaseLocator(0x001C+offset+i,DataType.TWO_BYTE_INT_UNSIGNED, master)); //单体电压
|
}
|
return batch;
|
}
|
|
/**
|
* 读取单体电压
|
* @param res
|
* @param index
|
* @param battData_RT
|
* @return
|
*/
|
public boolean putMonVolBatchResult(BatchResults<Integer> res, int index, BattData_RT battData_RT) {
|
if(res != null) {
|
//System.out.print("组号"+(index+1) + "\t");
|
for(int i=0;i<battData_RT.MonCount;i++) {
|
battData_RT.al_MonVol.get(i).monVol = ((float)res.getIntValue(i))/1000;
|
//System.out.print((i+1)+"#:"+battData_RT.al_MonVol.get(i).monVol+"\t");
|
}
|
//System.out.println();
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 读取单体内阻
|
* @param master
|
* @param index
|
* @param monCount
|
* @return
|
*/
|
public BatchRead<Integer> createMonResBatchRead(MyModbusMaster master, int index,int monCount) {
|
int offset = index*0x1000;
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
for(int i=0;i<monCount;i++) {
|
batch.addLocator(i,MyModbusUtils.createBaseLocator(0x04D4+offset+i,DataType.TWO_BYTE_INT_UNSIGNED, master)); //单体电压
|
}
|
return batch;
|
}
|
|
/**
|
* 读取单体内阻
|
* @param res
|
* @param index
|
* @param battData_RT
|
* @return
|
*/
|
public boolean putMonResBatchResult(BatchResults<Integer> res, int index, BattData_RT battData_RT) {
|
if(res != null) {
|
for(int i=0;i<battData_RT.MonCount;i++) {
|
battData_RT.al_MonVol.get(i).monRes = ((float)res.getIntValue(i))/1000;
|
}
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 读取单体温度
|
* @param master
|
* @param index
|
* @param monCount
|
* @return
|
*/
|
public BatchRead<Integer> createMonTmpBatchRead(MyModbusMaster master, int index,int monCount) {
|
int offset = index*0x1000;
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
for(int i=0;i<monCount;i++) {
|
batch.addLocator(i,MyModbusUtils.createBaseLocator(0x0278+offset+i,DataType.TWO_BYTE_INT_UNSIGNED, master)); //单体电压
|
}
|
return batch;
|
}
|
|
/**
|
* 读取单体温度
|
* @param res
|
* @param index
|
* @param battData_RT
|
* @return
|
*/
|
public boolean putMonTmpBatchResult(BatchResults<Integer> res, int index, BattData_RT battData_RT) {
|
if(res != null) {
|
for(int i=0;i<battData_RT.MonCount;i++) {
|
battData_RT.al_MonVol.get(i).monTmp = ((float)res.getIntValue(i)-100)/10;
|
}
|
return true;
|
}
|
return false;
|
}
|
/**
|
* 读取单体均衡电流
|
* @param master
|
* @param index
|
* @param monCount
|
* @return
|
*/
|
public BatchRead<Integer> createMonJhCurrBatchRead(MyModbusMaster master, int index,int monCount) {
|
int offset = index*0x1000;
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
for(int i=0;i<monCount;i++) {
|
batch.addLocator(i,MyModbusUtils.createBaseLocator(0x098D+offset+i,DataType.TWO_BYTE_INT_UNSIGNED, master)); //单体均衡电流
|
}
|
return batch;
|
}
|
|
/**
|
* 读取单体均衡电流
|
* @param res
|
* @param index
|
* @param battData_RT
|
* @return
|
*/
|
public boolean putMonJhCurrBatchResult(BatchResults<Integer> res, int index, BattData_RT battData_RT) {
|
if(res != null) {
|
for(int i=0;i<battData_RT.MonCount;i++) {
|
//System.out.println("均衡电流:"+res.getIntValue(i));
|
battData_RT.al_MonVol.get(i).monJHcurr = (float)res.getIntValue(i)/1000;
|
}
|
return true;
|
}
|
return false;
|
}
|
|
public void setCommData(MyModbusMaster master) {
|
this.com_count = master.getTolcommcount();
|
this.com_err_count = master.getTotalerr();
|
|
}
|
|
public BatchRead<Integer> createLithiumBatchRead(MyModbusMaster master, int index) {
|
int offset = index*0x1000;
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
batch.addLocator(0,MyModbusUtils.createBaseLocator(0x0ABE+offset,DataType.TWO_BYTE_INT_UNSIGNED, master)); //环境温度
|
batch.addLocator(1,MyModbusUtils.createBaseLocator(0x0ABF+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //功率温度
|
batch.addLocator(2,MyModbusUtils.createBaseLocator(0x0AC0+offset, DataType.TWO_BYTE_INT_SIGNED, master)); //剩余容量
|
batch.addLocator(3,MyModbusUtils.createBaseLocator(0x0AC1+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //自定义遥测量数量
|
batch.addLocator(4,MyModbusUtils.createBaseLocator(0x0AC2+offset, DataType.TWO_BYTE_INT_SIGNED, master)); //电池总容量
|
batch.addLocator(5,MyModbusUtils.createBaseLocator(0x0AC3+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //电池循环次数
|
batch.addLocator(6,MyModbusUtils.createBaseLocator(0x0AC4+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //环境温度告警状态
|
batch.addLocator(7,MyModbusUtils.createBaseLocator(0x0AC5+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //功率温度告警状态
|
batch.addLocator(8,MyModbusUtils.createBaseLocator(0x0AC6+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //充放电电流告警状态
|
batch.addLocator(9,MyModbusUtils.createBaseLocator(0x0AC7+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //电池总电压告警状态
|
batch.addLocator(10,MyModbusUtils.createBaseLocator(0x0AC8+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //自定义告警量数量
|
batch.addLocator(11,MyModbusUtils.createBaseLocator(0x0AC9+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //均衡事件代码
|
batch.addLocator(12,MyModbusUtils.createBaseLocator(0x0ACA+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //电压事件代码
|
batch.addLocator(13,MyModbusUtils.createBaseLocator(0x0ACB+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //温度事件代码
|
batch.addLocator(14,MyModbusUtils.createBaseLocator(0x0ACC+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //电流事件代码
|
batch.addLocator(15,MyModbusUtils.createBaseLocator(0x0ACD+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //FET状态代码
|
batch.addLocator(16,MyModbusUtils.createBaseLocator(0x0ACE+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //均衡状态代码
|
//batch.addLocator(17,MyModbusUtils.createBaseLocator(0x0ACF+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //系统状态代码
|
|
return batch;
|
}
|
|
public boolean putLithiumBatchResult(BatchResults<Integer> res, int index,BattData_RT battData_RT) {
|
if(null != res) {
|
if(null == lidata[index]) {
|
lidata[index] = new FBS9600_Lithium_Data(battData_RT.BattGroupId);
|
}
|
FBS9600_Lithium_Data data = lidata[index];
|
data.envir_tmp = ((float)res.getIntValue(0)-100)/10; //'环境温度',
|
data.power_tmp = ((float)res.getIntValue(1)-100)/10; //'功率温度',
|
data.rest_cap = (short)res.getValue(4); //'剩余容量',
|
data.remote_control_count = res.getIntValue(3); //'自定义遥控数量',
|
data.batt_total_cap = (short)res.getValue(4); //'电池总容量',
|
data.batt_cycles = res.getIntValue(5); //'电池循环次数',
|
data.evir_tmp_alm_state = res.getIntValue(6); //'环境温度告警状态',
|
data.power_tmp_alm_state = res.getIntValue(7); //'功率温度告警状态',
|
data.discharge_curr_alm_state = res.getIntValue(8); //'充放电电流告警状态',
|
data.batt_totalvol_alm_state = res.getIntValue(9); //'电池总电压告警状态',
|
data.custom_alm_count = res.getIntValue(10); //'自定义告警量数量',
|
data.junheng_event_code = res.getIntValue(11); //'均衡事件代码',
|
data.vol_event_code = res.getIntValue(12); //'电压事件代码',
|
data.tmp_event_code = res.getIntValue(13); //'温度事件代码',
|
data.curr_event_code = res.getIntValue(14); //'电流事件代码',
|
data.fet_state_code = res.getIntValue(15); //'FET状态代码',
|
data.junheng_state_code = res.getIntValue(16); //'均衡状态代码',
|
//data.sys_state_code = (int)res.getValue(17); //'系统状态代码',
|
return true;
|
}
|
return false;
|
}
|
|
public static void main(String[] args) {
|
short ff = 12;
|
System.out.println((float)ff);
|
}
|
}
|