From b8b5888b3b42b071be8c83a3cac250f0a3b63ecb Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 18 Jul 2014 16:05:49 +0000 Subject: [PATCH] mirrored new message format to client directories git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@169 8ec27952-4edc-4aab-86aa-e87bb2611832 --- .../models/send_receive/include/MsgFormat.h | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/clients/opal/models/send_receive/include/MsgFormat.h b/clients/opal/models/send_receive/include/MsgFormat.h index 4e081eb05..f738a4638 100644 --- a/clients/opal/models/send_receive/include/MsgFormat.h +++ b/clients/opal/models/send_receive/include/MsgFormat.h @@ -10,20 +10,39 @@ #include +#ifndef BYTE_ORDER + #define _BSD_SOURCE 1 + #include +#endif + /** Maximum number of dword values in a message */ -#define MSG_VALUES 16 +#define MSG_VALUES 16 + /** The current version number for the message format */ -#define MSG_VERSION 0 +#define MSG_VERSION 0 /** @todo Implement more message types */ -#define MSG_TYPE_DATA 0 -#define MSG_TYPE_START 1 -#define MSG_TYPE_STOP 2 +#define MSG_TYPE_DATA 0 /**< Message contains float values */ +#define MSG_TYPE_START 1 /**< Message marks the beginning of a new simulation case */ +#define MSG_TYPE_STOP 2 /**< Message marks the end of a simulation case */ + +#define MSG_ENDIAN_LITTLE 0 /**< Message values are in little endian format (float too!) */ +#define MSG_ENDIAN_BIG 1 /**< Message values are in bit endian format */ + +#if BYTE_ORDER == LITTLE_ENDIAN + #define MSG_ENDIAN_HOST MSG_ENDIAN_LITTLE +#elif BYTE_ORDER == BIG_ENDIAN + #define MSG_ENDIAN_HOST MSG_ENDIAN_BIG +#endif + +/** The total length of a message */ +#define MSG_LEN(values) (4 * (values + 1)) /** Initialize a message */ #define MSG_INIT(i) { \ .version = MSG_VERSION, \ .type = MSG_TYPE_DATA, \ + .endian = MSG_ENDIAN_HOST, \ .length = i, \ .sequence = 0 \ } @@ -34,18 +53,26 @@ **/ struct msg { - /** The version specifies the format of the remaining message */ - unsigned version : 4; - /** Data or control message */ - unsigned type : 2; - /** These bits are reserved for future extensions */ - unsigned __padding : 2; +#if BYTE_ORDER == BIG_ENDIAN + unsigned version: 4; /**< Specifies the format of the remaining message (see MGS_VERSION) */ + unsigned type : 2; /**< Data or control message (see MSG_TYPE_*) */ + unsigned endian : 1; /**< Specifies the byteorder of the message (see MSG_ENDIAN_*) */ + unsigned : 1; /**< Reserved padding bits */ +#else + unsigned : 1; /**< Reserved padding bits */ + unsigned endian : 1; /**< Specifies the byteorder of the message (see MSG_ENDIAN_*) */ + unsigned type : 2; /**< Data or control message (see MSG_TYPE_*) */ + unsigned version: 4; /**< Specifies the format of the remaining message (see MGS_VERSION) */ +#endif /** Number of valid dword values in msg::data[] */ uint8_t length; /** The sequence number gets incremented by one for consecutive messages */ uint16_t sequence; /** The message payload */ - float data[MSG_VALUES]; + union { + float f; + uint32_t i; + } data[MSG_VALUES]; } __attribute__((packed)); #endif /* _MSG_FORMAT_H_ */