]> git.mxchange.org Git - flightgear.git/blob - src/ATC/atis.hxx
Changes to match simgear changes which allow overriding the current
[flightgear.git] / src / ATC / atis.hxx
1 // atis.hxx -- ATIS class
2 //
3 // Written by Curtis Olson, started April 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21
22 #ifndef _FG_ATIS_HXX
23 #define _FG_ATIS_HXX
24
25 #include <stdio.h>
26
27 #include <simgear/compiler.h>
28 #include <simgear/math/sg_geodesy.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/magvar/magvar.hxx>
31 #include <simgear/timing/sg_time.hxx>
32
33 #ifdef SG_HAVE_STD_INCLUDES
34 #  include <istream>
35 #include <iomanip>
36 #elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
37 #  include <iostream.h>
38 #elif defined( __BORLANDC__ )
39 #  include <iostream>
40 #else
41 #  include <istream.h>
42 #include <iomanip.h>
43 #endif
44
45 #if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )
46 SG_USING_STD(istream);
47 #endif
48
49 #include <string>
50
51 SG_USING_STD(string);
52
53 //DCL - a complete guess for now.
54 #define FG_ATIS_DEFAULT_RANGE 30
55
56 class FGATIS {
57
58     char type;
59     double lon, lat;
60     double elev;
61     double x, y, z;
62     int freq;
63     int range;
64     string ident;               // Code of the airport its at.
65     string name;                // Name transmitted in the broadcast.
66     string info;                // The actual ATIS transmission
67                                 // This is not stored in default.atis but is generated
68                                 // from the prevailing conditions when required.
69
70     // for failure modeling
71     string trans_ident;         // transmitted ident
72     bool atis_failed;           // atis failed?
73
74 public:
75
76     FGATIS(void);
77     ~FGATIS(void);
78
79     inline char get_type() const { return type; }
80     inline double get_lon() const { return lon; }
81     inline double get_lat() const { return lat; }
82     inline double get_elev() const { return elev; }
83     inline double get_x() const { return x; }
84     inline double get_y() const { return y; }
85     inline double get_z() const { return z; }
86     inline int get_freq() const { return freq; }
87     inline int get_range() const { return range; }
88     inline const char *get_ident() { return ident.c_str(); }
89     inline string get_trans_ident() { return trans_ident; }
90     string get_transmission(void);
91 //    void get_transmission();
92
93     /* inline void set_type( char t ) { type = t; }
94     inline void set_lon( double l ) { lon = l; }
95     inline void set_lat( double l ) { lat = l; }
96     inline void set_elev( double e ) { elev = e; }
97     inline void set_freq( int f ) { freq = f; }
98     inline void set_range( int r ) { range = r; }
99     inline void set_dme( bool b ) { dme = b; }
100     inline void set_ident( char *i ) { strncpy( ident, i, 5 ); } */
101
102     friend istream& operator>> ( istream&, FGATIS& );
103 };
104
105
106 inline istream&
107 operator >> ( istream& in, FGATIS& a )
108 {
109     double f;
110     char ch;
111
112     static bool first_time = true;
113     static double julian_date = 0;
114     static const double MJD0    = 2415020.0;
115     if ( first_time ) {
116         julian_date = sgTimeCurrentMJD() + MJD0;
117         first_time = false;
118     }
119
120     in >> a.type;
121     
122     if ( a.type == '[' )
123       return in >> skipeol;
124
125     in >> a.lat >> a.lon >> a.elev >> f >> a.range 
126        >> a.ident;
127
128     a.name = "";
129     in >> ch;
130     a.name += ch;
131     while(1) {
132         //in >> noskipws
133         in.unsetf(ios::skipws);
134         in >> ch;
135         a.name += ch;
136         if((ch == '"') || (ch == 0x0A)) {
137             break;
138         }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
139     }
140     in.setf(ios::skipws);
141     //cout << "atis.name = " << a.name << '\n';
142
143     a.freq = (int)(f*100.0 + 0.5);
144
145     // cout << a.ident << endl;
146
147     // generate cartesian coordinates
148     Point3D geod( a.lon * SGD_DEGREES_TO_RADIANS, a.lat * SGD_DEGREES_TO_RADIANS, a.elev );
149     Point3D cart = sgGeodToCart( geod );
150     a.x = cart.x();
151     a.y = cart.y();
152     a.z = cart.z();
153
154     a.trans_ident = a.ident;
155     a.atis_failed = false;
156
157     return in >> skipeol;
158 }
159
160 #endif // _FG_ATIS_HXX