2014-07-14 11:49:44 +00:00
|
|
|
/** Generate random packages on stdout.
|
2014-06-05 09:34:47 +00:00
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
|
|
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "msg.h"
|
|
|
|
|
|
|
|
#define CLOCKID CLOCK_REALTIME
|
|
|
|
#define SIG SIGRTMIN
|
|
|
|
|
|
|
|
void tick(int sig, siginfo_t *si, void *ptr)
|
|
|
|
{
|
|
|
|
struct msg *m = (struct msg*) si->si_value.sival_ptr;
|
|
|
|
|
|
|
|
msg_random(m);
|
|
|
|
msg_fprint(stdout, m);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
printf("s2ss Simulator2Simulator Server v%s\n", VERSION);
|
|
|
|
printf("Copyright 2014, Institute for Automation of Complex Power Systems, EONERC\n");
|
|
|
|
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 signals */
|
|
|
|
struct sigaction sa_tick = {
|
|
|
|
.sa_flags = SA_SIGINFO,
|
|
|
|
.sa_sigaction = tick
|
|
|
|
};
|
|
|
|
|
|
|
|
sigemptyset(&sa_tick.sa_mask);
|
2014-06-05 09:35:10 +00:00
|
|
|
sigaction(SIG, &sa_tick, NULL);
|
2014-06-05 09:34:47 +00:00
|
|
|
|
|
|
|
/* Setup timer */
|
|
|
|
timer_t t;
|
|
|
|
struct sigevent sev = {
|
|
|
|
.sigev_notify = SIGEV_SIGNAL,
|
|
|
|
.sigev_signo = SIG,
|
2014-07-18 16:05:45 +00:00
|
|
|
.sigev_value.sival_ptr = &m
|
2014-06-05 09:34:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
double period = 1.0 / rate;
|
|
|
|
long sec = floor(period);
|
|
|
|
long nsec = (period - sec) * 1000000000;
|
|
|
|
|
|
|
|
struct itimerspec its = {
|
|
|
|
.it_interval = { sec, nsec },
|
|
|
|
.it_value = { 0, 1 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
timer_create(CLOCKID, &sev, &t);
|
|
|
|
timer_settime(t, 0, &its, NULL);
|
|
|
|
|
2014-07-04 15:58:10 +00:00
|
|
|
while (1) pause();
|
2014-06-05 09:34:47 +00:00
|
|
|
|
|
|
|
timer_delete(t);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|