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-03-27 12:28:13 +02:00
|
|
|
#include <villas/sample_io.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-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-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");
|
|
|
|
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");
|
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-07-13 01:56:01 +02:00
|
|
|
free(t);
|
2017-05-05 19:24:16 +00:00
|
|
|
|
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));
|
2016-11-20 12:59:37 -05:00
|
|
|
|
2016-02-07 03:17:45 +01:00
|
|
|
/* Allocate memory for message buffer */
|
2017-07-13 01:56:01 +02:00
|
|
|
s = n._vd;
|
|
|
|
|
|
|
|
t = alloc(SAMPLE_LEN(s->values));
|
2017-07-06 23:14:38 +02:00
|
|
|
|
2017-07-13 01:56:01 +02:00
|
|
|
t->capacity = s->values;
|
2014-06-05 09:34:47 +00:00
|
|
|
|
2016-02-07 01:11:51 +01:00
|
|
|
/* 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);
|
2016-02-07 03:17:45 +01:00
|
|
|
printf("# %-20s\t\t%s\n", "sec.nsec(seq)", "data[]");
|
2016-02-07 01:11:51 +01: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-07-13 01:56:01 +02:00
|
|
|
node_read(&n, &t, 1);
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-07-06 23:14:38 +02:00
|
|
|
sample_io_villas_fprint(stdout, t, SAMPLE_IO_ALL & ~SAMPLE_IO_OFFSET);
|
2015-05-06 12:05:07 +02:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
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
|
|
|
/** @} */
|