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