Event handler function – Echelon FTXL User Manual
Page 211

FTXL User’s Guide
199
• Creates the “event ready” event using the FTXL OSAL
OsalCreateEvent() function. The LonEventReady() callback handler
function uses this event to wake up the application task to process FTXL
network events.
• Calls the LonInit() function to initialize the FTXL LonTalk protocol stack
and FTXL Transceiver. If this function fails, the appTask() function calls
the FTXL OSAL OsalDeleteEvent() function to delete the “event ready”
event.
• If the LonInit() function is successful, the appTask() function begins an
infinite loop to wait for FTXL network events. When an event occurs, it
calls the LonEventPump() function to process the event.
Although the main() and appTask() functions for this application are part of an
example, you can use the same basic algorithmic approach for a production-level
application.
The the appTask() function is shown below.
/* The application task initializes the FTXL LonTalk
* protocol stack and implements the main control loop.
* The bulk of the application processing is performed in
* the myNvUpdateOccurred event handler.
*/
void appTask(void* pData) {
/* Create the “event ready” event, which is signaled by
* the myEventReady callback to wake this task up to
* process FTXL events.
*/
if (OsalCreateEvent(&eventReadyHandle) ==
OSALSTS_SUCCESS) {
/* Initialize the FTXL LonTalk API and FTXL Transceiver
*/
if (LonInit() == LonApiNoError) {
/* This is the main control loop, which runs
* forever. */
while (TRUE) {
/* 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();
}
}
OsalDeleteEvent(&eventReadyHandle);
}
}
Event Handler Function
To signal to the main application the occurrence of certain types of events, the
FTXL 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.