]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATC.hxx
Pass dt to update(...)
[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 ostream& operator << (ostream& os, atc_type atc);
87
88 class FGATC {
89
90 public:
91
92     virtual ~FGATC();
93
94     // Run the internal calculations
95     virtual void Update(double dt);
96
97     // Add plane to a stack
98     virtual void AddPlane(string pid);
99
100     // Remove plane from stack
101     virtual int RemovePlane();
102
103     // Indicate that this instance should output to the display if appropriate 
104     virtual void SetDisplay();
105
106     // Indicate that this instance should not output to the display
107     virtual void SetNoDisplay();
108
109     // Return the type of ATC station that the class represents
110     virtual atc_type GetType();
111         
112         // Set the core ATC data
113         void SetData(ATCData* d);
114         
115         inline double get_lon() const { return lon; }
116         inline void set_lon(const double ln) {lon = ln;}
117         inline double get_lat() const { return lat; }
118         inline void set_lat(const double lt) {lat = lt;}
119         inline double get_elev() const { return elev; }
120         inline void set_elev(const double ev) {elev = ev;}
121         inline double get_x() const { return x; }
122         inline void set_x(const double ecs) {x = ecs;}
123         inline double get_y() const { return y; }
124         inline void set_y(const double why) {y = why;}
125         inline double get_z() const { return z; }
126         inline void set_z(const double zed) {z = zed;}
127         inline int get_freq() const { return freq; }
128         inline void set_freq(const int fq) {freq = fq;}
129         inline int get_range() const { return range; }
130         inline void set_range(const int rg) {range = rg;}
131         inline const char* get_ident() { return ident.c_str(); }
132         inline void set_ident(const string id) {ident = id;}
133         inline const char* get_name() {return name.c_str();}
134         inline void set_name(const string nm) {name = nm;}
135         
136 protected:
137
138         // Render a transmission
139         // Outputs the transmission either on screen or as audio depending on user preference
140         // The refname is a string to identify this sample to the sound manager
141         // The repeating flag indicates whether the message should be repeated continuously or played once.
142         void Render(string msg, string refname, bool repeating);
143
144         // Cease rendering a transmission.
145         // Requires the sound manager refname if audio, else "".
146         void NoRender(string refname);
147
148         double lon, lat, elev;
149         double x, y, z;
150         int freq;
151         int range;
152         string ident;           // Code of the airport its at.
153         string name;            // Name transmitted in the broadcast.
154         
155         // Rendering related stuff
156         bool voice;                     // Flag - true if we are using voice
157         bool playing;           // Indicates a message in progress      
158         bool voiceOK;           // Flag - true if at least one voice has loaded OK
159         FGATCVoice* vPtr;
160 };
161
162 inline istream&
163 operator >> ( istream& fin, ATCData& a )
164 {
165         double f;
166         char ch;
167         char tp;
168
169         fin >> tp;
170         
171         switch(tp) {
172         case 'I':
173                 a.type = ATIS;
174                 break;
175         case 'T':
176                 a.type = TOWER;
177                 break;
178         case 'G':
179                 a.type = GROUND;
180                 break;
181         case 'A':
182                 a.type = APPROACH;
183                 break;
184         case '[':
185                 a.type = INVALID;
186                 return fin >> skipeol;
187         default:
188                 SG_LOG(SG_GENERAL, SG_ALERT, "Warning - unknown type \'" << tp << "\' found whilst reading ATC frequency data!\n");
189                 a.type = INVALID;
190                 return fin >> skipeol;
191         }
192
193         fin >> a.lat >> a.lon >> a.elev >> f >> a.range 
194         >> a.ident;
195         
196         a.name = "";
197         fin >> ch;
198         a.name += ch;
199         while(1) {
200                 //in >> noskipws
201                 fin.unsetf(ios::skipws);
202                 fin >> ch;
203                 a.name += ch;
204                 if((ch == '"') || (ch == 0x0A)) {
205                         break;
206                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
207         }
208         fin.setf(ios::skipws);
209         //cout << "Comm name = " << a.name << '\n';
210         
211         a.freq = (int)(f*100.0 + 0.5);
212         
213         // cout << a.ident << endl;
214         
215         // generate cartesian coordinates
216         Point3D geod( a.lon * SGD_DEGREES_TO_RADIANS, a.lat * SGD_DEGREES_TO_RADIANS, a.elev );
217         Point3D cart = sgGeodToCart( geod );
218         a.x = cart.x();
219         a.y = cart.y();
220         a.z = cart.z();
221         
222         return fin >> skipeol;
223 }
224
225
226 #endif  // _FG_ATC_HXX