package com.whyc.res;
|
|
import com.whyc.util.ComBase;
|
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
|
|
/**
|
* 内阻数据头
|
* @author LiJun
|
*
|
*/
|
public class RESDataHead {
|
public static final int BYTE_LEN = 4;
|
|
private int[] SYNCode = new int[2]; //固定值0xAA 0xAA
|
private int record_times; //记录次数,记录有多少笔RES_DATA数据
|
|
public boolean setHeadData(byte[] databuf) {
|
if(databuf.length < BYTE_LEN) {
|
return false;
|
}
|
ByteBuffer bf = ByteBuffer.allocate(databuf.length);
|
bf.order(ByteOrder.LITTLE_ENDIAN);
|
bf.put(databuf);
|
bf.position(0);
|
for(int i=0;i<SYNCode.length;i++) {
|
SYNCode[i] = ComBase.changeByteToInt(bf.get());
|
}
|
record_times = ComBase.changeShortToInt(bf.getShort());
|
System.out.println("次数:"+record_times);
|
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<4; n++)
|
{
|
if(1 != fis.read(tag, 0, 1))
|
{
|
file_end = true;
|
break;
|
}
|
if((0xAA != (tag[0]&0xFF)))
|
{
|
break;
|
}
|
}
|
|
if(n >= 4)
|
{
|
check_ok = true;
|
break;
|
}
|
if(true == file_end)
|
{
|
break;
|
}
|
}
|
} catch (IOException e) {
|
//e.printStackTrace();
|
}
|
return check_ok;
|
}
|
|
public int[] getSYNCode() {
|
return SYNCode;
|
}
|
public int getRecord_times() {
|
return record_times;
|
}
|
public void setSYNCode(int[] sYNCode) {
|
this.SYNCode = sYNCode;
|
}
|
public void setRecord_times(int record_times) {
|
this.record_times = record_times;
|
}
|
|
|
|
}
|