]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/ATC.hxx
Remove confusing default (missing) path from 2D panel code.
[flightgear.git] / src / ATCDCL / 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #ifndef _FG_ATC_HXX
23 #define _FG_ATC_HXX
24
25 #include <simgear/constants.h>
26 #include <simgear/compiler.h>
27 #include <simgear/props/props.hxx>
28 #include <simgear/misc/sgstream.hxx>
29 #include <simgear/math/sg_geodesy.hxx>
30 #include <simgear/debug/logstream.hxx>
31 #include <simgear/structure/SGSharedPtr.hxx>
32
33 #include <iosfwd>
34 #include <string>
35
36 #include "ATCVoice.hxx"
37
38 class SGSampleGroup;
39
40 // Convert a frequency in MHz to tens of kHz
41 // so we can use it e.g. as an index into commlist_freq
42 //
43 // If freq > 1000 assume it's already in tens of KHz;
44 // otherwise assume MHz.
45 //
46 // Note:  122.375 must be rounded DOWN to 12237 
47 // in order to be consistent with apt.dat et cetera.
48 inline int kHz10(double freq)
49 {
50  if (freq > 1000.) return int(freq);
51  return int(freq*100.0 + 0.25);
52 }
53  
54 enum plane_type {
55         UNKNOWN,
56         GA_SINGLE,
57         GA_HP_SINGLE,
58         GA_TWIN,
59         GA_JET,
60         MEDIUM,
61         HEAVY,
62         MIL_JET
63 };
64
65 // PlaneRec - a structure holding ATC-centric details of planes under control
66 // This might move or change eventually
67 struct PlaneRec {
68         PlaneRec() : type(UNKNOWN), squawkcode(0) {}
69         PlaneRec(const std::string& s) : type(UNKNOWN), callsign(s), squawkcode(0) {}
70         plane_type type;
71         std::string callsign;
72         int squawkcode;
73 };
74
75 // Possible types of ATC type that the radios may be tuned to.
76 // INVALID implies not tuned in to anything.
77 enum atc_type {
78         AWOS,
79         ATIS,
80         GROUND,
81         TOWER,
82         APPROACH,
83         DEPARTURE,
84         ENROUTE,
85   INVALID        /* must be last element;  see ATC_NUM_TYPES */
86 };
87
88 const int ATC_NUM_TYPES = 1 + INVALID;
89
90 // DCL - new experimental ATC data store
91 struct ATCData {
92         ATCData() : type(INVALID), cart(0, 0, 0), freq(0), range(0) {}
93         atc_type type;
94         SGGeod geod;
95         SGVec3d cart;
96         unsigned short int freq;
97         unsigned short int range;
98         std::string ident;
99         std::string name;
100 };
101
102 // perhaps we could use an FGRunway instead of this.
103 // That wouldn't cache the orthopos though.
104 struct RunwayDetails {
105         RunwayDetails() : end1ortho(0, 0, 0), end2ortho(0, 0, 0), hdg(0), length(-1), width(-1) {}
106         SGGeod threshold_pos;
107         SGVec3d end1ortho;      // ortho projection end1 (the threshold ATM)
108         SGVec3d end2ortho;      // ortho projection end2 (the take off end in the current hardwired scheme)
109         double hdg;             // true runway heading
110         double length;  // In *METERS*
111         double width;   // ditto
112         std::string rwyID;
113         int patternDirection;   // -1 for left, 1 for right
114 };
115
116 std::ostream& operator << (std::ostream& os, atc_type atc);
117
118 class FGATC {
119   friend class FGATCMgr;
120 public:
121         
122         FGATC();
123         virtual ~FGATC();
124         
125         virtual void Init()=0;
126   
127         // Run the internal calculations
128         // Derived classes should call this method from their own Update methods if they 
129         // wish to use the response timer functionality.
130         virtual void Update(double dt);
131         
132         // Recieve a coded callback from the ATC menu system based on the user's selection
133         virtual void ReceiveUserCallback(int code);
134         
135         // Add plane to a stack
136         virtual void AddPlane(const std::string& pid);
137         
138         // Remove plane from stack
139         virtual int RemovePlane();
140         
141         // Indicate that this instance should output to the display if appropriate 
142         inline void SetDisplay() { _display = true; }
143         
144         // Indicate that this instance should not output to the display
145         inline void SetNoDisplay() { _display = false; }
146         
147         // Generate the text of a message from its parameters and the current context.
148         virtual std::string GenText(const std::string& m, int c);
149         
150         // Returns true if OK to transmit on this frequency
151         inline bool GetFreqClear() { return freqClear; }
152         // Indicate that the frequency is in use
153         inline void SetFreqInUse() { freqClear = false; receiving = true; }
154         // Transmission to the ATC is finished and a response is required
155         void SetResponseReqd(const std::string& rid);
156         // Transmission finished - let ATC decide if a response is reqd and clear freq if necessary
157         void NotifyTransmissionFinished(const std::string& rid);
158         // Transmission finished and no response required
159         inline void ReleaseFreq() { freqClear = true; receiving = false; }      // TODO - check that the plane releasing the freq is the right one etc.
160         // The above 3 funcs under development!!
161         // The idea is that AI traffic or the user ATC dialog box calls FreqInUse() when they begin transmitting,
162         // and that the tower control sets freqClear back to true following a reply.
163         // AI traffic should check FreqClear() is true prior to transmitting.
164         // The user will just have to wait for a gap in dialog as in real life.
165         
166         // Return the type of ATC station that the class represents
167         inline atc_type GetType() { return _type; }
168         
169         // Set the core ATC data
170         void SetData(ATCData* d);
171
172         inline int get_freq() const { return freq; }
173         inline void set_freq(const int fq) {freq = fq;}
174         inline int get_range() const { return range; }
175         inline void set_range(const int rg) {range = rg;}
176         inline const std::string& get_ident() { return ident; }
177         inline void set_ident(const std::string& id) { ident = id; }
178         inline const std::string& get_name() { return name; }
179         inline void set_name(const std::string& nm) { name = nm; }
180         
181 protected:
182         
183         // Render a transmission
184         // Outputs the transmission either on screen or as audio depending on user preference
185         // The refname is a string to identify this sample to the sound manager
186         // The repeating flag indicates whether the message should be repeated continuously or played once.
187         void Render(std::string& msg, const float volume = 1.0, 
188         const std::string& refname = "", bool repeating = false);
189         
190         // Cease rendering all transmission from this station.
191         // Requires the sound manager refname if audio, else "".
192         void NoRender(const std::string& refname);
193         
194         // Transmit a message when channel becomes free of other dialog
195         void Transmit(int callback_code = 0);
196         
197         // Transmit a message if channel becomes free within timeout (seconds). timeout of zero implies no limit
198         void ConditionalTransmit(double timeout, int callback_code = 0);
199         
200         // Transmit regardless of other dialog on the channel eg emergency
201         void ImmediateTransmit(int callback_code = 0);
202         
203         virtual void ProcessCallback(int code);
204         
205         SGGeod _geod;
206         SGVec3d _cart;
207         int freq;
208         std::map<std::string,int> active_on;
209   
210         int range;
211         std::string ident;      // Code of the airport its at.
212         std::string name;       // Name transmitted in the broadcast.
213
214         
215         // Rendering related stuff
216         bool _voice;    // Flag - true if we are using voice
217         bool _playing;  // Indicates a message in progress      
218         bool _voiceOK;  // Flag - true if at least one voice has loaded OK
219         FGATCVoice* _vPtr;
220
221         SGSharedPtr<SGSampleGroup> _sgr; // default sample group;
222
223         
224         bool freqClear; // Flag to indicate if the frequency is clear of ongoing dialog
225         bool receiving; // Flag to indicate we are receiving a transmission
226         
227         
228         double responseTime; // Time to take from end of request transmission to beginning of response
229                                                  // The idea is that this will be slightly random.
230         
231         bool respond;   // Flag to indicate now is the time to respond - ie set following the count down of the response timer.
232         std::string responseID; // ID of the plane to respond to
233         bool runResponseCounter;        // Flag to indicate the response counter should be run
234         double responseCounter; // counter to implement the above
235         // Derived classes only need monitor this flag, and use the response ID, as long as they call FGATC::Update(...)
236         bool _runReleaseCounter;        // A timer for releasing the frequency after giving the message enough time to display
237         bool responseReqd;      // Flag to indicate we should be responding to a request/report 
238         double _releaseTime;
239         double _releaseCounter;
240   atc_type _type;
241         bool _display;  // Flag to indicate whether we should be outputting to the ATC display.
242         std::string pending_transmission; // derived classes set this string before calling Transmit(...)       
243         
244 private:
245         // Transmission timing stuff.
246         double _timeout;
247         bool _pending;
248         
249         int _callback_code;     // A callback code to be notified and processed by the derived classes
250                                                 // A value of zero indicates no callback required
251         bool _transmit;         // we are to transmit
252         bool _transmitting;     // we are transmitting
253         double _counter;
254         double _max_count;
255
256         SGPropertyNode_ptr _volume;
257         SGPropertyNode_ptr _enabled;
258         SGPropertyNode_ptr _atc_external;
259         SGPropertyNode_ptr _internal;
260 };
261
262 std::istream& operator>> ( std::istream& fin, ATCData& a );
263
264 #endif  // _FG_ATC_HXX