Echelon ISI User Manual

Page 89

Advertising
background image

87

ISI Programmer’s Guide

E

XAMPLE

1

The following example sends a network variable fetch message to a device
with a specified NV index, subnet ID, and node ID. These may be fetched

from the device table created in the previous section.

#include <msg_addr.h>
#include <netmgmt.h>

#define RETRY_COUNT 3
#define ENCODED_TX_TIMER 11 // 768ms
#define ENCODED_RPT_TIMER 2
#define PRIMARY_DOMAIN 0

msg_tag bind_info(nonbind) fetchNvTag;

// Issue a fetch NV request using the NV index on the remote
// device, and the remote device's subnet/node ID pair for the
// destination address. Return when the request has been sent;
// see when (resp_arrives) task for processing of the response.
void FetchNv(unsigned nvIndex, unsigned subnetId, unsigned nodeId)
{
NM_nv_fetch_request fetchRequest;

memset(&fetchRequest, 0, sizeof(NM_nv_fetch_request));

fetchRequest.nv_index = nvIndex;

memcpy(msg_out.data, &fetchRequest,
sizeof(NM_nv_fetch_request));

// Use Subnet/Node ID addressing
msg_out.dest_addr.snode.type = SUBNET_NODE;
msg_out.dest_addr.snode.domain = PRIMARY_DOMAIN;
msg_out.dest_addr.snode.subnet = subnetId;
msg_out.dest_addr.snode.node = nodeId;
msg_out.dest_addr.snode.retry = RETRY_COUNT;
msg_out.dest_addr.snode.tx_timer = ENCODED_TX_TIMER;
// Copy the relevant data to msg_out
msg_out.code = NM_opcode_base | (NM_nv_fetch &
NM_opcode_mask);

msg_out.service = REQUEST;
msg_out.tag = fetchNvTag; // Destination address
msg_send();
}

// Handle receipt of responses to the fetch request issued
// by the FetchNv() function.
when (resp_arrives(fetchNvTag)) {
NM_nv_fetch_response fetchResponse;

if (resp_in.code == (NM_resp_success | NM_nv_fetch)) {
memcpy(&fetchResponse, resp_in.data,
sizeof(NM_nv_fetch_response));

// Process returned NV Value
...
}
}

Advertising