Event handler functions – Echelon FTXL User Manual
Page 217
![background image](/manuals/735717/217/background.png)
FTXL User’s Guide
205
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) {
/* The CP may have been updated by reading
* non-volatile data. If it looks good, update
*
nciNvTypeLastKnownGoodValue.
*/
if (LON_GET_UNSIGNED_WORD(nciNvType.type_index)
== INDEX_SNVT_VOLT ||
LON_GET_UNSIGNED_WORD(nciNvType.type_index)
==
INDEX_SNVT_VOLT_MIL)
{
memcpy((void*)&nciNvTypeLastKnownGoodValue,
(void*)&nciNvType,
sizeof(SCPTnvType));
}
/* 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 Functions
To signal to the main application the occurrence of certain types of events, the
FTXL LonTalk API calls specific event handler functions. For the dynamic
interface example application, six of the API’s event handler functions have been
implemented to provide application-specific behavior.
The FtxlHandlers.c file contains the modified functions, each of which simply
calls a function in the main.c file that provides the application-specific behavior.