package com.whyc.alarm;
|
|
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.whyc.charge.Fbs5100BattParam;
|
import com.whyc.dto.ComFn;
|
import com.whyc.dto.Fbs5100ComBase;
|
import org.springframework.stereotype.Component;
|
|
@Component
|
public class Fbs5100AlarmData {
|
public Fbs5100AlarmParam alarmParam; //告警参数
|
|
public List<Fbs5100Alarm> alarms;
|
|
|
|
public int parse_result = Fbs5100ComBase.PARSE_RESULT_NULL;
|
|
public Fbs5100AlarmData() {
|
alarmParam = new Fbs5100AlarmParam();
|
|
alarms = new ArrayList<Fbs5100Alarm>();
|
}
|
|
|
public void parseFileData(String filePath)
|
{
|
|
FileInputStream fis = null;
|
try {
|
File f = new File(filePath);
|
//既不是核容放电也不是监测放电
|
if(!filePath.endsWith(".ALM")) {
|
parse_result = Fbs5100ComBase.PARSE_RESULT_FILETYPEERR;
|
return;
|
}
|
if(!f.exists()) {
|
parse_result = Fbs5100ComBase.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 = Fbs5100ComBase.PARSE_RESULT_SUCCESS;
|
}else {
|
parse_result = Fbs5100ComBase.PARSE_RESULT_FILEERROR;
|
}
|
|
while(true)
|
{
|
Fbs5100Alarm alm = new Fbs5100Alarm();
|
int tag = alm.checkDataHead(fis);
|
if((0xAA == tag))
|
{
|
byte[] databuf = new byte[Fbs5100Alarm.BYTE_LEN];
|
if(fis.read(databuf) == databuf.length)
|
{
|
//System.out.println(ComFn.bytesToHexString(databuf, databuf.length));
|
if(alm.putByteBuffer(databuf)){
|
alarms.add(alm);
|
}
|
|
}
|
}
|
if(tag == 1)
|
break;
|
}
|
}else {
|
parse_result = Fbs5100ComBase.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 < (Fbs5100BattParam.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.alarmParam.putByteBuffer(bf);
|
//System.out.println("alarmParam:"+flag);
|
|
return flag;
|
}
|
|
|
@Override
|
public String toString() {
|
return "Fbs5100AlarmData [alarmParam=" + alarmParam + ", alarms=" + alarms + ", parse_result=" + parse_result
|
+ "]";
|
}
|
}
|