~ubuntu-branches/ubuntu/precise/flightgear/precise

« back to all changes in this revision

Viewing changes to src/ATCDCL/ATC.hxx

  • Committer: Bazaar Package Importer
  • Author(s): Ove Kaaven
  • Date: 2011-01-30 15:46:35 UTC
  • mfrom: (3.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110130154635-rlynmg9n5hzxq5xe
Tags: 2.0.0-3
* Recommend fgfs-aircraft-base and fgfs-models-base.
  Closes. #610276.
* Added note about scenery SharedModels.tgz to README.Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include <simgear/constants.h>
26
26
#include <simgear/compiler.h>
 
27
#include <simgear/props/props.hxx>
27
28
#include <simgear/misc/sgstream.hxx>
28
29
#include <simgear/math/sg_geodesy.hxx>
29
30
#include <simgear/debug/logstream.hxx>
30
 
 
31
 
#include <istream>
32
 
#include <ostream>
33
 
 
 
31
#include <simgear/structure/SGSharedPtr.hxx>
 
32
 
 
33
#include <iosfwd>
34
34
#include <string>
35
35
 
36
36
#include "ATCVoice.hxx"
37
37
 
38
 
using std::ostream;
39
 
using std::string;
40
 
using std::ios;
 
38
class SGSampleGroup;
41
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
 
42
54
enum plane_type {
43
55
        UNKNOWN,
44
56
        GA_SINGLE,
61
73
// Possible types of ATC type that the radios may be tuned to.
62
74
// INVALID implies not tuned in to anything.
63
75
enum atc_type {
64
 
        INVALID,
 
76
        AWOS,
65
77
        ATIS,
66
78
        GROUND,
67
79
        TOWER,
68
80
        APPROACH,
69
81
        DEPARTURE,
70
 
        ENROUTE
 
82
        ENROUTE,
 
83
  INVALID        /* must be last element;  see ATC_NUM_TYPES */
71
84
};
72
85
 
73
 
const int ATC_NUM_TYPES = 7;
 
86
const int ATC_NUM_TYPES = 1 + INVALID;
74
87
 
75
88
// DCL - new experimental ATC data store
76
89
struct ATCData {
77
90
        atc_type type;
78
 
        // I've deliberately used float instead of double here to keep the size down - we'll be storing thousands of these in memory.
79
 
        // In fact, we could probably ditch x, y and z and generate on the fly as needed.
80
 
        // On the other hand, we'll probably end up reading this data directly from the DAFIF eventually anyway!!
81
 
        float lon, lat, elev;
82
 
        float x, y, z;
83
 
        //int freq;
 
91
        SGGeod geod;
 
92
        SGVec3d cart;
84
93
        unsigned short int freq;
85
 
        //int range;
86
94
        unsigned short int range;
87
95
        std::string ident;
88
96
        std::string name;
91
99
// perhaps we could use an FGRunway instead of this.
92
100
// That wouldn't cache the orthopos though.
93
101
struct RunwayDetails {
94
 
        Point3D threshold_pos;
95
 
        Point3D end1ortho;      // ortho projection end1 (the threshold ATM)
96
 
        Point3D end2ortho;      // ortho projection end2 (the take off end in the current hardwired scheme)
 
102
        SGGeod threshold_pos;
 
103
        SGVec3d end1ortho;      // ortho projection end1 (the threshold ATM)
 
104
        SGVec3d end2ortho;      // ortho projection end2 (the take off end in the current hardwired scheme)
97
105
        double hdg;             // true runway heading
98
106
        double length;  // In *METERS*
99
107
        double width;   // ditto
104
112
std::ostream& operator << (std::ostream& os, atc_type atc);
105
113
 
106
114
class FGATC {
107
 
        
 
115
  friend class FGATCMgr;
108
116
public:
109
117
        
110
118
        FGATC();
111
119
        virtual ~FGATC();
112
120
        
 
121
        virtual void Init()=0;
 
122
  
113
123
        // Run the internal calculations
114
124
        // Derived classes should call this method from their own Update methods if they 
115
125
        // wish to use the response timer functionality.
154
164
        
155
165
        // Set the core ATC data
156
166
        void SetData(ATCData* d);
157
 
        
158
 
        inline double get_lon() const { return lon; }
159
 
        inline void set_lon(const double ln) {lon = ln;}
160
 
        inline double get_lat() const { return lat; }
161
 
        inline void set_lat(const double lt) {lat = lt;}
162
 
        inline double get_elev() const { return elev; }
163
 
        inline void set_elev(const double ev) {elev = ev;}
164
 
        inline double get_x() const { return x; }
165
 
        inline void set_x(const double ecs) {x = ecs;}
166
 
        inline double get_y() const { return y; }
167
 
        inline void set_y(const double why) {y = why;}
168
 
        inline double get_z() const { return z; }
169
 
        inline void set_z(const double zed) {z = zed;}
 
167
 
170
168
        inline int get_freq() const { return freq; }
171
169
        inline void set_freq(const int fq) {freq = fq;}
172
170
        inline int get_range() const { return range; }
182
180
        // Outputs the transmission either on screen or as audio depending on user preference
183
181
        // The refname is a string to identify this sample to the sound manager
184
182
        // The repeating flag indicates whether the message should be repeated continuously or played once.
185
 
        void Render(std::string& msg, const std::string& refname = "", bool repeating = false);
 
183
        void Render(std::string& msg, const float volume = 1.0, 
 
184
        const std::string& refname = "", bool repeating = false);
186
185
        
187
186
        // Cease rendering all transmission from this station.
188
187
        // Requires the sound manager refname if audio, else "".
189
188
        void NoRender(const std::string& refname);
190
189
        
191
190
        // Transmit a message when channel becomes free of other dialog
192
 
    void Transmit(int callback_code = 0);
 
191
        void Transmit(int callback_code = 0);
193
192
        
194
193
        // Transmit a message if channel becomes free within timeout (seconds). timeout of zero implies no limit
195
194
        void ConditionalTransmit(double timeout, int callback_code = 0);
199
198
        
200
199
        virtual void ProcessCallback(int code);
201
200
        
202
 
        double lon, lat, elev;
203
 
        double x, y, z;
 
201
        SGGeod _geod;
 
202
        SGVec3d _cart;
204
203
        int freq;
 
204
        std::map<std::string,int> active_on;
 
205
  
205
206
        int range;
206
 
        std::string ident;              // Code of the airport its at.
207
 
        std::string name;               // Name transmitted in the broadcast.
208
 
        atc_type _type;
 
207
        std::string ident;      // Code of the airport its at.
 
208
        std::string name;       // Name transmitted in the broadcast.
 
209
 
209
210
        
210
211
        // Rendering related stuff
211
 
        bool _voice;                    // Flag - true if we are using voice
212
 
        bool _playing;          // Indicates a message in progress      
213
 
        bool _voiceOK;          // Flag - true if at least one voice has loaded OK
 
212
        bool _voice;    // Flag - true if we are using voice
 
213
        bool _playing;  // Indicates a message in progress      
 
214
        bool _voiceOK;  // Flag - true if at least one voice has loaded OK
214
215
        FGATCVoice* _vPtr;
215
216
 
216
 
        std::string pending_transmission;       // derived classes set this string before calling Transmit(...) 
217
 
        bool freqClear;         // Flag to indicate if the frequency is clear of ongoing dialog
218
 
        bool receiving;         // Flag to indicate we are receiving a transmission
219
 
        bool responseReqd;      // Flag to indicate we should be responding to a request/report 
 
217
        SGSharedPtr<SGSampleGroup> _sgr; // default sample group;
 
218
 
 
219
        
 
220
        bool freqClear; // Flag to indicate if the frequency is clear of ongoing dialog
 
221
        bool receiving; // Flag to indicate we are receiving a transmission
 
222
        
 
223
        
 
224
        double responseTime; // Time to take from end of request transmission to beginning of response
 
225
                                                 // The idea is that this will be slightly random.
 
226
        
 
227
        bool respond;   // Flag to indicate now is the time to respond - ie set following the count down of the response timer.
 
228
        std::string responseID; // ID of the plane to respond to
220
229
        bool runResponseCounter;        // Flag to indicate the response counter should be run
221
 
        double responseTime;    // Time to take from end of request transmission to beginning of response
222
 
                                                        // The idea is that this will be slightly random.
223
 
        double responseCounter;         // counter to implement the above
224
 
        std::string responseID; // ID of the plane to respond to
225
 
        bool respond;   // Flag to indicate now is the time to respond - ie set following the count down of the response timer.
 
230
        double responseCounter; // counter to implement the above
226
231
        // Derived classes only need monitor this flag, and use the response ID, as long as they call FGATC::Update(...)
227
232
        bool _runReleaseCounter;        // A timer for releasing the frequency after giving the message enough time to display
 
233
        bool responseReqd;      // Flag to indicate we should be responding to a request/report 
228
234
        double _releaseTime;
229
235
        double _releaseCounter;
230
 
        
231
 
        bool _display;          // Flag to indicate whether we should be outputting to the ATC display.
232
 
        bool _displaying;               // Flag to indicate whether we are outputting to the ATC display.
 
236
  atc_type _type;
 
237
        bool _display;  // Flag to indicate whether we should be outputting to the ATC display.
 
238
        std::string pending_transmission; // derived classes set this string before calling Transmit(...)       
233
239
        
234
240
private:
235
241
        // Transmission timing stuff.
 
242
        double _timeout;
236
243
        bool _pending;
237
 
        double _timeout;
 
244
        
238
245
        int _callback_code;     // A callback code to be notified and processed by the derived classes
239
246
                                                // A value of zero indicates no callback required
240
247
        bool _transmit;         // we are to transmit
241
248
        bool _transmitting;     // we are transmitting
242
249
        double _counter;
243
250
        double _max_count;
 
251
 
 
252
        SGPropertyNode_ptr _volume;
 
253
        SGPropertyNode_ptr _enabled;
 
254
        SGPropertyNode_ptr _atc_external;
 
255
        SGPropertyNode_ptr _internal;
244
256
};
245
257
 
246
 
inline std::istream&
247
 
operator >> ( std::istream& fin, ATCData& a )
248
 
{
249
 
        double f;
250
 
        char ch;
251
 
        char tp;
252
 
        
253
 
        fin >> tp;
254
 
        
255
 
        switch(tp) {
256
 
        case 'I':
257
 
                a.type = ATIS;
258
 
                break;
259
 
        case 'T':
260
 
                a.type = TOWER;
261
 
                break;
262
 
        case 'G':
263
 
                a.type = GROUND;
264
 
                break;
265
 
        case 'A':
266
 
                a.type = APPROACH;
267
 
                break;
268
 
        case '[':
269
 
                a.type = INVALID;
270
 
                return fin >> skipeol;
271
 
        default:
272
 
                SG_LOG(SG_GENERAL, SG_ALERT, "Warning - unknown type \'" << tp << "\' found whilst reading ATC frequency data!\n");
273
 
                a.type = INVALID;
274
 
                return fin >> skipeol;
275
 
        }
276
 
        
277
 
        fin >> a.lat >> a.lon >> a.elev >> f >> a.range 
278
 
        >> a.ident;
279
 
        
280
 
        a.name = "";
281
 
        fin >> ch;
282
 
        if(ch != '"') a.name += ch;
283
 
        while(1) {
284
 
                //in >> noskipws
285
 
                fin.unsetf(std::ios::skipws);
286
 
                fin >> ch;
287
 
                if((ch == '"') || (ch == 0x0A)) {
288
 
                        break;
289
 
                }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
290
 
                a.name += ch;
291
 
        }
292
 
        fin.setf(std::ios::skipws);
293
 
        //cout << "Comm name = " << a.name << '\n';
294
 
        
295
 
        a.freq = (int)(f*100.0 + 0.5);
296
 
        
297
 
        // cout << a.ident << endl;
298
 
        
299
 
        // generate cartesian coordinates
300
 
        Point3D geod( a.lon * SGD_DEGREES_TO_RADIANS, a.lat * SGD_DEGREES_TO_RADIANS, a.elev );
301
 
        Point3D cart = sgGeodToCart( geod );
302
 
        a.x = cart.x();
303
 
        a.y = cart.y();
304
 
        a.z = cart.z();
305
 
        
306
 
        return fin >> skipeol;
307
 
}
308
 
 
 
258
std::istream& operator>> ( std::istream& fin, ATCData& a );
309
259
 
310
260
#endif  // _FG_ATC_HXX