| 1 | // Extracted from trafficcontrol.hxx - classes to manage AIModels based air traffic control |
| 2 | // Written by Durk Talsma, started September 2006. |
| 3 | // |
| 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. |
| 8 | // |
| 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. |
| 13 | // |
| 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. |
| 17 | // |
| 18 | // $Id$ |
| 19 | |
| 20 | #ifndef ATC_CONTROLLER_HXX |
| 21 | #define ATC_CONTROLLER_HXX |
| 22 | |
| 23 | #include <Airports/airports_fwd.hxx> |
| 24 | |
| 25 | #include <osg/Geode> |
| 26 | #include <osg/Geometry> |
| 27 | #include <osg/MatrixTransform> |
| 28 | #include <osg/Shape> |
| 29 | |
| 30 | #include <simgear/compiler.h> |
| 31 | #include <simgear/constants.h> |
| 32 | #include <simgear/debug/logstream.hxx> |
| 33 | #include <simgear/structure/SGReferenced.hxx> |
| 34 | #include <simgear/structure/SGSharedPtr.hxx> |
| 35 | |
| 36 | #include <ATC/trafficcontrol.hxx> |
| 37 | |
| 38 | namespace ATCMessageState |
| 39 | { |
| 40 | enum Type |
| 41 | { |
| 42 | // 0 = Normal; no action required |
| 43 | NORMAL, |
| 44 | // 1 = "Acknowledge "Hold position |
| 45 | ACK_HOLD, |
| 46 | // 2 = "Acknowledge "Resume taxi". |
| 47 | ACK_RESUME_TAXI, |
| 48 | // 3 = "Issue TaxiClearance" |
| 49 | TAXI_CLEARED = 3, |
| 50 | // 4 = Acknowledge Taxi Clearance" |
| 51 | ACK_TAXI_CLEARED = 4, |
| 52 | // 5 = Post acknowlegde taxiclearance: Start taxiing |
| 53 | START_TAXI = 5, |
| 54 | // 6 = Report runway |
| 55 | REPORT_RUNWAY = 6, |
| 56 | // 7 = Acknowledge report runway |
| 57 | ACK_REPORT_RUNWAY = 7, |
| 58 | // 8 = Switch tower frequency |
| 59 | SWITCH_GROUND_TOWER = 8, |
| 60 | // 9 = Acknowledge switch tower frequency |
| 61 | ACK_SWITCH_GROUND_TOWER = 9, |
| 62 | // 10 = Cleared for takeoff |
| 63 | CLEARED_TAKEOFF, |
| 64 | ACK_CLEARED_TAKEOFF, |
| 65 | ANNOUNCE_ARRIVAL, |
| 66 | ACK_ARRIVAL, |
| 67 | HOLD, |
| 68 | CLEARED_TO_LAND, |
| 69 | ACK_CLEARED_TO_LAND, |
| 70 | LANDING_TAXI |
| 71 | }; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * class FGATCController |
| 76 | * NOTE: this class serves as an abstraction layer for all sorts of ATC controllers. |
| 77 | *************************************************************************************/ |
| 78 | class FGATCController |
| 79 | { |
| 80 | private: |
| 81 | |
| 82 | |
| 83 | protected: |
| 84 | // guard variable to avoid modifying state during destruction |
| 85 | bool _isDestroying = false; |
| 86 | bool initialized; |
| 87 | bool available; |
| 88 | time_t lastTransmission; |
| 89 | TrafficVector activeTraffic; |
| 90 | |
| 91 | double dt_count; |
| 92 | osg::Group* group; |
| 93 | FGAirportDynamics *parent = nullptr; |
| 94 | |
| 95 | std::string formatATCFrequency3_2(int ); |
| 96 | std::string genTransponderCode(const std::string& fltRules); |
| 97 | bool isUserAircraft(FGAIAircraft*); |
| 98 | void clearTrafficControllers(); |
| 99 | TrafficVectorIterator searchActiveTraffic(int id); |
| 100 | void eraseDeadTraffic(); |
| 101 | /**Returns the frequency to be used. */ |
| 102 | virtual int getFrequency() = 0; |
| 103 | public: |
| 104 | typedef enum { |
| 105 | MSG_ANNOUNCE_ENGINE_START, |
| 106 | MSG_REQUEST_ENGINE_START, |
| 107 | MSG_PERMIT_ENGINE_START, |
| 108 | MSG_DENY_ENGINE_START, |
| 109 | MSG_ACKNOWLEDGE_ENGINE_START, |
| 110 | MSG_REQUEST_PUSHBACK_CLEARANCE, |
| 111 | MSG_PERMIT_PUSHBACK_CLEARANCE, |
| 112 | MSG_HOLD_PUSHBACK_CLEARANCE, |
| 113 | MSG_ACKNOWLEDGE_SWITCH_GROUND_FREQUENCY, |
| 114 | MSG_INITIATE_CONTACT, |
| 115 | MSG_ACKNOWLEDGE_INITIATE_CONTACT, |
| 116 | MSG_REQUEST_TAXI_CLEARANCE, |
| 117 | MSG_ISSUE_TAXI_CLEARANCE, |
| 118 | MSG_ACKNOWLEDGE_TAXI_CLEARANCE, |
| 119 | MSG_HOLD_POSITION, |
| 120 | MSG_ACKNOWLEDGE_HOLD_POSITION, |
| 121 | MSG_RESUME_TAXI, |
| 122 | MSG_ACKNOWLEDGE_RESUME_TAXI, |
| 123 | MSG_REPORT_RUNWAY_HOLD_SHORT, |
| 124 | MSG_ACKNOWLEDGE_REPORT_RUNWAY_HOLD_SHORT, |
| 125 | MSG_CLEARED_FOR_TAKEOFF, |
| 126 | MSG_ACKNOWLEDGE_CLEARED_FOR_TAKEOFF, |
| 127 | MSG_SWITCH_TOWER_FREQUENCY, |
| 128 | MSG_ACKNOWLEDGE_SWITCH_TOWER_FREQUENCY, |
| 129 | MSG_ARRIVAL, |
| 130 | MSG_ACKNOWLEDGE_ARRIVAL, |
| 131 | MSG_HOLD, |
| 132 | MSG_ACKNOWLEDGE_HOLD, |
| 133 | MSG_CLEARED_TO_LAND, |
| 134 | MSG_ACKNOWLEDGE_CLEARED_TO_LAND |
| 135 | } AtcMsgId; |
| 136 | |
| 137 | typedef enum { |
| 138 | ATC_AIR_TO_GROUND, |
| 139 | ATC_GROUND_TO_AIR |
| 140 | } AtcMsgDir; |
| 141 | FGATCController(); |
| 142 | virtual ~FGATCController(); |
| 143 | void init(); |
| 144 | |
| 145 | virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, |
| 146 | double lat, double lon, |
| 147 | double hdg, double spd, double alt, double radius, int leg, |
| 148 | FGAIAircraft *aircraft) = 0; |
| 149 | virtual void updateAircraftInformation(int id, SGGeod geod, |
| 150 | double heading, double speed, double alt, double dt) = 0; |
| 151 | bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId, |
| 152 | AtcMsgDir msgDir); |
| 153 | |
| 154 | virtual void signOff(int id); |
| 155 | bool hasInstruction(int id); |
| 156 | FGATCInstruction getInstruction(int id); |
| 157 | |
| 158 | bool hasActiveTraffic() { |
| 159 | return ! activeTraffic.empty(); |
| 160 | }; |
| 161 | TrafficVector &getActiveTraffic() { |
| 162 | return activeTraffic; |
| 163 | }; |
| 164 | |
| 165 | double getDt() { |
| 166 | return dt_count; |
| 167 | }; |
| 168 | void setDt(double dt) { |
| 169 | dt_count = dt; |
| 170 | }; |
| 171 | void transmit(FGTrafficRecord *rec, FGAirportDynamics *parent, AtcMsgId msgId, AtcMsgDir msgDir, bool audible); |
| 172 | std::string getGateName(FGAIAircraft *aircraft); |
| 173 | virtual void render(bool) = 0; |
| 174 | virtual std::string getName() = 0; |
| 175 | virtual void update(double) = 0; |
| 176 | |
| 177 | |
| 178 | private: |
| 179 | AtcMsgDir lastTransmissionDirection; |
| 180 | }; |
| 181 | |
| 182 | #endif |