Importance of a default when clause – Echelon Neuron C User Manual

Page 140

Advertising
background image

128

How Devices Communicate Using Application Messages

Important: Assigning values to the msg_out object can invalidate fields in the

msg_in object. After receiving a message, you must examine or save any
necessary fields in the msg_in object

before starting

to send a message.

code

A numeric message code. See

Message Codes

on page 123.

len

The length of the message data.

data

The application data. This field is valid only if len is greater than 0.

MAXDATA is a function of the #pragma app_buf_in_size directive
(see Chapter 8,

Memory Management

, on page 173):

MAXDATA = app_buf_in_size – 6

or

,

MAXDATA = app_buf_in_size – 17
(if explicit addressing is used by any message or network variable in

the program)

authenticated

This field has the value TRUE if the message was

authenticated, and FALSE if the message was not authenticated.

service

The message service type; one of the following values:

ACKD - acknowledged service with retries
UNACKD

- unacknowledged service

UNACKD_RPT- repeated service (message sent multiple times)

REQUEST- request/response service. When a message is sent using

this service, the receiver device returns a response to the
sender device, and the sender processes the response.

The request/response mechanism is described later in

this chapter.

addr

An optional field in the incoming message that an application

program can look at to determine the source and destination of the

message. You can find the definition of the msg_in_addr type in the
<msg_addr.h> include file.

To use this field, you must include the <msg_addr.h> file.

duplicate When this boolean flag is TRUE, it indicates the message is a

duplicate request message passed to the application. Duplicate

request messages are passed to the application if the application

response contains data beyond the one-byte message code.

rcvtx

The receive-transaction ID that the message used in the device’s

transaction database.

Importance of a Default When Clause

Listing 3 (in

The msg_arrives Event

on page 126) illustrates an important

technique to be used with messages:

Any program that receives application

messages must be prepared to receive unwanted messages and discard them.

Discards can take the form shown in Listing 3, or can be a default case in a

switch statement.

Advertising