package com.dev.fbs9100;
|
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.Date;
|
|
public class FBS9100_SysState
|
{
|
public static final byte SYS_STATE_STOPPED = 0;
|
public static final byte SYS_STATE_DISCHARGING = 1;
|
public static final byte SYS_STATE_CHARGING = 2;
|
//--------------------------------------------------------//
|
private final int BYTE_LEN = 14;
|
//--------------------------------------------------------//
|
public Date Record_DateTime = new Date();
|
//--------------------------------------------------------//
|
public FBS9100_DateTime DTime = new FBS9100_DateTime(); //±ê×¼ÈÕÆÚʱ¼ä
|
public int TestType = 0; //²âÊÔÀàÐÍ(³äµç»ò·Åµç)
|
public int TestGroupNum = 1; //±»²âÊÔÐîµç³Ø×é±àºÅ1-4
|
public int WorkState = SYS_STATE_STOPPED; //ϵͳ¹¤×÷״̬
|
public int AlarmState = 0; //ϵͳ¸æ¾¯×´Ì¬
|
public int OnlineVolLow = 0; //ÔÚÏßµçѹ̫µÍ(Òì³£±êʶ)
|
public int CommCount = 0; //ͨÐżÆÊý
|
public int ErrCommCount = 0;
|
public long Alm_RecId = 0;
|
|
//---------------------------------------//
|
public int ResBattIndexMax; //±»²âÊÔµ¥ÌåµÄ×î´ó±àºÅË÷Òý
|
public int ResBattIndex; //±»²âÊÔµ¥ÌåµÄË÷Òý
|
//---------------------------------------//
|
|
public int CRC = 0;
|
|
public FBS9100_SysState clone()
|
{
|
FBS9100_SysState obj = new FBS9100_SysState();
|
|
obj.DTime = DTime.clone();
|
obj.TestType = TestType;
|
obj.TestGroupNum = TestGroupNum;
|
obj.WorkState = WorkState;
|
obj.AlarmState = AlarmState;
|
obj.OnlineVolLow = OnlineVolLow;
|
obj.CommCount = CommCount;
|
obj.ErrCommCount = ErrCommCount;
|
obj.CRC = CRC;
|
|
return obj;
|
}
|
|
public void setCommCountInc()
|
{
|
Record_DateTime = new Date();
|
|
CommCount += 1;
|
if(CommCount >= 90000000) {
|
CommCount = 1;
|
}
|
}
|
|
public void setErrCommCountInc()
|
{
|
ErrCommCount += 1;
|
if(ErrCommCount >= 90000000) {
|
ErrCommCount = 20;
|
}
|
}
|
|
public void setDateTime(FBS9100_DateTime dt)
|
{
|
DTime = dt;
|
}
|
|
public boolean putByteBuffer(final ByteBuffer bf)
|
{
|
if(bf.limit() < BYTE_LEN)
|
return false;
|
|
ByteBuffer tmpbuf = bf;
|
int crc0 = tmpbuf.getShort(BYTE_LEN-2) & 0xFFFF;
|
int crc1 = FBS9100_Crc16.CalCRC16(tmpbuf, BYTE_LEN-2);
|
if(crc0 != crc1)
|
return false;
|
|
tmpbuf.position(0);
|
DTime.putByteBuffer(tmpbuf);
|
TestType = FBS9100_ComBase.changeByteToInt(bf.get());
|
TestGroupNum = FBS9100_ComBase.changeByteToInt(bf.get());
|
WorkState = FBS9100_ComBase.changeByteToInt(bf.get());
|
AlarmState = FBS9100_ComBase.changeByteToInt(bf.get());
|
OnlineVolLow = FBS9100_ComBase.changeByteToInt(bf.get());
|
FBS9100_ComBase.changeByteToInt(bf.get());
|
CRC = FBS9100_ComBase.changeShortToInt(bf.getShort());
|
tmpbuf.compact();
|
tmpbuf.flip();
|
return true;
|
}
|
|
public ByteBuffer getByteBuffer()
|
{
|
ByteBuffer bytebuffer = ByteBuffer.allocate(BYTE_LEN);
|
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
|
|
bytebuffer.put(DTime.getBytes());
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(TestType));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(TestGroupNum));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(WorkState));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(AlarmState));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(OnlineVolLow));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(0));
|
|
CRC = FBS9100_Crc16.CalCRC16(bytebuffer, bytebuffer.position());
|
bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(CRC));
|
bytebuffer.flip();
|
//System.out.println(bytebuffer.limit()+"&&&&&&&&&&&&&&&&");
|
return bytebuffer;
|
}
|
|
@Override
|
public String toString() {
|
return "FBS9100_SysState [BYTE_LEN=" + BYTE_LEN + ", DTime=" + DTime + ", TestType=" + TestType
|
+ ", TestGroupNum=" + TestGroupNum + ", WorkState=" + WorkState + ", AlarmState=" + AlarmState
|
+ ", OnlineVolLow=" + OnlineVolLow + ", CommCount=" + CommCount + ", ErrCommCount=" + ErrCommCount
|
+ ", Alm_RecId=" + Alm_RecId + ", ResBattIndexMax=" + ResBattIndexMax + ", ResBattIndex=" + ResBattIndex
|
+ ", CRC=" + CRC + "]";
|
}
|
}
|
/***************************************************************************************
|
****************************** end of file (FBS_SysState) ******************************
|
***************************************************************************************/
|