Project

General

Profile

Statistics
| Revision:

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

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