2014-07-14 11:49:44 +00:00
|
|
|
/** Generate random packages on stdout.
|
2014-06-05 09:34:47 +00:00
|
|
|
*
|
2015-05-06 11:36:51 +02:00
|
|
|
* @file
|
2015-06-02 21:53:04 +02:00
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @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-05-05 19:24:16 +00:00
|
|
|
*
|
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-05-05 19:24:16 +00:00
|
|
|
*
|
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
|
|
|
*
|
2015-05-06 11:36:51 +02:00
|
|
|
* @addtogroup tools Test and debug tools
|
|
|
|
* @{
|
2015-06-02 21:53:04 +02:00
|
|
|
**********************************************************************************/
|
2014-06-05 09:34:47 +00:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2015-12-02 13:54:23 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
2014-06-05 09:34:47 +00:00
|
|
|
|
2016-11-20 02:45:39 -05:00
|
|
|
#include <villas/utils.h>
|
|
|
|
#include <villas/sample.h>
|
2017-08-14 14:42:07 +02:00
|
|
|
#include <villas/io/villas.h>
|
2016-11-20 02:45:39 -05:00
|
|
|
#include <villas/timing.h>
|
2017-07-06 23:14:38 +02:00
|
|
|
#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>
|
2017-07-06 23:14:38 +02:00
|
|
|
#include <villas/nodes/signal.h>
|
|
|
|
|
|
|
|
/* Some default values */
|
2017-07-13 01:56:01 +02:00
|
|
|
struct node n;
|
2017-07-06 23:14:38 +02:00
|
|
|
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-06 23:14:38 +02:00
|
|
|
|
2017-07-13 01:56:01 +02:00
|
|
|
struct sample *t;
|
|
|
|
|
2016-10-22 20:37:02 -04:00
|
|
|
void usage()
|
2016-02-07 03:17:45 +01:00
|
|
|
{
|
2017-05-03 19:26:58 +02:00
|
|
|
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");
|
2017-05-03 19:26:58 +02:00
|
|
|
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");
|
2017-08-30 22:41:15 +02:00
|
|
|
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");
|
2016-02-07 03:17:45 +01:00
|
|
|
|
|
|
|
print_copyright();
|
|
|
|
}
|
|
|
|
|
2017-07-06 23:14:38 +02:00
|
|
|
static void quit(int signal, siginfo_t *sinfo, void *ctx)
|
|
|
|
{
|
2017-07-13 01:56:01 +02:00
|
|
|
int ret;
|
2017-07-06 23:14:38 +02:00
|
|
|
|
2017-07-13 01:56:01 +02:00
|
|
|
ret = node_stop(&n);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to stop node");
|
2017-05-03 19:26:58 +02:00
|
|
|
|
2017-07-13 01:56:01 +02:00
|
|
|
ret = node_destroy(&n);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to destroy node");
|
2017-07-06 23:14:38 +02:00
|
|
|
|
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");
|
|
|
|
|
2017-08-14 14:42:07 +02:00
|
|
|
p = plugin_lookup(PLUGIN_TYPE_IO, format);
|
2017-08-05 21:02:09 +02:00
|
|
|
if (!p)
|
|
|
|
error("Invalid output format '%s'", format);
|
|
|
|
|
2017-08-14 14:42:07 +02:00
|
|
|
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");
|
|
|
|
|
2017-08-14 14:42:07 +02:00
|
|
|
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");
|
2014-06-05 09:34:47 +00:00
|
|
|
|
2017-07-13 01:56:01 +02:00
|
|
|
ret = node_start(&n);
|
2017-07-06 23:14:38 +02:00
|
|
|
if (ret)
|
|
|
|
serror("Failed to start node");
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-07-06 23:14:38 +02:00
|
|
|
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);
|
2015-05-06 12:05:07 +02:00
|
|
|
}
|
2014-06-05 09:34:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-06 11:36:51 +02:00
|
|
|
|
2015-08-07 01:11:43 +02:00
|
|
|
/** @} */
|