2014-07-07 07:53:42 +00:00
|
|
|
/** Message format
|
|
|
|
*
|
|
|
|
* @file
|
2015-06-02 21:53:04 +02:00
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
2017-04-27 12:56:43 +02:00
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASnode
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-06-02 21:53:04 +02:00
|
|
|
*********************************************************************************/
|
2014-07-07 07:53:42 +00:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2014-07-07 07:53:42 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2014-07-14 10:47:41 +00:00
|
|
|
/** The current version number for the message format */
|
2017-04-23 22:11:55 +02:00
|
|
|
#define MSG_VERSION 2
|
2014-07-07 07:53:42 +00:00
|
|
|
|
|
|
|
/** @todo Implement more message types */
|
2014-07-18 16:05:48 +00:00
|
|
|
#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 */
|
|
|
|
|
2015-10-09 13:04:52 +02:00
|
|
|
/** The total size in bytes of a message */
|
2016-06-08 22:38:21 +02:00
|
|
|
#define MSG_LEN(values) (sizeof(struct msg) + MSG_DATA_LEN(values))
|
|
|
|
|
|
|
|
/** The length of \p values values in bytes. */
|
|
|
|
#define MSG_DATA_LEN(values) (sizeof(float) * (values))
|
|
|
|
|
|
|
|
/** The offset to the first data value in a message. */
|
|
|
|
#define MSG_DATA_OFFSET(msg) ((char *) (msg) + offsetof(struct msg, data))
|
|
|
|
|
|
|
|
/** Initialize a message with default values */
|
2016-07-11 18:19:23 +02:00
|
|
|
#define MSG_INIT(len, seq) (struct msg) {\
|
|
|
|
.version = MSG_VERSION, \
|
|
|
|
.type = MSG_TYPE_DATA, \
|
|
|
|
.length = len, \
|
2016-06-08 22:38:21 +02:00
|
|
|
.sequence = seq \
|
|
|
|
}
|
2015-06-02 22:36:17 +02:00
|
|
|
|
2015-10-09 13:04:52 +02:00
|
|
|
/** The timestamp of a message in struct timespec format */
|
2015-06-02 22:36:17 +02:00
|
|
|
#define MSG_TS(msg) (struct timespec) { \
|
|
|
|
.tv_sec = (msg)->ts.sec, \
|
|
|
|
.tv_nsec = (msg)->ts.nsec \
|
|
|
|
}
|
2014-07-18 16:05:48 +00:00
|
|
|
|
|
|
|
/** This message format is used by all clients
|
2014-07-07 07:53:42 +00:00
|
|
|
*
|
|
|
|
* @diafile msg_format.dia
|
|
|
|
**/
|
|
|
|
struct msg
|
|
|
|
{
|
2017-06-26 07:10:42 +00:00
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
|
|
unsigned rsvd1 : 2; /**< Reserved bits */
|
|
|
|
unsigned type : 2; /**< Data or control message (see MSG_TYPE_*) */
|
|
|
|
unsigned version: 4; /**< Specifies the format of the remaining message (see MGS_VERSION) */
|
|
|
|
#elif BYTE_ORDER == BIG_ENDIAN
|
2015-06-02 22:36:17 +02:00
|
|
|
unsigned version: 4; /**< Specifies the format of the remaining message (see MGS_VERSION) */
|
|
|
|
unsigned type : 2; /**< Data or control message (see MSG_TYPE_*) */
|
2017-04-23 22:11:55 +02:00
|
|
|
unsigned rsvd1 : 2; /**< Reserved bits */
|
2017-06-26 07:10:42 +00:00
|
|
|
#endif
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-06-26 07:10:42 +00:00
|
|
|
uint8_t rsvd2; /**< Reserved bits */
|
2017-04-23 22:11:55 +02:00
|
|
|
uint16_t length; /**< The number of values in msg::data[]. */
|
|
|
|
uint32_t sequence; /**< The sequence number is incremented by one for consecutive messages. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-04-23 22:11:55 +02:00
|
|
|
/** A timestamp per message. */
|
2015-06-02 22:36:17 +02:00
|
|
|
struct {
|
2016-06-08 22:38:21 +02:00
|
|
|
uint32_t sec; /**< Seconds since 1970-01-01 00:00:00 */
|
2015-10-08 10:51:48 +02:00
|
|
|
uint32_t nsec; /**< Nanoseconds of the current second. */
|
2015-06-02 22:36:17 +02:00
|
|
|
} ts;
|
2014-08-31 14:43:28 +00:00
|
|
|
|
2017-04-23 22:11:55 +02:00
|
|
|
/** The message payload. */
|
2014-07-18 16:05:48 +00:00
|
|
|
union {
|
2017-04-23 22:11:55 +02:00
|
|
|
float f; /**< Floating point values. */
|
|
|
|
uint32_t i; /**< Integer values. */
|
2016-01-14 22:59:57 +01:00
|
|
|
} data[];
|
2017-06-26 07:10:42 +00:00
|
|
|
} __attribute__((packed));
|