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/src/signal.c

146 lines
3.7 KiB
C
Raw Normal View History

/** Generate random packages on stdout.
*
* @file
2015-06-02 21:53:04 +02:00
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 12:56:43 +02: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.
*
2017-04-27 12:56:43 +02:00
* 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.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2015-06-02 21:53:04 +02:00
*
* @addtogroup tools Test and debug tools
* @{
2015-06-02 21:53:04 +02:00
**********************************************************************************/
#include <unistd.h>
#include <math.h>
#include <string.h>
2016-11-20 02:45:39 -05:00
#include <villas/utils.h>
#include <villas/sample.h>
#include <villas/sample_io.h>
2016-11-20 02:45:39 -05:00
#include <villas/timing.h>
#include <villas/node.h>
2017-07-13 01:56:01 +02:00
#include <villas/plugin.h>
#include <villas/nodes/signal.h>
/* Some default values */
2017-07-13 01:56:01 +02:00
struct node n;
struct log l;
2017-07-13 01:56:01 +02:00
struct sample *t;
2016-10-22 20:37:02 -04:00
void usage()
{
printf("Usage: villas-signal [OPTIONS] SIGNAL\n");
printf(" SIGNAL is on of the following signal types:\n");
printf(" mixed\n");
printf(" random\n");
printf(" sine\n");
printf(" triangle\n");
printf(" square\n");
printf(" ramp\n");
printf("\n");
printf(" OPTIONS is one or more of the following options:\n");
printf(" -d LVL set debug level\n");
printf(" -v NUM specifies how many values a message should contain\n");
printf(" -r HZ how many messages per second\n");
printf(" -n non real-time mode. do not throttle output.\n");
printf(" -f HZ the frequency of the signal\n");
printf(" -a FLT the amplitude\n");
printf(" -D FLT the standard deviation for 'random' signals\n");
printf(" -l NUM only send LIMIT messages and stop\n\n");
print_copyright();
}
static void quit(int signal, siginfo_t *sinfo, void *ctx)
{
2017-07-13 01:56:01 +02:00
int ret;
2017-07-13 01:56:01 +02:00
ret = node_stop(&n);
if (ret)
error("Failed to stop node");
2017-07-13 01:56:01 +02:00
ret = node_destroy(&n);
if (ret)
error("Failed to destroy node");
2017-07-13 01:56:01 +02:00
free(t);
2017-07-13 01:56:01 +02:00
info(CLR_GRN("Goodbye!"));
exit(EXIT_SUCCESS);
2017-07-06 23:20:57 +02:00
}
int main(int argc, char *argv[])
{
int ret;
2017-07-13 01:56:01 +02:00
struct plugin *p;
struct signal *s;
2017-07-06 23:20:57 +02:00
ret = log_init(&l, l.level, LOG_ALL);
if (ret)
error("Failed to initialize log");
2017-07-13 01:56:01 +02:00
2017-07-06 23:20:57 +02:00
ret = signals_init(quit);
if (ret)
error("Failed to intialize signals");
2017-07-13 01:56:01 +02:00
p = plugin_lookup(PLUGIN_TYPE_NODE, "signal");
if (!p)
error("Signal generation is not supported.");
ret = node_init(&n, &p->node);
if (ret)
error("Failed to initialize node");
ret = node_parse_cli(&n, argc, argv);
if (ret)
error("Failed to parse command line options");
ret = node_check(&n);
if (ret)
error("Failed to verify node configuration");
info("Starting signal generation: %s", node_name(&n));
/* Allocate memory for message buffer */
2017-07-13 01:56:01 +02:00
s = n._vd;
t = alloc(SAMPLE_LEN(s->values));
2017-07-13 01:56:01 +02:00
t->capacity = s->values;
/* Print header */
2016-06-08 23:21:42 +02:00
printf("# VILLASnode signal params: type=%s, values=%u, rate=%f, limit=%d, amplitude=%f, freq=%f\n",
2017-07-13 01:56:01 +02:00
argv[optind], s->values, s->rate, s->limit, s->amplitude, s->frequency);
printf("# %-20s\t\t%s\n", "sec.nsec(seq)", "data[]");
2017-07-13 01:56:01 +02:00
ret = node_start(&n);
if (ret)
serror("Failed to start node");
for (;;) {
2017-07-13 01:56:01 +02:00
node_read(&n, &t, 1);
sample_io_villas_fprint(stdout, t, SAMPLE_IO_ALL & ~SAMPLE_IO_OFFSET);
fflush(stdout);
}
return 0;
}
2015-08-07 01:11:43 +02:00
/** @} */