Event handler function, Stack applications – Echelon LonTal Stack User Manual

Page 224

Advertising
background image

212

Appendix G: Appendix G


Example LonTalk

Stack Applications

LonResgisterUniqueId(&uid);

#endif

sts = LonInit();

if

(sts == LonApiNoError)

{

/* This is the main control loop, which runs forever. */

while

(!shutdownApp)

{

/* Whenever the ready event is fired, process events by calling

* LonEventPump. The ready event is fired by the myEventReady
* callback.
*/

if

(OsalWaitForEvent(eventReadyHandle, OSAL_WAIT_FOREVER) ==

OSALSTS_SUCCESS)
{
LonEventPump();
}

if

(sendServicPin)

{
LonSendServicePin();
sendServicPin = FALSE;
}
}
}

else

{
printf(

"Error: LonInit failed with error #%d\n"

, sts);

}
LonExit();
appTaskRunning = FALSE;

Event Handler Function

To signal to the main application the occurrence of certain types of events, the
LonTalk API calls specific event handler functions. For the simple voltage

amplifier example application, only one of the API’s event handler functions has

been implemented to provide application-specific behavior.

The FtxlHandlers.c file contains the modified LonNvUpdateOccurred()

function, which is called when the host processor receives a network-variable
update. This function simply calls the myNvUpdateOccurred() function in the

main.c file that provides the application-specific behavior. This functional

separation approach keeps changes to the LonTalk Interface Developer
utility-generated files to a minimum. For a production-level application, you can

place application-specific code wherever your application design requires it.
The myNvUpdateOccurred() function contains a C switch statement, which
contains a single case statement because the VoltActuator functional block

includes only a single input network variable, nviVolt.

The case statement for the nviVolt network variable (specified by the

LonNvIndexNviVolt network variable index) calls the
ProcessNviVoltUpdate() utility function to perform the following tasks:

• Perform range checking for the network variable
• Set the output network variable to double the value of the input network

variable

• Propagate the output network variable to the network

Advertising