2017-03-25 21:11:52 +01:00
|
|
|
/** Sample value remapping for mux.
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2020-01-20 17:17:00 +01:00
|
|
|
* @copyright 2014-2020, 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/>.
|
2017-03-25 21:11:52 +01:00
|
|
|
*********************************************************************************/
|
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
#include <regex>
|
|
|
|
#include <iostream>
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2017-12-09 02:19:28 +08:00
|
|
|
#include <villas/mapping.h>
|
|
|
|
#include <villas/sample.h>
|
|
|
|
#include <villas/list.h>
|
2019-04-23 13:09:50 +02:00
|
|
|
#include <villas/utils.hpp>
|
2020-07-04 16:22:10 +02:00
|
|
|
#include <villas/exceptions.hpp>
|
2017-12-09 02:19:28 +08:00
|
|
|
#include <villas/node.h>
|
2018-03-26 14:08:26 +02:00
|
|
|
#include <villas/signal.h>
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2019-06-23 13:35:42 +02:00
|
|
|
using namespace villas;
|
2021-06-21 16:12:47 -04:00
|
|
|
using namespace villas::node;
|
2019-06-04 16:55:38 +02:00
|
|
|
using namespace villas::utils;
|
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
int mapping_entry_parse_str(struct mapping_entry *me, const std::string &str)
|
2017-03-25 21:11:52 +01:00
|
|
|
{
|
2020-09-10 11:15:33 +02:00
|
|
|
std::smatch mr;
|
|
|
|
std::regex re(RE_MAPPING);
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
if (!std::regex_match(str, mr, re))
|
|
|
|
goto invalid_format;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
if (mr[1].matched)
|
|
|
|
me->node_name = strdup(mr.str(1).c_str());
|
2020-09-10 13:22:33 +02:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
if (mr[9].matched)
|
|
|
|
me->node_name = strdup(mr.str(9).c_str());
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
if (mr[6].matched) {
|
|
|
|
me->data.first = strdup(mr.str(6).c_str());
|
2020-09-10 13:22:33 +02:00
|
|
|
me->data.last = mr[7].matched
|
|
|
|
? strdup(mr.str(7).c_str())
|
|
|
|
: nullptr;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
me->type = MappingType::DATA;
|
2017-08-28 12:48:15 +02:00
|
|
|
}
|
2020-09-10 11:15:33 +02:00
|
|
|
else if (mr[10].matched) {
|
|
|
|
me->data.first = strdup(mr.str(10).c_str());
|
2020-09-10 13:22:33 +02:00
|
|
|
me->data.last = mr[11].matched
|
|
|
|
? strdup(mr.str(11).c_str())
|
|
|
|
: nullptr;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
me->type = MappingType::DATA;
|
2017-08-28 12:48:15 +02:00
|
|
|
}
|
2020-09-10 11:15:33 +02:00
|
|
|
else if (mr[8].matched) {
|
|
|
|
me->data.first = strdup(mr.str(8).c_str());
|
2020-09-10 13:22:33 +02:00
|
|
|
me->data.last = nullptr;
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
me->type = MappingType::DATA;
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
2020-09-10 11:15:33 +02:00
|
|
|
else if (mr[2].matched) {
|
|
|
|
me->stats.type = Stats::lookupType(mr.str(3));
|
|
|
|
me->stats.metric = Stats::lookupMetric(mr.str(2));
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
me->type = MappingType::STATS;
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
2020-09-10 11:15:33 +02:00
|
|
|
else if (mr[5].matched) {
|
|
|
|
if (mr.str(5) == "origin")
|
2019-06-23 16:13:23 +02:00
|
|
|
me->timestamp.type = MappingTimestampType::ORIGIN;
|
2020-09-10 11:15:33 +02:00
|
|
|
else if (mr.str(5) == "received")
|
2019-06-23 16:13:23 +02:00
|
|
|
me->timestamp.type = MappingTimestampType::RECEIVED;
|
2020-09-10 11:15:33 +02:00
|
|
|
else
|
2017-03-25 21:11:52 +01:00
|
|
|
goto invalid_format;
|
2018-05-24 09:05:42 +02:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
me->type = MappingType::TIMESTAMP;
|
|
|
|
}
|
|
|
|
else if (mr[4].matched) {
|
|
|
|
if (mr.str(4) == "sequence")
|
|
|
|
me->header.type = MappingHeaderType::SEQUENCE;
|
|
|
|
else if (mr.str(4) == "length")
|
|
|
|
me->header.type = MappingHeaderType::LENGTH;
|
2018-05-24 09:05:42 +02:00
|
|
|
else
|
|
|
|
goto invalid_format;
|
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
me->type = MappingType::HEADER;
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
2020-09-10 11:15:33 +02:00
|
|
|
/* Only node name given.. We map all data */
|
|
|
|
else if (me->node_name) {
|
|
|
|
me->data.first = nullptr;
|
|
|
|
me->data.last = nullptr;
|
2017-08-28 12:48:15 +02:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
me->type = MappingType::DATA;
|
|
|
|
}
|
2017-08-28 12:48:15 +02:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
invalid_format:
|
2020-09-10 13:22:33 +02:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
throw RuntimeError("Failed to parse mapping expression: {}", str);
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
|
|
|
|
2020-09-10 13:22:33 +02:00
|
|
|
int mapping_entry_init(struct mapping_entry *me)
|
|
|
|
{
|
|
|
|
me->type = MappingType::UNKNOWN;
|
|
|
|
|
|
|
|
me->node = nullptr;
|
|
|
|
me->node_name = nullptr;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mapping_entry_destroy(struct mapping_entry *me)
|
|
|
|
{
|
|
|
|
if (me->node_name)
|
|
|
|
free(me->node_name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-16 14:15:14 +01:00
|
|
|
int mapping_entry_parse(struct mapping_entry *me, json_t *json)
|
2017-03-25 21:11:52 +01:00
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
2021-02-16 14:15:14 +01:00
|
|
|
str = json_string_value(json);
|
2017-03-25 21:11:52 +01:00
|
|
|
if (!str)
|
|
|
|
return -1;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
return mapping_entry_parse_str(me, str);
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 14:15:14 +01:00
|
|
|
int mapping_list_parse(struct vlist *ml, json_t *json)
|
2017-08-31 09:42:36 +02:00
|
|
|
{
|
2019-03-09 00:32:22 +01:00
|
|
|
int ret;
|
2017-08-31 09:42:36 +02:00
|
|
|
|
|
|
|
size_t i;
|
|
|
|
json_t *json_entry;
|
|
|
|
json_t *json_mapping;
|
|
|
|
|
2021-02-16 14:15:14 +01:00
|
|
|
if (json_is_string(json)) {
|
2017-08-31 09:42:36 +02:00
|
|
|
json_mapping = json_array();
|
2021-02-16 14:15:14 +01:00
|
|
|
json_array_append(json_mapping, json);
|
2017-08-31 09:42:36 +02:00
|
|
|
}
|
2021-02-16 14:15:14 +01:00
|
|
|
else if (json_is_array(json))
|
|
|
|
json_mapping = json_incref(json);
|
2017-08-31 09:42:36 +02:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
json_array_foreach(json_mapping, i, json_entry) {
|
2020-01-21 16:26:51 +01:00
|
|
|
auto *me = new struct mapping_entry;
|
2020-07-04 16:22:10 +02:00
|
|
|
if (!me)
|
|
|
|
throw MemoryAllocationError();
|
2017-08-31 09:42:36 +02:00
|
|
|
|
2020-09-10 13:22:33 +02:00
|
|
|
ret = mapping_entry_init(me);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
ret = mapping_entry_parse(me, json_entry);
|
2017-08-31 09:42:36 +02:00
|
|
|
if (ret)
|
2017-09-05 01:07:11 +02:00
|
|
|
goto out;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2019-03-09 00:32:22 +01:00
|
|
|
vlist_push(ml, me);
|
2017-08-31 09:42:36 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 01:07:11 +02:00
|
|
|
ret = 0;
|
|
|
|
|
2018-08-02 10:50:23 +02:00
|
|
|
out: json_decref(json_mapping);
|
2017-09-05 01:07:11 +02:00
|
|
|
|
|
|
|
return ret;
|
2017-08-31 09:42:36 +02:00
|
|
|
}
|
|
|
|
|
2019-03-09 00:32:22 +01:00
|
|
|
int mapping_update(const struct mapping_entry *me, struct sample *remapped, const struct sample *original)
|
2017-03-25 21:11:52 +01:00
|
|
|
{
|
2019-04-07 15:13:40 +02:00
|
|
|
unsigned len = me->length;
|
|
|
|
|
|
|
|
if (me->offset + len > remapped->capacity)
|
2017-08-30 23:52:32 +02:00
|
|
|
return -1;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
switch (me->type) {
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingType::STATS:
|
2019-06-23 13:35:42 +02:00
|
|
|
remapped->data[me->offset] = me->node->stats->getValue(me->stats.metric, me->stats.type);
|
2019-02-15 09:40:38 +01:00
|
|
|
break;
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingType::TIMESTAMP: {
|
2018-08-06 11:08:23 +02:00
|
|
|
const struct timespec *ts;
|
2017-08-30 23:52:32 +02:00
|
|
|
|
2018-08-06 10:10:17 +02:00
|
|
|
switch (me->timestamp.type) {
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingTimestampType::RECEIVED:
|
2017-08-30 23:52:32 +02:00
|
|
|
ts = &original->ts.received;
|
|
|
|
break;
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingTimestampType::ORIGIN:
|
2017-08-30 23:52:32 +02:00
|
|
|
ts = &original->ts.origin;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2019-03-09 00:32:22 +01:00
|
|
|
remapped->data[me->offset + 0].i = ts->tv_sec;
|
|
|
|
remapped->data[me->offset + 1].i = ts->tv_nsec;
|
2017-08-28 14:35:50 +02:00
|
|
|
break;
|
2017-08-30 23:52:32 +02:00
|
|
|
}
|
2017-08-28 14:35:50 +02:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingType::HEADER:
|
2018-08-06 10:10:17 +02:00
|
|
|
switch (me->header.type) {
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingHeaderType::LENGTH:
|
2019-03-09 00:32:22 +01:00
|
|
|
remapped->data[me->offset].i = original->length;
|
2017-08-30 23:52:32 +02:00
|
|
|
break;
|
2019-03-09 00:32:22 +01:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingHeaderType::SEQUENCE:
|
2019-03-09 00:32:22 +01:00
|
|
|
remapped->data[me->offset].i = original->sequence;
|
2017-08-30 23:52:32 +02:00
|
|
|
break;
|
2019-03-09 00:32:22 +01:00
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
default:
|
|
|
|
return -1;
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
2017-08-30 23:52:32 +02:00
|
|
|
break;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingType::DATA:
|
2019-04-07 15:13:40 +02:00
|
|
|
for (unsigned j = me->data.offset,
|
|
|
|
i = me->offset;
|
|
|
|
j < MIN(original->length, (unsigned) (me->data.offset + me->length));
|
|
|
|
j++,
|
|
|
|
i++)
|
|
|
|
{
|
2018-08-20 18:31:27 +02:00
|
|
|
if (j >= original->length)
|
2019-03-09 00:32:22 +01:00
|
|
|
remapped->data[i].f = -1;
|
2018-08-20 18:31:27 +02:00
|
|
|
else
|
2019-03-09 00:32:22 +01:00
|
|
|
remapped->data[i] = original->data[j];
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
len = MIN((unsigned) me->length, original->length - me->data.offset);
|
2017-08-30 23:52:32 +02:00
|
|
|
break;
|
2020-09-10 13:22:33 +02:00
|
|
|
|
|
|
|
case MappingType::UNKNOWN:
|
|
|
|
return -1;
|
2017-08-30 23:52:32 +02:00
|
|
|
}
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
if (me->offset + len > remapped->length)
|
|
|
|
remapped->length = me->offset + len;
|
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-08-28 14:35:50 +02:00
|
|
|
|
2019-03-09 00:32:22 +01:00
|
|
|
int mapping_list_remap(const struct vlist *ml, struct sample *remapped, const struct sample *original)
|
2017-08-30 23:52:32 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2017-08-28 14:35:50 +02:00
|
|
|
|
2019-03-09 00:32:22 +01:00
|
|
|
for (size_t i = 0; i < vlist_length(ml); i++) {
|
|
|
|
struct mapping_entry *me = (struct mapping_entry *) vlist_at(ml, i);
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-03-09 00:32:22 +01:00
|
|
|
ret = mapping_update(me, remapped, original);
|
2017-08-30 23:52:32 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-09-02 14:20:38 +02:00
|
|
|
}
|
2018-08-02 10:46:03 +02:00
|
|
|
|
2021-06-21 16:12:47 -04:00
|
|
|
int mapping_entry_prepare(struct mapping_entry *me, NodeList &nodes)
|
2019-03-09 00:32:22 +01:00
|
|
|
{
|
2020-09-10 11:15:33 +02:00
|
|
|
if (me->node_name && me->node == nullptr) {
|
2021-06-21 16:12:47 -04:00
|
|
|
me->node = nodes.lookup(me->node_name);
|
2020-09-10 11:15:33 +02:00
|
|
|
if (!me->node)
|
|
|
|
throw RuntimeError("Invalid node name in mapping: {}", me->node_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (me->type == MappingType::DATA) {
|
|
|
|
int first = -1, last = -1;
|
|
|
|
|
|
|
|
if (me->data.first) {
|
|
|
|
if (me->node)
|
2021-06-24 06:23:58 -04:00
|
|
|
first = vlist_lookup_index<struct signal>(node_input_signals(me->node), me->data.first);
|
2020-09-10 11:15:33 +02:00
|
|
|
|
|
|
|
if (first < 0) {
|
|
|
|
char *endptr;
|
|
|
|
first = strtoul(me->data.first, &endptr, 10);
|
|
|
|
if (endptr != me->data.first + strlen(me->data.first))
|
|
|
|
throw RuntimeError("Failed to parse data index in mapping: {}", me->data.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Map all signals */
|
|
|
|
me->data.offset = 0;
|
|
|
|
me->length = -1;
|
|
|
|
goto end;
|
|
|
|
}
|
2019-03-09 00:32:22 +01:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
if (me->data.last) {
|
|
|
|
if (me->node)
|
2021-06-24 06:23:58 -04:00
|
|
|
last = vlist_lookup_index<struct signal>(node_input_signals(me->node), me->data.last);
|
2019-03-09 00:32:22 +01:00
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
if (last < 0) {
|
|
|
|
char *endptr;
|
|
|
|
last = strtoul(me->data.last, &endptr, 10);
|
|
|
|
if (endptr != me->data.last + strlen(me->data.last))
|
|
|
|
throw RuntimeError("Failed to parse data index in mapping: {}", me->data.last);
|
|
|
|
}
|
2019-03-09 00:32:22 +01:00
|
|
|
}
|
2020-09-10 11:15:33 +02:00
|
|
|
else
|
|
|
|
last = first; /* single element: data[5] => data[5-5] */
|
|
|
|
|
|
|
|
if (last < first)
|
|
|
|
throw RuntimeError("Invalid data range indices for mapping: {} < {}", last, first);
|
|
|
|
|
|
|
|
me->data.offset = first;
|
|
|
|
me->length = last - first + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (me->length < 0) {
|
2020-10-21 20:56:51 +02:00
|
|
|
struct vlist *sigs = node_input_signals(me->node);
|
2020-09-10 11:15:33 +02:00
|
|
|
|
|
|
|
me->length = vlist_length(sigs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-21 16:12:47 -04:00
|
|
|
int mapping_list_prepare(struct vlist *ml, NodeList &nodes)
|
2020-09-10 11:15:33 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
for (size_t i = 0, off = 0; i < vlist_length(ml); i++) {
|
|
|
|
struct mapping_entry *me = (struct mapping_entry *) vlist_at(ml, i);
|
|
|
|
|
|
|
|
ret = mapping_entry_prepare(me, nodes);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-03-09 00:32:22 +01:00
|
|
|
|
|
|
|
me->offset = off;
|
|
|
|
off += me->length;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-10 11:15:33 +02:00
|
|
|
int mapping_entry_to_str(const struct mapping_entry *me, unsigned index, char **str)
|
2018-08-02 10:46:03 +02:00
|
|
|
{
|
|
|
|
const char *type;
|
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
assert(me->length == 0 || (int) index < me->length);
|
2018-08-02 10:46:03 +02:00
|
|
|
|
|
|
|
if (me->node)
|
2018-08-20 18:31:27 +02:00
|
|
|
strcatf(str, "%s.", node_name_short(me->node));
|
2018-08-02 10:46:03 +02:00
|
|
|
|
|
|
|
switch (me->type) {
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingType::STATS:
|
2019-02-15 09:40:38 +01:00
|
|
|
strcatf(str, "stats.%s.%s",
|
2019-06-23 13:35:42 +02:00
|
|
|
Stats::metrics[me->stats.metric].name,
|
|
|
|
Stats::types[me->stats.type].name
|
2019-02-15 09:40:38 +01:00
|
|
|
);
|
2018-08-02 10:46:03 +02:00
|
|
|
break;
|
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingType::HEADER:
|
2018-08-06 10:10:17 +02:00
|
|
|
switch (me->header.type) {
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingHeaderType::LENGTH:
|
2018-10-21 22:37:49 +01:00
|
|
|
type = "length";
|
|
|
|
break;
|
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingHeaderType::SEQUENCE:
|
2018-10-21 22:37:49 +01:00
|
|
|
type = "sequence";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-04-07 15:13:40 +02:00
|
|
|
type = nullptr;
|
2018-08-02 10:46:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
strcatf(str, "hdr.%s", type);
|
|
|
|
break;
|
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingType::TIMESTAMP:
|
2018-08-06 10:10:17 +02:00
|
|
|
switch (me->timestamp.type) {
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingTimestampType::ORIGIN:
|
2018-10-21 22:37:49 +01:00
|
|
|
type = "origin";
|
|
|
|
break;
|
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingTimestampType::RECEIVED:
|
2018-10-21 22:37:49 +01:00
|
|
|
type = "received";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-04-07 15:13:40 +02:00
|
|
|
type = nullptr;
|
2018-08-02 10:46:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
strcatf(str, "ts.%s.%s", type, index == 0 ? "sec" : "nsec");
|
|
|
|
break;
|
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
case MappingType::DATA:
|
2021-06-24 06:23:58 -04:00
|
|
|
if (me->node && index < vlist_length(node_input_signals(me->node))) {
|
|
|
|
struct signal *s = (struct signal *) vlist_at(node_input_signals(me->node), index);
|
2018-08-02 10:46:03 +02:00
|
|
|
|
|
|
|
strcatf(str, "data[%s]", s->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcatf(str, "data[%u]", index);
|
|
|
|
break;
|
2020-09-10 13:22:33 +02:00
|
|
|
|
|
|
|
case MappingType::UNKNOWN:
|
|
|
|
return -1;
|
2018-08-02 10:46:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|