Application task function – Echelon LonTal Stack User Manual

Page 223

Advertising
background image

LonTalk Stack Developer’s Guide

211

OsalSleep(10);
}
OsalCloseTaskHandle(taskHandle);
}
OsalDeleteEvent(&eventReadyHandle);
}

return

0;

}

Application Task Function

The appTask() function is contained in the main.c file, and it performs the
following tasks:

1. If the device is an IP-852 device, registers the devices unique ID. The

example registers a dummy unique ID. A real IP-852 device must register a
valid unique ID obtained from Echelon.

2. Calls the LonInit() function to initialize the LonTalk protocol stack. If this

function fails, the appTask() function prints an error and terminates.

3. If the LonInit() function succeeds, the appTask() function begins a loop to

wait for LonTalk Stack network events or for the main task to signal that it

is time to shutdown. When a LonTalk Stack network event occurs, it does

the following:

a. Calls the LonEventPump() function to process the event.

b. If the sendServicePin variable was set by the main task, calls

LonSendServicePin() to send a service pin message.

4. Upon termination, the appTask() function does the following:

a. Calls the LonExit() function to destroy the LonTalk protocol stack.

b. Sets the appTaskRunning flag to false to signal the main task that it is

done.

c. Returns.

You can use the same basic algorithmic approach with the main() and

appTask() functions for a production-level application.

The appTask() function is shown below.

/* The application task initializes the LonTalk protocol stack and
* implements the main control loop. The bulk of the application processing
* is performed in the myNvUpdateOccurred event handler.
*/

void

appTask(

int

taskIndex)

{

/* Create the "event ready" event, which is signaled by the myEventReady

* callback to wake this task up to process LonTalkStack events.
*/

/* Initialize the LonTalk Stack */

LonApiError sts;

#if

FEATURE_INCLUDED(IP852)

#pragma

message

(

"Warning: TBD - Must set a valid UniqueID for IP-852

interface!!!"

)

// TBD - Set the unique ID.

LonUniqueId uid = { 0xBA, 0xDB, 0xAD, 0xBA, 0xDB, 0xAD };

Advertising