]> git.mxchange.org Git - flightgear.git/blob - src/ATC/trafficcontrol.hxx
850a0f930c6fa1c81867b69bc6633a4d04c60da4
[flightgear.git] / src / ATC / trafficcontrol.hxx
1 // trafficcontrol.hxx - classes to manage AIModels based air traffic control
2 // Written by Durk Talsma, started September 2006.
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 2 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //
18 // $Id$
19
20
21 #ifndef _TRAFFIC_CONTROL_HXX_
22 #define _TRAFFIC_CONTROL_HXX_
23
24
25 #ifndef __cplusplus
26 # error This library requires C++
27 #endif
28
29
30 #include <simgear/compiler.h>
31 #include <simgear/debug/logstream.hxx>
32
33
34
35 #include <string>
36 #include <vector>
37
38 using std::string;
39 using std::vector;
40
41
42 typedef vector<int> intVec;
43 typedef vector<int>::iterator intVecIterator;
44
45
46 class FGAIFlightPlan;  // forward reference
47 class FGGroundNetwork; // forward reference
48 //class FGAISchedule;    // forward reference
49 class FGAIAircraft;    // forward reference
50
51 /**************************************************************************************
52  * class FGATCInstruction
53  * like class FGATC Controller, this class definition should go into its own file
54  * and or directory... For now, just testing this stuff out though...
55  *************************************************************************************/
56 class FGATCInstruction
57 {
58 private:
59   bool holdPattern;
60   bool holdPosition;
61   bool changeSpeed;
62   bool changeHeading;
63   bool changeAltitude;
64   bool resolveCircularWait;
65
66   double speed;
67   double heading;
68   double alt;
69 public:
70
71   FGATCInstruction();
72   bool hasInstruction   ();
73   bool getHoldPattern   () { return holdPattern;    };
74   bool getHoldPosition  () { return holdPosition;   };
75   bool getChangeSpeed   () { return changeSpeed;    };
76   bool getChangeHeading () { return changeHeading;  };
77   bool getChangeAltitude() { return changeAltitude; };
78
79   double getSpeed       () { return speed; };
80   double getHeading     () { return heading; };
81   double getAlt         () { return alt; };
82
83   bool getCheckForCircularWait() { return resolveCircularWait; };
84
85   void setHoldPattern   (bool val) { holdPattern    = val; };
86   void setHoldPosition  (bool val) { holdPosition   = val; };
87   void setChangeSpeed   (bool val) { changeSpeed    = val; };
88   void setChangeHeading (bool val) { changeHeading  = val; };
89   void setChangeAltitude(bool val) { changeAltitude = val; };
90
91   void setResolveCircularWait (bool val) { resolveCircularWait = val; }; 
92
93   void setSpeed       (double val) { speed   = val; };
94   void setHeading     (double val) { heading = val; };
95   void setAlt         (double val) { alt     = val; };
96 };
97
98
99
100
101
102 /**************************************************************************************
103  * class FGTrafficRecord
104  *************************************************************************************/
105 class FGTrafficRecord
106 {
107 private:
108   int id, waitsForId;
109   int currentPos;
110   int leg;
111   int state;
112   time_t timer;
113   intVec intentions;
114   FGATCInstruction instruction;
115   double latitude, longitude, heading, speed, altitude, radius;
116   string runway;
117   //FGAISchedule *trafficRef;
118   FGAIAircraft *aircraft;
119   
120   
121 public:
122   FGTrafficRecord();
123   
124   void setId(int val)  { id = val; };
125   void setRadius(double rad) { radius = rad;};
126   void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
127   void setRunway(string rwy) { runway = rwy;};
128   void setLeg(int lg) { leg = lg;};
129   int getId() { return id;};
130   int getState() { return state;};
131   FGATCInstruction getInstruction() { return instruction;};
132   bool hasInstruction() { return instruction.hasInstruction(); };
133   void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
134   bool checkPositionAndIntentions(FGTrafficRecord &other);
135   int  crosses                   (FGGroundNetwork *, FGTrafficRecord &other); 
136   bool isOpposing                (FGGroundNetwork *, FGTrafficRecord &other, int node);
137
138   bool onRoute(FGGroundNetwork *, FGTrafficRecord &other);
139
140   bool getSpeedAdjustment() { return instruction.getChangeSpeed(); };
141   
142   double getLatitude () { return latitude ; };
143   double getLongitude() { return longitude; };
144   double getHeading  () { return heading  ; };
145   double getSpeed    () { return speed    ; };
146   double getAltitude () { return altitude ; };
147   double getRadius   () { return radius   ; };
148
149   int getWaitsForId  () { return waitsForId; };
150
151   void setSpeedAdjustment(double spd);
152   void setHeadingAdjustment(double heading);
153   void clearSpeedAdjustment  () { instruction.setChangeSpeed  (false); };
154   void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
155
156   bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
157   bool hasHoldPosition() { return instruction.getHoldPosition(); };
158   void setHoldPosition (bool inst) { instruction.setHoldPosition(inst); };
159
160   void setWaitsForId(int id) { waitsForId = id; };
161
162   void setResolveCircularWait()   { instruction.setResolveCircularWait(true);  };
163   void clearResolveCircularWait() { instruction.setResolveCircularWait(false); };
164
165   string getRunway() { return runway; };
166   //void setCallSign(string clsgn) { callsign = clsgn; };
167   void setAircraft(FGAIAircraft *ref) { aircraft = ref;};
168   void updateState() { state++;};
169   //string getCallSign() { return callsign; };
170   FGAIAircraft *getAircraft() { return aircraft;};
171   int getTime() { return timer; };
172   int getLeg() { return leg; };
173   void setTime(time_t time) { timer = time; };
174 };
175
176 typedef vector<FGTrafficRecord> TrafficVector;
177 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
178
179
180 /***********************************************************************
181  * Active runway, a utility class to keep track of which aircraft has
182  * clearance for a given runway.
183  **********************************************************************/
184 class ActiveRunway
185 {
186 private:
187   string rwy;
188   int currentlyCleared;
189 public:
190   ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; };
191   
192   string getRunwayName() { return rwy; };
193   int    getCleared   () { return currentlyCleared; };
194 };
195
196 typedef vector<ActiveRunway> ActiveRunwayVec;
197 typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
198
199 /**
200  * class FGATCController
201  * NOTE: this class serves as an abstraction layer for all sorts of ATC controller. 
202  *************************************************************************************/
203 class FGATCController
204 {
205 private:
206   double dt_count;
207
208
209   string formatATCFrequency3_2(int );
210
211 public:
212   typedef enum {
213       MSG_ANNOUNCE_ENGINE_START,
214       MSG_REQUEST_ENGINE_START, 
215       MSG_PERMIT_ENGINE_START,
216       MSG_DENY_ENGINE_START,
217       MSG_ACKNOWLEDGE_ENGINE_START } AtcMsgId;
218   typedef enum {
219       ATC_AIR_TO_GROUND,
220       ATC_GROUND_TO_AIR } AtcMsgDir;
221   FGATCController() { dt_count = 0;};
222   virtual ~FGATCController() {};
223   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
224                                 double lat, double lon,
225                                 double hdg, double spd, double alt, double radius, int leg,
226                                 FGAIAircraft *aircraft) = 0;
227   virtual void             signOff(int id) = 0;
228   virtual void             update(int id, double lat, double lon, 
229                                   double heading, double speed, double alt, double dt) = 0;
230   virtual bool             hasInstruction(int id) = 0;
231   virtual FGATCInstruction getInstruction(int id) = 0;
232
233   double getDt() { return dt_count; };
234   void   setDt(double dt) { dt_count = dt;};
235   void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir);
236   string getGateName(FGAIAircraft *aircraft);
237 };
238
239 /******************************************************************************
240  * class FGTowerControl
241  *****************************************************************************/
242 class FGTowerController : public FGATCController
243 {
244 private:
245   TrafficVector activeTraffic;
246   ActiveRunwayVec activeRunways;
247   
248 public:
249   FGTowerController();
250   virtual ~FGTowerController() {};
251   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
252                                 double lat, double lon,
253                                 double hdg, double spd, double alt, double radius, int leg,
254                                 FGAIAircraft *aircraft);
255   virtual void             signOff(int id);
256   virtual void             update(int id, double lat, double lon, 
257                                   double heading, double speed, double alt, double dt);
258   virtual bool             hasInstruction(int id);
259   virtual FGATCInstruction getInstruction(int id);
260
261   bool hasActiveTraffic() { return activeTraffic.size() != 0; };
262   TrafficVector &getActiveTraffic() { return activeTraffic; };
263 };
264
265 /******************************************************************************
266  * class FGStartupController
267  * handle 
268  *****************************************************************************/
269
270 class FGStartupController : public FGATCController
271 {
272 private:
273   TrafficVector activeTraffic;
274   bool available;
275   time_t lastTransmission;
276   //ActiveRunwayVec activeRunways;
277   
278 public:
279   FGStartupController();
280   virtual ~FGStartupController() {};
281   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
282                                 double lat, double lon,
283                                 double hdg, double spd, double alt, double radius, int leg,
284                                 FGAIAircraft *aircraft);
285   virtual void             signOff(int id);
286   virtual void             update(int id, double lat, double lon, 
287                                   double heading, double speed, double alt, double dt);
288   virtual bool             hasInstruction(int id);
289   virtual FGATCInstruction getInstruction(int id);
290
291   bool hasActiveTraffic() { return activeTraffic.size() != 0; };
292   TrafficVector &getActiveTraffic() { return activeTraffic; };
293
294 }; 
295
296 #endif // _TRAFFIC_CONTROL_HXX