1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/include/villas/nodes/signal.hpp

108 lines
2.5 KiB
C++
Raw Normal View History

/** Node-type for signal generation.
*
* @file
* @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
*********************************************************************************/
#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);
public:
SignalNode(const uuid_t &id = {}, const std::string &name = "");
virtual
const std::string & getDetails();
virtual
int parse(json_t *json);
virtual
int start();
virtual
int stop();
virtual
int prepare();
virtual
std::vector<int> getPollFDs();
};
} // namespace node
} // namespace villas