mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
signal: add support for name-based signal mapping
This commit is contained in:
parent
fdf4a9c251
commit
b1046ff641
3 changed files with 30 additions and 10 deletions
|
@ -27,6 +27,7 @@
|
|||
|
||||
/* Forward declarations */
|
||||
struct list;
|
||||
struct node;
|
||||
|
||||
struct signal {
|
||||
char *name; /**< The name of the signal. */
|
||||
|
@ -41,3 +42,5 @@ int signal_destroy(struct signal *s);
|
|||
int signal_parse(struct signal *s, json_t *cfg);
|
||||
|
||||
int signal_parse_list(struct list *list, json_t *cfg);
|
||||
|
||||
int signal_get_offset(const char *str, struct node *n);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <villas/list.h>
|
||||
#include <villas/utils.h>
|
||||
#include <villas/node.h>
|
||||
#include <villas/signal.h>
|
||||
|
||||
int mapping_parse_str(struct mapping_entry *me, const char *str, struct list *nodes)
|
||||
{
|
||||
|
@ -131,7 +132,7 @@ int mapping_parse_str(struct mapping_entry *me, const char *str, struct list *no
|
|||
goto invalid_format;
|
||||
}
|
||||
else if (!strcmp(type, "data")) {
|
||||
char *first_str, *last_str, *endptr;
|
||||
char *first_str, *last_str;
|
||||
|
||||
me->type = MAPPING_TYPE_DATA;
|
||||
|
||||
|
@ -143,15 +144,9 @@ int mapping_parse_str(struct mapping_entry *me, const char *str, struct list *no
|
|||
if (!last_str)
|
||||
last_str = first_str; /* single element: data[5] => data[5-5] */
|
||||
|
||||
first = strtoul(first_str, &endptr, 10);
|
||||
if (endptr != first_str + strlen(first_str))
|
||||
goto invalid_format;
|
||||
|
||||
last = strtoul(last_str, &endptr, 10);
|
||||
if (endptr != last_str + strlen(last_str))
|
||||
goto invalid_format;
|
||||
|
||||
if (last < first)
|
||||
first = signal_get_offset(first_str, me->node);
|
||||
last = signal_get_offset(last_str, me->node);
|
||||
if (first < 0 || last < 0 || last < first)
|
||||
goto invalid_format;
|
||||
|
||||
me->data.offset = first;
|
||||
|
|
22
lib/signal.c
22
lib/signal.c
|
@ -25,6 +25,7 @@
|
|||
#include "villas/signal.h"
|
||||
#include "villas/list.h"
|
||||
#include "villas/utils.h"
|
||||
#include "villas/node.h"
|
||||
|
||||
int signal_destroy(struct signal *s)
|
||||
{
|
||||
|
@ -72,3 +73,24 @@ int signal_parse_list(struct list *list, json_t *cfg)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int signal_get_offset(const char *str, struct node *n)
|
||||
{
|
||||
int idx;
|
||||
char *endptr;
|
||||
struct signal *s;
|
||||
|
||||
/* Lets try to find a signal with a matching name */
|
||||
if (n) {
|
||||
s = list_lookup(&n->signals, str);
|
||||
if (s)
|
||||
return list_index(&n->signals, s);
|
||||
}
|
||||
|
||||
/* Lets try to interpret the signal name as an index */
|
||||
idx = strtoul(str, &endptr, 10);
|
||||
if (endptr == str + strlen(str))
|
||||
return idx;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue