]> git.mxchange.org Git - flightgear.git/blob - src/ATC/atis.hxx
e5b785d8f270ccbfa4dfdf4876d969beff6b8506
[flightgear.git] / src / ATC / atis.hxx
1 // atis.hxx -- ATIS class
2 //
3 // Written by David Luff, started October 2001.
4 // Based on nav.hxx by Curtis Olson, started April 2000.
5 //
6 // Copyright (C) 2001  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
23 #ifndef _FG_ATIS_HXX
24 #define _FG_ATIS_HXX
25
26 #include <stdio.h>
27 #include <string>
28
29 #include <simgear/compiler.h>
30 #include <simgear/math/sg_geodesy.hxx>
31 #include <simgear/misc/sgstream.hxx>
32 #include <simgear/magvar/magvar.hxx>
33 #include <simgear/timing/sg_time.hxx>
34
35 #ifdef SG_HAVE_STD_INCLUDES
36 #  include <istream>
37 #  include <iomanip>
38 #elif defined( __BORLANDC__ ) || (__APPLE__)
39 #  include <iostream>
40 #else
41 #  include <istream.h>
42 #  include <iomanip.h>
43 #endif
44
45 SG_USING_STD(istream);
46 SG_USING_STD(string);
47
48 #include "ATC.hxx"
49
50 //DCL - a complete guess for now.
51 #define FG_ATIS_DEFAULT_RANGE 30
52
53 class FGATIS : public FGATC {
54         
55         char type;
56         double lon, lat, elev;
57         double x, y, z;
58         int freq;
59         int range;
60         bool display;           // Flag to indicate whether we should be outputting to the ATC display.
61         bool displaying;                // Flag to indicate whether we are outputting to the ATC display.
62         string ident;           // Code of the airport its at.
63         string name;            // Name transmitted in the broadcast.
64         string transmission;    // The actual ATIS transmission
65         // This is not stored in default.atis but is generated
66         // from the prevailing conditions when required.
67         
68         // for failure modeling
69         string trans_ident;             // transmitted ident
70         bool atis_failed;               // atis failed?
71         
72         // Aircraft position
73         // ATIS is actually a special case in that unlike other ATC eg.tower it doesn't actually know about
74         // or the whereabouts of the aircraft it is transmitting to.  However, to ensure consistancy of
75         // operation with the other ATC classes the ATIS class must calculate range to the aircraft in order
76         // to decide whether to render the transmission - hence the users plane details must be stored.
77         //SGPropertyNode *airplane_lon_node; 
78         //SGPropertyNode *airplane_lat_node;
79         //SGPropertyNode *airplane_elev_node; 
80         
81         public:
82         
83         FGATIS(void);
84         ~FGATIS(void);
85         
86         //run the ATIS instance
87         void Update(void);
88         
89         //Indicate that this instance should be outputting to the ATC display
90         inline void SetDisplay(void) {display = true;}
91         
92         //Indicate that this instance should not be outputting to the ATC display
93         inline void SetNoDisplay(void) {display = false;}
94         
95         inline char get_type() const { return type; }
96         inline double get_lon() const { return lon; }
97         inline double get_lat() const { return lat; }
98         inline double get_elev() const { return elev; }
99         inline double get_x() const { return x; }
100         inline double get_y() const { return y; }
101         inline double get_z() const { return z; }
102         inline int get_freq() const { return freq; }
103         inline int get_range() const { return range; }
104         inline const char* GetIdent() { return ident.c_str(); }
105         inline string get_trans_ident() { return trans_ident; }
106         inline atc_type GetType() { return ATIS; }
107         inline void set_refname(string r) { refname = r; } 
108         
109         private:
110         
111         string refname;         // Holds the refname of a transmission in progress
112         
113         //Update the transmission string
114         void UpdateTransmission(void);
115         
116         /* inline void set_type( char t ) { type = t; }
117         inline void set_lon( double l ) { lon = l; }
118         inline void set_lat( double l ) { lat = l; }
119         inline void set_elev( double e ) { elev = e; }
120         inline void set_freq( int f ) { freq = f; }
121         inline void set_range( int r ) { range = r; }
122         inline void set_dme( bool b ) { dme = b; }
123         inline void set_ident( char *i ) { strncpy( ident, i, 5 ); } */
124         
125         friend istream& operator>> ( istream&, FGATIS& );
126 };
127
128
129 inline istream&
130 operator >> ( istream& in, FGATIS& a )
131 {
132         double f;
133         char ch;
134         
135         static bool first_time = true;
136         static double julian_date = 0;
137         static const double MJD0    = 2415020.0;
138         if ( first_time ) {
139                 julian_date = sgTimeCurrentMJD(0, 0) + MJD0;
140                 first_time = false;
141         }
142         
143         in >> a.type;
144         
145         if ( a.type == '[' )
146                 return in >> skipeol;
147         
148         in >> a.lat >> a.lon >> a.elev >> f >> a.range 
149         >> a.ident;
150         
151         a.name = "";
152         in >> ch;
153         a.name += ch;
154         while(1) {
155                 //in >> noskipws
156                 in.unsetf(ios::skipws);
157                 in >> ch;
158                 a.name += ch;
159                 if((ch == '"') || (ch == 0x0A)) {
160                         break;
161                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
162         }
163         in.setf(ios::skipws);
164         //cout << "atis.name = " << a.name << '\n';
165         
166         a.freq = (int)(f*100.0 + 0.5);
167         
168         // cout << a.ident << endl;
169         
170         // generate cartesian coordinates
171         Point3D geod( a.lon * SGD_DEGREES_TO_RADIANS, a.lat * SGD_DEGREES_TO_RADIANS, a.elev );
172         Point3D cart = sgGeodToCart( geod );
173         a.x = cart.x();
174         a.y = cart.y();
175         a.z = cart.z();
176         
177         a.trans_ident = a.ident;
178         a.atis_failed = false;
179         
180         return in >> skipeol;
181 }
182
183 #endif // _FG_ATIS_HXX