package testElectronJ;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.Arrays;
|
|
|
/**
|
* FBO测试数据[每个对象为一笔数据]
|
* @author LiJun
|
*
|
*/
|
@Slf4j
|
public class FboData {
|
public static final int MAX_GROUPMODULE_NUM = 5;
|
|
public DataType m_DataType; //数据类型
|
public int CRC16;
|
public TestTime m_TestTime; //数据时间
|
public int BattGroup; //组数 未使用 2
|
public int BattSum; //单体数 未使用 2
|
public float OnlineVol; //未使用 4
|
public float SumVoltage; //总电压 4
|
public float SumCurrent; //总电流 2
|
public float testCap; //测试容量
|
public float actualCap; //实际容量 预估数据
|
public float residualCap; //剩余容量
|
public int residualTime; //剩余时间
|
public float Temp_Envi; //环境温度
|
public float Humi_Envi; //环境湿度
|
|
public FboDataHeadStart.DateTime InsDate; //绝缘测试日期
|
public float PosInsRes; //正极绝缘电阻
|
public float NegInsRes; //负极绝缘电阻
|
public float SingleVol[]; //0.001 //单体电压
|
public float SubCurrent[]; //未使用 //单体电流
|
public float testSubCap[]; //未使用 //单体测试容量
|
public float actualSubCap[]; //未使用 //实际容量
|
public float residualSubCap[]; //未使用 //剩余容量
|
public int residualSubTime[]; //未使用 //剩余时间
|
|
public FboData() {
|
// TODO Auto-generated constructor stub
|
}
|
|
public FboData(int BattGroup) {
|
this.m_DataType = new DataType();
|
this.m_TestTime = new TestTime();
|
this.InsDate = new FboDataHeadStart().new DateTime();
|
this.SingleVol = new float[BattGroup]; //0.001 //单体电压
|
this.SubCurrent = new float[BattGroup]; //未使用 //单体电流
|
this.testSubCap = new float[BattGroup]; //未使用 //单体测试容量
|
this.actualSubCap = new float[BattGroup]; //未使用 //实际容量
|
this.residualSubCap = new float[BattGroup]; //未使用 //剩余容量
|
this.residualSubTime = new int[BattGroup]; //未使用 //剩余时间
|
}
|
|
|
|
/**
|
* 数据类型
|
* @author LiJun
|
*
|
*/
|
public class DataType{
|
public int typeTag0;
|
public int typeTag1;
|
public int typeTag2;
|
public int typeTag3;
|
|
public DataType clone(){
|
DataType tmp = new DataType();
|
tmp.typeTag0 = this.typeTag0;
|
tmp.typeTag1 = this.typeTag1;
|
tmp.typeTag2 = this.typeTag2;
|
tmp.typeTag3 = this.typeTag3;
|
|
return tmp;
|
}
|
|
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)) && (0xFB != (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);
|
}
|
|
public void setType(int type)
|
{
|
typeTag0 = type;
|
typeTag1 = type;
|
typeTag2 = type;
|
typeTag3 = type;
|
}
|
}
|
|
|
public class TestTime{
|
public int hour;
|
public int minute;
|
public int second;
|
|
|
@Override
|
public String toString() {
|
return "TestTime [hour=" + hour + ", minute=" + minute + ", second=" + second + "]";
|
}
|
|
public String hms(){
|
StringBuffer sb = new StringBuffer();
|
if (hour > 0) {
|
if(hour<10){
|
sb.append("0"+hour + ":");
|
}else{
|
sb.append(hour + ":");
|
}
|
}else{
|
sb.append("00"+ ":");
|
}
|
if (minute > 0) {
|
if(minute<10){
|
sb.append("0"+minute + ":");
|
}else{
|
sb.append(minute + ":");
|
}
|
}else{
|
sb.append("00" + ":");
|
}
|
if (second > 0) {
|
if(second<10){
|
sb.append("0"+second);
|
}else{
|
sb.append(second);
|
}
|
}else{
|
sb.append("00");
|
}
|
return sb.toString();
|
}
|
|
|
}
|
|
|
public void setData(byte[] databuf) {
|
ByteBuffer bf = ByteBuffer.allocate(databuf.length);
|
bf.order(ByteOrder.LITTLE_ENDIAN);
|
bf.put(databuf);
|
bf.position(0);
|
|
this.CRC16 = ComBase.changeShortToInt(bf.getShort());
|
this.m_TestTime.hour = ComBase.changeByteToInt(bf.get()); //数据时间
|
this.m_TestTime.minute = ComBase.changeByteToInt(bf.get()); //数据时间
|
this.m_TestTime.second = ComBase.changeByteToInt(bf.get()); //数据时间
|
this.BattGroup = ComBase.changeByteToInt(bf.get()); //组数 未使用 2
|
this.BattSum = ComBase.changeShortToInt(bf.getShort()); //单体数 未使用 2
|
this.OnlineVol = (float)bf.getInt()/1000; //未使用 4
|
this.SumVoltage = (float)bf.getInt()/1000; //总电压 4
|
this.SumCurrent = (float)(bf.getShort())/10; //总电流 2
|
// if(this.m_DataType.typeTag0 == 0xFD){
|
// this.SumCurrent = (-1)*Math.abs(this.SumCurrent);
|
// }
|
|
this.testCap = ComBase.changeShortToFloat(bf.getShort()); //测试容量
|
this.actualCap = ComBase.changeShortToFloat(bf.getShort()); //实际容量 预估数据
|
this.residualCap = ComBase.changeShortToFloat(bf.getShort()); //剩余容量
|
this.residualTime = ComBase.changeShortToInt(bf.getShort()); //剩余时间
|
this.Temp_Envi = (float)ComBase.changeShortToFloat(bf.getShort())/10-20; //环境温度
|
this.Humi_Envi = (float)ComBase.changeShortToFloat(bf.getShort())/10; //环境湿度
|
|
this.InsDate.year = ComBase.changeByteToInt(bf.get()); //年
|
this.InsDate.month = ComBase.changeByteToInt(bf.get()); //月
|
this.InsDate.day = ComBase.changeByteToInt(bf.get()); //日
|
this.InsDate.hour = ComBase.changeByteToInt(bf.get()); //时
|
this.InsDate.minute = ComBase.changeByteToInt(bf.get()); //分
|
this.InsDate.second = ComBase.changeByteToInt(bf.get()); //秒
|
|
this.PosInsRes = ComBase.changeShortToFloat(bf.getShort()); //正极绝缘电阻
|
this.NegInsRes = ComBase.changeShortToFloat(bf.getShort()); //负极绝缘电阻
|
for(int i=0;i<SingleVol.length;i++) {
|
SingleVol[i] = (float)bf.getInt()/1000; //0.001 //单体电压
|
}
|
for(int i=0;i<SubCurrent.length;i++) {
|
SubCurrent[i] = ComBase.changeShortToFloat(bf.getShort()); //未使用 //单体电流
|
}
|
for(int i=0;i<testSubCap.length;i++) {
|
testSubCap[i] = ComBase.changeShortToFloat(bf.getShort()); //未使用 //单体测试容量
|
}
|
for(int i=0;i<actualSubCap.length;i++) {
|
actualSubCap[i] = ComBase.changeShortToFloat(bf.getShort());
|
}
|
for(int i=0;i<residualSubCap.length;i++) {
|
residualSubCap[i] = ComBase.changeShortToFloat(bf.getShort()); //未使用 //剩余容量
|
}
|
for(int i=0;i<residualSubTime.length;i++) {
|
residualSubTime[i] = ComBase.changeShortToInt(bf.getShort()); //未使用 //剩余时间
|
}
|
|
//System.out.println(this);
|
}
|
|
|
@Override
|
public String toString() {
|
return "FboData [m_DataType=" + m_DataType + ", CRC16=" + CRC16 + ", m_TestTime=" + m_TestTime + ", BattGroup="
|
+ BattGroup + ", BattSum=" + BattSum + ", OnlineVol=" + OnlineVol + ", SumVoltage=" + SumVoltage
|
+ ", SumCurrent=" + SumCurrent + ", testCap=" + testCap + ", actualCap=" + actualCap + ", residualCap="
|
+ residualCap + ", residualTime=" + residualTime + ", Temp_Envi=" + Temp_Envi + ", Humi_Envi="
|
+ Humi_Envi + ", PosInsRes=" + PosInsRes + ", NegInsRes=" + NegInsRes + ", SingleVol="
|
+ Arrays.toString(SingleVol) + ", SubCurrent=" + Arrays.toString(SubCurrent) + ", testSubCap="
|
+ Arrays.toString(testSubCap) + ", actualSubCap=" + Arrays.toString(actualSubCap) + ", residualSubCap="
|
+ Arrays.toString(residualSubCap) + ", residualSubTime=" + Arrays.toString(residualSubTime) + "]";
|
}
|
|
|
}
|