From d6ea18d3a1a85c67ff39f8ee501f632520333387 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 1 Sep 2017 07:50:35 +0200 Subject: [PATCH] signal: added new counter signal type --- etc/example.conf | 2 +- include/villas/nodes/signal.h | 1 + lib/nodes/signal.c | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/etc/example.conf b/etc/example.conf index c3b0c1d14..13a5ee074 100644 --- a/etc/example.conf +++ b/etc/example.conf @@ -171,7 +171,7 @@ nodes = { signal_node = { type = "signal", - signal = "sine", # One of: sine, square, ramp, triangle, random, mixed, constant" + signal = "sine", # One of: sine, square, ramp, counter, constant, triangle, random, mixed, constant" values = 4, # Number of values per sample amplitude = 2.3, # Amplitude of generated signals frequency = 10, # Frequency of generated signals diff --git a/include/villas/nodes/signal.h b/include/villas/nodes/signal.h index 24343e685..7e9ebed64 100644 --- a/include/villas/nodes/signal.h +++ b/include/villas/nodes/signal.h @@ -42,6 +42,7 @@ enum signal_type { SIGNAL_TYPE_SQUARE, SIGNAL_TYPE_TRIANGLE, SIGNAL_TYPE_RAMP, + SIGNAL_TYPE_COUNTER, SIGNAL_TYPE_CONSTANT, SIGNAL_TYPE_MIXED }; diff --git a/lib/nodes/signal.c b/lib/nodes/signal.c index e84dbe65f..2a998b68c 100644 --- a/lib/nodes/signal.c +++ b/lib/nodes/signal.c @@ -39,6 +39,8 @@ enum signal_type signal_lookup_type(const char *type) return SIGNAL_TYPE_TRIANGLE; else if (!strcmp(type, "ramp")) return SIGNAL_TYPE_RAMP; + else if (!strcmp(type, "counter")) + return SIGNAL_TYPE_COUNTER; else if (!strcmp(type, "constant")) return SIGNAL_TYPE_CONSTANT; else if (!strcmp(type, "mixed")) @@ -242,7 +244,8 @@ int signal_read(struct node *n, struct sample *smps[], unsigned cnt) case SIGNAL_TYPE_SINE: t->data[i].f = s->offset + s->amplitude * sin(running * s->frequency * 2 * M_PI); break; case SIGNAL_TYPE_TRIANGLE: t->data[i].f = s->offset + s->amplitude * (fabs(fmod(running * s->frequency, 1) - .5) - 0.25) * 4; break; case SIGNAL_TYPE_SQUARE: t->data[i].f = s->offset + s->amplitude * ( (fmod(running * s->frequency, 1) < .5) ? -1 : 1); break; - case SIGNAL_TYPE_RAMP: t->data[i].f = s->offset + s->amplitude * fmod(running, s->frequency); break; + case SIGNAL_TYPE_RAMP: t->data[i].f = s->offset + s->amplitude * fmod(running, s->frequency); break; + case SIGNAL_TYPE_COUNTER: t->data[i].f = s->offset + s->amplitude * s->counter; break; case SIGNAL_TYPE_RANDOM: s->last[i] += box_muller(0, s->stddev); t->data[i].f = s->last[i]; @@ -269,6 +272,7 @@ char * signal_print(struct node *n) switch (s->type) { case SIGNAL_TYPE_MIXED: type = "mixed"; break; case SIGNAL_TYPE_RAMP: type = "ramp"; break; + case SIGNAL_TYPE_COUNTER: type = "counter"; break; case SIGNAL_TYPE_TRIANGLE: type = "triangle"; break; case SIGNAL_TYPE_SQUARE: type = "square"; break; case SIGNAL_TYPE_SINE: type = "sine"; break;