System information
Appendix D. JAVA Example Code
D-5
//SetupDl gets the PakBusAddress by using the GetCommand procedure
public static void SetupDL()
{
GetCommandStatus = 0;
NameList = "\0";
GetCommand();
SendPb();
}
/**
* GetLoggerAddress will broadcast the network to get a response
* from the DL to get the pakbus address. This will not work for
* multiple DL's they will all respond
*/
public static void GetCommand()
{
CreateHeader();
out_packet.hi_protocol_code = Packet.protocol_pakctrl;
out_packet.message_type = 0x07;
out_packet.tran_no = 0x07;
out_packet.add_string(NameList);
}
/**
* Creates the PakBus header
*/
public static void CreateHeader()
{
out_packet = new Packet();
out_packet.src_address = source_address;
out_packet.dest_address = dest_address;
}
/**
* calculates the signature for a buffer
*/
static char calcSigFor(byte[] buff, int len, char seed)
{
int j, n;
char rtn = seed;
// calculate a representative number for the byte block using the CSI
// signature algorithm.
for(n = 0; n < len; n++)
{
if(n == 0 && buff[0] == 0xBD && len > 1) //Ignore first 0xBD
n = 1;
j = rtn;
rtn = (char)((rtn << 1) & (char)0x01FF);
if(rtn >= (int)0x100)
rtn++;
rtn = (char)(((rtn + (j >> 8) + buff[n]) & (char)0xFF) | (j <<
8));
}
return rtn;
} // calcSigFor