Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.04 KB)

1 986 bneuman
#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 993 ayeager
#include <robot_shared.h>
10 986 bneuman
#include <string.h>
11 906 bcoltin
12 986 bneuman
13 993 ayeager
RobotShared* shared_state;
14 986 bneuman
15
void *tick(int sig)
16
{
17 993 ayeager
  printf("robot process paused. suspending\n");
18 986 bneuman
19
  if(raise(SIGTSTP)<0)
20
    printf("could not kill self!\n");
21
22
  printf("robot resumed\n");
23
24
  return NULL;
25
}
26
27
28 906 bcoltin
void dragonfly_init(int config)
29
{
30 986 bneuman
  struct itimerval iv;
31
  int ret;
32 906 bcoltin
33 996 bneuman
  shared_state = shmat(atoi(getenv("memory_id")), NULL, 0);
34
35 986 bneuman
  if(shared_state < 0)
36
  {
37 996 bneuman
    printf("unable to get shared memory region\n");
38
    return 1;
39 993 ayeager
  }
40 986 bneuman
41
42
  printf("hello. I am a robot w/ memory_id %s\n", getenv("memory_id"));
43
44
45
  iv.it_interval.tv_sec = 1;
46
  iv.it_interval.tv_usec = 0;
47
  iv.it_value.tv_sec = 3;
48
  iv.it_value.tv_usec = 0;
49
50
  signal(SIGVTALRM, tick);
51
52
  ret = setitimer(ITIMER_VIRTUAL, &iv, NULL);
53
54
  printf("setitimer returned %d.\n waiting...\n", ret);
55
  fflush(stdout);
56
57
  //TODO: clean up code??
58
59 906 bcoltin
}