Project

General

Profile

Revision 986

moved stuff from robot_test into libsim.c
libsim now contains the timer (pause/resume) stuff

Also commented andrew's code because it broke the build

View differences:

main.c
13 13
int create_robot(char *execname, int id, SimulatorRobot* sim_memory)
14 14
{
15 15
  /* do shared memory stuff here */
16
  key_t key = IPC_PRIVATE;
16
  // key_t key = IPC_PRIVATE;
17 17
  /*Memory accessible only to children and gives them read/write priveledge*/
18
  sim_memory->robotSharedMemoryID = shmget(key, sizeof(RobotShared), IPC_CREAT | 0666);
18
  //  sim_memory->robotSharedMemoryID = shmget(key, sizeof(RobotShared), IPC_CREAT | 0666);
19 19
  
20
  if(sim_memory->robotSharedMemoryID < 0)
20
  /*  if(sim_memory->robotSharedMemoryID < 0)
21 21
  {
22 22
	  printf("error getting shared memory\n");
23 23
	  return -1;
......
30 30
	printf("error attaching parent process\n");
31 31
	return -1;
32 32
  }
33
  
33
  */
34 34
  /*Init robot structure here*/
35
  sim_memory->robotState->motor1 = 0;
36
  sim_memory->robotState->motor2 = 0;
37

  
35
  /*  sim_memory->robotState->motor1 = 0;
36
      sim_memory->robotState->motor2 = 0;*/
38 37
  int pid;
39 38

  
40 39
  if((pid = fork())<0){
......
43 42
  }                       
44 43
  
45 44
  char var[21];
46
  sprintf(var, "memory_id=%d", sim_memory->robotSharedMemoryID);
47 45
  char *envp[] = {var, NULL};
48 46

  
49 47
  if(!pid){
50 48
    /* restore default sigchld handler */
51 49
    signal(SIGCHLD, SIG_DFL);
52 50

  
51
    sprintf(var, "memory_id=%d", 1);//sim_memory->robotSharedMemoryID);
52

  
53 53
    execve(execname, NULL, envp);  //TODO: keep the other env. stuff around
54 54
    printf ("error! exec failed\n");
55 55
	
......
61 61

  
62 62
int free_robot(SimulatorRobot sim)                       
63 63
{
64
	shmdt(sim.robotState);
65
	return shmctl(sim.robotSharedMemoryID, IPC_RMID, NULL); 
64
  return 0;/*
65
 	shmdt(sim.robotState);
66
	return shmctl(sim.robotSharedMemoryID, IPC_RMID, NULL); */
66 67
}
67 68

  
68 69
void *sig_chld_handler(int sig)
......
85 86
{
86 87
  signal(SIGCHLD, sig_chld_handler);
87 88

  
88
  SimulatorRobot sim;
89
  //SimulatorRobot sim;
89 90

  
90
  create_robot("robot_test/robot", 0, &sim);
91
  if(argc<=1){
92
    printf("Usage: simulator <robot execetuable>\n");
93
    exit(-1);
94
  }
91 95

  
96
  create_robot(argv[1], 0, NULL/*&sim*/);
97

  
92 98
  printf("returned to parent\n");
93 99

  
94 100
  int x;
95
  for(x = 0; x <10000; x++)
96
	  printf("motor 1: %d\n", x);
101
  /*  for(x = 0; x <10000; x++)
102
      printf("motor 1: %d\n", x);*/
97 103

  
98 104
  gtk_gui_run(argc, argv);
99 105

  

Also available in: Unified diff