package FBS9100;
|
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
|
|
public class FBS9100_DFU implements Cloneable
|
{
|
private final int BYTE_LEN = 518;
|
private final int BYTE_LEN_READ = 6;
|
|
public int op_cmd = 0;
|
public int test_cmd = 0;
|
|
public int DataBlockIndex = 0;
|
public int DataLen = 0;
|
public byte[] DataDfu = new byte[512];
|
public int CRC = 0;
|
|
public FBS9100_DFU clone()
|
{
|
FBS9100_DFU obj = null;
|
try
|
{
|
obj = (FBS9100_DFU)super.clone();
|
}
|
catch(CloneNotSupportedException e)
|
{
|
e.printStackTrace();
|
}
|
return obj;
|
}
|
|
public void clear()
|
{
|
CRC = 0;
|
}
|
|
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.compact();
|
tmpbuf.flip();
|
|
return true;
|
}
|
|
public ByteBuffer getByteBuffer(int num, int data_len)
|
{
|
ByteBuffer bytebuffer = ByteBuffer.allocate(BYTE_LEN);
|
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
|
|
DataBlockIndex = num;
|
DataLen = data_len;
|
bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(DataBlockIndex));
|
bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(DataLen));
|
for(int n=0; n<DataDfu.length; n++) {
|
DataDfu[n] = (byte) n;
|
}
|
bytebuffer.put(DataDfu);
|
CRC = FBS9100_Crc16.CalCRC16(bytebuffer, bytebuffer.position());
|
bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(CRC));
|
|
bytebuffer.flip();
|
|
return bytebuffer;
|
}
|
|
public ByteBuffer getReadByteBuffer(int num, int data_len)
|
{
|
ByteBuffer bytebuffer = ByteBuffer.allocate(BYTE_LEN_READ);
|
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
|
|
DataBlockIndex = num;
|
DataLen = data_len;
|
bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(DataBlockIndex));
|
bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(DataLen));
|
CRC = FBS9100_Crc16.CalCRC16(bytebuffer, bytebuffer.position());
|
bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(CRC));
|
|
bytebuffer.flip();
|
|
return bytebuffer;
|
}
|
}
|
/***************************************************************************************
|
****************************** end of file (FBS_TestParam) *****************************
|
***************************************************************************************/
|