mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
signal: use pools
This commit is contained in:
parent
44c4e9d52f
commit
602a8f51eb
2 changed files with 21 additions and 14 deletions
|
@ -99,7 +99,6 @@ int signal_parse(struct node *n, json_t *cfg)
|
|||
|
||||
int signal_parse_cli(struct node *n, int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
char *type;
|
||||
|
||||
struct signal *s = n->_vd;
|
||||
|
@ -158,11 +157,12 @@ check: if (optarg == endptr)
|
|||
|
||||
type = argv[optind];
|
||||
|
||||
ret = signal_lookup_type(type);
|
||||
if (ret == -1)
|
||||
s->type = signal_lookup_type(type);
|
||||
if (s->type == -1)
|
||||
error("Invalid signal type: %s", type);
|
||||
|
||||
s->type = ret;
|
||||
/* We know the expected number of values. */
|
||||
n->samplelen = s->values;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -240,13 +240,13 @@ int signal_read(struct node *n, struct sample *smps[], unsigned cnt)
|
|||
t->length = n->samplelen;
|
||||
|
||||
for (int i = 0; i < MIN(s->values, t->capacity); i++) {
|
||||
int rtype = (s->type != SIGNAL_TYPE_MIXED) ? s->type : i % 5;
|
||||
int rtype = (s->type != SIGNAL_TYPE_MIXED) ? s->type : i % 7;
|
||||
switch (rtype) {
|
||||
case SIGNAL_TYPE_CONSTANT: t->data[i].f = s->offset + s->amplitude; break;
|
||||
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);
|
||||
|
|
23
src/signal.c
23
src/signal.c
|
@ -33,6 +33,7 @@
|
|||
#include <villas/io/villas.h>
|
||||
#include <villas/timing.h>
|
||||
#include <villas/node.h>
|
||||
#include <villas/pool.h>
|
||||
#include <villas/plugin.h>
|
||||
#include <villas/nodes/signal.h>
|
||||
|
||||
|
@ -40,6 +41,7 @@
|
|||
struct node n;
|
||||
struct log l;
|
||||
struct io io;
|
||||
struct pool q;
|
||||
|
||||
struct sample *t;
|
||||
|
||||
|
@ -53,6 +55,8 @@ void usage()
|
|||
printf(" triangle\n");
|
||||
printf(" square\n");
|
||||
printf(" ramp\n");
|
||||
printf(" constants\n");
|
||||
printf(" counter\n");
|
||||
printf("\n");
|
||||
printf(" OPTIONS is one or more of the following options:\n");
|
||||
printf(" -d LVL set debug level\n");
|
||||
|
@ -89,12 +93,14 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx)
|
|||
if (ret)
|
||||
error("Failed to destroy output");
|
||||
|
||||
ret = pool_destroy(&q);
|
||||
if (ret)
|
||||
error("Failed to destroy pool");
|
||||
|
||||
ret = log_stop(&l);
|
||||
if (ret)
|
||||
error("Failed to stop log");
|
||||
|
||||
free(t);
|
||||
|
||||
info(CLR_GRN("Goodbye!"));
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -146,20 +152,21 @@ int main(int argc, char *argv[])
|
|||
if (ret)
|
||||
error("Failed to verify node configuration");
|
||||
|
||||
/* Allocate memory for message buffer */
|
||||
struct signal *s = n._vd;
|
||||
|
||||
t = alloc(SAMPLE_LEN(s->values));
|
||||
|
||||
t->capacity = s->values;
|
||||
ret = pool_init(&q, 1, SAMPLE_LEN(n.samplelen), &memtype_heap);
|
||||
if (ret)
|
||||
error("Failed to initialize pool");
|
||||
|
||||
ret = node_start(&n);
|
||||
if (ret)
|
||||
serror("Failed to start node");
|
||||
|
||||
for (;;) {
|
||||
sample_alloc(&q, &t, 1);
|
||||
|
||||
node_read(&n, &t, 1);
|
||||
io_print(&io, &t, 1);
|
||||
|
||||
sample_put(t);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue