From 3b359b5a250b6383ce111980f28a719e16446e25 Mon Sep 17 00:00:00 2001 From: Administrator <1525436766@qq.com> Date: 星期二, 07 二月 2023 15:53:59 +0800 Subject: [PATCH] 添加接口以及添加告警文件解析 --- FBS9600ForFBO_Parse/src/com/fgkj/alm/Alarm_DataInfo.java | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 112 insertions(+), 1 deletions(-) diff --git a/FBS9600ForFBO_Parse/src/com/fgkj/alm/Alarm_DataInfo.java b/FBS9600ForFBO_Parse/src/com/fgkj/alm/Alarm_DataInfo.java index 3173ef7..146f774 100644 --- a/FBS9600ForFBO_Parse/src/com/fgkj/alm/Alarm_DataInfo.java +++ b/FBS9600ForFBO_Parse/src/com/fgkj/alm/Alarm_DataInfo.java @@ -1,20 +1,91 @@ package com.fgkj.alm; +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.Date; import java.util.List; +import com.fgkj.bres.FileDataParseInfo_Interface; import com.fgkj.data.ComBase; -public class Alarm_DataInfo { +public class Alarm_DataInfo implements FileDataParseInfo_Interface{ public AlarmDataHead almDataHead; public List<AlarmData> almDatas; + + public int parse_result = PARSE_RESULT_NULL; //鏂囦欢瑙f瀽缁撴灉 + public final int file_type = FILE_TYPE_ALM; //鏂囦欢绫诲瀷 public Alarm_DataInfo() { almDataHead = new AlarmDataHead(); almDatas = new ArrayList<Alarm_DataInfo.AlarmData>(); + } + + + @Override + public void readFileData(String filePath) { + FileInputStream fis = null; + try { + File f = new File(filePath); + if(!filePath.endsWith(".alm") && !filePath.endsWith(".ALM")) { + System.out.println("鏂囦欢鏍煎紡閿欒"); + parse_result = PARSE_RESULT_FILETYPEERR; + return; + } + if(!f.exists()) { + parse_result = PARSE_RESULT_NOTFOUNDFILE; + System.out.println("鏂囦欢涓嶅瓨鍦�.........."); + return; + } + fis = new FileInputStream(f); + byte[] buf = new byte[4]; + if(fis.read(buf, 0, buf.length) == AlarmDataHead.BYTE_LEN) + { + if(this.almDataHead.setHeadData(buf)) { + parse_result = PARSE_RESULT_SUCCESS; + }else { + parse_result = PARSE_RESULT_FILEERROR; + } + while(true) + { + if(almDataHead.checkDataHead(fis)) + { + byte[] databuf = new byte[AlarmData.BYTE_LEN]; + if(fis.read(databuf) == databuf.length) + { + AlarmData almData = new AlarmData(); + if(almData.setData(databuf)) { + //System.out.println(resData); + almDatas.add(almData); + } + } + } + if(fis.available() <1) { + //System.out.println("瑙f瀽瀹屾垚"); + break; + + } + } + }else { + parse_result = PARSE_RESULT_FILEERROR; + } + + } catch (IOException e) { + e.printStackTrace(); + } finally { + if(null != fis) + { + try { + fis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } //鍛婅澶撮儴鏁版嵁 @@ -39,6 +110,44 @@ //System.out.println("琛屾暟锛�"+record_line); return true; } + + public boolean checkDataHead(FileInputStream fis) + { + boolean check_ok = false; + boolean file_end = false; + byte[] tag = new byte[1]; + try { + while(true) + { + int n = 0; + for(n=0; n<2; n++) + { + if(1 != fis.read(tag, 0, 1)) + { + file_end = true; + break; + } + if((0xAA != (tag[0]&0xFF))) + { + break; + } + } + + if(n >= 2) + { + check_ok = true; + break; + } + if(true == file_end) + { + break; + } + } + } catch (IOException e) { + //e.printStackTrace(); + } + return check_ok; + } } //鍛婅璇︽儏 @@ -104,4 +213,6 @@ } } + + } -- Gitblit v1.9.1