]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/navrecord.hxx
This should apply, and everything should build cleanly, in isolation from the
[flightgear.git] / src / Navaids / navrecord.hxx
1 // navrecord.hxx -- generic vor/dme/ndb class
2 //
3 // Written by Curtis Olson, started May 2004.
4 //
5 // Copyright (C) 2004  Curtis L. Olson - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _FG_NAVRECORD_HXX
25 #define _FG_NAVRECORD_HXX
26
27 #include <stdio.h>
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 #include <simgear/structure/SGSharedPtr.hxx>
36 #include <simgear/structure/SGReferenced.hxx>
37
38 #include <istream>
39
40 #define FG_NAV_DEFAULT_RANGE 50 // nm
41 #define FG_LOC_DEFAULT_RANGE 18 // nm
42 #define FG_DME_DEFAULT_RANGE 50 // nm
43 #define FG_NAV_MAX_RANGE 300    // nm
44
45 // Shield the rest of FG from possibly changing details of Robins navaid type numbering system.
46 // Currently only the GPS code uses this - extra types (LOC, GS etc) may need to be added
47 // should other FG code choose to use this. 
48 enum fg_nav_types {
49     FG_NAV_VOR,
50     FG_NAV_NDB,
51     FG_NAV_ILS,
52     FG_NAV_ANY
53 };
54
55 class FGNavRecord : public SGReferenced {
56
57     int type;
58     SGGeod pos;                // location in geodetic coords (degrees)
59     SGVec3d cart;              // location in cartesian coords (earth centered)
60     int freq;
61     int range;
62     double multiuse;            // can be slaved variation of VOR
63                                 // (degrees) or localizer heading
64                                 // (degrees) or dme bias (nm)
65
66     std::string ident;          // navaid ident
67     std::string name;                // verbose name in nav database
68     std::string apt_id;              // corresponding airport id
69
70
71     bool serviceable;           // for failure modeling
72     std::string trans_ident;         // for failure modeling
73
74 public:
75
76     inline FGNavRecord(void);
77     inline ~FGNavRecord(void) {}
78
79     inline int get_type() const { return type; }
80     inline fg_nav_types get_fg_type() const;
81     inline double get_lon() const { return pos.getLongitudeDeg(); } // degrees
82     inline void set_lon( double l ) { pos.setLongitudeDeg(l); } // degrees
83     inline double get_lat() const { return pos.getLatitudeDeg(); } // degrees
84     inline void set_lat( double l ) { pos.setLatitudeDeg(l); } // degrees
85     inline double get_elev_ft() const { return pos.getElevationFt(); }
86     inline void set_elev_ft( double e ) { pos.setElevationFt(e); }
87     const SGGeod& get_pos() const { return pos; }
88     const SGVec3d& get_cart() const { return cart; }
89     inline int get_freq() const { return freq; }
90     inline int get_range() const { return range; }
91     inline double get_multiuse() const { return multiuse; }
92     inline void set_multiuse( double m ) { multiuse = m; }
93     inline const char *get_ident() const { return ident.c_str(); }
94     inline const std::string& get_name() const { return name; }
95     inline const std::string& get_apt_id() const { return apt_id; }
96     inline bool get_serviceable() const { return serviceable; }
97     inline const char *get_trans_ident() const { return trans_ident.c_str(); }
98
99     friend std::istream& operator>> ( std::istream&, FGNavRecord& );
100 };
101
102
103 inline
104 FGNavRecord::FGNavRecord(void) :
105     type(0),
106     pos(SGGeod::fromDeg(0, 0)),
107     cart(0, 0, 0),
108     freq(0),
109     range(0),
110     multiuse(0.0),
111     ident(""),
112     name(""),
113     apt_id(""),
114     serviceable(true),
115     trans_ident("")
116 {
117 }
118
119
120 inline fg_nav_types FGNavRecord::get_fg_type() const {
121     switch(type) {
122     case 2: return(FG_NAV_NDB);
123     case 3: return(FG_NAV_VOR);
124     case 4: return(FG_NAV_ILS);
125     default: return(FG_NAV_ANY);
126     }
127 }
128
129
130 inline std::istream&
131 operator >> ( std::istream& in, FGNavRecord& n )
132 {
133     in >> n.type;
134     
135     if ( n.type == 99 ) {
136         return in >> skipeol;
137     }
138
139     double lat, lon, elev_ft;
140     in >> lat >> lon >> elev_ft >> n.freq >> n.range >> n.multiuse
141        >> n.ident;
142     n.pos.setLatitudeDeg(lat);
143     n.pos.setLongitudeDeg(lon);
144     n.pos.setElevationFt(elev_ft);
145     getline( in, n.name );
146
147     // silently multiply adf frequencies by 100 so that adf
148     // vs. nav/loc frequency lookups can use the same code.
149     if ( n.type == 2 ) {
150         n.freq *= 100;
151     }
152
153     // Remove any leading spaces before the name
154     while ( n.name.substr(0,1) == " " ) {
155         n.name = n.name.erase(0,1);
156     }
157
158     if ( n.type >= 4 && n.type <= 9 ) {
159         // these types are always associated with an airport id
160         std::string::size_type pos = n.name.find(" ");
161         n.apt_id = n.name.substr(0, pos);
162     }
163
164     // Ranges are included with the latest data format, no need to
165     // assign our own defaults, unless the range is not set for some
166     // reason.
167
168     if ( n.range < 0.1 ) {
169         // assign default ranges
170     
171         if ( n.type == 2 || n.type == 3 ) {
172             n.range = FG_NAV_DEFAULT_RANGE;
173         } else if ( n.type == 4 || n.type == 5 || n.type == 6 ) {
174             n.range = FG_LOC_DEFAULT_RANGE;
175         } else if ( n.type == 12 ) {
176             n.range = FG_DME_DEFAULT_RANGE;
177         } else {
178             n.range = FG_LOC_DEFAULT_RANGE;
179         }
180     }
181
182     // transmitted ident (same as ident unless modeling a fault)
183     n.trans_ident = n.ident;
184
185     // generate cartesian coordinates
186     n.cart = SGVec3d::fromGeod(n.pos);
187
188     return in;
189 }
190
191 class FGTACANRecord : public SGReferenced {
192
193     std::string channel;                
194     int freq;
195      
196 public:
197     
198     inline FGTACANRecord(void);
199     inline ~FGTACANRecord(void) {}
200
201     inline const std::string& get_channel() const { return channel; }
202     inline int get_freq() const { return freq; }
203     friend std::istream& operator>> ( std::istream&, FGTACANRecord& );
204     };
205
206
207 inline
208 FGTACANRecord::FGTACANRecord(void) :
209     channel(""),
210     freq(0)
211     
212 {
213 }
214
215 inline std::istream&
216 operator >> ( std::istream& in, FGTACANRecord& n )
217 {
218     in >> n.channel >> n.freq ;
219     //getline( in, n.name );
220
221     return in;
222 }
223 #endif // _FG_NAVRECORD_HXX