The msg_receive( ) function, Format of an incoming message – Echelon Neuron C User Manual
Page 139

Neuron C Programmer’s Guide
127
{
// Do nothing, just discard it
}
To prevent the incoming message queue from becoming blocked, a program that
receives application messages, such as that shown in Listing 3, should contain a
default when clause with an unqualified msg_arrives event as shown in the
example. This is explained further in
Importance of a Default When Clause
on
page 128.
The msg_receive( ) Function
The msg_receive( ) function has the following syntax:
boolean msg_receive(void);
This function receives a message into the msg_in object. The function returns
TRUE if a new message is received, otherwise it returns FALSE.
If no message is received, this function does not wait for one. You might need to
use this function to receive more than one message in a single task, for example,
in bypass mode (bypass mode is also called direct event processing). If there
already is a received message, it is discarded (that is, its buffer space is freed).
Calling msg_receive( ) or resp_receive( ) has the side-effect of calling
post_events( ). Thus, a call to msg_receive( ) or resp_receive( ) defines a critical
section boundary (see
on page 138).
When you use the msg_receive( ) function, all messages are received in “raw”
form, and special events such as online, offline, and wink can be used, but you
must check for these events explicitly through message code checks. For these
reasons, you cannot use msg_receive( ) if the application program handles any
special events (that is, wink, online, and offline).
Format of an Incoming Message
The name for the incoming message object is msg_in. This definition is built into
Neuron C. A message is read by examining the appropriate fields in the object.
The fields of the msg_in object are read-only; you cannot assign values to them.
An incoming message is predefined as follows:
typedef enum {FALSE, TRUE} boolean;
typedef enum {ACKD, UNACKD_RPT,
UNACKD, REQUEST} service_type;
struct {
int code;
// message code
int len;
// length of message data
int data[MAXDATA];
// message data
boolean authenticated; // TRUE if message was
// authenticated
service_type service; // service type used by sender
msg_in_addr addr;
// see
boolean duplicate;
// the message is a duplicate
unsigned rcvtx;
// the message's receive tx ID
} msg_in;