Project

General

Profile

Statistics
| Revision:

root / branches / simulator / projects / simulator / libsim / libsim.c @ 986

History | View | Annotate | Download (1.06 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

    
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

    
30
void dragonfly_init(int config)
31
{
32
  struct itimerval iv;
33
  int ret;
34

    
35
  /*shared_state = shmat(atoi(envp[0]), NULL, 0);
36
  if(shared_state < 0)
37
  {
38
          printf("unable to get shared memory region\n");
39
          return 1;
40
          }*/
41

    
42
                                             
43
  printf("hello. I am a robot w/ memory_id %s\n", getenv("memory_id"));
44

    
45

    
46
  iv.it_interval.tv_sec = 1;
47
  iv.it_interval.tv_usec = 0;
48
  iv.it_value.tv_sec = 3;
49
  iv.it_value.tv_usec = 0;
50

    
51
  signal(SIGVTALRM, tick);
52

    
53
  ret = setitimer(ITIMER_VIRTUAL, &iv, NULL);
54

    
55
  printf("setitimer returned %d.\n waiting...\n", ret);
56
  fflush(stdout);
57

    
58
  //TODO: clean up code??
59

    
60
}
61