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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
36 #include "ATCVoice.hxx"
45 // Convert a frequency in MHz to tens of kHz
46 // so we can use it e.g. as an index into commlist_freq
48 // If freq > 1000 assume it's already in tens of KHz;
49 // otherwise assume MHz.
51 // Note: 122.375 must be rounded DOWN to 12237
52 // in order to be consistent with apt.dat et cetera.
53 inline int kHz10(double freq)
55 if (freq > 1000.) return int(freq);
56 return int(freq*100.0 + 0.25);
59 // Possible types of ATC type that the radios may be tuned to.
60 // INVALID implies not tuned in to anything.
69 INVALID /* must be last element; see ATC_NUM_TYPES */
72 const int ATC_NUM_TYPES = 1 + INVALID;
74 // DCL - new experimental ATC data store
76 ATCData() : type(INVALID), cart(0, 0, 0), freq(0), range(0) {}
80 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 RunwayDetails() : end1ortho(0, 0, 0), end2ortho(0, 0, 0), hdg(0), length(-1), width(-1) {}
91 SGVec3d end1ortho; // ortho projection end1 (the threshold ATM)
92 SGVec3d end2ortho; // ortho projection end2 (the take off end in the current hardwired scheme)
93 double hdg; // true runway heading
94 double length; // In *METERS*
95 double width; // ditto
97 int patternDirection; // -1 for left, 1 for right
100 std::ostream& operator << (std::ostream& os, atc_type atc);
103 friend class FGATCMgr;
109 virtual void Init()=0;
111 // Run the internal calculations
112 // Derived classes should call this method from their own Update methods if they
113 // wish to use the response timer functionality.
114 virtual void Update(double dt);
116 // Recieve a coded callback from the ATC menu system based on the user's selection
117 virtual void ReceiveUserCallback(int code);
119 // Indicate that this instance should output to the display if appropriate
120 inline void SetDisplay() { _display = true; }
122 // Indicate that this instance should not output to the display
123 inline void SetNoDisplay() { _display = false; }
125 // Generate the text of a message from its parameters and the current context.
126 virtual std::string GenText(const std::string& m, int c);
128 // Returns true if OK to transmit on this frequency
129 inline bool GetFreqClear() { return freqClear; }
130 // Indicate that the frequency is in use
131 inline void SetFreqInUse() { freqClear = false; receiving = true; }
132 // Transmission to the ATC is finished and a response is required
133 void SetResponseReqd(const std::string& rid);
134 // Transmission finished - let ATC decide if a response is reqd and clear freq if necessary
135 void NotifyTransmissionFinished(const std::string& rid);
136 // Transmission finished and no response required
137 inline void ReleaseFreq() { freqClear = true; receiving = false; } // TODO - check that the plane releasing the freq is the right one etc.
138 // The above 3 funcs under development!!
139 // The idea is that AI traffic or the user ATC dialog box calls FreqInUse() when they begin transmitting,
140 // and that the tower control sets freqClear back to true following a reply.
141 // AI traffic should check FreqClear() is true prior to transmitting.
142 // The user will just have to wait for a gap in dialog as in real life.
144 // Return the type of ATC station that the class represents
145 inline atc_type GetType() { return _type; }
147 // Set the core ATC data
148 void SetStation(flightgear::CommStation* sta);
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 std::string& get_ident() { return ident; }
155 inline void set_ident(const std::string& id) { ident = id; }
156 inline const std::string& get_name() { return name; }
157 inline void set_name(const std::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(std::string& msg, const float volume = 1.0,
166 const std::string& refname = "", bool repeating = false);
168 // Cease rendering all transmission from this station.
169 // Requires the sound manager refname if audio, else "".
170 void NoRender(const std::string& refname);
175 std::map<std::string,int> active_on;
178 std::string ident; // Code of the airport its at.
179 std::string name; // Name transmitted in the broadcast.
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
188 SGSharedPtr<SGSampleGroup> _sgr; // default sample group;
191 bool freqClear; // Flag to indicate if the frequency is clear of ongoing dialog
192 bool receiving; // Flag to indicate we are receiving a transmission
195 double responseTime; // Time to take from end of request transmission to beginning of response
196 // The idea is that this will be slightly random.
198 bool respond; // Flag to indicate now is the time to respond - ie set following the count down of the response timer.
199 std::string responseID; // ID of the plane to respond to
200 bool runResponseCounter; // Flag to indicate the response counter should be run
201 double responseCounter; // counter to implement the above
202 // Derived classes only need monitor this flag, and use the response ID, as long as they call FGATC::Update(...)
203 bool _runReleaseCounter; // A timer for releasing the frequency after giving the message enough time to display
204 bool responseReqd; // Flag to indicate we should be responding to a request/report
206 double _releaseCounter;
208 bool _display; // Flag to indicate whether we should be outputting to the ATC display.
209 std::string pending_transmission; // derived classes set this string before calling Transmit(...)
212 // Transmission timing stuff.
215 bool _transmit; // we are to transmit
216 bool _transmitting; // we are transmitting
220 SGPropertyNode_ptr _volume;
221 SGPropertyNode_ptr _enabled;
222 SGPropertyNode_ptr _atc_external;
223 SGPropertyNode_ptr _internal;
226 std::istream& operator>> ( std::istream& fin, ATCData& a );
228 #endif // _FG_ATC_HXX