beautypg.com

Echelon ISI User Manual

Page 87

background image

85

ISI Programmer’s Guide

// connection table index provided.
void SendConnectionTableResponse(unsigned index, boolean success) {
IsiMessage response;
unsigned length;

if (success) {
response.Header.Code = isiRdcs;

response.Msg.Rdcs.Index = index;
memcpy(&response.Msg.Rdcs.Data, IsiGetConnection(index),
sizeof(response.Msg.Rdcs.Data));
length = sizeof(IsiMessageHeader)+sizeof(IsiRdcs);
} else {
response.Header.Code = isiRdcf;
length = sizeof(IsiMessageHeader);
}
memcpy(resp_out.data, &response, length);
resp_send();
}

when (msg_arrives) {

IsiMessage request;
unsigned index, connectionTableSize;
const IsiConnection* pConnection;

if (IsiApproveMsg() && IsiProcessMsgS()) {
// The message is approved (it is a genuine ISI message), but
// was not processed by IsiProcessMsgS(). This might be a
// connection table request.

memcpy(&request, msg_in.data, msg_in.len);
connectionTableSize = IsiGetConnectionTableSize();

if (request.Header.Code == isiRdct) {

// This is a connection table read request

index = request.Msg.Rdct.Index;

if (request.Msg.Rdct.Host != ISI_NO_ASSEMBLY) {
// Try locating a connection table entry that is active and
// report the requested assembly as the host assembly
while (index < connectionTableSize) {
pConnection = IsiGetConnection(index);
if (pConnection->State >= isiConnectionStateInUse
&& pConnection->Host == request.Msg.Rdct.Host) {
break;

}
++index;
}
} else if (request.Msg.Rdct.Member != ISI_NO_ASSEMBLY) {
// Try locating a connection table entry that is active and
// report the requested assembly as the member assembly
while (index < connectionTableSize) {
pConnection = IsiGetConnection(index);
if (pConnection->State >= isiConnectionStateInUse
&& pConnection->Member == request.Msg.Rdct.Member) {
break;
}
++index;

}
}
SendConnectionTableResponse(index, index < connectionTableSize);
}
}