]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATC.hxx
Oops - a boo boo of monumental proportions completely took ATC off the air...
[flightgear.git] / src / ATC / ATC.hxx
1 // FGATC - abstract base class for the various actual atc classes 
2 // such as FGATIS, FGTower etc.
3 //
4 // Written by David Luff, started Feburary 2002.
5 //
6 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
7 //
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.
12 //
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.
17 //
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.
21
22 #ifndef _FG_ATC_HXX
23 #define _FG_ATC_HXX
24
25 #include <simgear/compiler.h>
26 #include <simgear/misc/sgstream.hxx>
27 #include <simgear/math/sg_geodesy.hxx>
28 #include <simgear/debug/logstream.hxx>
29
30 #include STL_IOSTREAM
31 #include STL_STRING
32
33 #include "ATCVoice.hxx"
34
35 SG_USING_STD(ostream);
36 SG_USING_STD(string);
37 SG_USING_STD(ios);
38
39 enum plane_type {
40         UNKNOWN,
41         GA_SINGLE,
42         GA_HP_SINGLE,
43         GA_TWIN,
44         GA_JET,
45         MEDIUM,
46         HEAVY,
47         MIL_JET
48 };
49
50 // PlaneRec - a structure holding ATC-centric details of planes under control
51 // This might move or change eventually
52 struct PlaneRec {
53         plane_type type;
54         string callsign;
55         int squawkcode;
56 };
57
58 // Possible types of ATC type that the radios may be tuned to.
59 // INVALID implies not tuned in to anything.
60 enum atc_type {
61         INVALID,
62         ATIS,
63         GROUND,
64         TOWER,
65         APPROACH,
66         DEPARTURE,
67         ENROUTE
68 }; 
69
70 // DCL - new experimental ATC data store
71 struct ATCData {
72         atc_type type;
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!!
76         float lon, lat, elev;
77         float x, y, z;
78         //int freq;
79         unsigned short int freq;
80         //int range;
81         unsigned short int range;
82         string ident;
83         string name;
84 };
85
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
95         string rwyID;
96 };
97
98 ostream& operator << (ostream& os, atc_type atc);
99
100 class FGATC {
101         
102 public:
103         
104         FGATC();
105         virtual ~FGATC();
106         
107         // Run the internal calculations
108         // Derived classes should call this method from their own Update methods if they 
109         // wish to use the response timer functionality.
110         virtual void Update(double dt);
111         
112         // Add plane to a stack
113         virtual void AddPlane(string pid);
114         
115         // Remove plane from stack
116         virtual int RemovePlane();
117         
118         // Indicate that this instance should output to the display if appropriate 
119         virtual void SetDisplay();
120         
121         // Indicate that this instance should not output to the display
122         virtual void SetNoDisplay();
123         
124         // Returns true if OK to transmit on this frequency
125         inline bool GetFreqClear() { return freqClear; }
126         // Indicate that the frequency is in use
127         inline void SetFreqInUse() { freqClear = false; }
128         // Transmission to the ATC is finished and a response is required
129         void SetResponseReqd(string rid);
130         // The above 3 funcs under development!!
131         // The idea is that AI traffic or the user ATC dialog box calls FreqInUse() when they begin transmitting,
132         // and that the tower control sets freqClear back to true following a reply.
133         // AI traffic should check FreqClear() is true prior to transmitting.
134         // The user will just have to wait for a gap in dialog as in real life.
135         
136         // Return the type of ATC station that the class represents
137         virtual atc_type GetType();
138         
139         // Set the core ATC data
140         void SetData(ATCData* d);
141         
142         inline double get_lon() const { return lon; }
143         inline void set_lon(const double ln) {lon = ln;}
144         inline double get_lat() const { return lat; }
145         inline void set_lat(const double lt) {lat = lt;}
146         inline double get_elev() const { return elev; }
147         inline void set_elev(const double ev) {elev = ev;}
148         inline double get_x() const { return x; }
149         inline void set_x(const double ecs) {x = ecs;}
150         inline double get_y() const { return y; }
151         inline void set_y(const double why) {y = why;}
152         inline double get_z() const { return z; }
153         inline void set_z(const double zed) {z = zed;}
154         inline int get_freq() const { return freq; }
155         inline void set_freq(const int fq) {freq = fq;}
156         inline int get_range() const { return range; }
157         inline void set_range(const int rg) {range = rg;}
158         inline const char* get_ident() { return ident.c_str(); }
159         inline void set_ident(const string id) {ident = id;}
160         inline const char* get_name() {return name.c_str();}
161         inline void set_name(const string nm) {name = nm;}
162         
163 protected:
164         
165         // Render a transmission
166         // Outputs the transmission either on screen or as audio depending on user preference
167         // The refname is a string to identify this sample to the sound manager
168         // The repeating flag indicates whether the message should be repeated continuously or played once.
169         void Render(string msg, string refname, bool repeating);
170         
171         // Cease rendering a transmission.
172         // Requires the sound manager refname if audio, else "".
173         void NoRender(string refname);
174         
175         double lon, lat, elev;
176         double x, y, z;
177         int freq;
178         int range;
179         string ident;           // Code of the airport its at.
180         string name;            // Name transmitted in the broadcast.
181         
182         // Rendering related stuff
183         bool voice;                     // Flag - true if we are using voice
184         bool playing;           // Indicates a message in progress      
185         bool voiceOK;           // Flag - true if at least one voice has loaded OK
186         FGATCVoice* vPtr;
187         
188         bool freqClear;         // Flag to indicate if the frequency is clear of ongoing dialog
189         bool responseReqd;      // Flag to indicate we should be responding to a request/report 
190         double responseTime;    // Time to take from end of request transmission to beginning of response
191                                                         // The idea is that this will be slightly random.
192         double responseCounter;         // counter to implement the above
193         string responseID;      // ID of the plane to respond to
194         bool respond;   // Flag to indicate now is the time to respond - ie set following the count down of the response timer.
195         // Derived classes only need monitor this flag, and use the response ID, as long as they call FGATC::Update(...)
196 };
197
198 inline istream&
199 operator >> ( istream& fin, ATCData& a )
200 {
201         double f;
202         char ch;
203         char tp;
204         
205         fin >> tp;
206         
207         switch(tp) {
208         case 'I':
209                 a.type = ATIS;
210                 break;
211         case 'T':
212                 a.type = TOWER;
213                 break;
214         case 'G':
215                 a.type = GROUND;
216                 break;
217         case 'A':
218                 a.type = APPROACH;
219                 break;
220         case '[':
221                 a.type = INVALID;
222                 return fin >> skipeol;
223         default:
224                 SG_LOG(SG_GENERAL, SG_ALERT, "Warning - unknown type \'" << tp << "\' found whilst reading ATC frequency data!\n");
225                 a.type = INVALID;
226                 return fin >> skipeol;
227         }
228         
229         fin >> a.lat >> a.lon >> a.elev >> f >> a.range 
230         >> a.ident;
231         
232         a.name = "";
233         fin >> ch;
234         a.name += ch;
235         while(1) {
236                 //in >> noskipws
237                 fin.unsetf(ios::skipws);
238                 fin >> ch;
239                 a.name += ch;
240                 if((ch == '"') || (ch == 0x0A)) {
241                         break;
242                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
243         }
244         fin.setf(ios::skipws);
245         //cout << "Comm name = " << a.name << '\n';
246         
247         a.freq = (int)(f*100.0 + 0.5);
248         
249         // cout << a.ident << endl;
250         
251         // generate cartesian coordinates
252         Point3D geod( a.lon * SGD_DEGREES_TO_RADIANS, a.lat * SGD_DEGREES_TO_RADIANS, a.elev );
253         Point3D cart = sgGeodToCart( geod );
254         a.x = cart.x();
255         a.y = cart.y();
256         a.z = cart.z();
257         
258         return fin >> skipeol;
259 }
260
261
262 #endif  // _FG_ATC_HXX