root / branches / simulator / projects / simulator / libsim / libsim.c @ 1020
History | View | Annotate | Download (1.04 KB)
1 |
#include <stdio.h> |
---|---|
2 |
#include <stdlib.h> |
3 |
#include <sys/time.h> |
4 |
#include <signal.h> |
5 |
#include <unistd.h> |
6 |
#include <stdlib.h> |
7 |
#include <sys/shm.h> |
8 |
#include <sys/ipc.h> |
9 |
#include <robot_shared.h> |
10 |
#include <string.h> |
11 |
RobotShared* shared_state; |
12 |
|
13 |
void *tick(int sig) |
14 |
{ |
15 |
printf("robot process paused. suspending\n");
|
16 |
|
17 |
if(raise(SIGTSTP)<0) |
18 |
printf("could not kill self!\n");
|
19 |
|
20 |
printf("robot resumed\n");
|
21 |
|
22 |
return NULL; |
23 |
} |
24 |
|
25 |
|
26 |
void dragonfly_init(int config) |
27 |
{ |
28 |
struct itimerval iv;
|
29 |
int ret;
|
30 |
|
31 |
shared_state = shmat(atoi(getenv("memory_id")), NULL, 0); |
32 |
|
33 |
if(shared_state < 0) |
34 |
{ |
35 |
printf("unable to get shared memory region\n");
|
36 |
return 1; |
37 |
} |
38 |
|
39 |
|
40 |
printf("hello. I am a robot w/ memory_id %s\n", getenv("memory_id")); |
41 |
|
42 |
|
43 |
iv.it_interval.tv_sec = 0;
|
44 |
iv.it_interval.tv_usec = 50000;
|
45 |
iv.it_value.tv_sec = 0;
|
46 |
iv.it_value.tv_usec = 50000;
|
47 |
|
48 |
signal(SIGVTALRM, tick); |
49 |
|
50 |
ret = setitimer(ITIMER_VIRTUAL, &iv, NULL);
|
51 |
|
52 |
printf("setitimer returned %d.\n waiting...\n", ret);
|
53 |
fflush(stdout); |
54 |
|
55 |
//TODO: clean up code??
|
56 |
|
57 |
} |
58 |
|