beautypg.com

Echelon ISI User Manual

Page 81

background image

79

ISI Programmer’s Guide

msg_out.dest_addr.bcast.rpt_timer = ENCODED_RPT_TIMER;
msg_out.dest_addr.bcast.retry = RETRY_COUNT;
msg_out.dest_addr.bcast.tx_timer = ENCODED_TX_TIMER;
msg_out.dest_addr.bcast.subnet = 0;
msg_out.tag = discoveryTag;
queryIdRequest.selector = SELECTED;
memcpy(msg_out.data, &queryIdRequest,

sizeof(NM_query_id_request));
msg_send();
}

// Handle incoming responses. For successful responses to
// the query ID request, store the response data and process according
// to the application's needs.
// Issue a respond_to_query(MODE_OFF) command to the device that responded
// to the query, requesting that the same device should refrain from responding
// to repeated queries, and repeat the Query ID request to the remaining
// devices in the domain.
when (resp_arrives(discoveryTag)) {
NM_query_id_response queryIdResponse;


if (resp_in.code == (NM_resp_success|NM_query_id)) {
// Save response data:
memcpy(&queryIdResponse, resp_in.data,
sizeof(NM_query_id_response));

// To do: Process new device here...
...

// Disable this device's query ID response
msg_out.dest_addr.nrnid.type = NEURON_ID;
msg_out.dest_addr.nrnid.domain = PRIMARY_DOMAIN;
msg_out.dest_addr.nrnid.rpt_timer = ENCODED_RPT_TIMER;

msg_out.dest_addr.nrnid.retry = RETRY_COUNT;
msg_out.dest_addr.nrnid.tx_timer = ENCODED_TX_TIMER;
memcpy(msg_out.dest_addr.nrnid.nid, queryIdResponse.neuron_id,
NEURON_ID_LEN);
msg_out.code = NM_opcode_base | NM_respond_to_query;
msg_out.tag = discoveryTag;
msg_out.service = REQUEST;
msg_out.data[0] = MODE_OFF;
msg_send();

// Try again to query the ID message from other devices
QueryNetwork();

}
}

// Start the device discovery process by enabling each device's
// response to Query ID request, and issueing such a request.
// Repeat the query for every
void DiscoverDevices(void)
{
RespondOn();
QueryNetwork();
}