package com.fgkj.fbs5100;
|
|
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 java.util.List;
|
|
import com.fgkj.data.ComFn;
|
|
/**
|
* 配网电源
|
* @author LiJun
|
* 充电数据结构体
|
*/
|
public class FBS5100_ChargeData {
|
public FBS5100_BattParam battParam; //电池参数
|
public FBS5100_ChargeParam chargeParam; //测试参数
|
public FBS5100_ChargeState chargeState; //容量状态
|
|
public List<FBS5100_FBSData> fbsDatas;
|
|
public int parse_result = FBS5100_ComBase.PARSE_RESULT_NULL;
|
|
public FBS5100_ChargeData() {
|
battParam = new FBS5100_BattParam();
|
chargeParam = new FBS5100_ChargeParam();
|
chargeState = new FBS5100_ChargeState();
|
fbsDatas = new ArrayList<FBS5100_FBSData>();
|
}
|
|
public void parseFileData(String filePath)
|
{
|
|
FileInputStream fis = null;
|
try {
|
File f = new File(filePath);
|
//非充电文件
|
if(!filePath.endsWith(".CHR")) {
|
parse_result = FBS5100_ComBase.PARSE_RESULT_FILETYPEERR;
|
return;
|
}
|
if(!f.exists()) {
|
parse_result = FBS5100_ComBase.PARSE_RESULT_NOTFOUNDFILE;
|
return;
|
//System.out.println("文件不存在..........");
|
}
|
fis = new FileInputStream(f);
|
byte[] buf = new byte[1024];
|
if(fis.read(buf, 0, buf.length) == 1024)
|
{
|
if(this.readDataHead(buf)) {
|
parse_result = FBS5100_ComBase.PARSE_RESULT_SUCCESS;
|
}else {
|
parse_result = FBS5100_ComBase.PARSE_RESULT_FILEERROR;
|
}
|
|
while(true)
|
{
|
FBS5100_FBSData fbsData = new FBS5100_FBSData();
|
int tag = fbsData.checkDataHead(fis);
|
if((0xFD == tag) || (0xFC == tag) || (0xFB == tag))
|
{
|
byte[] databuf = new byte[FBS5100_FBSData.BYTE_LEN - 4];
|
if(fis.read(databuf) == databuf.length)
|
{
|
//System.out.println(ComFn.bytesToHexString(databuf, databuf.length));
|
|
if(fbsData.putByteBuffer(databuf)) {
|
fbsDatas.add(fbsData);
|
}
|
}
|
}
|
if(tag == 1)
|
break;
|
}
|
}else {
|
parse_result = FBS5100_ComBase.PARSE_RESULT_FILEERROR;
|
}
|
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
if(null != fis)
|
{
|
try {
|
fis.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
|
//解析数据头
|
public boolean readDataHead(byte[] buf) {
|
System.out.println(ComFn.bytesToHexString(buf, buf.length));
|
boolean flag = false;
|
if(buf.length < (FBS5100_BattParam.BYTE_LEN + FBS5100_ChargeParam.BYTE_LEN + FBS5100_ChargeState.BYTE_LEN)) {
|
System.out.println("头部数据长度异常");
|
return flag;
|
}
|
ByteBuffer bf = ByteBuffer.allocate(buf.length);
|
bf.order(ByteOrder.LITTLE_ENDIAN);
|
bf.put(buf);
|
bf.position(0);
|
flag = this.battParam.putByteBuffer(bf);
|
//System.out.println("battParam:"+flag);
|
flag &= this.chargeParam.putByteBuffer(bf);
|
//System.out.println("chargeParam:"+flag);
|
flag &= this.chargeState.putByteBuffer(bf);
|
//System.out.println("chargeState:"+flag);
|
return flag;
|
}
|
|
@Override
|
public String toString() {
|
return "FBS5100_ChargeData [battParam=" + battParam + ", chargeParam=" + chargeParam + ", chargeState="
|
+ chargeState + ", fbsDatas=" + fbsDatas + ", parse_result=" + parse_result + "]";
|
}
|
}
|