Echelon ISI User Manual

Page 90

Advertising
background image

ISI Programmer’s Guide

88

E

XAMPLE

2

The following example sends an explicit network variable update to a device
in the device table created in the previous section after sending a query NV

request to determine the selector of the target network variable.

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

#define RETRY_COUNT 3
#define ENCODED_TX_TIMER 8 // 256ms
#define ENCODED_RPT_TIMER 2
#define PRIMARY_DOMAIN 0


#define NV_UPDATE_MESSAGE 0x80u

// This explicit message tag is used when querying the remote
// network variable's configuration, and when issuing the
// acknowledged network variable update.
msg_tag bind_info(nonbind) nvTag;

// This variable holds the remote device's subnet/node ID pair,
// used when sending the acknowledged NV update which copies
// the value from a local network variable, indicated by the
// localNvIndex detail, to a remote input network variable.
struct {

unsigned subnetId;
unsigned nodeId;
unsigned localNvIndex;
} nvUpdateJob;

// Initiate an acknowledged network variable update by copying
// relevant data into the nvUpdateJob variable. The function
// then issues a network variable configuration request, which is
// required to obtain the remote network variable's selector value.
// The when (resp_arrives) task, below, handles the response to that
// request and issues the acknowledged network variable update.
void InitiateNvUpdate(unsigned remoteNvIndex, unsigned
localNvIndex,

unsigned remoteSubnetId, unsigned
remoteNodeId) {

NM_query_nv_cnfg_request queryNvRequest;

// Preserve data needed when the NV configuration response arrives
nvUpdateJob.localNvIndex = localNvIndex;
nvUpdateJob.subnetId = remoteSubnetId;
nvUpdateJob.nodeId = remoteNodeId;

// Prepare the network variable configuration request
memset(&queryNvRequest, 0, sizeof(NM_query_nv_cnfg_request));
queryNvRequest.nv_index = remoteNvIndex;

memcpy(msg_out.data, &queryNvRequest,
sizeof(NM_query_nv_cnfg_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 = remoteSubnetId;
msg_out.dest_addr.snode.node = remoteNodeId;
msg_out.dest_addr.snode.retry = RETRY_COUNT;
msg_out.dest_addr.snode.tx_timer = ENCODED_TX_TIMER;

Advertising