2021-08-10 10:12:48 -04:00
|
|
|
/** Node-type for signal generation.
|
|
|
|
*
|
|
|
|
* @file
|
2022-12-14 17:41:58 +01:00
|
|
|
* @author Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
|
2022-07-04 18:20:03 +02:00
|
|
|
* @license Apache 2.0
|
2021-08-10 10:12:48 -04:00
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <villas/timing.hpp>
|
|
|
|
#include <villas/task.hpp>
|
|
|
|
#include <villas/node.hpp>
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
|
|
|
/* Forward declarations */
|
|
|
|
struct Sample;
|
|
|
|
|
|
|
|
class SignalNodeSignal {
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum class Type {
|
|
|
|
RANDOM,
|
|
|
|
SINE,
|
|
|
|
SQUARE,
|
|
|
|
TRIANGLE,
|
|
|
|
RAMP,
|
|
|
|
COUNTER,
|
|
|
|
CONSTANT,
|
|
|
|
PULSE,
|
|
|
|
MIXED
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Type type;
|
|
|
|
|
|
|
|
double frequency; /**< Frequency of the generated signals. */
|
|
|
|
double amplitude; /**< Amplitude of the generated signals. */
|
|
|
|
double stddev; /**< Standard deviation of random signals (normal distributed). */
|
|
|
|
double offset; /**< A constant bias. */
|
|
|
|
double pulse_width; /**< Width of a pulse with respect to the rate (duration = pulse_width/rate) */
|
|
|
|
double pulse_low; /**< Amplitude when pulse signal is off */
|
|
|
|
double pulse_high; /**< Amplitude when pulse signal is on */
|
|
|
|
double phase; /**< Phase (rad) offset with respect to program start */
|
|
|
|
double last; /**< The values from the previous period which are required for random walk. */
|
|
|
|
|
|
|
|
public:
|
|
|
|
SignalNodeSignal(json_t *json);
|
|
|
|
|
|
|
|
int parse(json_t *json);
|
|
|
|
|
|
|
|
static
|
|
|
|
enum Type lookupType(const std::string &type);
|
|
|
|
|
|
|
|
static
|
|
|
|
std::string typeToString(enum Type type);
|
|
|
|
|
|
|
|
void start();
|
|
|
|
|
|
|
|
void read(unsigned c, double t, double rate, SignalData *d);
|
|
|
|
|
|
|
|
Signal::Ptr toSignal(Signal::Ptr tpl) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SignalNode : public Node {
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<SignalNodeSignal> signals;
|
|
|
|
|
|
|
|
struct Task task; /**< Timer for periodic events. */
|
|
|
|
int rt; /**< Real-time mode? */
|
|
|
|
|
|
|
|
double rate; /**< Sampling rate. */
|
|
|
|
bool monitor_missed; /**< Boolean, if set, node counts missed steps and warns user. */
|
|
|
|
int limit; /**< The number of values which should be generated by this node. <0 for infinite. */
|
|
|
|
|
|
|
|
struct timespec started; /**< Point in time when this node was started. */
|
|
|
|
unsigned missed_steps; /**< Total number of missed steps. */
|
|
|
|
|
2022-04-01 14:55:08 +02:00
|
|
|
virtual
|
|
|
|
int _read(struct Sample *smps[], unsigned cnt);
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
public:
|
2023-06-30 10:51:01 +02:00
|
|
|
SignalNode(const uuid_t &id = {}, const std::string &name = "");
|
2021-08-10 10:12:48 -04:00
|
|
|
|
|
|
|
virtual
|
|
|
|
const std::string & getDetails();
|
|
|
|
|
|
|
|
virtual
|
2023-06-30 10:51:01 +02:00
|
|
|
int parse(json_t *json);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
|
|
|
virtual
|
|
|
|
int start();
|
|
|
|
|
|
|
|
virtual
|
|
|
|
int stop();
|
|
|
|
|
|
|
|
virtual
|
|
|
|
int prepare();
|
|
|
|
|
|
|
|
virtual
|
|
|
|
std::vector<int> getPollFDs();
|
|
|
|
};
|
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|