Echelon Neuron C User Manual
Page 126

114
Using Functional Blocks to Implement a Device Interface
Node Object implementation can then direct this request to code specific to the
requested functional block by calling the functional block’s director function. The
director function provides an easy way for the device to manage its functional
blocks and make sure that events and commands are directed to the proper
functional block.
Example:
An implementation of the SFPTnodeObject functional block receives requests
through the nviRequest mandatory member network variable input. Examples
for these requests are the RQ_DISABLED and RQ_ENABLED requests, which
requests one or more objects to enter the disabled or enabled state, respectively.
These requests can apply to the Node Object functional block, to an individual
functional block other than the Node Object functional block, or to all functional
blocks implemented on the device. A SFPTnodeObject implementation can
inspect the scope of the command received, and route the command to the right
director function as follows:
when (nv_update_occurs(nviRequest))
{
if (nviRequest.object_id == MyNodeObj::global_index) {
// NodeObject must handle this:
MyNodeObj::director(nviRequest.object_request);
} else {
// route the command to the best director:
... (see
below)
}
}
When a network variable update is received, you can determine the functional
block containing the network variable by using the built-in fblock_index_map
variable. This mapping array has an element for each network variable, and
each corresponding element contains the global index of the functional block of
which the network variable is a member. If the network variable is not a
member of a functional block, the corresponding element contains 0xFF, meaning
"no functional block".
You can also directly call the director for a functional block by specifying the
functional block index. To do this, call the fblock_director( ) system function.
This function has the same prototype as an individual director, and allows calling
any functional block’s director function through FB global index. The
fblock_director( ) function automatically selects which of the actual director
functions to call, and returns when that director function completes. If the
functional block does not have a director, the fblock_director( ) function returns
and does nothing.
Using this structure, the above example can be completed with code that routes
the command received to the most appropriate director:
Example:
when (nv_update_occurs(nviRequest))
{
if (nviRequest.object_id == MyNodeObj::global_index) {
// NodeObject must handle this:
MyNodeObj::director(nviRequest.object_request);
} else {
// route the command to the best director: