2023-09-04 12:21:37 +02:00
|
|
|
/* Message format.
|
2014-07-07 07:53:42 +00:00
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
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
|
|
|
|
2019-06-23 16:57:00 +02:00
|
|
|
#include <cstdint>
|
2014-07-07 07:53:42 +00:00
|
|
|
|
2014-07-14 10:47:41 +00:00
|
|
|
// The current version number for the message format
|
2023-09-07 11:46:39 +02:00
|
|
|
#define MSG_VERSION 2
|
2014-07-07 07:53:42 +00:00
|
|
|
|
2023-09-04 18:16:15 +02:00
|
|
|
// TODO: Implement more message types
|
2023-09-07 11:46:39 +02:00
|
|
|
#define MSG_TYPE_DATA 0 // Message contains float / integer 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
|
2014-07-18 16:05:48 +00:00
|
|
|
|
2015-10-09 13:04:52 +02:00
|
|
|
// The total size in bytes of a message
|
2023-09-07 11:46:39 +02:00
|
|
|
#define MSG_LEN(values) (sizeof(struct Message) + MSG_DATA_LEN(values))
|
2016-06-08 22:38:21 +02:00
|
|
|
|
|
|
|
// The length of \p values values in bytes.
|
2023-09-07 11:46:39 +02:00
|
|
|
#define MSG_DATA_LEN(values) (sizeof(float) * (values))
|
2016-06-08 22:38:21 +02:00
|
|
|
|
|
|
|
// The offset to the first data value in a message.
|
2023-09-07 11:46:39 +02:00
|
|
|
#define MSG_DATA_OFFSET(msg) ((char *)(msg) + offsetof(struct Message, data))
|
2016-06-08 22:38:21 +02:00
|
|
|
|
2015-10-09 13:04:52 +02:00
|
|
|
// The timestamp of a message in struct timespec format
|
2023-09-07 11:46:39 +02:00
|
|
|
#define MSG_TS(msg, i) \
|
|
|
|
i.tv_sec = (msg)->ts.sec; \
|
|
|
|
i.tv_nsec = (msg)->ts.nsec;
|
2014-07-18 16:05:48 +00:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
2023-09-04 18:16:15 +02:00
|
|
|
// This message format is used by all clients
|
2023-09-07 11:46:39 +02:00
|
|
|
struct Message {
|
2017-06-29 20:43:03 +02:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2023-09-07 11:46:39 +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_*)
|
|
|
|
unsigned reserved1 : 2; // Reserved bits
|
2017-06-29 20:43:03 +02:00
|
|
|
#elif BYTE_ORDER == LITTLE_ENDIAN
|
2023-09-07 11:46:39 +02:00
|
|
|
unsigned reserved1 : 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)
|
2018-06-29 08:37:14 +02:00
|
|
|
#else
|
2023-09-07 11:46:39 +02:00
|
|
|
#error Invalid byte-order
|
2017-06-26 07:10:42 +00:00
|
|
|
#endif
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
uint8_t source_index; // An id which identifies the source of this sample.
|
|
|
|
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
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// A timestamp per message.
|
|
|
|
struct {
|
|
|
|
uint32_t sec; // Seconds since 1970-01-01 00:00:00
|
|
|
|
uint32_t nsec; // Nanoseconds of the current second
|
|
|
|
} ts;
|
2014-08-31 14:43:28 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// The message payload.
|
|
|
|
union {
|
|
|
|
float f; // Floating point values
|
|
|
|
uint32_t i; // Integer values
|
|
|
|
} data[];
|
2017-06-26 07:10:42 +00:00
|
|
|
} __attribute__((packed));
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|