package com.fgkj.bts;
|
|
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 DELL
|
*
|
*/
|
public class BTS_DisChargeData {
|
|
public int parse_result = BTS_ComBase.PARSE_RESULT_NULL; //解析结果
|
|
public BTS_BattParam battParam; //电池参数
|
public BTS_DischargeParam dischargeParam; //核容参数
|
public BTS_CapState capState; //容量参数
|
|
public List<BTS_FbsData> fbsDatas; //每次记录的单体数据
|
|
public BTS_DisChargeData() {
|
battParam = new BTS_BattParam();
|
dischargeParam = new BTS_DischargeParam();
|
capState = new BTS_CapState();
|
fbsDatas = new ArrayList<BTS_FbsData>();
|
}
|
|
|
|
|
/**
|
* 解析充电数据
|
* @param filePath
|
*/
|
public void readDisFile(String filePath)
|
{
|
FileInputStream fis = null;
|
try {
|
File f = new File(filePath);
|
if(!filePath.endsWith(".BCP") || !filePath.toUpperCase().endsWith(".BCP")) {
|
//文件格式错误
|
parse_result = BTS_ComBase.PARSE_RESULT_FILETYPEERR;
|
return;
|
}
|
if(!f.exists()) {
|
//文件不存在
|
parse_result = BTS_ComBase.PARSE_RESULT_NOTFOUNDFILE;
|
return;
|
//System.out.println("文件不存在..........");
|
}
|
fis = new FileInputStream(f);
|
byte[] buf = new byte[2048];
|
if(fis.read(buf, 0, buf.length) == 2048)
|
{
|
if(this.checkTestDataHead(buf)) {
|
parse_result = BTS_ComBase.PARSE_RESULT_SUCCESS;
|
}else {
|
parse_result = BTS_ComBase.PARSE_RESULT_FILEERROR;
|
}
|
BTS_DataType dataType = new BTS_DataType();
|
|
while(true)
|
{
|
int tag = dataType.checkDataHead(fis);
|
if((0xFD == tag) || (0xFC == tag) || (0xFB == tag))
|
{
|
|
System.out.println("#################");
|
byte[] databuf = new byte[BTS_FbsData.BASIC_LEN + (battParam.EachGroupBattCount*battParam.BattGroupCount)*2 -4];
|
if(fis.read(databuf) == databuf.length)
|
{
|
ByteBuffer bf = ByteBuffer.allocate(databuf.length + BTS_DataType.BYTE_LEN);
|
bf.order(ByteOrder.LITTLE_ENDIAN);
|
bf.put(dataType.getDataTypeByte());
|
bf.put(databuf);
|
bf.flip();
|
bf.position(0);
|
|
System.out.println(ComFn.bytesToHexString(databuf, databuf.length));
|
BTS_FbsData fbsData = new BTS_FbsData();
|
if(fbsData.putByteBuffer(bf, 0, 0)) {
|
fbsDatas.add(fbsData);
|
}
|
}
|
}
|
if(tag == 1)
|
break;
|
}
|
}else {
|
parse_result = BTS_ComBase.PARSE_RESULT_FILEERROR;
|
}
|
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
if(null != fis)
|
{
|
try {
|
fis.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
|
/**
|
* 解析文件头数据
|
* @return
|
*/
|
public boolean checkTestDataHead(byte[] buf) {
|
boolean checkOk = true;
|
ByteBuffer buffer = ByteBuffer.allocate(buf.length);
|
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
buffer.put(buf);
|
buffer.flip();
|
buffer.position(0);
|
checkOk = checkOk && battParam.putByteBuffer(buffer);
|
System.out.println(battParam);
|
System.out.println("checkTestDataHead:"+checkOk);
|
|
checkOk = checkOk && dischargeParam.putByteBuffer(buffer);
|
System.out.println(dischargeParam);
|
System.out.println("checkTestDataHead:"+checkOk);
|
|
capState.putByteBuffer(buffer);
|
return checkOk;
|
}
|
}
|
|
|