package com.dev.btse.data;
|
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.Random;
|
|
import com.battmonitor.base.Crc16;
|
|
public class TmpSensor_ComBuf {
|
TmpSensor_Cmd m_CMD = new TmpSensor_Cmd();
|
|
public TmpSensor_Cmd getTmpSensorCmd()
|
{
|
return this.m_CMD;
|
}
|
|
public boolean putByteBuffer(final ByteBuffer bf)
|
{
|
if(false == m_CMD.putByteBuffer(bf))
|
return false;
|
|
return true;
|
}
|
|
public static ByteBuffer makeTmpSensorCommBuf(int addr, int cmd,int reg_index, ByteBuffer bf, boolean aes_en)
|
{
|
TmpSensor_Cmd m_CMD = new TmpSensor_Cmd();
|
ByteBuffer buffer = ByteBuffer.allocate(m_CMD.BYTE_LEN + bf.limit() + 32 );
|
buffer.order(ByteOrder.BIG_ENDIAN); //ÉèÖÃByteBufferµÄ×Ö½ÚÐò
|
|
m_CMD.makeCmd(addr, cmd,reg_index,getByteCountByReg(reg_index));
|
buffer.put(m_CMD.getByteBuffer());
|
buffer.put(bf);
|
|
if(true == aes_en) {
|
Random rd = new Random();
|
if(0 == (buffer.position()%Ecb_Aes.AES_BLOCK_SIZE)) {
|
for(int n=0; n<(Ecb_Aes.AES_BLOCK_SIZE/4); n++) {
|
buffer.putInt(rd.nextInt());
|
}
|
} else {
|
int cnt = Ecb_Aes.AES_BLOCK_SIZE - (buffer.position()%Ecb_Aes.AES_BLOCK_SIZE);
|
for(int n=0; n<cnt; n++) {
|
buffer.put((byte) rd.nextInt());
|
}
|
}
|
}
|
int CRC = Crc16.CalCRC16(buffer, buffer.position());
|
buffer.putShort(FBS9100_ComBase.changeIntToShort(CRC));
|
buffer.flip();
|
|
return buffer;
|
}
|
|
|
/**
|
* ¸ù¾Ý¼Ä´æÆ÷Æ«ÒÆµØÖ·»ñÈ¡¼Ä´æÆ÷¸öÊý
|
* @return
|
*/
|
public static int getByteCountByReg(int reg_index) {
|
int bytecount = 0;
|
switch(reg_index) {
|
case TmpSensor_ComBase.CMD_GETTMPSENSORSTATE:
|
return TmpSensorState.REG_BYTECOUNT;
|
}
|
return bytecount;
|
}
|
/***************************************************************************************
|
****************************** end of file (FBS_ComBuf) ********************************
|
***************************************************************************************/
|
}
|