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