Blame |
Last modification |
View Log
| RSS feed
/**************************************
* Project ATCSim
* Developed By :
* 1) Tushar Bansal
* 2) Chirag Patel
* IMIT 2003-04
* Real Time Operating System
***************************************/
/***************************************
* Air Traffic Controller Simulation *
****************************************/
#include <kernel/kern.h> //include the SHARK kernel header
#include <drivers/glib.h> //include the graphics library
#include <drivers/keyb.h> //include the keyboard library
#include <semaphore.h> //include the semaphore library
#include <stdlib.h> //include the standard library
#include <math.h> //include the math library for random
#include <string.h>
#include <drivers/keyb.h>
#ifndef _ATCSIM_HEADER_
#include "atcsim.h"
#endif
#ifndef _SIM_AREA_HEADER_
#include "sim_area.h"
#endif
mutex_t mut_number_of_planes
; //used to protect the number_of_planes global variable
mutex_t mut_STARTSIM
; //used to protect the global variable STARTSIM used to avoid refreshing screen
sem_t mut_planeinzone
[MAX_ATCS
][MAX_PLANES
];
sem_t mut_aeroplane
[MAX_PLANES
];
sem_t graphics_mutex
; //used for mututal exclusion of display
//resolution to use
const int maxheight
=768;
const int maxwidth
=1024;
const int bpp
=16;
void init_scenario
()
{
//display the headings at the top
grx_text
("Air Traffic Controller Simulation", 0, 0,white
, black
);
grx_text
("Esc : Exit",500, 0, gray
, black
);
grx_text
("Space : Create a plane",500,16, gray
, black
);
#ifdef JET_ON
scenario_jetcontrol
();
#endif
#ifdef JET_ON
init_jetcontrol
();
#endif
read_airports_info
();
read_aeroplanes_info
();
}
void end_sim
()
{
grx_close
();
int planeid
;
if (STARTSIM
!=-1)
{
for (planeid
=0;planeid
<MAX_PLANES
;planeid
++)
{
// cab_delete(atc_plane_cab_id[planeid]);
cab_delete
(plane_atc_cab_id
[planeid
]);
}
}
cprintf
("Thanks for using Air Traffic Controller Simulation!\n");
}
int main
(int argc
, char **argv
)
{
int i
=0,j
;
TIME seme
; /* used to init the random seed */
/* randomize!!!! */
seme
= sys_gettime
(NULL
);
srand(seme
);
sem_init
(&graphics_mutex
,0,1);
for (j
=0;j
<MAX_ATCS
;j
++)
{
for(i
=0;i
<MAX_PLANES
;i
++)
{
sem_init
(&mut_aeroplane
[i
],0,1);
sem_init
(&mut_planeinzone
[j
][i
],0,1);
}
}
sys_atrunlevel
(end_sim
, NULL
, RUNLEVEL_BEFORE_EXIT
);
if (grx_init
() < 1)
{
cprintf
("System Aborted because cannot initialize graphics\n");
sys_abort
(1);
}
if (grx_open
(maxwidth
,maxheight
,bpp
) < 0)
{
cprintf
("Graphics error\n");
sys_abort
(1);
}
// useful colors ...
white
= rgb16
(255,255,255);
black
= rgb16
(0,0,0);
red
= rgb16
(255,0,0);
gray
= rgb16
(128,128,128);
green
= rgb16
(0,255,0);
blue
= rgb16
(0,0,255);
PI_mutexattr_t a
,b
;
PI_mutexattr_default
(a
);
PI_mutexattr_default
(b
);
for (i
=0;i
<MAX_PLANES
;i
++)
sem_init
(&mut_aeroplane
[i
],0,1);
mutex_init
(&mut_STARTSIM
,&a
);
mutex_init
(&mut_number_of_planes
,&b
);
//to display the static information for the first time
//read the airport file and display the airports
//read the aeroplane model file and display the aeroplanes
init_scenario
();
//to display the grid
//to initiliaze the ATCs
//to display the airports
//init_cabs();
init_simulation
();
//to activate the Manager ATC TASK
init_atcs
();
//to activate the jet control tasks
group_activate
(JETCONTROL
);
//to start the planes
init_planes
();
return 0;
}