Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (999 Bytes)

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