mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added new tool to generate random packages
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@20 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
e89a128c53
commit
f23ef963a6
3 changed files with 115 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ doc/latex/
|
|||
|
||||
server
|
||||
test
|
||||
random
|
||||
|
|
9
Makefile
9
Makefile
|
@ -1,4 +1,4 @@
|
|||
TARGETS = server test
|
||||
TARGETS = server sim random
|
||||
|
||||
SRCS = server.c test.c node.c path.c utils.c msg.c
|
||||
VPATH = src
|
||||
|
@ -9,9 +9,9 @@ RM = rm -f
|
|||
GIT_TAG = $(shell git describe --tags --abbrev=0)
|
||||
GIT_REV = $(shell git rev-parse --short HEAD)
|
||||
|
||||
V ?= 0
|
||||
V ?= 4
|
||||
|
||||
LDFLAGS = -pthread -lrt
|
||||
LDFLAGS = -pthread -lrt -lm
|
||||
CFLAGS = -g -std=c99 -Iinclude/ -D_XOPEN_SOURCE=500 -DV=$(V)
|
||||
CFLAGS += -D__GIT_REV__='"$(GIT_REV)"' -D__GIT_TAG__='"$(GIT_TAG)"'
|
||||
|
||||
|
@ -20,7 +20,8 @@ CFLAGS += -D__GIT_REV__='"$(GIT_REV)"' -D__GIT_TAG__='"$(GIT_TAG)"'
|
|||
all: $(TARGETS)
|
||||
|
||||
server: node.o msg.o utils.o path.o
|
||||
test: msg.o utils.o
|
||||
sim: msg.o utils.o
|
||||
random: msg.o utils.o
|
||||
|
||||
%.d: %.c
|
||||
$(CC) -MM $(CFLAGS) $< -o $@
|
||||
|
|
109
src/random.c
Normal file
109
src/random.c
Normal file
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* Generate random packages on stdout
|
||||
*
|
||||
* @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 quit(int sig, siginfo_t *si, void *ptr)
|
||||
{
|
||||
debug(1, "Good night");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
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[])
|
||||
{
|
||||
if (argc != 4) {
|
||||
printf("Usage: %s DEVID VALUES RATE\n", argv[0]);
|
||||
printf(" DEVID is the device id of this node\n");
|
||||
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);
|
||||
}
|
||||
|
||||
int rate = atoi(argv[3]);
|
||||
struct msg msg = {
|
||||
.dev_id = atoi(argv[1]),
|
||||
.msg_len = atoi(argv[2]) * sizeof(double),
|
||||
.seq_no = 0,
|
||||
.data = { 0 }
|
||||
};
|
||||
|
||||
/* Setup signals */
|
||||
struct sigaction sa_tick = {
|
||||
.sa_flags = SA_SIGINFO,
|
||||
.sa_sigaction = tick
|
||||
};
|
||||
|
||||
struct sigaction sa_quit = {
|
||||
.sa_flags = SA_SIGINFO,
|
||||
.sa_sigaction = quit
|
||||
};
|
||||
|
||||
sigemptyset(&sa_tick.sa_mask);
|
||||
sigemptyset(&sa_quit.sa_mask);
|
||||
|
||||
if (sigaction(SIGINT, &sa_quit, NULL)) {
|
||||
error("Failed sigaction(): %s", strerror(errno));
|
||||
}
|
||||
|
||||
if (sigaction(SIG, &sa_tick, NULL)) {
|
||||
error("Failed sigaction(): %s", strerror(errno));
|
||||
}
|
||||
|
||||
/* Setup timer */
|
||||
timer_t t;
|
||||
struct sigevent sev = {
|
||||
.sigev_notify = SIGEV_SIGNAL,
|
||||
.sigev_signo = SIG,
|
||||
.sigev_value.sival_ptr = &msg
|
||||
};
|
||||
|
||||
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 */
|
||||
printf("# %-6s %-8s %-12s\n", "dev_id", "seq_no", "data");
|
||||
|
||||
timer_create(CLOCKID, &sev, &t);
|
||||
timer_settime(t, 0, &its, NULL);
|
||||
|
||||
while(1) pause();
|
||||
|
||||
timer_delete(t);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue