2008-07-13 12:51:06 +00:00
|
|
|
// trafficcontrol.hxx - classes to manage AIModels based air traffic control
|
|
|
|
// Written by Durk Talsma, started September 2006.
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _TRAFFIC_CONTROL_HXX_
|
|
|
|
#define _TRAFFIC_CONTROL_HXX_
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
2010-08-29 17:25:34 +00:00
|
|
|
// There is probably a better include than sg_geodesy to get the SG_NM_TO_METER...
|
|
|
|
#include <simgear/math/sg_geodesy.hxx>
|
2008-07-13 12:51:06 +00:00
|
|
|
#include <simgear/debug/logstream.hxx>
|
2011-04-03 15:58:16 +00:00
|
|
|
#include <simgear/structure/SGReferenced.hxx>
|
|
|
|
#include <simgear/structure/SGSharedPtr.hxx>
|
2008-07-13 12:51:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-07-25 18:38:29 +00:00
|
|
|
#include <string>
|
2008-07-13 12:51:06 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2008-07-27 16:25:13 +00:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
2008-07-13 12:51:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef vector<int> intVec;
|
|
|
|
typedef vector<int>::iterator intVecIterator;
|
|
|
|
|
|
|
|
|
|
|
|
class FGAIFlightPlan; // forward reference
|
|
|
|
class FGGroundNetwork; // forward reference
|
|
|
|
class FGAIAircraft; // forward reference
|
|
|
|
|
|
|
|
/**************************************************************************************
|
|
|
|
* class FGATCInstruction
|
|
|
|
* like class FGATC Controller, this class definition should go into its own file
|
|
|
|
* and or directory... For now, just testing this stuff out though...
|
|
|
|
*************************************************************************************/
|
|
|
|
class FGATCInstruction
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
bool holdPattern;
|
|
|
|
bool holdPosition;
|
|
|
|
bool changeSpeed;
|
|
|
|
bool changeHeading;
|
|
|
|
bool changeAltitude;
|
|
|
|
bool resolveCircularWait;
|
|
|
|
|
|
|
|
double speed;
|
|
|
|
double heading;
|
|
|
|
double alt;
|
|
|
|
public:
|
|
|
|
|
|
|
|
FGATCInstruction();
|
|
|
|
bool hasInstruction ();
|
|
|
|
bool getHoldPattern () { return holdPattern; };
|
|
|
|
bool getHoldPosition () { return holdPosition; };
|
|
|
|
bool getChangeSpeed () { return changeSpeed; };
|
|
|
|
bool getChangeHeading () { return changeHeading; };
|
|
|
|
bool getChangeAltitude() { return changeAltitude; };
|
|
|
|
|
|
|
|
double getSpeed () { return speed; };
|
|
|
|
double getHeading () { return heading; };
|
|
|
|
double getAlt () { return alt; };
|
|
|
|
|
|
|
|
bool getCheckForCircularWait() { return resolveCircularWait; };
|
|
|
|
|
|
|
|
void setHoldPattern (bool val) { holdPattern = val; };
|
|
|
|
void setHoldPosition (bool val) { holdPosition = val; };
|
|
|
|
void setChangeSpeed (bool val) { changeSpeed = val; };
|
|
|
|
void setChangeHeading (bool val) { changeHeading = val; };
|
|
|
|
void setChangeAltitude(bool val) { changeAltitude = val; };
|
|
|
|
|
|
|
|
void setResolveCircularWait (bool val) { resolveCircularWait = val; };
|
|
|
|
|
|
|
|
void setSpeed (double val) { speed = val; };
|
|
|
|
void setHeading (double val) { heading = val; };
|
|
|
|
void setAlt (double val) { alt = val; };
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************
|
|
|
|
* class FGTrafficRecord
|
|
|
|
*************************************************************************************/
|
|
|
|
class FGTrafficRecord
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int id, waitsForId;
|
|
|
|
int currentPos;
|
|
|
|
int leg;
|
2010-02-21 14:15:18 +00:00
|
|
|
int frequencyId;
|
2008-07-13 12:51:06 +00:00
|
|
|
int state;
|
2010-01-30 15:40:33 +00:00
|
|
|
bool allowTransmission;
|
2008-07-13 12:51:06 +00:00
|
|
|
time_t timer;
|
|
|
|
intVec intentions;
|
|
|
|
FGATCInstruction instruction;
|
|
|
|
double latitude, longitude, heading, speed, altitude, radius;
|
|
|
|
string runway;
|
|
|
|
//FGAISchedule *trafficRef;
|
|
|
|
FGAIAircraft *aircraft;
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
FGTrafficRecord();
|
|
|
|
|
|
|
|
void setId(int val) { id = val; };
|
|
|
|
void setRadius(double rad) { radius = rad;};
|
|
|
|
void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
|
|
|
|
void setRunway(string rwy) { runway = rwy;};
|
|
|
|
void setLeg(int lg) { leg = lg;};
|
|
|
|
int getId() { return id;};
|
|
|
|
int getState() { return state;};
|
2010-04-25 16:11:30 +00:00
|
|
|
void setState(int s) { state = s;}
|
2008-07-13 12:51:06 +00:00
|
|
|
FGATCInstruction getInstruction() { return instruction;};
|
|
|
|
bool hasInstruction() { return instruction.hasInstruction(); };
|
|
|
|
void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
|
|
|
|
bool checkPositionAndIntentions(FGTrafficRecord &other);
|
|
|
|
int crosses (FGGroundNetwork *, FGTrafficRecord &other);
|
|
|
|
bool isOpposing (FGGroundNetwork *, FGTrafficRecord &other, int node);
|
|
|
|
|
|
|
|
bool onRoute(FGGroundNetwork *, FGTrafficRecord &other);
|
|
|
|
|
|
|
|
bool getSpeedAdjustment() { return instruction.getChangeSpeed(); };
|
|
|
|
|
|
|
|
double getLatitude () { return latitude ; };
|
|
|
|
double getLongitude() { return longitude; };
|
|
|
|
double getHeading () { return heading ; };
|
|
|
|
double getSpeed () { return speed ; };
|
|
|
|
double getAltitude () { return altitude ; };
|
|
|
|
double getRadius () { return radius ; };
|
|
|
|
|
|
|
|
int getWaitsForId () { return waitsForId; };
|
|
|
|
|
|
|
|
void setSpeedAdjustment(double spd);
|
|
|
|
void setHeadingAdjustment(double heading);
|
|
|
|
void clearSpeedAdjustment () { instruction.setChangeSpeed (false); };
|
|
|
|
void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
|
|
|
|
|
|
|
|
bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
|
|
|
|
bool hasHoldPosition() { return instruction.getHoldPosition(); };
|
|
|
|
void setHoldPosition (bool inst) { instruction.setHoldPosition(inst); };
|
|
|
|
|
|
|
|
void setWaitsForId(int id) { waitsForId = id; };
|
|
|
|
|
|
|
|
void setResolveCircularWait() { instruction.setResolveCircularWait(true); };
|
|
|
|
void clearResolveCircularWait() { instruction.setResolveCircularWait(false); };
|
|
|
|
|
|
|
|
string getRunway() { return runway; };
|
|
|
|
//void setCallSign(string clsgn) { callsign = clsgn; };
|
|
|
|
void setAircraft(FGAIAircraft *ref) { aircraft = ref;};
|
2010-01-30 15:40:33 +00:00
|
|
|
void updateState() { state++; allowTransmission=true; };
|
2008-07-13 12:51:06 +00:00
|
|
|
//string getCallSign() { return callsign; };
|
|
|
|
FGAIAircraft *getAircraft() { return aircraft;};
|
|
|
|
int getTime() { return timer; };
|
|
|
|
int getLeg() { return leg; };
|
|
|
|
void setTime(time_t time) { timer = time; };
|
2010-01-30 15:40:33 +00:00
|
|
|
|
|
|
|
bool pushBackAllowed();
|
|
|
|
bool allowTransmissions() { return allowTransmission; };
|
|
|
|
void suppressRepeatedTransmissions () { allowTransmission=false; };
|
|
|
|
void allowRepeatedTransmissions () { allowTransmission=true; };
|
2010-02-21 14:15:18 +00:00
|
|
|
void nextFrequency() { frequencyId++; };
|
|
|
|
int getNextFrequency() { return frequencyId; };
|
2008-07-13 12:51:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef vector<FGTrafficRecord> TrafficVector;
|
|
|
|
typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
|
|
|
|
|
2010-08-29 17:25:34 +00:00
|
|
|
typedef vector<time_t> TimeVector;
|
|
|
|
typedef vector<time_t>::iterator TimeVectorIterator;
|
|
|
|
|
2008-07-13 12:51:06 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Active runway, a utility class to keep track of which aircraft has
|
|
|
|
* clearance for a given runway.
|
|
|
|
**********************************************************************/
|
|
|
|
class ActiveRunway
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
string rwy;
|
|
|
|
int currentlyCleared;
|
2010-08-29 17:25:34 +00:00
|
|
|
double distanceToFinal;
|
|
|
|
TimeVector estimatedArrivalTimes;
|
2008-07-13 12:51:06 +00:00
|
|
|
public:
|
2010-08-29 17:25:34 +00:00
|
|
|
ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; distanceToFinal = 6.0 * SG_NM_TO_METER; };
|
2008-07-13 12:51:06 +00:00
|
|
|
|
|
|
|
string getRunwayName() { return rwy; };
|
|
|
|
int getCleared () { return currentlyCleared; };
|
2010-08-29 17:25:34 +00:00
|
|
|
double getApproachDistance() { return distanceToFinal; };
|
|
|
|
//time_t getEstApproachTime() { return estimatedArrival; };
|
|
|
|
|
|
|
|
//void setEstApproachTime(time_t time) { estimatedArrival = time; };
|
|
|
|
time_t requestTimeSlot(time_t eta);
|
2008-07-13 12:51:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef vector<ActiveRunway> ActiveRunwayVec;
|
|
|
|
typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* class FGATCController
|
2010-08-29 17:25:34 +00:00
|
|
|
* NOTE: this class serves as an abstraction layer for all sorts of ATC controllers.
|
2008-07-13 12:51:06 +00:00
|
|
|
*************************************************************************************/
|
|
|
|
class FGATCController
|
|
|
|
{
|
2010-04-25 08:32:53 +00:00
|
|
|
protected:
|
|
|
|
bool available;
|
|
|
|
time_t lastTransmission;
|
|
|
|
|
2008-07-13 12:51:06 +00:00
|
|
|
double dt_count;
|
2009-02-07 17:17:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
string formatATCFrequency3_2(int );
|
2009-03-22 13:49:51 +00:00
|
|
|
string genTransponderCode(string fltRules);
|
2009-02-07 17:17:07 +00:00
|
|
|
|
2008-07-13 12:51:06 +00:00
|
|
|
public:
|
|
|
|
typedef enum {
|
|
|
|
MSG_ANNOUNCE_ENGINE_START,
|
2010-04-25 08:32:53 +00:00
|
|
|
MSG_REQUEST_ENGINE_START,
|
2008-07-13 12:51:06 +00:00
|
|
|
MSG_PERMIT_ENGINE_START,
|
|
|
|
MSG_DENY_ENGINE_START,
|
2010-01-30 15:40:33 +00:00
|
|
|
MSG_ACKNOWLEDGE_ENGINE_START,
|
|
|
|
MSG_REQUEST_PUSHBACK_CLEARANCE,
|
2010-04-25 08:32:53 +00:00
|
|
|
MSG_PERMIT_PUSHBACK_CLEARANCE,
|
2010-02-21 14:15:18 +00:00
|
|
|
MSG_HOLD_PUSHBACK_CLEARANCE,
|
2010-04-25 08:32:53 +00:00
|
|
|
MSG_ACKNOWLEDGE_SWITCH_GROUND_FREQUENCY,
|
|
|
|
MSG_INITIATE_CONTACT,
|
|
|
|
MSG_ACKNOWLEDGE_INITIATE_CONTACT,
|
|
|
|
MSG_REQUEST_TAXI_CLEARANCE,
|
|
|
|
MSG_ISSUE_TAXI_CLEARANCE,
|
|
|
|
MSG_ACKNOWLEDGE_TAXI_CLEARANCE,
|
|
|
|
MSG_HOLD_POSITION,
|
|
|
|
MSG_ACKNOWLEDGE_HOLD_POSITION,
|
|
|
|
MSG_RESUME_TAXI,
|
|
|
|
MSG_ACKNOWLEDGE_RESUME_TAXI } AtcMsgId;
|
2008-07-13 12:51:06 +00:00
|
|
|
typedef enum {
|
|
|
|
ATC_AIR_TO_GROUND,
|
|
|
|
ATC_GROUND_TO_AIR } AtcMsgDir;
|
2010-04-25 08:32:53 +00:00
|
|
|
FGATCController();
|
2011-04-03 15:58:16 +00:00
|
|
|
virtual ~FGATCController();
|
2008-07-13 12:51:06 +00:00
|
|
|
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
|
2011-04-03 15:58:16 +00:00
|
|
|
double lat, double lon,
|
|
|
|
double hdg, double spd, double alt, double radius, int leg,
|
|
|
|
FGAIAircraft *aircraft) = 0;
|
2008-07-13 12:51:06 +00:00
|
|
|
virtual void signOff(int id) = 0;
|
2011-04-03 15:58:16 +00:00
|
|
|
virtual void updateAircraftInformation(int id, double lat, double lon,
|
|
|
|
double heading, double speed, double alt, double dt) = 0;
|
2008-07-13 12:51:06 +00:00
|
|
|
virtual bool hasInstruction(int id) = 0;
|
|
|
|
virtual FGATCInstruction getInstruction(int id) = 0;
|
|
|
|
|
|
|
|
double getDt() { return dt_count; };
|
|
|
|
void setDt(double dt) { dt_count = dt;};
|
|
|
|
void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir);
|
|
|
|
string getGateName(FGAIAircraft *aircraft);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* class FGTowerControl
|
|
|
|
*****************************************************************************/
|
|
|
|
class FGTowerController : public FGATCController
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
TrafficVector activeTraffic;
|
|
|
|
ActiveRunwayVec activeRunways;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FGTowerController();
|
|
|
|
virtual ~FGTowerController() {};
|
|
|
|
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
|
|
|
|
double lat, double lon,
|
|
|
|
double hdg, double spd, double alt, double radius, int leg,
|
|
|
|
FGAIAircraft *aircraft);
|
|
|
|
virtual void signOff(int id);
|
2011-04-03 15:58:16 +00:00
|
|
|
virtual void updateAircraftInformation(int id, double lat, double lon,
|
2008-07-13 12:51:06 +00:00
|
|
|
double heading, double speed, double alt, double dt);
|
|
|
|
virtual bool hasInstruction(int id);
|
|
|
|
virtual FGATCInstruction getInstruction(int id);
|
|
|
|
|
|
|
|
bool hasActiveTraffic() { return activeTraffic.size() != 0; };
|
|
|
|
TrafficVector &getActiveTraffic() { return activeTraffic; };
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* class FGStartupController
|
|
|
|
* handle
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
class FGStartupController : public FGATCController
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
TrafficVector activeTraffic;
|
|
|
|
//ActiveRunwayVec activeRunways;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FGStartupController();
|
|
|
|
virtual ~FGStartupController() {};
|
|
|
|
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
|
|
|
|
double lat, double lon,
|
|
|
|
double hdg, double spd, double alt, double radius, int leg,
|
|
|
|
FGAIAircraft *aircraft);
|
|
|
|
virtual void signOff(int id);
|
2011-04-03 15:58:16 +00:00
|
|
|
virtual void updateAircraftInformation(int id, double lat, double lon,
|
2008-07-13 12:51:06 +00:00
|
|
|
double heading, double speed, double alt, double dt);
|
|
|
|
virtual bool hasInstruction(int id);
|
|
|
|
virtual FGATCInstruction getInstruction(int id);
|
|
|
|
|
|
|
|
bool hasActiveTraffic() { return activeTraffic.size() != 0; };
|
|
|
|
TrafficVector &getActiveTraffic() { return activeTraffic; };
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-08-29 17:25:34 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* class FGTowerControl
|
|
|
|
*****************************************************************************/
|
|
|
|
class FGApproachController : public FGATCController
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
TrafficVector activeTraffic;
|
|
|
|
ActiveRunwayVec activeRunways;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FGApproachController();
|
|
|
|
virtual ~FGApproachController() {};
|
|
|
|
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
|
|
|
|
double lat, double lon,
|
|
|
|
double hdg, double spd, double alt, double radius, int leg,
|
|
|
|
FGAIAircraft *aircraft);
|
|
|
|
virtual void signOff(int id);
|
2011-04-03 15:58:16 +00:00
|
|
|
virtual void updateAircraftInformation(int id, double lat, double lon,
|
2010-08-29 17:25:34 +00:00
|
|
|
double heading, double speed, double alt, double dt);
|
|
|
|
virtual bool hasInstruction(int id);
|
|
|
|
virtual FGATCInstruction getInstruction(int id);
|
|
|
|
|
|
|
|
ActiveRunway* getRunway(string name);
|
|
|
|
|
|
|
|
bool hasActiveTraffic() { return activeTraffic.size() != 0; };
|
|
|
|
TrafficVector &getActiveTraffic() { return activeTraffic; };
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-13 12:51:06 +00:00
|
|
|
#endif // _TRAFFIC_CONTROL_HXX
|