package com.whyc.service;
|
|
import com.whyc.mcp.*;
|
import com.whyc.util.StaticInf;
|
import org.springframework.stereotype.Service;
|
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
|
@Service
|
public class TestDataInfoService {
|
|
//mch/mcp解析
|
public TestDataInfo readFileData(String filePath) {
|
TestDataInfo testDataInfo=new TestDataInfo();
|
int parse_result = StaticInf.PARSE_RESULT_NULL;;
|
FileInputStream fis = null;
|
try {
|
File f = new File(filePath);
|
if((!filePath.endsWith(".MCP") && !filePath.endsWith(".mcp")) && (!filePath.endsWith(".MCH") && !filePath.endsWith(".mch"))) {
|
parse_result = StaticInf.PARSE_RESULT_FILETYPEERR;
|
}
|
if(!f.exists()) {
|
parse_result =StaticInf. PARSE_RESULT_NOTFOUNDFILE;
|
}
|
fis = new FileInputStream(f);
|
byte[] buf = new byte[MonitorDataInfo.BYTE_LEN];
|
if(fis.read(buf, 0, buf.length) == MonitorDataInfo.BYTE_LEN)
|
{
|
if(testDataInfo.monitorDataInfo.setHeadData(buf)) {
|
parse_result = StaticInf.PARSE_RESULT_SUCCESS;
|
}else {
|
parse_result = StaticInf.PARSE_RESULT_FILEERROR;
|
}
|
while(true)
|
{
|
if(testDataInfo.monitorDataInfo.checkDataHead(fis))
|
{
|
int bufLength=FBSData.BYTE_LEN - MVolData.BYTE_LEN +(testDataInfo.monitorDataInfo.battparam.eachGroupBattCount*testDataInfo.monitorDataInfo.battparam.battGroupCount)*2;
|
byte[] databuf = new byte[bufLength];
|
if(fis.read(databuf) == databuf.length)
|
{
|
FBSData fbsData = new FBSData(testDataInfo.monitorDataInfo.monitorstate.testType);
|
if(fbsData.setData(databuf)) {
|
testDataInfo.fbsDatas.add(fbsData);
|
}
|
}
|
}
|
if(fis.available() <1) {
|
break;
|
|
}
|
}
|
}else {
|
parse_result = StaticInf.PARSE_RESULT_FILEERROR;
|
}
|
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
if(null != fis)
|
{
|
try {
|
fis.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
testDataInfo.setFile_type(testDataInfo.monitorDataInfo.monitorstate.testType);
|
testDataInfo.setParse_result(parse_result);
|
return testDataInfo;
|
}
|
}
|