Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1664 pj 1
/**************************************
2
 *      Project ATCSim
3
 *      Developed By :
4
 *              1) Tushar Bansal
5
 *              2) Chirag Patel
6
 *      IMIT 2003-04
7
 *      Real Time Operating System
8
***************************************/
9
/***************************************
10
*  Air Traffic Controller Simulation   *
11
****************************************/
12
 
13
#include <kernel/kern.h>   //include the SHARK kernel header
14
#include <drivers/glib.h>  //include the graphics library
15
#include <drivers/keyb.h>  //include the keyboard library
16
#include <semaphore.h>     //include the semaphore library
17
#include <stdlib.h>                //include the standard library
18
#include <math.h>          //include the math library for random
19
#include <string.h>
20
#include <drivers/keyb.h>
21
 
22
 
23
#ifndef _ATCSIM_HEADER_
24
#include "atcsim.h"
25
#endif
26
 
27
#ifndef _SIM_AREA_HEADER_
28
#include "sim_area.h"
29
#endif
30
 
31
mutex_t mut_number_of_planes;  //used to protect the number_of_planes global variable
32
mutex_t mut_STARTSIM;  //used to protect the global variable STARTSIM used to avoid refreshing screen
33
sem_t mut_planeinzone[MAX_ATCS][MAX_PLANES];
34
 
35
sem_t mut_aeroplane[MAX_PLANES];
36
sem_t graphics_mutex;  //used for mututal exclusion of display
37
 
38
//resolution to use
39
const int maxheight=768;
40
const int maxwidth=1024;
41
const int bpp=16;
42
 
43
void init_scenario()
44
{
45
        //display the headings at the top
46
        grx_text("Air Traffic Controller Simulation", 0, 0,white , black );
47
        grx_text("Esc  : Exit",500, 0, gray, black );
48
        grx_text("Space   : Create a plane",500,16, gray, black );
49
 
50
        #ifdef JET_ON
51
        scenario_jetcontrol();
52
        #endif
53
 
54
        #ifdef JET_ON
55
        init_jetcontrol();
56
        #endif
57
 
58
        read_airports_info();
59
        read_aeroplanes_info();
60
}
61
 
62
 
63
void end_sim()
64
{
65
        grx_close();
66
        int planeid;
67
 
68
        if (STARTSIM!=-1)
69
        {
70
                for (planeid=0;planeid<MAX_PLANES;planeid++)
71
                {
72
                //      cab_delete(atc_plane_cab_id[planeid]);
73
                        cab_delete(plane_atc_cab_id[planeid]);
74
                }
75
        }
76
        cprintf("Thanks for using Air Traffic Controller Simulation!\n");
77
}
78
 
79
 
80
int main(int argc, char **argv)
81
{
82
        int i=0,j;
83
        TIME seme;          /* used to init the random seed */
84
        /* randomize!!!! */
85
        seme = sys_gettime(NULL);
86
        srand(seme);
87
 
88
        sem_init(&graphics_mutex,0,1);
89
 
90
        for (j=0;j<MAX_ATCS;j++)
91
        {
92
                for(i=0;i<MAX_PLANES;i++)
93
                {
94
                        sem_init(&mut_aeroplane[i],0,1);
95
                        sem_init(&mut_planeinzone[j][i],0,1);
96
                }
97
        }
98
 
99
        sys_atrunlevel(end_sim, NULL, RUNLEVEL_BEFORE_EXIT);
100
 
101
        if (grx_init() < 1)
102
        {
103
                cprintf("System Aborted because cannot initialize graphics\n");
104
                sys_abort(1);
105
        }
106
 
107
        if (grx_open(maxwidth,maxheight,bpp) < 0)
108
        {
109
                cprintf("Graphics error\n");
110
                sys_abort(1);
111
        }
112
 
113
        // useful colors ...
114
        white = rgb16(255,255,255);
115
        black = rgb16(0,0,0);
116
        red   = rgb16(255,0,0);
117
        gray  = rgb16(128,128,128);
118
        green = rgb16(0,255,0);
119
        blue = rgb16(0,0,255);
120
 
121
        PI_mutexattr_t a,b;
122
        PI_mutexattr_default(a);
123
        PI_mutexattr_default(b);
124
        for (i=0;i<MAX_PLANES;i++)
125
                sem_init(&mut_aeroplane[i],0,1);
126
 
127
        mutex_init(&mut_STARTSIM,&a);
128
        mutex_init(&mut_number_of_planes,&b);
129
 
130
        //to display the static information for the first time
131
        //read the airport file and display the airports
132
        //read the aeroplane model file and display the aeroplanes
133
        init_scenario();
134
        //to display the grid
135
        //to initiliaze the ATCs
136
        //to display the airports
137
 
138
        //init_cabs();
139
        init_simulation();
140
 
141
        //to activate the Manager ATC TASK
142
        init_atcs();
143
 
144
        //to activate the jet control tasks
145
        group_activate(JETCONTROL);
146
 
147
        //to start the planes
148
        init_planes();
149
 
150
        return 0;
151
}