package com.dev.ntm.data.fbo;
|
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.ArrayList;
|
|
import com.dev.ntm.cmd.NTM_Crc16;
|
import com.dev.ntm.data.idc.IdcData;
|
|
public class FboData {
|
public static int BattSumMax = 500;
|
public FboDataType m_DataType = new FboDataType();
|
public int CRC16;
|
public FboTestTime m_TestTime = new FboTestTime();
|
public int BattGroup;
|
public int BattSum;
|
public float OnlineVol;
|
public float SumVoltage;
|
public float SumCurrent;
|
public float[] SubCurrent = new float[4];
|
public float AllCap;
|
public float[] SubCap = new float[4];
|
public float[] SingleVol = null;
|
|
public FboData(int batt_sum) {
|
BattSum = batt_sum;
|
if(BattSum > BattSumMax)
|
BattSum = BattSumMax;
|
else if (BattSum < 0) {
|
BattSum = 0;
|
}
|
|
SingleVol = new float[BattSum];
|
}
|
|
public boolean setData(byte[] buf)
|
{
|
ByteBuffer bf = ByteBuffer.allocate(2048);
|
bf.order(ByteOrder.LITTLE_ENDIAN);
|
bf.put((byte) (m_DataType.TypeTag0&0xFF));
|
bf.put((byte) (m_DataType.TypeTag1&0xFF));
|
bf.put((byte) (m_DataType.TypeTag2&0xFF));
|
bf.put((byte) (m_DataType.TypeTag3&0xFF));
|
bf.put(buf);
|
bf.flip();
|
/*
|
m_DataType.TypeTag0 = (int) (bf.get()&0xFF);
|
m_DataType.TypeTag1 = (int) (bf.get()&0xFF);
|
m_DataType.TypeTag2 = (int) (bf.get()&0xFF);
|
m_DataType.TypeTag3 = (int) (bf.get()&0xFF);
|
*/
|
CRC16 = bf.getShort(4)&0xFFFF;
|
bf.putShort(4, (short) 0x0000);
|
int calcrc = NTM_Crc16.CalCRC16(bf, bf.limit());
|
//System.out.println("CRC16:" + CRC16 + ", calcrc:" + calcrc);
|
if(CRC16 != calcrc) {
|
return false;
|
}
|
|
bf.position(6);
|
m_TestTime.hour = (int) (bf.get()&0xFF);
|
m_TestTime.minute = (int) (bf.get()&0xFF);
|
m_TestTime.second = (int) (bf.get()&0xFF);
|
BattGroup = (int) (bf.get()&0xFF);
|
|
int batt_cnt = (int) (bf.getShort()&0xFFFF);
|
if(batt_cnt > BattSum)
|
batt_cnt = BattSum;
|
else if (batt_cnt < 0) {
|
batt_cnt = 0;
|
}
|
|
OnlineVol = ((float) (bf.getShort()&0xFFFF)) / 10;
|
SumVoltage = ((float) (bf.getShort()&0xFFFF)) / 10;
|
|
SumCurrent = ((float) (bf.getShort()&0xFFFF)) / 10;
|
if(0xFD == m_DataType.TypeTag0) {
|
SumCurrent *= -1;
|
}
|
for(int n=0; n<4; n++)
|
{
|
SubCurrent[n] = ((float) (bf.getShort()&0xFFFF)) / 10;
|
if(0xFD == m_DataType.TypeTag0) {
|
SubCurrent[n] *= -1;
|
}
|
}
|
|
AllCap = ((float) (bf.getShort()&0xFFFF));
|
if(0xFD == m_DataType.TypeTag0) {
|
AllCap *= -1;
|
}
|
for(int n=0; n<4; n++)
|
{
|
SubCap[n] = ((float) (bf.getShort()&0xFFFF));
|
if(0xFD == m_DataType.TypeTag0) {
|
SubCap[n] *= -1;
|
}
|
}
|
|
for(int n=0; n<batt_cnt; n++) {
|
SingleVol[n] = ((float) (bf.getShort()&0xFFFF)) / 1000;
|
}
|
|
return true;
|
}
|
|
public static void checkFboFile(File file, FboDataInf data_inf, ArrayList<FboData> al_fbo_data)
|
{
|
File f = file;
|
FileInputStream fis = null;
|
try {
|
fis = new FileInputStream(f);
|
byte[] buf = new byte[256];
|
if(fis.read(buf, 0, buf.length) == 256)
|
{
|
data_inf.setDataInf(buf);
|
while(true)
|
{
|
FboDataType mType = new FboDataType();
|
int tag = mType.checkDataHead(fis);
|
if((0xFD == tag) || (0xFC == tag))
|
{
|
byte[] databuf = new byte[data_inf.BattSum*2 + 32];
|
if(fis.read(databuf) == databuf.length)
|
{
|
FboData m_FboData = new FboData(data_inf.BattSum);
|
m_FboData.m_DataType = mType;
|
if(true == m_FboData.setData(databuf)) {
|
al_fbo_data.add(m_FboData);
|
}
|
}
|
}
|
if(tag == 1)
|
break;
|
}
|
}
|
} catch (IOException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
} finally {
|
if(null != fis)
|
{
|
try {
|
fis.close();
|
} catch (IOException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
|
|
public void setData(IdcData i_data) {
|
m_DataType.TypeTag0 = i_data.DataType;
|
m_DataType.TypeTag1 = i_data.DataType;
|
m_DataType.TypeTag2 = i_data.DataType;
|
m_DataType.TypeTag3 = i_data.DataType;
|
|
OnlineVol = 0;
|
SumVoltage = i_data.SumVol;
|
SumCurrent = i_data.SumCur;
|
SubCurrent[0] = SumCurrent;
|
|
AllCap = i_data.SumAH;
|
SubCap[0] = AllCap;
|
|
int param = (-1);
|
if(0xFC == m_DataType.TypeTag0) {
|
param = 1;
|
}
|
SumCurrent = Math.abs(SumCurrent) * param;
|
SubCurrent[0] = Math.abs(SubCurrent[0]) * param;
|
|
AllCap = Math.abs(AllCap) * param;
|
SubCap[0] = Math.abs(SubCap[0]) * param;
|
|
for(int n=0; n<400; n++)
|
{
|
SingleVol[n] = i_data.MonomerVol[n];
|
}
|
}
|
|
public int getMinIndex()
|
{
|
int num = 0;
|
float min = 800000;
|
for(int n=0; n<SingleVol.length; n++)
|
{
|
if((SingleVol[n] > 0.1) && (SingleVol[n] < min))
|
{
|
min = SingleVol[n];
|
num = n;
|
}
|
}
|
|
return num;
|
}
|
|
public int getMaxIndex()
|
{
|
int num = 0;
|
float max = 0;
|
for(int n=0; n<SingleVol.length; n++)
|
{
|
if((SingleVol[n] > 0.1) && (max < SingleVol[n]))
|
{
|
max = SingleVol[n];
|
num = n;
|
}
|
}
|
|
return num;
|
}
|
|
public float getMinVol()
|
{
|
float min = 800000;
|
for(int n=0; n<SingleVol.length; n++)
|
{
|
if((SingleVol[n] > 0.1) && (SingleVol[n] < min))
|
{
|
min = SingleVol[n];
|
}
|
}
|
|
return min;
|
}
|
|
public float getMaxVol()
|
{
|
float max = 0;
|
for(int n=0; n<SingleVol.length; n++)
|
{
|
if((SingleVol[n] > 0.1) && (max < SingleVol[n]))
|
{
|
max = SingleVol[n];
|
}
|
}
|
|
return max;
|
}
|
}
|