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>
|
|
|
|
* @copyright 2014-2015, Institute for Automation of Complex Power Systems, EONERC
|
|
|
|
* This file is part of S2SS. All Rights Reserved. Proprietary and confidential.
|
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
|
|
|
*
|
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 <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
2015-05-06 12:05:07 +02:00
|
|
|
#include <sys/timerfd.h>
|
2014-06-05 09:34:47 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "msg.h"
|
2015-06-02 22:06:15 +02:00
|
|
|
#include "timing.h"
|
2014-06-05 09:34:47 +00:00
|
|
|
|
|
|
|
#define CLOCKID CLOCK_REALTIME
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2014-07-04 15:58:11 +00:00
|
|
|
if (argc != 3) {
|
|
|
|
printf("Usage: %s VALUES RATE\n", argv[0]);
|
2014-06-05 09:34:47 +00:00
|
|
|
printf(" VALUES is the number of values a message contains\n");
|
|
|
|
printf(" RATE how many messages per second\n\n");
|
2015-03-21 18:16:28 +01:00
|
|
|
|
|
|
|
printf("Simulator2Simulator Server %s (built on %s %s)\n",
|
|
|
|
BLU(VERSION), MAG(__DATE__), MAG(__TIME__));
|
2015-06-02 21:53:04 +02:00
|
|
|
printf(" copyright 2014-2015, Institute for Automation of Complex Power Systems, EONERC\n");
|
2015-03-21 18:16:28 +01:00
|
|
|
printf(" Steffen Vogel <StVogel@eonerc.rwth-aachen.de>\n");
|
2015-03-21 18:03:55 +01:00
|
|
|
|
2014-06-05 09:34:47 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-07-04 15:58:11 +00:00
|
|
|
int rate = atoi(argv[2]);
|
2014-07-18 16:05:45 +00:00
|
|
|
struct msg m = MSG_INIT(atoi(argv[1]));
|
2014-06-05 09:34:47 +00:00
|
|
|
|
|
|
|
/* Setup timer */
|
2015-05-06 12:05:07 +02:00
|
|
|
struct itimerspec its = {
|
2015-06-02 21:59:31 +02:00
|
|
|
.it_interval = time_from_double(1 / rate),
|
2015-05-06 12:05:07 +02:00
|
|
|
.it_value = { 1, 0 }
|
2014-06-05 09:34:47 +00:00
|
|
|
};
|
|
|
|
|
2015-05-06 12:05:07 +02:00
|
|
|
int tfd = timerfd_create(CLOCK_REALTIME, 0);
|
|
|
|
if (tfd < 0)
|
|
|
|
serror("Failed to create timer");
|
2014-06-05 09:34:47 +00:00
|
|
|
|
2015-05-06 12:05:07 +02:00
|
|
|
if (timerfd_settime(tfd, 0, &its, NULL))
|
|
|
|
serror("Failed to start timer");
|
2014-06-05 09:34:47 +00:00
|
|
|
|
|
|
|
/* Print header */
|
2014-07-04 15:58:11 +00:00
|
|
|
fprintf(stderr, "# %-6s%-12s\n", "seq", "data");
|
2014-06-05 09:34:47 +00:00
|
|
|
|
2015-05-06 13:20:02 +02:00
|
|
|
/* Block until 1/p->rate seconds elapsed */
|
2015-05-19 16:54:28 +02:00
|
|
|
m.sequence += (uint16_t) timerfd_wait(tfd);
|
|
|
|
|
2015-06-02 22:24:44 +02:00
|
|
|
for (;;) {
|
2015-05-06 12:05:07 +02:00
|
|
|
msg_random(&m);
|
|
|
|
msg_fprint(stdout, &m);
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
2014-06-05 09:34:47 +00:00
|
|
|
|
2015-05-06 12:05:07 +02:00
|
|
|
close(tfd);
|
2014-06-05 09:34:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-06 11:36:51 +02:00
|
|
|
|
|
|
|
/** @} */
|