From 502128a5a3174f16ba82aab52eccab5bf3d426f6 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 5 Jun 2015 11:05:39 +0200 Subject: [PATCH] updated OPAL AsyncIP code to new message version --- .../models/send_receive/include/msg_format.h | 75 +++++++++++-------- .../opal_udp/models/send_receive/src/s2ss.c | 4 +- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/clients/opal_udp/models/send_receive/include/msg_format.h b/clients/opal_udp/models/send_receive/include/msg_format.h index 40c21453b..d7b41d6cc 100644 --- a/clients/opal_udp/models/send_receive/include/msg_format.h +++ b/clients/opal_udp/models/send_receive/include/msg_format.h @@ -1,9 +1,11 @@ /** Message format * - * @author Steffen Vogel - * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC * @file - */ + * @author Steffen Vogel + * @copyright 2014-2015, Institute for Automation of Complex Power Systems, EONERC + * This file is part of S2SS. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + *********************************************************************************/ #ifndef _MSG_FORMAT_H_ #define _MSG_FORMAT_H_ @@ -14,7 +16,7 @@ #define _BSD_SOURCE 1 #include #elif defined(__PPC__) /* Xilinx toolchain */ - #include + #include #endif #include "config.h" @@ -23,34 +25,40 @@ #define MSG_VALUES MAX_VALUES /** The current version number for the message format */ -#define MSG_VERSION 0 +#define MSG_VERSION 1 /** @todo Implement more message types */ #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 */ +#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 + #define MSG_ENDIAN_HOST MSG_ENDIAN_LITTLE #elif BYTE_ORDER == BIG_ENDIAN - #define MSG_ENDIAN_HOST MSG_ENDIAN_BIG + #define MSG_ENDIAN_HOST MSG_ENDIAN_BIG #else #error "Unknown byte order!" #endif /** The total length of a message */ -#define MSG_LEN(values) (4 * (values + 1)) +#define MSG_LEN(msg) (4 * ((msg)->length + 4)) + +#define MSG_TS(msg) (struct timespec) { \ + .tv_sec = (msg)->ts.sec, \ + .tv_nsec = (msg)->ts.nsec \ +} /** Initialize a message */ -#define MSG_INIT(i) { \ - .version = MSG_VERSION, \ - .type = MSG_TYPE_DATA, \ - .endian = MSG_ENDIAN_HOST, \ - .length = i, \ - .sequence = 0 \ +#define MSG_INIT(i) (struct msg) { \ + .version = MSG_VERSION, \ + .type = MSG_TYPE_DATA, \ + .endian = MSG_ENDIAN_HOST, \ + .length = i, \ + .sequence = 0, \ + .rsvd1 = 0, .rsvd2 = 0 \ } /** This message format is used by all clients @@ -60,27 +68,34 @@ struct msg { #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 */ + 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 rsvd1 : 1; /**< Reserved bits */ #elif BYTE_ORDER == LITTLE_ENDIAN - 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) */ + unsigned rsvd1 : 1; /**< Reserved 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 + unsigned rsvd2 : 8; /**< Reserved bits */ + + /** The number of values in msg::data[] */ + uint16_t length; - /** Number of valid dword values in msg::data[] */ - uint8_t length; - /** The sequence number gets incremented by one for consecutive messages */ - uint16_t sequence; + uint32_t sequence; /**< The sequence number is incremented by one for consecutive messages */ + + /** A timestamp per message */ + struct { + uint32_t sec; /**< Seconds since 1970-01-01 00:00:00 */ + uint32_t nsec; /**< Nanoseconds since 1970-01-01 00:00:00 */ + } ts; /** The message payload */ union { - float f; /**< Floating point values (note msg::endian) */ + float f; /**< Floating point values (note msg::endian) */ uint32_t i; /**< Integer values (note msg::endian) */ } data[MSG_VALUES]; -} __attribute__((aligned(4), packed)); +} __attribute__((aligned(64), packed)); #endif /* _MSG_FORMAT_H_ */ diff --git a/clients/opal_udp/models/send_receive/src/s2ss.c b/clients/opal_udp/models/send_receive/src/s2ss.c index 41d4d3cd2..34b714aa6 100644 --- a/clients/opal_udp/models/send_receive/src/s2ss.c +++ b/clients/opal_udp/models/send_receive/src/s2ss.c @@ -132,7 +132,7 @@ static void *SendToIPPort(void *arg) for (i = 0; i < msg.length; i++) msg.data[i].f = (float) mdldata[i]; - msg_size = MSG_LEN(msg.length); + msg_size = MSG_LEN(&msg); /**********************************************************************/ /* Perform the actual write to the ip port */ @@ -205,7 +205,7 @@ static void *RecvFromIPPort(void *arg) if (msg.endian != MSG_ENDIAN_HOST) msg_swap(&msg); - msg_size = MSG_LEN(msg.length); + msg_size = MSG_LEN(&msg); /***********************************************************************/ if (n < 1) {