2021-08-10 10:12:48 -04:00
|
|
|
/* Sample value remapping for path source muxing.
|
2017-03-25 21:11:52 +01: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
|
2017-03-25 21:11:52 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-08-03 00:19:27 +02:00
|
|
|
#include <jansson.h>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <memory>
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2020-03-04 12:41:55 +01:00
|
|
|
#include <villas/common.hpp>
|
2021-06-21 16:12:47 -04:00
|
|
|
#include <villas/node_list.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/stats.hpp>
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
#define RE_MAPPING_INDEX "[a-zA-Z0-9_]+"
|
|
|
|
#define RE_MAPPING_RANGE "(" RE_MAPPING_INDEX ")(?:-(" RE_MAPPING_INDEX "))?"
|
|
|
|
|
|
|
|
#define RE_MAPPING_STATS "stats\\.([a-z]+)\\.([a-z]+)"
|
|
|
|
#define RE_MAPPING_HDR "hdr\\.(sequence|length)"
|
|
|
|
#define RE_MAPPING_TS "ts\\.(origin|received)"
|
|
|
|
#define RE_MAPPING_DATA1 "data\\[" RE_MAPPING_RANGE "\\]"
|
|
|
|
#define RE_MAPPING_DATA2 "(?:data\\.)?(" RE_MAPPING_INDEX ")"
|
|
|
|
#define RE_MAPPING \
|
|
|
|
"(?:(" RE_NODE_NAME ")\\.(?:" RE_MAPPING_STATS "|" RE_MAPPING_HDR \
|
|
|
|
"|" RE_MAPPING_TS "|" RE_MAPPING_DATA1 "|" RE_MAPPING_DATA2 \
|
|
|
|
")|(" RE_NODE_NAME ")(?:\\[" RE_MAPPING_RANGE "\\])?)"
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
// Forward declarations
|
2021-08-10 10:12:48 -04:00
|
|
|
class Node;
|
|
|
|
struct Sample;
|
|
|
|
class Signal;
|
2018-08-06 10:10:17 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
class MappingEntry {
|
2018-08-06 10:10:17 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
public:
|
|
|
|
using Ptr = std::shared_ptr<MappingEntry>;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
enum class Type { UNKNOWN, DATA, STATS, HEADER, TIMESTAMP };
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
enum class HeaderType { LENGTH, SEQUENCE };
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
enum class TimestampType { ORIGIN, RECEIVED };
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
Node *node; // The node to which this mapping refers.
|
|
|
|
enum Type type; // The mapping type. Selects one of the union fields below.
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2018-08-06 10:10:17 +02:00
|
|
|
/* The number of values which is covered by this mapping entry.
|
|
|
|
*
|
|
|
|
* A value of 0 indicates that all remaining values starting from the offset of a sample should be mapped.
|
|
|
|
*/
|
|
|
|
int length;
|
2021-05-10 00:12:30 +02:00
|
|
|
unsigned offset; // Offset of this mapping entry within sample::data
|
2017-03-25 21:11:52 +01:00
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int offset;
|
2021-08-10 10:12:48 -04:00
|
|
|
Signal *signal;
|
2020-09-10 11:15:33 +02:00
|
|
|
|
2020-09-10 13:22:33 +02:00
|
|
|
char *first;
|
|
|
|
char *last;
|
2017-03-25 21:11:52 +01:00
|
|
|
} data;
|
2017-08-28 14:35:50 +02:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
struct {
|
2021-08-10 10:12:48 -04:00
|
|
|
enum Stats::Metric metric;
|
|
|
|
enum Stats::Type type;
|
2017-03-25 21:11:52 +01:00
|
|
|
} stats;
|
2017-08-28 14:35:50 +02:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
struct {
|
2021-08-10 10:12:48 -04:00
|
|
|
enum HeaderType type;
|
2018-08-06 10:10:17 +02:00
|
|
|
} header;
|
2017-08-28 14:35:50 +02:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
struct {
|
2021-08-10 10:12:48 -04:00
|
|
|
enum TimestampType type;
|
2018-08-06 10:10:17 +02:00
|
|
|
} timestamp;
|
2017-03-25 21:11:52 +01:00
|
|
|
};
|
2020-09-10 11:15:33 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
std::string nodeName; // Used for between parse and prepare only.
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
MappingEntry();
|
2020-09-10 13:22:33 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int prepare(NodeList &nodes);
|
2020-09-10 13:22:33 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int update(struct Sample *remapped, const struct Sample *original) const;
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int parse(json_t *json);
|
2017-08-31 09:42:36 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int parseString(const std::string &str);
|
2018-08-02 10:46:03 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
std::string toString(unsigned index) const;
|
2019-03-09 00:32:22 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
Signal::Ptr toSignal(unsigned index) const;
|
|
|
|
};
|
2019-03-09 00:32:22 +01:00
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|