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 FGAIAircraft; // forward reference
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
63 bool resolveCircularWait;
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; };
78 double getSpeed () { return speed; };
79 double getHeading () { return heading; };
80 double getAlt () { return alt; };
82 bool getCheckForCircularWait() { return resolveCircularWait; };
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; };
90 void setResolveCircularWait (bool val) { resolveCircularWait = val; };
92 void setSpeed (double val) { speed = val; };
93 void setHeading (double val) { heading = val; };
94 void setAlt (double val) { alt = val; };
101 /**************************************************************************************
102 * class FGTrafficRecord
103 *************************************************************************************/
104 class FGTrafficRecord
111 bool allowTransmission;
114 FGATCInstruction instruction;
115 double latitude, longitude, heading, speed, altitude, radius;
117 //FGAISchedule *trafficRef;
118 FGAIAircraft *aircraft;
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);
138 bool onRoute(FGGroundNetwork *, FGTrafficRecord &other);
140 bool getSpeedAdjustment() { return instruction.getChangeSpeed(); };
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 ; };
149 int getWaitsForId () { return waitsForId; };
151 void setSpeedAdjustment(double spd);
152 void setHeadingAdjustment(double heading);
153 void clearSpeedAdjustment () { instruction.setChangeSpeed (false); };
154 void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
156 bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
157 bool hasHoldPosition() { return instruction.getHoldPosition(); };
158 void setHoldPosition (bool inst) { instruction.setHoldPosition(inst); };
160 void setWaitsForId(int id) { waitsForId = id; };
162 void setResolveCircularWait() { instruction.setResolveCircularWait(true); };
163 void clearResolveCircularWait() { instruction.setResolveCircularWait(false); };
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; };
175 bool pushBackAllowed();
176 bool allowTransmissions() { return allowTransmission; };
177 void suppressRepeatedTransmissions () { allowTransmission=false; };
178 void allowRepeatedTransmissions () { allowTransmission=true; };
181 typedef vector<FGTrafficRecord> TrafficVector;
182 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
185 /***********************************************************************
186 * Active runway, a utility class to keep track of which aircraft has
187 * clearance for a given runway.
188 **********************************************************************/
193 int currentlyCleared;
195 ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; };
197 string getRunwayName() { return rwy; };
198 int getCleared () { return currentlyCleared; };
201 typedef vector<ActiveRunway> ActiveRunwayVec;
202 typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
205 * class FGATCController
206 * NOTE: this class serves as an abstraction layer for all sorts of ATC controller.
207 *************************************************************************************/
208 class FGATCController
214 string formatATCFrequency3_2(int );
215 string genTransponderCode(string fltRules);
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;
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;
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);
248 /******************************************************************************
249 * class FGTowerControl
250 *****************************************************************************/
251 class FGTowerController : public FGATCController
254 TrafficVector activeTraffic;
255 ActiveRunwayVec activeRunways;
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);
270 bool hasActiveTraffic() { return activeTraffic.size() != 0; };
271 TrafficVector &getActiveTraffic() { return activeTraffic; };
274 /******************************************************************************
275 * class FGStartupController
277 *****************************************************************************/
279 class FGStartupController : public FGATCController
282 TrafficVector activeTraffic;
284 time_t lastTransmission;
285 //ActiveRunwayVec activeRunways;
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);
300 bool hasActiveTraffic() { return activeTraffic.size() != 0; };
301 TrafficVector &getActiveTraffic() { return activeTraffic; };
305 #endif // _TRAFFIC_CONTROL_HXX