package com.whyc.abe;
|
|
import com.whyc.constant.ConstantDefined;
|
|
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;
|
|
public class ABEDataParase {
|
|
public List<ABEFBSData> getFbsData() {
|
return fbsData;
|
}
|
|
public void setFbsData(List<ABEFBSData> fbsData) {
|
this.fbsData = fbsData;
|
}
|
|
public ABEDataHeadStart getFbsDataStart() {
|
return fbsDataStart;
|
}
|
|
public void setFbsDataStart(ABEDataHeadStart fbsDataStart) {
|
this.fbsDataStart = fbsDataStart;
|
}
|
|
public ABEDataHeadStop getFbsDataStop() {
|
return fbsDataStop;
|
}
|
|
public void setFbsDataStop(ABEDataHeadStop fbsDataStop) {
|
this.fbsDataStop = fbsDataStop;
|
}
|
|
public int getParse_result() {
|
return parse_result;
|
}
|
|
public void setParse_result(int parse_result) {
|
this.parse_result = parse_result;
|
}
|
|
public List<ABEFBSData> fbsData;
|
public ABEDataHeadStart fbsDataStart;
|
public ABEDataHeadStop fbsDataStop;
|
|
public int parse_result = ConstantDefined.PARSE_RESULT_NULL;
|
|
public void readFBSFile(String filePath)
|
{
|
//int Data_Type = -1;
|
FileInputStream fis = null;
|
try {
|
File f = new File(filePath);
|
if(filePath.toUpperCase().endsWith(".DDF")) {
|
//放电数据文件
|
fbsDataStart = new ABEDisDataHeadStart();
|
fbsDataStop = new ABETestDataHeadStop();
|
//Data_Type = ConstantDefined.DATA_TYPE_DIS;
|
}else if(filePath.toUpperCase().endsWith(".CCF")) {
|
//充电数据文件
|
fbsDataStart = new ABEChrDataHeadStart();
|
fbsDataStop = new ABETestDataHeadStop();
|
//Data_Type = ConstantDefined.DATA_TYPE_DIS;
|
}else {
|
//非法文件
|
parse_result = ConstantDefined.PARSE_RESULT_FILETYPEERR;
|
return;
|
}
|
if(!f.exists()) {
|
//文件不存在
|
parse_result = ConstantDefined.PARSE_RESULT_NOTFOUNDFILE;
|
//System.out.println("文件不存在..........");
|
return;
|
}
|
fis = new FileInputStream(f);
|
|
/*if(ConstantDefined.DATA_TYPE_DIS == Data_Type) {
|
|
}else if(ConstantDefined.DATA_TYPE_CHR == Data_Type) {
|
fbsDataStart = new ABEChrDataHeadStart();
|
fbsDataStop = new ABETestDataHeadStop();
|
}else if(ConstantDefined.DATA_TYPE_RULE == Data_Type){
|
fbsDataStart = new ABECycleDataHeadStart();
|
fbsDataStop = new ABECycleDataHeadStop();
|
}else {
|
parse_result = ConstantDefined.PARSE_RESULT_FILETYPEERR;
|
return;
|
}*/
|
byte[] buf = new byte[512];
|
//解析文件头
|
if(fis.read(buf, 0, buf.length) == 512)
|
{
|
ByteBuffer bf = ByteBuffer.allocate(buf.length);
|
bf.order(ByteOrder.LITTLE_ENDIAN);
|
bf.put(buf);
|
bf.position(0);
|
|
if(this.fbsDataStart.setDataInf(bf) && this.fbsDataStop.setDataInf(bf)) {
|
parse_result = ConstantDefined.PARSE_RESULT_SUCCESS;
|
|
} else {
|
parse_result = ConstantDefined.PARSE_RESULT_FILEERROR;
|
return;
|
}
|
|
fbsData = new ArrayList<>();
|
ABEDataType mType = new ABEDataType();
|
while(true)
|
{
|
int tag = mType.checkDataHead(fis);
|
if((0xFD == tag) || (0xFC == tag) || (0xFB == tag))
|
{
|
//解析每一笔单体数据
|
byte[] databuf = new byte[8 + 80 + 2];
|
if(fis.read(databuf) == databuf.length)
|
{
|
ABEFBSData m_FbsData = new ABEFBSData();
|
m_FbsData.m_DataType = mType;
|
m_FbsData.setData(databuf);
|
fbsData.add(m_FbsData);
|
}
|
}
|
if(tag == 1) {
|
break;
|
}
|
}
|
}else {
|
parse_result = ConstantDefined.PARSE_RESULT_FILEERROR;
|
}
|
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
if(null != fis)
|
{
|
try {
|
fis.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
|
|
public static void main(String[] args) {
|
ABEDataParase fbs = new ABEDataParase();
|
//fbo.readFboFile("D:/test/F2022-03-09 11.26.12.FBX");
|
//fbo.readFboFile("D:/test/F2022-03-09 16.22.37.FBX");
|
//fbo.readFboFile("D:/test/F2022-03-10 11.12.30.FBX");
|
fbs.readFBSFile("C:\\Users\\29550\\Documents\\WeChat Files\\wxid_uh2bej4ad4ya22\\FileStorage\\File\\2022-09\\F2022-08-02-094422-1.DDF");
|
//fbs.readFBSFile("D:\\桌面文件备份\\公司各种设备资料\\硬件数据文件解析相关\\ABE文件解析相关\\数据文件\\F2022-08-02-094422-1.DDF");
|
//fbs.readFBSFile("D:\\桌面文件备份\\公司各种设备资料\\硬件数据文件解析相关\\ABE文件解析相关\\数据文件\\F2022-08-02-094422-1.DDF");
|
//fbs.readFBSFile("D:\\桌面文件备份\\公司各种设备资料\\硬件数据文件解析相关\\ABE文件解析相关\\数据文件\\F2022-08-03-165222-7.CCF");
|
System.out.println(fbs);
|
}
|
|
}
|