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
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++;};
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; };
176 typedef vector<FGTrafficRecord> TrafficVector;
177 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
180 /***********************************************************************
181 * Active runway, a utility class to keep track of which aircraft has
182 * clearance for a given runway.
183 **********************************************************************/
188 int currentlyCleared;
190 ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; };
192 string getRunwayName() { return rwy; };
193 int getCleared () { return currentlyCleared; };
196 typedef vector<ActiveRunway> ActiveRunwayVec;
197 typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
200 * class FGATCController
201 * NOTE: this class serves as an abstraction layer for all sorts of ATC controller.
202 *************************************************************************************/
203 class FGATCController
209 string formatATCFrequency3_2(int );
210 string genTransponderCode(string fltRules);
214 MSG_ANNOUNCE_ENGINE_START,
215 MSG_REQUEST_ENGINE_START,
216 MSG_PERMIT_ENGINE_START,
217 MSG_DENY_ENGINE_START,
218 MSG_ACKNOWLEDGE_ENGINE_START } AtcMsgId;
221 ATC_GROUND_TO_AIR } AtcMsgDir;
222 FGATCController() { dt_count = 0;};
223 virtual ~FGATCController() {};
224 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
225 double lat, double lon,
226 double hdg, double spd, double alt, double radius, int leg,
227 FGAIAircraft *aircraft) = 0;
228 virtual void signOff(int id) = 0;
229 virtual void update(int id, double lat, double lon,
230 double heading, double speed, double alt, double dt) = 0;
231 virtual bool hasInstruction(int id) = 0;
232 virtual FGATCInstruction getInstruction(int id) = 0;
234 double getDt() { return dt_count; };
235 void setDt(double dt) { dt_count = dt;};
236 void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir);
237 string getGateName(FGAIAircraft *aircraft);
240 /******************************************************************************
241 * class FGTowerControl
242 *****************************************************************************/
243 class FGTowerController : public FGATCController
246 TrafficVector activeTraffic;
247 ActiveRunwayVec activeRunways;
251 virtual ~FGTowerController() {};
252 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
253 double lat, double lon,
254 double hdg, double spd, double alt, double radius, int leg,
255 FGAIAircraft *aircraft);
256 virtual void signOff(int id);
257 virtual void update(int id, double lat, double lon,
258 double heading, double speed, double alt, double dt);
259 virtual bool hasInstruction(int id);
260 virtual FGATCInstruction getInstruction(int id);
262 bool hasActiveTraffic() { return activeTraffic.size() != 0; };
263 TrafficVector &getActiveTraffic() { return activeTraffic; };
266 /******************************************************************************
267 * class FGStartupController
269 *****************************************************************************/
271 class FGStartupController : public FGATCController
274 TrafficVector activeTraffic;
276 time_t lastTransmission;
277 //ActiveRunwayVec activeRunways;
280 FGStartupController();
281 virtual ~FGStartupController() {};
282 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
283 double lat, double lon,
284 double hdg, double spd, double alt, double radius, int leg,
285 FGAIAircraft *aircraft);
286 virtual void signOff(int id);
287 virtual void update(int id, double lat, double lon,
288 double heading, double speed, double alt, double dt);
289 virtual bool hasInstruction(int id);
290 virtual FGATCInstruction getInstruction(int id);
292 bool hasActiveTraffic() { return activeTraffic.size() != 0; };
293 TrafficVector &getActiveTraffic() { return activeTraffic; };
297 #endif // _TRAFFIC_CONTROL_HXX