]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/ATC.hxx
ATCDCL cleanup, part II.
[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 namespace flightgear
41 {
42     class CommStation;
43 }
44
45 // Possible types of ATC type that the radios may be tuned to.
46 // INVALID implies not tuned in to anything.
47 enum atc_type {
48         AWOS,
49         ATIS,
50         GROUND,
51         TOWER,
52         APPROACH,
53         DEPARTURE,
54         ENROUTE,
55         INVALID  /* must be last element;  see ATC_NUM_TYPES */
56 };
57
58 #ifdef OLD_ATC_MGR
59 const int ATC_NUM_TYPES = 1 + INVALID;
60
61 // DCL - new experimental ATC data store
62 struct ATCData {
63         ATCData() : type(INVALID), cart(0, 0, 0), freq(0), range(0) {}
64         atc_type type;
65         SGGeod geod;
66         SGVec3d cart;
67         unsigned short int freq;
68         unsigned short int range;
69         std::string ident;
70         std::string name;
71 };
72
73 // perhaps we could use an FGRunway instead of this.
74 // That wouldn't cache the orthopos though.
75 struct RunwayDetails {
76         RunwayDetails() : end1ortho(0, 0, 0), end2ortho(0, 0, 0), hdg(0), length(-1), width(-1) {}
77         SGGeod threshold_pos;
78         SGVec3d end1ortho;      // ortho projection end1 (the threshold ATM)
79         SGVec3d end2ortho;      // ortho projection end2 (the take off end in the current hardwired scheme)
80         double hdg;             // true runway heading
81         double length;  // In *METERS*
82         double width;   // ditto
83         std::string rwyID;
84         int patternDirection;   // -1 for left, 1 for right
85 };
86
87 std::ostream& operator << (std::ostream& os, atc_type atc);
88 #endif
89
90 class FGATC {
91         friend class FGATISMgr;
92 public:
93         
94         FGATC();
95         virtual ~FGATC();
96         
97         virtual void Init()=0;
98   
99         // Run the internal calculations
100         // Derived classes should call this method from their own Update methods if they 
101         // wish to use the response timer functionality.
102         virtual void Update(double dt);
103         
104         // Indicate that this instance should output to the display if appropriate 
105         inline void SetDisplay() { _display = true; }
106         
107         // Indicate that this instance should not output to the display
108         inline void SetNoDisplay() { _display = false; }
109         
110 #ifdef OLD_ATC_MGR
111         // Receive a coded callback from the ATC menu system based on the user's selection
112         virtual void ReceiveUserCallback(int code);
113
114         // Generate the text of a message from its parameters and the current context.
115         virtual std::string GenText(const std::string& m, int c);
116         
117         // Returns true if OK to transmit on this frequency
118         inline bool GetFreqClear() { return freqClear; }
119         // Indicate that the frequency is in use
120         inline void SetFreqInUse() { freqClear = false; receiving = true; }
121         // Transmission to the ATC is finished and a response is required
122         void SetResponseReqd(const std::string& rid);
123         // Transmission finished - let ATC decide if a response is reqd and clear freq if necessary
124         void NotifyTransmissionFinished(const std::string& rid);
125         // Transmission finished and no response required
126         inline void ReleaseFreq() { freqClear = true; receiving = false; }      // TODO - check that the plane releasing the freq is the right one etc.
127         // The above 3 funcs under development!!
128         // The idea is that AI traffic or the user ATC dialog box calls FreqInUse() when they begin transmitting,
129         // and that the tower control sets freqClear back to true following a reply.
130         // AI traffic should check FreqClear() is true prior to transmitting.
131         // The user will just have to wait for a gap in dialog as in real life.
132         
133         
134
135         inline int get_freq() const { return freq; }
136         inline void set_freq(const int fq) {freq = fq;}
137         inline int get_range() const { return range; }
138         inline void set_range(const int rg) {range = rg;}
139 #endif
140         // Return the type of ATC station that the class represents
141         inline atc_type GetType() { return _type; }
142
143         // Set the core ATC data
144     void SetStation(flightgear::CommStation* sta);
145
146         inline const std::string& get_ident() { return ident; }
147         inline void set_ident(const std::string& id) { ident = id; }
148         inline const std::string& get_name() { return name; }
149         inline void set_name(const std::string& nm) { name = nm; }
150
151 protected:
152         
153         // Render a transmission
154         // Outputs the transmission either on screen or as audio depending on user preference
155         // The refname is a string to identify this sample to the sound manager
156         // The repeating flag indicates whether the message should be repeated continuously or played once.
157         void Render(std::string& msg, const float volume = 1.0, 
158         const std::string& refname = "", bool repeating = false);
159         
160         // Cease rendering all transmission from this station.
161         // Requires the sound manager refname if audio, else "".
162         void NoRender(const std::string& refname);
163         
164         virtual FGATCVoice* GetVoicePointer() = 0;
165
166         SGGeod _geod;
167         SGVec3d _cart;
168         int freq;
169         flightgear::CommStation* _currentStation;
170
171         int range;
172         std::string ident;      // Code of the airport its at.
173         std::string name;       // Name transmitted in the broadcast.
174         std::string _currentMsg; // Current message being transmitted
175
176         // Rendering related stuff
177         bool _voice;    // Flag - true if we are using voice
178         bool _playing;  // Indicates a message in progress
179         FGATCVoice* _vPtr;
180
181         SGSharedPtr<SGSampleGroup> _sgr; // default sample group;
182
183 #ifdef OLD_ATC_MGR
184         bool freqClear; // Flag to indicate if the frequency is clear of ongoing dialog
185         bool receiving; // Flag to indicate we are receiving a transmission
186         
187         
188         double responseTime; // Time to take from end of request transmission to beginning of response
189                                                  // The idea is that this will be slightly random.
190         
191         bool respond;   // Flag to indicate now is the time to respond - ie set following the count down of the response timer.
192         std::string responseID; // ID of the plane to respond to
193         bool runResponseCounter;        // Flag to indicate the response counter should be run
194         double responseCounter; // counter to implement the above
195         // Derived classes only need monitor this flag, and use the response ID, as long as they call FGATC::Update(...)
196         bool _runReleaseCounter;        // A timer for releasing the frequency after giving the message enough time to display
197         bool responseReqd;      // Flag to indicate we should be responding to a request/report 
198         double _releaseTime;
199         double _releaseCounter;
200         std::string pending_transmission; // derived classes set this string before calling Transmit(...)
201 #endif
202         atc_type _type;
203         bool _display;  // Flag to indicate whether we should be outputting to the ATC display.
204
205 private:
206
207 #ifdef OLD_ATC_MGR
208         // Transmission timing stuff.
209         double _timeout;
210         bool _pending;
211         bool _transmit;         // we are to transmit
212         bool _transmitting;     // we are transmitting
213         double _counter;
214         double _max_count;
215 #endif
216
217         SGPropertyNode_ptr _masterVolume;
218         SGPropertyNode_ptr _enabled;
219         SGPropertyNode_ptr _atc_external;
220         SGPropertyNode_ptr _internal;
221 };
222
223 #ifdef OLD_ATC_MGR
224 std::istream& operator>> ( std::istream& fin, ATCData& a );
225 #endif
226
227 #endif  // _FG_ATC_HXX