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
|
|
|
*********************************************************************************/
|
|
|
|
|
2019-06-23 16:57:00 +02:00
|
|
|
#include <cstring>
|
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;
|
2019-06-04 16:55:38 +02:00
|
|
|
using namespace villas::utils;
|
|
|
|
|
2019-01-07 10:28:55 +01:00
|
|
|
int mapping_parse_str(struct mapping_entry *me, const char *str, struct vlist *nodes)
|
2017-03-25 21:11:52 +01:00
|
|
|
{
|
2019-02-18 01:09:33 +01:00
|
|
|
char *cpy, *node, *type, *field, *end, *lasts;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
cpy = strdup(str);
|
|
|
|
if (!cpy)
|
|
|
|
return -1;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-28 12:48:15 +02:00
|
|
|
if (nodes) {
|
2019-02-18 01:09:33 +01:00
|
|
|
node = strtok_r(cpy, ".", &lasts);
|
2018-08-20 18:31:27 +02:00
|
|
|
if (!node) {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Missing node name");
|
2017-08-28 12:48:15 +02:00
|
|
|
goto invalid_format;
|
2018-08-20 18:31:27 +02:00
|
|
|
}
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
me->node = (struct node *) vlist_lookup(nodes, node);
|
2018-08-20 18:31:27 +02:00
|
|
|
if (!me->node) {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Unknown node %s", node);
|
2017-08-28 12:48:15 +02:00
|
|
|
goto invalid_format;
|
2018-08-20 18:31:27 +02:00
|
|
|
}
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
type = strtok_r(nullptr, ".[", &lasts);
|
2017-08-28 12:48:15 +02:00
|
|
|
if (!type)
|
2019-04-07 15:13:40 +02:00
|
|
|
type = strf("data");
|
2017-08-28 12:48:15 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-07 15:13:40 +02:00
|
|
|
me->node = nullptr;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2019-02-18 01:09:33 +01:00
|
|
|
type = strtok_r(cpy, ".[", &lasts);
|
2017-08-28 12:48:15 +02:00
|
|
|
if (!type)
|
|
|
|
goto invalid_format;
|
|
|
|
}
|
2017-03-25 21:11:52 +01:00
|
|
|
|
|
|
|
if (!strcmp(type, "stats")) {
|
2019-06-23 16:13:23 +02:00
|
|
|
me->type = MappingType::STATS;
|
2017-09-23 23:50:45 -06:00
|
|
|
me->length = 1;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
char *metric = strtok_r(nullptr, ".", &lasts);
|
2019-02-15 09:40:38 +01:00
|
|
|
if (!metric)
|
2017-03-25 21:11:52 +01:00
|
|
|
goto invalid_format;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
type = strtok_r(nullptr, ".", &lasts);
|
2019-02-15 09:40:38 +01:00
|
|
|
if (!type)
|
2017-03-25 21:11:52 +01:00
|
|
|
goto invalid_format;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-06-23 13:35:42 +02:00
|
|
|
me->stats.metric = Stats::lookupMetric(metric);
|
|
|
|
me->stats.type = Stats::lookupType(type);
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(type, "hdr")) {
|
2019-06-23 16:13:23 +02:00
|
|
|
me->type = MappingType::HEADER;
|
2017-09-23 23:50:45 -06:00
|
|
|
me->length = 1;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
field = strtok_r(nullptr, ".", &lasts);
|
2018-08-20 18:31:27 +02:00
|
|
|
if (!field) {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Missing header type");
|
2017-03-25 21:11:52 +01:00
|
|
|
goto invalid_format;
|
2018-08-20 18:31:27 +02:00
|
|
|
}
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
if (!strcmp(field, "sequence"))
|
2019-06-23 16:13:23 +02:00
|
|
|
me->header.type = MappingHeaderType::SEQUENCE;
|
2017-03-25 21:11:52 +01:00
|
|
|
else if (!strcmp(field, "length"))
|
2019-06-23 16:13:23 +02:00
|
|
|
me->header.type = MappingHeaderType::LENGTH;
|
2018-08-20 18:31:27 +02:00
|
|
|
else {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Invalid header type");
|
2017-03-25 21:11:52 +01:00
|
|
|
goto invalid_format;
|
2018-08-20 18:31:27 +02:00
|
|
|
}
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(type, "ts")) {
|
2019-06-23 16:13:23 +02:00
|
|
|
me->type = MappingType::TIMESTAMP;
|
2017-09-23 23:50:45 -06:00
|
|
|
me->length = 2;
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
field = strtok_r(nullptr, ".", &lasts);
|
2018-08-20 18:31:27 +02:00
|
|
|
if (!field) {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Missing timestamp type");
|
2017-03-25 21:11:52 +01:00
|
|
|
goto invalid_format;
|
2018-08-20 18:31:27 +02:00
|
|
|
}
|
2017-03-25 21:11:52 +01:00
|
|
|
|
|
|
|
if (!strcmp(field, "origin"))
|
2019-06-23 16:13:23 +02:00
|
|
|
me->timestamp.type = MappingTimestampType::ORIGIN;
|
2017-03-25 21:11:52 +01:00
|
|
|
else if (!strcmp(field, "received"))
|
2019-06-23 16:13:23 +02:00
|
|
|
me->timestamp.type = MappingTimestampType::RECEIVED;
|
2018-08-20 18:31:27 +02:00
|
|
|
else {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Invalid timestamp type");
|
2017-03-25 21:11:52 +01:00
|
|
|
goto invalid_format;
|
2018-08-20 18:31:27 +02:00
|
|
|
}
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(type, "data")) {
|
2018-03-26 14:08:26 +02:00
|
|
|
char *first_str, *last_str;
|
2018-05-24 09:05:42 +02:00
|
|
|
int first = -1, last = -1;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
me->type = MappingType::DATA;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
first_str = strtok_r(nullptr, "-]", &lasts);
|
2017-08-28 12:48:15 +02:00
|
|
|
if (first_str) {
|
2018-05-24 09:05:42 +02:00
|
|
|
if (me->node)
|
2019-02-06 13:11:57 +01:00
|
|
|
first = vlist_lookup_index(&me->node->in.signals, first_str);
|
2017-08-28 12:48:15 +02:00
|
|
|
|
2018-05-24 09:05:42 +02:00
|
|
|
if (first < 0) {
|
|
|
|
char *endptr;
|
|
|
|
first = strtoul(first_str, &endptr, 10);
|
2018-08-20 18:31:27 +02:00
|
|
|
if (endptr != first_str + strlen(first_str)) {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Failed to parse data range");
|
2018-05-24 09:05:42 +02:00
|
|
|
goto invalid_format;
|
2018-08-20 18:31:27 +02:00
|
|
|
}
|
2018-05-24 09:05:42 +02:00
|
|
|
}
|
2017-08-28 12:48:15 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-08-20 18:31:27 +02:00
|
|
|
/* Map all signals */
|
2017-09-23 23:50:45 -06:00
|
|
|
me->data.offset = 0;
|
2019-03-09 00:32:22 +01:00
|
|
|
me->length = -1;
|
2018-05-24 09:05:42 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2019-04-07 15:13:40 +02:00
|
|
|
last_str = strtok_r(nullptr, "]", &lasts);
|
2018-05-24 09:05:42 +02:00
|
|
|
if (last_str) {
|
|
|
|
if (me->node)
|
2019-02-06 13:11:57 +01:00
|
|
|
last = vlist_lookup_index(&me->node->in.signals, last_str);
|
2018-05-24 09:05:42 +02:00
|
|
|
|
|
|
|
if (last < 0) {
|
|
|
|
char *endptr;
|
|
|
|
last = strtoul(last_str, &endptr, 10);
|
2018-08-20 18:31:27 +02:00
|
|
|
if (endptr != last_str + strlen(last_str)) {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Failed to parse data range");
|
2018-05-24 09:05:42 +02:00
|
|
|
goto invalid_format;
|
2018-08-20 18:31:27 +02:00
|
|
|
}
|
2018-05-24 09:05:42 +02:00
|
|
|
}
|
2017-08-28 12:48:15 +02:00
|
|
|
}
|
2018-05-24 09:05:42 +02:00
|
|
|
else
|
|
|
|
last = first; /* single element: data[5] => data[5-5] */
|
|
|
|
|
|
|
|
if (last < first)
|
|
|
|
goto invalid_format;
|
|
|
|
|
|
|
|
me->data.offset = first;
|
|
|
|
me->length = last - first + 1;
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
goto invalid_format;
|
|
|
|
|
2018-05-24 09:05:42 +02:00
|
|
|
end: /* Check that there is no garbage at the end */
|
2019-04-07 15:13:40 +02:00
|
|
|
end = strtok_r(nullptr, "", &lasts);
|
2017-08-28 12:48:15 +02:00
|
|
|
if (end)
|
|
|
|
goto invalid_format;
|
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
free(cpy);
|
2017-08-28 12:48:15 +02:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
invalid_format:
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
free(cpy);
|
2017-08-28 12:48:15 +02:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-01-07 10:28:55 +01:00
|
|
|
int mapping_parse(struct mapping_entry *me, json_t *cfg, struct vlist *nodes)
|
2017-03-25 21:11:52 +01:00
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
2018-08-20 18:31:27 +02:00
|
|
|
str = json_string_value(cfg);
|
2017-03-25 21:11:52 +01:00
|
|
|
if (!str)
|
|
|
|
return -1;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-09-23 23:50:45 -06:00
|
|
|
return mapping_parse_str(me, str, nodes);
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
|
|
|
|
2019-03-09 00:32:22 +01:00
|
|
|
int mapping_list_parse(struct vlist *ml, json_t *cfg, struct vlist *nodes)
|
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;
|
|
|
|
|
|
|
|
if (json_is_string(cfg)) {
|
|
|
|
json_mapping = json_array();
|
|
|
|
json_array_append(json_mapping, cfg);
|
|
|
|
}
|
|
|
|
else if (json_is_array(cfg))
|
2017-09-05 01:07:11 +02:00
|
|
|
json_mapping = json_incref(cfg);
|
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
|
|
|
|
2018-08-02 10:50:23 +02:00
|
|
|
ret = mapping_parse(me, json_entry, nodes);
|
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;
|
|
|
|
}
|
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
|
|
|
|
2019-03-09 00:32:22 +01:00
|
|
|
int mapping_list_prepare(struct vlist *ml)
|
|
|
|
{
|
|
|
|
for (size_t i = 0, off = 0; i < vlist_length(ml); i++) {
|
|
|
|
struct mapping_entry *me = (struct mapping_entry *) vlist_at(ml, i);
|
|
|
|
|
|
|
|
if (me->length < 0) {
|
2019-06-23 16:13:23 +02:00
|
|
|
struct vlist *sigs = node_get_signals(me->node, NodeDir::IN);
|
2019-03-09 00:32:22 +01:00
|
|
|
|
|
|
|
me->length = vlist_length(sigs);
|
|
|
|
}
|
|
|
|
|
|
|
|
me->offset = off;
|
|
|
|
off += me->length;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:08:23 +02:00
|
|
|
int mapping_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:
|
2019-02-06 13:11:57 +01:00
|
|
|
if (me->node && index < vlist_length(&me->node->in.signals)) {
|
2019-04-07 15:13:40 +02:00
|
|
|
struct signal *s = (struct signal *) vlist_at(&me->node->in.signals, index);
|
2018-08-02 10:46:03 +02:00
|
|
|
|
|
|
|
strcatf(str, "data[%s]", s->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcatf(str, "data[%u]", index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|