1 // trafficcontrol.hxx - classes to manage AIModels based air traffic control
2 // Written by Durk Talsma, started September 2006.
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.
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.
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.
21 #ifndef _TRAFFIC_CONTROL_HXX_
22 #define _TRAFFIC_CONTROL_HXX_
26 # error This library requires C++
30 #include <simgear/compiler.h>
31 #include <simgear/debug/logstream.hxx>
42 typedef vector<int> intVec;
43 typedef vector<int>::iterator intVecIterator;
46 class FGAIFlightPlan; // forward reference
47 class FGGroundNetwork; // forward reference
48 //class FGAISchedule; // forward reference
49 class FGAIAircraft; // forward reference
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
64 bool resolveCircularWait;
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; };
79 double getSpeed () { return speed; };
80 double getHeading () { return heading; };
81 double getAlt () { return alt; };
83 bool getCheckForCircularWait() { return resolveCircularWait; };
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; };
91 void setResolveCircularWait (bool val) { resolveCircularWait = val; };
93 void setSpeed (double val) { speed = val; };
94 void setHeading (double val) { heading = val; };
95 void setAlt (double val) { alt = val; };
102 /**************************************************************************************
103 * class FGTrafficRecord
104 *************************************************************************************/
105 class FGTrafficRecord
112 bool allowTransmission;
115 FGATCInstruction instruction;
116 double latitude, longitude, heading, speed, altitude, radius;
118 //FGAISchedule *trafficRef;
119 FGAIAircraft *aircraft;
125 void setId(int val) { id = val; };
126 void setRadius(double rad) { radius = rad;};
127 void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
128 void setRunway(string rwy) { runway = rwy;};
129 void setLeg(int lg) { leg = lg;};
130 int getId() { return id;};
131 int getState() { return state;};
132 FGATCInstruction getInstruction() { return instruction;};
133 bool hasInstruction() { return instruction.hasInstruction(); };
134 void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
135 bool checkPositionAndIntentions(FGTrafficRecord &other);
136 int crosses (FGGroundNetwork *, FGTrafficRecord &other);
137 bool isOpposing (FGGroundNetwork *, FGTrafficRecord &other, int node);
139 bool onRoute(FGGroundNetwork *, FGTrafficRecord &other);
141 bool getSpeedAdjustment() { return instruction.getChangeSpeed(); };
143 double getLatitude () { return latitude ; };
144 double getLongitude() { return longitude; };
145 double getHeading () { return heading ; };
146 double getSpeed () { return speed ; };
147 double getAltitude () { return altitude ; };
148 double getRadius () { return radius ; };
150 int getWaitsForId () { return waitsForId; };
152 void setSpeedAdjustment(double spd);
153 void setHeadingAdjustment(double heading);
154 void clearSpeedAdjustment () { instruction.setChangeSpeed (false); };
155 void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
157 bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
158 bool hasHoldPosition() { return instruction.getHoldPosition(); };
159 void setHoldPosition (bool inst) { instruction.setHoldPosition(inst); };
161 void setWaitsForId(int id) { waitsForId = id; };
163 void setResolveCircularWait() { instruction.setResolveCircularWait(true); };
164 void clearResolveCircularWait() { instruction.setResolveCircularWait(false); };
166 string getRunway() { return runway; };
167 //void setCallSign(string clsgn) { callsign = clsgn; };
168 void setAircraft(FGAIAircraft *ref) { aircraft = ref;};
169 void updateState() { state++; allowTransmission=true; };
170 //string getCallSign() { return callsign; };
171 FGAIAircraft *getAircraft() { return aircraft;};
172 int getTime() { return timer; };
173 int getLeg() { return leg; };
174 void setTime(time_t time) { timer = time; };
176 bool pushBackAllowed();
177 bool allowTransmissions() { return allowTransmission; };
178 void suppressRepeatedTransmissions () { allowTransmission=false; };
179 void allowRepeatedTransmissions () { allowTransmission=true; };
182 typedef vector<FGTrafficRecord> TrafficVector;
183 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
186 /***********************************************************************
187 * Active runway, a utility class to keep track of which aircraft has
188 * clearance for a given runway.
189 **********************************************************************/
194 int currentlyCleared;
196 ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; };
198 string getRunwayName() { return rwy; };
199 int getCleared () { return currentlyCleared; };
202 typedef vector<ActiveRunway> ActiveRunwayVec;
203 typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
206 * class FGATCController
207 * NOTE: this class serves as an abstraction layer for all sorts of ATC controller.
208 *************************************************************************************/
209 class FGATCController
215 string formatATCFrequency3_2(int );
216 string genTransponderCode(string fltRules);
220 MSG_ANNOUNCE_ENGINE_START,
221 MSG_REQUEST_ENGINE_START,
222 MSG_PERMIT_ENGINE_START,
223 MSG_DENY_ENGINE_START,
224 MSG_ACKNOWLEDGE_ENGINE_START,
225 MSG_REQUEST_PUSHBACK_CLEARANCE,
226 MSG_PERMIT_PUSHBACK_CLEARANCE,
227 MSG_HOLD_PUSHBACK_CLEARANCE } AtcMsgId;
230 ATC_GROUND_TO_AIR } AtcMsgDir;
231 FGATCController() { dt_count = 0;};
232 virtual ~FGATCController() {};
233 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
234 double lat, double lon,
235 double hdg, double spd, double alt, double radius, int leg,
236 FGAIAircraft *aircraft) = 0;
237 virtual void signOff(int id) = 0;
238 virtual void update(int id, double lat, double lon,
239 double heading, double speed, double alt, double dt) = 0;
240 virtual bool hasInstruction(int id) = 0;
241 virtual FGATCInstruction getInstruction(int id) = 0;
243 double getDt() { return dt_count; };
244 void setDt(double dt) { dt_count = dt;};
245 void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir);
246 string getGateName(FGAIAircraft *aircraft);
249 /******************************************************************************
250 * class FGTowerControl
251 *****************************************************************************/
252 class FGTowerController : public FGATCController
255 TrafficVector activeTraffic;
256 ActiveRunwayVec activeRunways;
260 virtual ~FGTowerController() {};
261 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
262 double lat, double lon,
263 double hdg, double spd, double alt, double radius, int leg,
264 FGAIAircraft *aircraft);
265 virtual void signOff(int id);
266 virtual void update(int id, double lat, double lon,
267 double heading, double speed, double alt, double dt);
268 virtual bool hasInstruction(int id);
269 virtual FGATCInstruction getInstruction(int id);
271 bool hasActiveTraffic() { return activeTraffic.size() != 0; };
272 TrafficVector &getActiveTraffic() { return activeTraffic; };
275 /******************************************************************************
276 * class FGStartupController
278 *****************************************************************************/
280 class FGStartupController : public FGATCController
283 TrafficVector activeTraffic;
285 time_t lastTransmission;
286 //ActiveRunwayVec activeRunways;
289 FGStartupController();
290 virtual ~FGStartupController() {};
291 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
292 double lat, double lon,
293 double hdg, double spd, double alt, double radius, int leg,
294 FGAIAircraft *aircraft);
295 virtual void signOff(int id);
296 virtual void update(int id, double lat, double lon,
297 double heading, double speed, double alt, double dt);
298 virtual bool hasInstruction(int id);
299 virtual FGATCInstruction getInstruction(int id);
301 bool hasActiveTraffic() { return activeTraffic.size() != 0; };
302 TrafficVector &getActiveTraffic() { return activeTraffic; };
306 #endif // _TRAFFIC_CONTROL_HXX