2018-03-21 16:59:19 +01:00
|
|
|
/** Signal meta data.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @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
|
2018-03-21 16:59:19 +01: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-06-23 16:57:00 +02:00
|
|
|
#include <jansson.h>
|
|
|
|
|
2019-04-23 13:05:31 +02:00
|
|
|
#include <atomic>
|
|
|
|
|
2020-07-04 18:16:03 +02:00
|
|
|
#include <villas/signal_list.h>
|
|
|
|
#include <villas/signal_type.h>
|
|
|
|
#include <villas/signal_data.h>
|
2018-08-13 15:31:39 +02:00
|
|
|
|
|
|
|
/* "I" defined by complex.h collides with a define in OpenSSL */
|
|
|
|
#undef I
|
2018-03-21 16:59:19 +01:00
|
|
|
|
|
|
|
/* Forward declarations */
|
2018-08-02 10:47:53 +02:00
|
|
|
struct mapping_entry;
|
2018-03-21 16:59:19 +01:00
|
|
|
|
2018-08-06 10:24:45 +02:00
|
|
|
/** Signal descriptor.
|
|
|
|
*
|
|
|
|
* This data structure contains meta data about samples values in struct sample::data
|
|
|
|
*/
|
2018-03-21 16:59:19 +01:00
|
|
|
struct signal {
|
2018-08-06 11:14:45 +02:00
|
|
|
char *name; /**< The name of the signal. */
|
|
|
|
char *unit; /**< The unit of the signal. */
|
2018-08-06 10:24:45 +02:00
|
|
|
|
2018-08-13 15:31:39 +02:00
|
|
|
union signal_data init; /**< The initial value of the signal. */
|
|
|
|
|
2018-05-25 12:55:01 +02:00
|
|
|
int enabled;
|
2018-08-06 10:24:45 +02:00
|
|
|
|
2019-04-23 13:05:31 +02:00
|
|
|
std::atomic<int> refcnt; /**< Reference counter. */
|
2018-08-06 11:14:45 +02:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
enum SignalType type;
|
2018-03-21 16:59:19 +01:00
|
|
|
};
|
|
|
|
|
2018-08-13 15:31:39 +02:00
|
|
|
/** Initialize a signal with default values. */
|
2020-09-10 11:11:42 +02:00
|
|
|
int signal_init(struct signal *s) __attribute__ ((warn_unused_result));
|
2018-08-01 17:00:56 +02:00
|
|
|
|
2018-08-13 15:31:39 +02:00
|
|
|
/** Destroy a signal and release memory. */
|
2020-09-10 11:11:42 +02:00
|
|
|
int signal_destroy(struct signal *s) __attribute__ ((warn_unused_result));
|
2018-08-13 15:31:39 +02:00
|
|
|
|
|
|
|
/** Allocate memory for a new signal, and initialize it with provided values. */
|
2020-09-10 11:11:42 +02:00
|
|
|
struct signal * signal_create(const char *name, const char *unit, enum SignalType fmt) __attribute__ ((warn_unused_result));
|
2018-08-13 15:31:39 +02:00
|
|
|
|
|
|
|
/** Destroy and release memory of signal. */
|
2020-09-10 11:11:42 +02:00
|
|
|
int signal_free(struct signal *s) __attribute__ ((warn_unused_result));
|
2018-08-13 15:31:39 +02:00
|
|
|
|
2018-08-06 11:14:45 +02:00
|
|
|
/** Increase reference counter. */
|
2018-08-07 09:22:26 +02:00
|
|
|
int signal_incref(struct signal *s);
|
2018-08-06 11:14:45 +02:00
|
|
|
|
|
|
|
/** Decrease reference counter. */
|
2018-08-07 09:22:26 +02:00
|
|
|
int signal_decref(struct signal *s);
|
2018-08-06 11:14:45 +02:00
|
|
|
|
2018-08-20 18:31:27 +02:00
|
|
|
/** Copy a signal. */
|
|
|
|
struct signal * signal_copy(struct signal *s);
|
|
|
|
|
2018-08-13 15:31:39 +02:00
|
|
|
/** Parse signal description. */
|
2021-02-16 14:15:14 +01:00
|
|
|
int signal_parse(struct signal *s, json_t *json);
|
2018-08-13 15:31:39 +02:00
|
|
|
|
2021-07-06 18:30:46 +02:00
|
|
|
char * signal_print(const struct signal *s, const union signal_data *d = nullptr);
|
|
|
|
|
2018-08-13 15:31:39 +02:00
|
|
|
/** Initialize signal from a mapping_entry. */
|
2018-08-02 10:47:53 +02:00
|
|
|
int signal_init_from_mapping(struct signal *s, const struct mapping_entry *me, unsigned index);
|
|
|
|
|
2020-08-17 17:04:55 +02:00
|
|
|
/** Produce JSON representation of signal. */
|
|
|
|
json_t * signal_to_json(struct signal *s);
|