1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

signal: add signal_print() function

This commit is contained in:
Steffen Vogel 2021-07-06 18:30:46 +02:00
parent 082986bf86
commit d8c2b2f781
2 changed files with 25 additions and 0 deletions

View file

@ -78,6 +78,8 @@ struct signal * signal_copy(struct signal *s);
/** Parse signal description. */
int signal_parse(struct signal *s, json_t *json);
char * signal_print(const struct signal *s, const union signal_data *d = nullptr);
/** Initialize signal from a mapping_entry. */
int signal_init_from_mapping(struct signal *s, const struct mapping_entry *me, unsigned index);

View file

@ -245,3 +245,26 @@ json_t * signal_to_json(struct signal *s)
return json_sig;
}
char * signal_print(const struct signal *s, const union signal_data *d)
{
char *buf = nullptr;
if (s->name)
strcatf(&buf, " %s", s->name);
if (s->unit)
strcatf(&buf, " [%s]", s->unit);
strcatf(&buf, "(%s)", signal_type_to_str(s->type));
if (d) {
char val[32];
signal_data_print_str(d, s->type, val, sizeof(val));
strcatf(&buf, " = %s", val);
}
return buf;
}