package com.fgkj.mcp; 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.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; import com.fgkj.bres.FileDataParseInfo_Interface; import com.fgkj.bres.RES_Crc16; import com.fgkj.data.ComBase; /** * FBS充放电数据解析 * @author LiJun * */ public class TestDataInfo implements FileDataParseInfo_Interface{ public int parse_result = PARSE_RESULT_NULL; //文件解析结果 public int file_type = FILE_TYPE_NULL; //文件类型 public MonitorDataInfo testDataInfo; public List FBSDatas; public TestDataInfo() { testDataInfo = new MonitorDataInfo(); FBSDatas = new ArrayList(); } @Override public void readFileData(String filePath) { FileInputStream fis = null; try { File f = new File(filePath); if((!filePath.endsWith(".MCP") && !filePath.endsWith(".mcp")) && (!filePath.endsWith(".MCH") && !filePath.endsWith(".mch"))) { 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[MonitorDataInfo.BYTE_LEN]; if(fis.read(buf, 0, buf.length) == MonitorDataInfo.BYTE_LEN) { if(this.testDataInfo.setHeadData(buf)) { parse_result = PARSE_RESULT_SUCCESS; }else { parse_result = PARSE_RESULT_FILEERROR; } while(true) { if(testDataInfo.checkDataHead(fis)) { byte[] databuf = new byte[FBSData.BYTE_LEN - MVolData.BYTE_LEN +(testDataInfo.battparam.eachGroupBattCount*testDataInfo.battparam.battGroupCount)*2]; //System.out.println("databuf.length:"+databuf.length); if(fis.read(databuf) == databuf.length) { FBSData fbsData = new FBSData(testDataInfo.monitorstate.testType); if(fbsData.setData(databuf)) { System.out.println(fbsData); FBSDatas.add(fbsData); } } } if(fis.available() <1) { //System.out.println("解析完成"); break; } } }else { parse_result = PARSE_RESULT_FILEERROR; } } catch (IOException e) { e.printStackTrace(); } finally { if(null != fis) { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } } } /** * 测试时长 * @author LiJun * */ public class TestTime{ public static final int BYTE_LEN = 3; public int hour; //时 public int minute; //分 public int second; //秒 public void setTestTime(ByteBuffer bf) { if(bf.limit() < BYTE_LEN) { return; } this.hour = ComBase.changeByteToInt(bf.get()); this.minute = ComBase.changeByteToInt(bf.get()); this.second = ComBase.changeByteToInt(bf.get()); } } public class VolCurrData{ public static final int BYTE_LEN = 80; public static final int GROUP_COUNT_MAX = 4; public float onlinevol[] = new float[GROUP_COUNT_MAX];//在线电压 分辨率0.1V public float groupvol[] = new float[GROUP_COUNT_MAX];//组端电压 分辨率0.1V public int battstate[] = new int[GROUP_COUNT_MAX];//电池状态,见表2 public float battcurr[] = new float[GROUP_COUNT_MAX];//电流 分辨率0.1A public int battcap[] = new int[GROUP_COUNT_MAX];//已测容量 AH public float batttemp[] = new float[GROUP_COUNT_MAX];//温度,预留,没使用 public int monMAX_num[] = new int[GROUP_COUNT_MAX];//最高单体索引号 public int monMIN_num[] = new int[GROUP_COUNT_MAX];//最低单体索引号 public float monvolMAX[] = new float[GROUP_COUNT_MAX];//最高单体电压 0.001V public float monvolMIN[] = new float[GROUP_COUNT_MAX];//最低单体电压 0.001V public boolean puByteBuffer(ByteBuffer bf) { //System.err.println(ComFn.bytesToHexString(bf.array(), bf.array().length)); bf.position(0); if(bf.remaining() < BYTE_LEN) { return false; } for(int i=0;i= 4) { if(tag[0] == 0xFA) { file_type = FILE_TYPE_MCP; } if(tag[0] == 0xFB) { file_type = FILE_TYPE_MCH; } check_ok = true; break; } if(true == file_end) { break; } } } catch (IOException e) { //e.printStackTrace(); } return check_ok; } public boolean setHeadData(byte[] buf) { boolean flag = false; if(buf.length < BYTE_LEN) { return flag; } ByteBuffer bf = ByteBuffer.allocate(buf.length); bf.order(ByteOrder.LITTLE_ENDIAN); bf.position(0); bf.put(buf); bf.flip(); //System.out.println("bf len:"+bf.remaining()); flag = battparam.putByteBuffer(bf); //System.out.println(battparam); bf.position(0); //System.out.println("bf len:"+bf.remaining()); flag &= monitorparam.putByteBuffer(bf); bf.position(0); flag &= monitorstate.putByteBuffer(bf); return flag; } } public class DateTime{ private static final int BYTE_LEN = 6; public int year; public int month; public int day; public int hour; public int minute; public int second; public Date time; public DateTime() { } public void setDateTime(ByteBuffer bf) { if(bf.remaining()< BYTE_LEN) { return; } this.year = ComBase.changeByteToInt(bf.get()); this.month = ComBase.changeByteToInt(bf.get()); this.day = ComBase.changeByteToInt(bf.get()); this.hour = ComBase.changeByteToInt(bf.get()); this.minute = ComBase.changeByteToInt(bf.get()); this.second = ComBase.changeByteToInt(bf.get()); time = getFBODateTime(); //System.out.println(year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second); } public Date getFBODateTime() { Calendar c = Calendar.getInstance(); c.set(2000+year, month, day, hour, minute, second); return c.getTime(); //return Com.get_DT_FromStr(year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second, Com.DTF_YMDhms); } } public static void main(String[] args) { TestDataInfo info = new TestDataInfo(); info.readFileData("D:\\桌面文件备份\\公司各种设备资料\\FBS存储文件解析/M2021-06-22 13.08.40.MCP"); //info.readFileData("D:\\桌面文件备份\\公司各种设备资料\\FBS存储文件解析/M2021-06-22 13.12.45.MCH"); //info.readFileData("D:\\桌面文件备份\\公司各种设备资料\\FBS存储文件解析/M2021-08-13 09.40.06.MCP"); } }