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

176 lines
4.2 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/io/villas.h>
2016-11-20 02:45:39 -05:00
#include <villas/timing.h>
#include <villas/node.h>
2017-09-03 10:52:00 +02:00
#include <villas/pool.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-08-05 21:02:09 +02:00
struct io io;
2017-09-03 10:52:00 +02:00
struct pool q;
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");
2017-09-03 10:52:00 +02:00
printf(" constants\n");
printf(" counter\n");
printf("\n");
printf(" OPTIONS is one or more of the following options:\n");
2017-08-05 21:02:09 +02:00
printf(" -d LVL set debug level\n");
printf(" -f FMT set the format\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(" -o OFF the DC bias\n");
2017-08-05 21:02:09 +02:00
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-08-05 21:02:09 +02:00
ret = io_close(&io);
if (ret)
error("Failed to close output");
ret = io_destroy(&io);
if (ret)
error("Failed to destroy output");
2017-09-03 10:52:00 +02:00
ret = pool_destroy(&q);
if (ret)
error("Failed to destroy pool");
2017-07-13 22:13:58 +02:00
ret = log_stop(&l);
if (ret)
error("Failed to stop log");
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;
2017-08-05 21:02:09 +02:00
char *format = "villas"; /** @todo hardcoded for now */
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-13 22:13:58 +02:00
ret = log_start(&l);
if (ret)
error("Failed to start log");
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");
p = plugin_lookup(PLUGIN_TYPE_IO, format);
2017-08-05 21:02:09 +02:00
if (!p)
error("Invalid output format '%s'", format);
ret = io_init(&io, &p->io, IO_FLUSH | (IO_FORMAT_ALL & ~IO_FORMAT_OFFSET));
2017-08-05 21:02:09 +02:00
if (ret)
error("Failed to initialize output");
ret = io_open(&io, NULL);
2017-08-05 21:02:09 +02:00
if (ret)
error("Failed to open output");
2017-07-13 01:56:01 +02:00
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");
2017-09-03 10:52:00 +02:00
ret = pool_init(&q, 1, SAMPLE_LEN(n.samplelen), &memtype_heap);
if (ret)
error("Failed to initialize pool");
2017-07-13 01:56:01 +02:00
ret = node_start(&n);
if (ret)
serror("Failed to start node");
for (;;) {
2017-09-03 10:52:00 +02:00
sample_alloc(&q, &t, 1);
2017-07-13 01:56:01 +02:00
node_read(&n, &t, 1);
2017-08-05 21:02:09 +02:00
io_print(&io, &t, 1);
2017-09-03 10:52:00 +02:00
sample_put(t);
}
return 0;
}
2015-08-07 01:11:43 +02:00
/** @} */