AMX Message Exchange Manager
K
A
DAK
115
8.3 Message Exchange ApplicationThe following example, coded in C, is provided to illustrate the use of the AMX Message
Exchange Manager.
This example illustrates a solution to the problem posed in the introduction (Chapter 8.1).
Two message processing tasks, A and B, accept and service the messages from the data
acquisition and data base tasks and the Timer Procedure. The processing tasks expect
messages to arrive within 5 seconds.
A Restart Procedure creates the message exchange with message queues 0, 2 and 3, each
of depth 10. In our example, the tasks and Timer Procedure assume a valid message
exchange id has been provided in variable msgexch. The Restart Procedure also creates
and starts the Timer Procedure.
The creation and starting of tasks A and B and the creation of the data acquisition and
data base tasks is outside the scope of this example. It is assumed that if the Restart
Procedure is unable to create the message exchange, the tasks will not be started.
Since we do not know how the data acquisition task and the data base update task were
created, we will assume that their task ids are available in global variables as would be
the case if the AMX Configuration Builder had been used to create the tasks.
The Timer Procedure triggers the data acquisition task once a second and sends a
time-stamp message to the message exchange at the highest priority, 0.
The data acquisition task samples the data, triggers the data base update task and sends a
data sample message to the message exchange at medium priority 2.
The data base update task processes the sampled data, updates the data base and sends a
data update message to the message exchange at low priority 3.
Note that the two tasks, sttaskA and sttaskB, share a common re-entrant task body,
sttask. In practice, procedure sttaskB could be eliminated and Task B could be created
with sttaskA as the task start address. The example is coded to more clearly illustrate
that two tasks actually exist.