1 // navrecord.hxx -- generic vor/dme/ndb class
3 // Written by Curtis Olson, started May 2004.
5 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
24 #ifndef _FG_NAVRECORD_HXX
25 #define _FG_NAVRECORD_HXX
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>
35 #include <simgear/structure/SGSharedPtr.hxx>
36 #include <simgear/structure/SGReferenced.hxx>
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
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.
55 class FGNavRecord : public SGReferenced {
58 SGGeod pos; // location in geodetic coords (degrees)
59 SGVec3d cart; // location in cartesian coords (earth centered)
62 double multiuse; // can be slaved variation of VOR
63 // (degrees) or localizer heading
64 // (degrees) or dme bias (nm)
66 std::string ident; // navaid ident
67 std::string name; // verbose name in nav database
68 std::string apt_id; // corresponding airport id
71 bool serviceable; // for failure modeling
72 std::string trans_ident; // for failure modeling
76 inline FGNavRecord(void);
77 inline ~FGNavRecord(void) {}
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(); }
99 friend std::istream& operator>> ( std::istream&, FGNavRecord& );
104 FGNavRecord::FGNavRecord(void) :
106 pos(SGGeod::fromDeg(0, 0)),
120 inline fg_nav_types FGNavRecord::get_fg_type() const {
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);
131 operator >> ( std::istream& in, FGNavRecord& n )
135 if ( n.type == 99 ) {
136 return in >> skipeol;
139 double lat, lon, elev_ft;
140 in >> lat >> lon >> elev_ft >> n.freq >> n.range >> n.multiuse
142 n.pos.setLatitudeDeg(lat);
143 n.pos.setLongitudeDeg(lon);
144 n.pos.setElevationFt(elev_ft);
145 getline( in, n.name );
147 // silently multiply adf frequencies by 100 so that adf
148 // vs. nav/loc frequency lookups can use the same code.
153 // Remove any leading spaces before the name
154 while ( n.name.substr(0,1) == " " ) {
155 n.name = n.name.erase(0,1);
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);
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
168 if ( n.range < 0.1 ) {
169 // assign default ranges
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;
178 n.range = FG_LOC_DEFAULT_RANGE;
182 // transmitted ident (same as ident unless modeling a fault)
183 n.trans_ident = n.ident;
185 // generate cartesian coordinates
186 n.cart = SGVec3d::fromGeod(n.pos);
191 class FGTACANRecord : public SGReferenced {
198 inline FGTACANRecord(void);
199 inline ~FGTACANRecord(void) {}
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& );
208 FGTACANRecord::FGTACANRecord(void) :
216 operator >> ( std::istream& in, FGTACANRecord& n )
218 in >> n.channel >> n.freq ;
219 //getline( in, n.name );
223 #endif // _FG_NAVRECORD_HXX