2017-03-25 21:11:52 +01:00
|
|
|
/** Sample value remapping for mux.
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2018-08-20 18:39:04 +02:00
|
|
|
* @copyright 2017-2018, 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
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-12-09 02:19:28 +08:00
|
|
|
#include <villas/mapping.h>
|
|
|
|
#include <villas/stats.h>
|
|
|
|
#include <villas/sample.h>
|
|
|
|
#include <villas/list.h>
|
|
|
|
#include <villas/utils.h>
|
|
|
|
#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-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
|
|
|
{
|
2017-07-24 15:30:47 +02:00
|
|
|
int id;
|
2017-08-28 12:48:15 +02:00
|
|
|
char *cpy, *node, *type, *field, *subfield, *end;
|
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) {
|
|
|
|
node = strtok(cpy, ".");
|
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-01-07 10:28:55 +01:00
|
|
|
me->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
|
|
|
|
2017-08-28 12:48:15 +02:00
|
|
|
type = strtok(NULL, ".[");
|
|
|
|
if (!type)
|
|
|
|
type = "data";
|
|
|
|
}
|
|
|
|
else {
|
2017-09-23 23:50:45 -06:00
|
|
|
me->node = NULL;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-28 12:48:15 +02:00
|
|
|
type = strtok(cpy, ".[");
|
|
|
|
if (!type)
|
|
|
|
goto invalid_format;
|
|
|
|
}
|
2017-03-25 21:11:52 +01:00
|
|
|
|
|
|
|
if (!strcmp(type, "stats")) {
|
2017-09-23 23:50:45 -06:00
|
|
|
me->type = MAPPING_TYPE_STATS;
|
|
|
|
me->length = 1;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
field = strtok(NULL, ".");
|
2018-08-20 18:31:27 +02:00
|
|
|
if (!field) {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Missing stats 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
|
|
|
subfield = strtok(NULL, ".");
|
2018-08-20 18:31:27 +02:00
|
|
|
if (!subfield) {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Missing stats sub-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-07-24 15:30:47 +02:00
|
|
|
id = stats_lookup_id(field);
|
2018-08-20 18:31:27 +02:00
|
|
|
if (id < 0) {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Invalid stats 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-09-23 23:50:45 -06:00
|
|
|
me->stats.id = id;
|
2017-07-24 15:30:47 +02:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
if (!strcmp(subfield, "total"))
|
2017-09-23 23:50:45 -06:00
|
|
|
me->stats.type = MAPPING_STATS_TYPE_TOTAL;
|
2017-03-25 21:11:52 +01:00
|
|
|
else if (!strcmp(subfield, "last"))
|
2017-09-23 23:50:45 -06:00
|
|
|
me->stats.type = MAPPING_STATS_TYPE_LAST;
|
2017-03-25 21:11:52 +01:00
|
|
|
else if (!strcmp(subfield, "lowest"))
|
2017-09-23 23:50:45 -06:00
|
|
|
me->stats.type = MAPPING_STATS_TYPE_LOWEST;
|
2017-03-25 21:11:52 +01:00
|
|
|
else if (!strcmp(subfield, "highest"))
|
2017-09-23 23:50:45 -06:00
|
|
|
me->stats.type = MAPPING_STATS_TYPE_HIGHEST;
|
2017-03-25 21:11:52 +01:00
|
|
|
else if (!strcmp(subfield, "mean"))
|
2017-09-23 23:50:45 -06:00
|
|
|
me->stats.type = MAPPING_STATS_TYPE_MEAN;
|
2017-03-25 21:11:52 +01:00
|
|
|
else if (!strcmp(subfield, "var"))
|
2017-09-23 23:50:45 -06:00
|
|
|
me->stats.type = MAPPING_STATS_TYPE_VAR;
|
2017-03-25 21:11:52 +01:00
|
|
|
else if (!strcmp(subfield, "stddev"))
|
2017-09-23 23:50:45 -06:00
|
|
|
me->stats.type = MAPPING_STATS_TYPE_STDDEV;
|
2018-08-20 18:31:27 +02:00
|
|
|
else {
|
2018-10-21 21:36:08 +01:00
|
|
|
warning("Invalid stats sub-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, "hdr")) {
|
2018-08-06 10:10:17 +02:00
|
|
|
me->type = MAPPING_TYPE_HEADER;
|
2017-09-23 23:50:45 -06:00
|
|
|
me->length = 1;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
field = strtok(NULL, ".");
|
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"))
|
2018-08-06 10:10:17 +02:00
|
|
|
me->header.type = MAPPING_HEADER_TYPE_SEQUENCE;
|
2017-03-25 21:11:52 +01:00
|
|
|
else if (!strcmp(field, "length"))
|
2018-08-06 10:10:17 +02:00
|
|
|
me->header.type = MAPPING_HEADER_TYPE_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")) {
|
2018-08-06 10:10:17 +02:00
|
|
|
me->type = MAPPING_TYPE_TIMESTAMP;
|
2017-09-23 23:50:45 -06:00
|
|
|
me->length = 2;
|
2017-03-25 21:11:52 +01:00
|
|
|
|
|
|
|
field = strtok(NULL, ".");
|
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"))
|
2018-08-06 10:10:17 +02:00
|
|
|
me->timestamp.type = MAPPING_TIMESTAMP_TYPE_ORIGIN;
|
2017-03-25 21:11:52 +01:00
|
|
|
else if (!strcmp(field, "received"))
|
2018-08-06 10:10:17 +02:00
|
|
|
me->timestamp.type = MAPPING_TIMESTAMP_TYPE_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
|
|
|
|
2017-09-23 23:50:45 -06:00
|
|
|
me->type = MAPPING_TYPE_DATA;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-03-25 21:11:52 +01:00
|
|
|
first_str = strtok(NULL, "-]");
|
2017-08-28 12:48:15 +02:00
|
|
|
if (first_str) {
|
2018-05-24 09:05:42 +02:00
|
|
|
if (me->node)
|
2019-01-07 10:28:55 +01:00
|
|
|
first = vlist_lookup_index(&me->node->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-01-07 10:28:55 +01:00
|
|
|
me->length = me->node ? vlist_length(&me->node->signals) : 0;
|
2018-05-24 09:05:42 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_str = strtok(NULL, "]");
|
|
|
|
if (last_str) {
|
|
|
|
if (me->node)
|
2019-01-07 10:28:55 +01:00
|
|
|
last = vlist_lookup_index(&me->node->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 */
|
2017-08-28 12:48:15 +02:00
|
|
|
end = strtok(NULL, "");
|
|
|
|
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-01-07 10:28:55 +01:00
|
|
|
int mapping_parse_list(struct vlist *l, json_t *cfg, struct vlist *nodes)
|
2017-08-31 09:42:36 +02:00
|
|
|
{
|
2017-08-31 11:31:09 +02:00
|
|
|
int ret, off;
|
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;
|
|
|
|
|
|
|
|
off = 0;
|
|
|
|
json_array_foreach(json_mapping, i, json_entry) {
|
2018-08-02 10:50:23 +02:00
|
|
|
struct mapping_entry *me = (struct mapping_entry *) alloc(sizeof(struct mapping_entry));
|
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
|
|
|
|
2018-08-02 10:50:23 +02:00
|
|
|
me->offset = off;
|
|
|
|
off += me->length;
|
2017-08-31 09:42:36 +02:00
|
|
|
|
2019-01-07 10:28:55 +01:00
|
|
|
vlist_push(l, 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
|
|
|
}
|
|
|
|
|
2018-08-06 11:08:23 +02:00
|
|
|
int mapping_update(const struct mapping_entry *me, struct sample *remapped, const struct sample *original, const struct stats *s)
|
2017-03-25 21:11:52 +01:00
|
|
|
{
|
2017-08-30 23:52:32 +02:00
|
|
|
int len = me->length;
|
|
|
|
int off = me->offset;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
/* me->length == 0 means that we want to take all values */
|
|
|
|
if (!len)
|
|
|
|
len = original->length;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
if (len + off > remapped->capacity)
|
|
|
|
return -1;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
switch (me->type) {
|
|
|
|
case MAPPING_TYPE_STATS: {
|
2018-08-06 11:08:23 +02:00
|
|
|
const struct hist *h = &s->histograms[me->stats.id];
|
2017-08-30 23:52:32 +02:00
|
|
|
|
|
|
|
switch (me->stats.type) {
|
|
|
|
case MAPPING_STATS_TYPE_TOTAL:
|
2018-08-20 18:31:27 +02:00
|
|
|
remapped->data[off++].i = h->total;
|
2017-08-30 23:52:32 +02:00
|
|
|
break;
|
|
|
|
case MAPPING_STATS_TYPE_LAST:
|
|
|
|
remapped->data[off++].f = h->last;
|
|
|
|
break;
|
|
|
|
case MAPPING_STATS_TYPE_HIGHEST:
|
|
|
|
remapped->data[off++].f = h->highest;
|
|
|
|
break;
|
|
|
|
case MAPPING_STATS_TYPE_LOWEST:
|
|
|
|
remapped->data[off++].f = h->lowest;
|
|
|
|
break;
|
|
|
|
case MAPPING_STATS_TYPE_MEAN:
|
|
|
|
remapped->data[off++].f = hist_mean(h);
|
|
|
|
break;
|
|
|
|
case MAPPING_STATS_TYPE_STDDEV:
|
|
|
|
remapped->data[off++].f = hist_stddev(h);
|
|
|
|
break;
|
|
|
|
case MAPPING_STATS_TYPE_VAR:
|
|
|
|
remapped->data[off++].f = hist_var(h);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2017-03-25 21:11:52 +01:00
|
|
|
|
2018-08-06 10:10:17 +02:00
|
|
|
case MAPPING_TYPE_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) {
|
|
|
|
case MAPPING_TIMESTAMP_TYPE_RECEIVED:
|
2017-08-30 23:52:32 +02:00
|
|
|
ts = &original->ts.received;
|
|
|
|
break;
|
2018-08-06 10:10:17 +02:00
|
|
|
case MAPPING_TIMESTAMP_TYPE_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
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
remapped->data[off++].i = ts->tv_sec;
|
|
|
|
remapped->data[off++].i = ts->tv_nsec;
|
2017-03-25 21:11:52 +01:00
|
|
|
|
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
|
|
|
|
2018-08-06 10:10:17 +02:00
|
|
|
case MAPPING_TYPE_HEADER:
|
|
|
|
switch (me->header.type) {
|
|
|
|
case MAPPING_HEADER_TYPE_LENGTH:
|
2017-08-30 23:52:32 +02:00
|
|
|
remapped->data[off++].i = original->length;
|
|
|
|
break;
|
2018-08-06 10:10:17 +02:00
|
|
|
case MAPPING_HEADER_TYPE_SEQUENCE:
|
2017-08-30 23:52:32 +02:00
|
|
|
remapped->data[off++].i = original->sequence;
|
|
|
|
break;
|
|
|
|
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
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
case MAPPING_TYPE_DATA:
|
|
|
|
for (int j = me->data.offset; j < len + me->data.offset; j++) {
|
2018-08-20 18:31:27 +02:00
|
|
|
if (j >= original->length)
|
2017-08-30 23:52:32 +02:00
|
|
|
remapped->data[off++].f = 0;
|
2018-08-20 18:31:27 +02:00
|
|
|
else
|
2017-08-30 23:52:32 +02:00
|
|
|
remapped->data[off++] = original->data[j];
|
2017-03-25 21:11:52 +01:00
|
|
|
}
|
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-08-28 14:35:50 +02:00
|
|
|
|
2019-01-07 10:28:55 +01:00
|
|
|
int mapping_remap(const struct vlist *m, struct sample *remapped, const struct sample *original, const struct stats *s)
|
2017-08-30 23:52:32 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2017-08-28 14:35:50 +02:00
|
|
|
|
2019-01-07 10:28:55 +01:00
|
|
|
for (size_t i = 0; i < vlist_length(m); i++) {
|
|
|
|
struct mapping_entry *me = (struct mapping_entry *) vlist_at(m, i);
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-08-30 23:52:32 +02:00
|
|
|
ret = mapping_update(me, remapped, original, s);
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
|
|
|
assert(me->length == 0 || index < me->length);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
case MAPPING_TYPE_STATS:
|
|
|
|
switch (me->stats.type) {
|
2018-08-06 10:24:45 +02:00
|
|
|
case MAPPING_STATS_TYPE_TOTAL:
|
|
|
|
type = "total";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_STATS_TYPE_LAST:
|
|
|
|
type = "last";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_STATS_TYPE_LOWEST:
|
|
|
|
type = "lowest";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_STATS_TYPE_HIGHEST:
|
|
|
|
type = "highest";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_STATS_TYPE_MEAN:
|
|
|
|
type = "mean";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_STATS_TYPE_VAR:
|
|
|
|
type = "var";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_STATS_TYPE_STDDEV:
|
|
|
|
type = "stddev";
|
|
|
|
break;
|
2018-10-21 22:37:49 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
type = NULL;
|
2018-08-02 10:46:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
strcatf(str, "stats.%s", type);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_TYPE_HEADER:
|
2018-08-06 10:10:17 +02:00
|
|
|
switch (me->header.type) {
|
2018-10-21 22:37:49 +01:00
|
|
|
case MAPPING_HEADER_TYPE_LENGTH:
|
|
|
|
type = "length";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_HEADER_TYPE_SEQUENCE:
|
|
|
|
type = "sequence";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
type = NULL;
|
2018-08-02 10:46:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
strcatf(str, "hdr.%s", type);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_TYPE_TIMESTAMP:
|
2018-08-06 10:10:17 +02:00
|
|
|
switch (me->timestamp.type) {
|
2018-10-21 22:37:49 +01:00
|
|
|
case MAPPING_TIMESTAMP_TYPE_ORIGIN:
|
|
|
|
type = "origin";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_TIMESTAMP_TYPE_RECEIVED:
|
|
|
|
type = "received";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
type = NULL;
|
2018-08-02 10:46:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
strcatf(str, "ts.%s.%s", type, index == 0 ? "sec" : "nsec");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPPING_TYPE_DATA:
|
2019-01-07 10:28:55 +01:00
|
|
|
if (me->node && index < vlist_length(&me->node->signals)) {
|
|
|
|
struct signal *s = vlist_at(&me->node->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;
|
|
|
|
}
|