root / branches / simulator / projects / simulator / simulator / robot_test / robot.c @ 984
History | View | Annotate | Download (1.08 KB)
1 | 981 | bneuman | #include <stdio.h> |
---|---|---|---|
2 | #include <sys/time.h> |
||
3 | #include <signal.h> |
||
4 | #include <unistd.h> |
||
5 | #include <stdlib.h> |
||
6 | 984 | ayeager | #include <sys/shm.h> |
7 | #include <sys/ipc.h> |
||
8 | #include <robot_shared.h> |
||
9 | #include <string.h> |
||
10 | 981 | bneuman | |
11 | volatile int i; |
||
12 | |||
13 | 984 | ayeager | RobotShared* shared_state; |
14 | |||
15 | 981 | bneuman | void *tick(int sig) |
16 | { |
||
17 | printf("robot process paused. suspending\n");
|
||
18 | |||
19 | 984 | ayeager | shared_state->motor1++; |
20 | |||
21 | 981 | bneuman | 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 | 984 | ayeager | 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 | 981 | bneuman | 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 | 984 | ayeager | shmdt(shared_state); |
62 | 981 | bneuman | return 0; |
63 | } |