]> git.mxchange.org Git - flightgear.git/blob - src/ATC/trafficcontrol.hxx
Improve handling of type DOUBLE in generic i/o protocol.
[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 FGAIAircraft;    // forward reference
49
50 /**************************************************************************************
51  * class FGATCInstruction
52  * like class FGATC Controller, this class definition should go into its own file
53  * and or directory... For now, just testing this stuff out though...
54  *************************************************************************************/
55 class FGATCInstruction
56 {
57 private:
58   bool holdPattern;
59   bool holdPosition;
60   bool changeSpeed;
61   bool changeHeading;
62   bool changeAltitude;
63   bool resolveCircularWait;
64
65   double speed;
66   double heading;
67   double alt;
68 public:
69
70   FGATCInstruction();
71   bool hasInstruction   ();
72   bool getHoldPattern   () { return holdPattern;    };
73   bool getHoldPosition  () { return holdPosition;   };
74   bool getChangeSpeed   () { return changeSpeed;    };
75   bool getChangeHeading () { return changeHeading;  };
76   bool getChangeAltitude() { return changeAltitude; };
77
78   double getSpeed       () { return speed; };
79   double getHeading     () { return heading; };
80   double getAlt         () { return alt; };
81
82   bool getCheckForCircularWait() { return resolveCircularWait; };
83
84   void setHoldPattern   (bool val) { holdPattern    = val; };
85   void setHoldPosition  (bool val) { holdPosition   = val; };
86   void setChangeSpeed   (bool val) { changeSpeed    = val; };
87   void setChangeHeading (bool val) { changeHeading  = val; };
88   void setChangeAltitude(bool val) { changeAltitude = val; };
89
90   void setResolveCircularWait (bool val) { resolveCircularWait = val; }; 
91
92   void setSpeed       (double val) { speed   = val; };
93   void setHeading     (double val) { heading = val; };
94   void setAlt         (double val) { alt     = val; };
95 };
96
97
98
99
100
101 /**************************************************************************************
102  * class FGTrafficRecord
103  *************************************************************************************/
104 class FGTrafficRecord
105 {
106 private:
107   int id, waitsForId;
108   int currentPos;
109   int leg;
110   int state;
111   bool allowTransmission;
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++; allowTransmission=true; };
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   bool pushBackAllowed();
176   bool allowTransmissions() { return allowTransmission; };
177   void suppressRepeatedTransmissions () { allowTransmission=false; };
178   void allowRepeatedTransmissions () { allowTransmission=true; };
179 };
180
181 typedef vector<FGTrafficRecord> TrafficVector;
182 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
183
184
185 /***********************************************************************
186  * Active runway, a utility class to keep track of which aircraft has
187  * clearance for a given runway.
188  **********************************************************************/
189 class ActiveRunway
190 {
191 private:
192   string rwy;
193   int currentlyCleared;
194 public:
195   ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; };
196   
197   string getRunwayName() { return rwy; };
198   int    getCleared   () { return currentlyCleared; };
199 };
200
201 typedef vector<ActiveRunway> ActiveRunwayVec;
202 typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
203
204 /**
205  * class FGATCController
206  * NOTE: this class serves as an abstraction layer for all sorts of ATC controller. 
207  *************************************************************************************/
208 class FGATCController
209 {
210 private:
211   double dt_count;
212
213
214   string formatATCFrequency3_2(int );
215   string genTransponderCode(string fltRules);
216
217 public:
218   typedef enum {
219       MSG_ANNOUNCE_ENGINE_START,
220       MSG_REQUEST_ENGINE_START, 
221       MSG_PERMIT_ENGINE_START,
222       MSG_DENY_ENGINE_START,
223       MSG_ACKNOWLEDGE_ENGINE_START,
224       MSG_REQUEST_PUSHBACK_CLEARANCE,
225       MSG_PERMIT_PUSHBACK_CLEARANCE, 
226       MSG_HOLD_PUSHBACK_CLEARANCE } AtcMsgId;
227   typedef enum {
228       ATC_AIR_TO_GROUND,
229       ATC_GROUND_TO_AIR } AtcMsgDir;
230   FGATCController() { dt_count = 0;};
231   virtual ~FGATCController() {};
232   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
233                                 double lat, double lon,
234                                 double hdg, double spd, double alt, double radius, int leg,
235                                 FGAIAircraft *aircraft) = 0;
236   virtual void             signOff(int id) = 0;
237   virtual void             update(int id, double lat, double lon, 
238                                   double heading, double speed, double alt, double dt) = 0;
239   virtual bool             hasInstruction(int id) = 0;
240   virtual FGATCInstruction getInstruction(int id) = 0;
241
242   double getDt() { return dt_count; };
243   void   setDt(double dt) { dt_count = dt;};
244   void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir);
245   string getGateName(FGAIAircraft *aircraft);
246 };
247
248 /******************************************************************************
249  * class FGTowerControl
250  *****************************************************************************/
251 class FGTowerController : public FGATCController
252 {
253 private:
254   TrafficVector activeTraffic;
255   ActiveRunwayVec activeRunways;
256   
257 public:
258   FGTowerController();
259   virtual ~FGTowerController() {};
260   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
261                                 double lat, double lon,
262                                 double hdg, double spd, double alt, double radius, int leg,
263                                 FGAIAircraft *aircraft);
264   virtual void             signOff(int id);
265   virtual void             update(int id, double lat, double lon, 
266                                   double heading, double speed, double alt, double dt);
267   virtual bool             hasInstruction(int id);
268   virtual FGATCInstruction getInstruction(int id);
269
270   bool hasActiveTraffic() { return activeTraffic.size() != 0; };
271   TrafficVector &getActiveTraffic() { return activeTraffic; };
272 };
273
274 /******************************************************************************
275  * class FGStartupController
276  * handle 
277  *****************************************************************************/
278
279 class FGStartupController : public FGATCController
280 {
281 private:
282   TrafficVector activeTraffic;
283   bool available;
284   time_t lastTransmission;
285   //ActiveRunwayVec activeRunways;
286   
287 public:
288   FGStartupController();
289   virtual ~FGStartupController() {};
290   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
291                                 double lat, double lon,
292                                 double hdg, double spd, double alt, double radius, int leg,
293                                 FGAIAircraft *aircraft);
294   virtual void             signOff(int id);
295   virtual void             update(int id, double lat, double lon, 
296                                   double heading, double speed, double alt, double dt);
297   virtual bool             hasInstruction(int id);
298   virtual FGATCInstruction getInstruction(int id);
299
300   bool hasActiveTraffic() { return activeTraffic.size() != 0; };
301   TrafficVector &getActiveTraffic() { return activeTraffic; };
302
303 }; 
304
305 #endif // _TRAFFIC_CONTROL_HXX