package com.dev.bts.data; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class FBS9100_StatAndParam { private final int BYTE_LEN = 6; public int dev_id = 0; public String dev_ipaddr = "127.0.0.1"; public int op_cmd = FBS9100_ComBase.CMD_NULL; public int op_cmd_ack = FBS9100_ComBase.CMD_NULL; public int test_type = FBS9100_ComBase.TestType_NULL; public String dev_reg_code; public long dev_station_id = 0; public FBS9100_SysState m_SysState = new FBS9100_SysState(); //public int[] Mcu_Id = new int[4]; public String m_DevVersion = ""; public String m_GPRS_inf = ""; public long dev_comm_data_flowsum = 0; public int CRC = 0; public FBS9100_StatAndParam(String ipaddr, int devid) { dev_ipaddr = ipaddr; dev_id = devid; } public void makeDevCommDataFlowSum (int dat_len) { int datlen = dat_len; if(datlen < 64) { datlen = 64; } dev_comm_data_flowsum += datlen; } public boolean putByteBuffer(final ByteBuffer bf) { if(bf.limit() != BYTE_LEN){ return false; } ByteBuffer tmpbuf = bf; /*int id = */tmpbuf.getInt(); int crc0 = tmpbuf.getShort() & 0xFFFF; int crc1 = FBS9100_Crc16.CalCRC16(tmpbuf, BYTE_LEN-2); if(crc0 != crc1){ System.out.println("crc´íÎó"); return false; } tmpbuf.position(0); dev_id = tmpbuf.getInt(); tmpbuf.compact(); tmpbuf.flip(); return true; } public ByteBuffer getByteBuffer() { ByteBuffer bytebuffer = ByteBuffer.allocate(BYTE_LEN); bytebuffer.order(ByteOrder.LITTLE_ENDIAN); //bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(dev_id)); bytebuffer.putInt(dev_id); CRC = FBS9100_Crc16.CalCRC16(bytebuffer, bytebuffer.position()); bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(CRC)); bytebuffer.flip(); //System.out.println("bytebuffer limit"+bytebuffer.limit()); return bytebuffer; } @Override public String toString() { return "FBS9100_StatAndParam [BYTE_LEN=" + BYTE_LEN + ", dev_id=" + dev_id + ", dev_ipaddr=" + dev_ipaddr + ", op_cmd=" + op_cmd_ack + ", test_type=" + test_type + "]"; } }