1 // FGATC - abstract base class for the various actual atc classes
2 // such as FGATIS, FGTower etc.
4 // Written by David Luff, started Feburary 2002.
6 // Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <simgear/compiler.h>
26 #include <simgear/misc/sgstream.hxx>
27 #include <simgear/math/sg_geodesy.hxx>
28 #include <simgear/debug/logstream.hxx>
33 #include "ATCVoice.hxx"
35 SG_USING_STD(ostream);
50 // PlaneRec - a structure holding ATC-centric details of planes under control
51 // This might move or change eventually
58 // Possible types of ATC type that the radios may be tuned to.
59 // INVALID implies not tuned in to anything.
70 // DCL - new experimental ATC data store
73 // I've deliberately used float instead of double here to keep the size down - we'll be storing thousands of these in memory.
74 // In fact, we could probably ditch x, y and z and generate on the fly as needed.
75 // On the other hand, we'll probably end up reading this data directly from the DAFIF eventually anyway!!
79 unsigned short int freq;
81 unsigned short int range;
86 // perhaps we could use an FGRunway instead of this.
87 // That wouldn't cache the orthopos though.
88 struct RunwayDetails {
89 Point3D threshold_pos;
90 Point3D end1ortho; // ortho projection end1 (the threshold ATM)
91 Point3D end2ortho; // ortho projection end2 (the take off end in the current hardwired scheme)
92 double hdg; // true runway heading
93 double length; // In *METERS*
94 double width; // ditto
98 ostream& operator << (ostream& os, atc_type atc);
107 // Run the internal calculations
108 virtual void Update(double dt);
110 // Add plane to a stack
111 virtual void AddPlane(string pid);
113 // Remove plane from stack
114 virtual int RemovePlane();
116 // Indicate that this instance should output to the display if appropriate
117 virtual void SetDisplay();
119 // Indicate that this instance should not output to the display
120 virtual void SetNoDisplay();
122 // Returns true if OK to transmit on this frequency
123 inline bool FreqClear() { return freqClear; }
124 // Indicate that the frequency is in use
125 inline void FreqInUse() { freqClear = false; }
126 // Under development!!
127 // The idea is that AI traffic or the user ATC dialog box calls FreqInUse() when they begin transmitting,
128 // and that the tower control sets freqClear back to true following a reply.
129 // AI traffic should check FreqClear() is true prior to transmitting.
130 // The user will just have to wait for a gap in dialog as in real life.
132 // Return the type of ATC station that the class represents
133 virtual atc_type GetType();
135 // Set the core ATC data
136 void SetData(ATCData* d);
138 inline double get_lon() const { return lon; }
139 inline void set_lon(const double ln) {lon = ln;}
140 inline double get_lat() const { return lat; }
141 inline void set_lat(const double lt) {lat = lt;}
142 inline double get_elev() const { return elev; }
143 inline void set_elev(const double ev) {elev = ev;}
144 inline double get_x() const { return x; }
145 inline void set_x(const double ecs) {x = ecs;}
146 inline double get_y() const { return y; }
147 inline void set_y(const double why) {y = why;}
148 inline double get_z() const { return z; }
149 inline void set_z(const double zed) {z = zed;}
150 inline int get_freq() const { return freq; }
151 inline void set_freq(const int fq) {freq = fq;}
152 inline int get_range() const { return range; }
153 inline void set_range(const int rg) {range = rg;}
154 inline const char* get_ident() { return ident.c_str(); }
155 inline void set_ident(const string id) {ident = id;}
156 inline const char* get_name() {return name.c_str();}
157 inline void set_name(const string nm) {name = nm;}
161 // Render a transmission
162 // Outputs the transmission either on screen or as audio depending on user preference
163 // The refname is a string to identify this sample to the sound manager
164 // The repeating flag indicates whether the message should be repeated continuously or played once.
165 void Render(string msg, string refname, bool repeating);
167 // Cease rendering a transmission.
168 // Requires the sound manager refname if audio, else "".
169 void NoRender(string refname);
171 double lon, lat, elev;
175 string ident; // Code of the airport its at.
176 string name; // Name transmitted in the broadcast.
178 // Rendering related stuff
179 bool voice; // Flag - true if we are using voice
180 bool playing; // Indicates a message in progress
181 bool voiceOK; // Flag - true if at least one voice has loaded OK
184 bool freqClear; // Flag to indicate if the frequency is clear of ongoing dialog
188 operator >> ( istream& fin, ATCData& a )
211 return fin >> skipeol;
213 SG_LOG(SG_GENERAL, SG_ALERT, "Warning - unknown type \'" << tp << "\' found whilst reading ATC frequency data!\n");
215 return fin >> skipeol;
218 fin >> a.lat >> a.lon >> a.elev >> f >> a.range
226 fin.unsetf(ios::skipws);
229 if((ch == '"') || (ch == 0x0A)) {
231 } // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
233 fin.setf(ios::skipws);
234 //cout << "Comm name = " << a.name << '\n';
236 a.freq = (int)(f*100.0 + 0.5);
238 // cout << a.ident << endl;
240 // generate cartesian coordinates
241 Point3D geod( a.lon * SGD_DEGREES_TO_RADIANS, a.lat * SGD_DEGREES_TO_RADIANS, a.elev );
242 Point3D cart = sgGeodToCart( geod );
247 return fin >> skipeol;
251 #endif // _FG_ATC_HXX