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