]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/trafficcontrol.hxx
Merge branch 'next' into durk-atc
[flightgear.git] / src / ATC / trafficcontrol.hxx
index 6633fec7038e4e29d091e78a4762fbb9fdec92b4..66381af52f140e930c307c33a790b13e7546340c 100644 (file)
 
 
 #include <simgear/compiler.h>
+// There is probably a better include than sg_geodesy to get the SG_NM_TO_METER...
+#include <simgear/math/sg_geodesy.hxx>
 #include <simgear/debug/logstream.hxx>
-
-
+#include <simgear/structure/SGReferenced.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
 
 #include <string>
 #include <vector>
@@ -45,7 +47,6 @@ typedef vector<int>::iterator intVecIterator;
 
 class FGAIFlightPlan;  // forward reference
 class FGGroundNetwork; // forward reference
-//class FGAISchedule;    // forward reference
 class FGAIAircraft;    // forward reference
 
 /**************************************************************************************
@@ -130,6 +131,7 @@ public:
   void setLeg(int lg) { leg = lg;};
   int getId() { return id;};
   int getState() { return state;};
+  void setState(int s) { state = s;}
   FGATCInstruction getInstruction() { return instruction;};
   bool hasInstruction() { return instruction.hasInstruction(); };
   void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
@@ -185,6 +187,9 @@ public:
 typedef vector<FGTrafficRecord> TrafficVector;
 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
 
+typedef vector<time_t> TimeVector;
+typedef vector<time_t>::iterator TimeVectorIterator;
+
 
 /***********************************************************************
  * Active runway, a utility class to keep track of which aircraft has
@@ -195,11 +200,18 @@ class ActiveRunway
 private:
   string rwy;
   int currentlyCleared;
+  double distanceToFinal;
+  TimeVector estimatedArrivalTimes;
 public:
-  ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; };
+  ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; distanceToFinal = 6.0 * SG_NM_TO_METER; };
   
   string getRunwayName() { return rwy; };
   int    getCleared   () { return currentlyCleared; };
+  double getApproachDistance() { return distanceToFinal; };
+  //time_t getEstApproachTime() { return estimatedArrival; };
+
+  //void setEstApproachTime(time_t time) { estimatedArrival = time; };
+  time_t requestTimeSlot(time_t eta);
 };
 
 typedef vector<ActiveRunway> ActiveRunwayVec;
@@ -207,47 +219,68 @@ typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
 
 /**
  * class FGATCController
- * NOTE: this class serves as an abstraction layer for all sorts of ATC controller. 
+ * NOTE: this class serves as an abstraction layer for all sorts of ATC controllers
  *************************************************************************************/
 class FGATCController
 {
 private:
+     bool initialized;
+
+protected:
+  bool available;
+  time_t lastTransmission;
+
   double dt_count;
 
 
   string formatATCFrequency3_2(int );
   string genTransponderCode(string fltRules);
+  bool isUserAircraft(FGAIAircraft*); 
 
 public:
   typedef enum {
       MSG_ANNOUNCE_ENGINE_START,
-      MSG_REQUEST_ENGINE_START, 
+      MSG_REQUEST_ENGINE_START,
       MSG_PERMIT_ENGINE_START,
       MSG_DENY_ENGINE_START,
       MSG_ACKNOWLEDGE_ENGINE_START,
       MSG_REQUEST_PUSHBACK_CLEARANCE,
-      MSG_PERMIT_PUSHBACK_CLEARANCE, 
+      MSG_PERMIT_PUSHBACK_CLEARANCE,
       MSG_HOLD_PUSHBACK_CLEARANCE,
-      MSG_ACKNOWLEDGE_SWITCH_GROUND_FREQUENCY } AtcMsgId;
+      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;
   typedef enum {
       ATC_AIR_TO_GROUND,
       ATC_GROUND_TO_AIR } AtcMsgDir;
-  FGATCController() { dt_count = 0;};
-  virtual ~FGATCController() {};
+  FGATCController();
+  virtual ~FGATCController();
+  void init();
+
   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) = 0;
+                                double lat, double lon,
+                                double hdg, double spd, double alt, double radius, int leg,
+                                FGAIAircraft *aircraft) = 0;
   virtual void             signOff(int id) = 0;
-  virtual void             update(int id, double lat, double lon, 
-                                 double heading, double speed, double alt, double dt) = 0;
+  virtual void             updateAircraftInformation(int id, double lat, double lon, 
+                                                     double heading, double speed, double alt, double dt) = 0;
   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);
+  void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir, bool audible);
   string getGateName(FGAIAircraft *aircraft);
+
+private:
+ AtcMsgDir lastTransmissionDirection;
 };
 
 /******************************************************************************
@@ -267,7 +300,7 @@ public:
                                double hdg, double spd, double alt, double radius, int leg,
                                FGAIAircraft *aircraft);
   virtual void             signOff(int id);
-  virtual void             update(int id, double lat, double lon, 
+  virtual void             updateAircraftInformation(int id, double lat, double lon, 
                                  double heading, double speed, double alt, double dt);
   virtual bool             hasInstruction(int id);
   virtual FGATCInstruction getInstruction(int id);
@@ -285,8 +318,6 @@ class FGStartupController : public FGATCController
 {
 private:
   TrafficVector activeTraffic;
-  bool available;
-  time_t lastTransmission;
   //ActiveRunwayVec activeRunways;
   
 public:
@@ -297,7 +328,7 @@ public:
                                double hdg, double spd, double alt, double radius, int leg,
                                FGAIAircraft *aircraft);
   virtual void             signOff(int id);
-  virtual void             update(int id, double lat, double lon, 
+  virtual void             updateAircraftInformation(int id, double lat, double lon, 
                                  double heading, double speed, double alt, double dt);
   virtual bool             hasInstruction(int id);
   virtual FGATCInstruction getInstruction(int id);
@@ -305,6 +336,39 @@ public:
   bool hasActiveTraffic() { return activeTraffic.size() != 0; };
   TrafficVector &getActiveTraffic() { return activeTraffic; };
 
+  // Hpoefully, we can move this function to the base class, but I need to verify what is needed for the other controllers before doing so.
+  bool checkTransmissionState(int st, time_t now, time_t startTime, TrafficVectorIterator i, AtcMsgId msgId,
+                               AtcMsgDir msgDir);
+
 }; 
 
+/******************************************************************************
+ * 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);
+  virtual void             updateAircraftInformation(int id, double lat, double lon, 
+                                 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; };
+};
+
+
 #endif // _TRAFFIC_CONTROL_HXX