System information

Appendix D. JAVA Example Code
D-17
public byte link_state;
public short dest_address;
public byte expect_more_code;
public byte priority;
public short src_address;
public short hi_protocol_code;
public byte message_type;
public byte tran_no;
public static final byte link_off_line = 8;
public static final byte link_ring = 9;
public static final byte link_ready = 10;
public static final byte link_finished = 11;
public static final byte link_pause = 12;
public static final byte expect_last = 0;
public static final byte expect_more = 1;
public static final byte expect_neutral = 2;
public static final byte expect_reverse = 3;
public static final byte pri_low = 0;
public static final byte pri_normal = 1;
public static final byte pri_high = 2;
public static final byte pri_extra_high = 3;
public static final byte protocol_pakctrl = 0;
public static final byte protocol_bmp5 = 1;
public Packet()
{
link_state = link_ready;
expect_more_code = expect_more;
priority = pri_high;
src_address = 0;
dest_address = 0;
hi_protocol_code = protocol_bmp5;
message_type = 0;
tran_no = 0;
read_index = storage_len = 0;
}
public Packet(byte[] buff, int len) throws Exception
{
// the incoming packet must have at least enough bytes
// to satisfy the header
if(len < 12)
throw new Exception("Invalid packet length");
// we will assume that the buffer being passed in has already
// been framed and dequoted. We will further assume that it
// has a BD at the beginning and a BD at the end along with the
// signature nullifier. Our internal buffer will throw the
// framing and the header away and keep only the packet content.
int word1 = (((int)buff[0]) << 8) | ((int)buff[1]);
int word2 = (((int)buff[2]) << 8) | ((int)buff[3]);
int word3 = (((int)buff[4]) << 8) | ((int)buff[5]);
int word4 = (((int)buff[6]) << 8) | ((int)buff[7]);
link_state = (byte)((word1 & 0xF000) >> 12);
dest_address = (short)(word1 & 0x0FFF);
expect_more_code = (byte)((word2 & 0xC000) >> 14);
priority = (byte)((word2 & 0x0300) >> 12);
src_address = (short)(word2 & 0x0FFF);
hi_protocol_code = (byte)((word3 & 0xF000) >> 12);