package com.whyc.mcp;
|
|
import com.whyc.util.StaticInf;
|
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
|
public class MonitorDataInfo {
|
public static final int BYTE_LEN = BattParam.BYTE_LEN + SYSMonitorParam.BYTE_LEN + SYSMonitorState.BYTE_LEN;
|
|
public BattParam battparam; //电池参数
|
public SYSMonitorParam monitorparam; //未使用
|
public SYSMonitorState monitorstate;
|
|
|
public MonitorDataInfo() {
|
battparam = new BattParam();
|
monitorparam = new SYSMonitorParam();
|
monitorstate = new SYSMonitorState();
|
}
|
|
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((0xFA != (tag[0]&0xFF)) && (0xFB != (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 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();
|
flag = battparam.putByteBuffer(bf);
|
bf.position(0);
|
flag &= monitorparam.putByteBuffer(bf);
|
bf.position(0);
|
flag &= monitorstate.putByteBuffer(bf);
|
|
return flag;
|
}
|
}
|