1 // navrecord.cxx -- 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.
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/misc/sg_path.hxx>
31 #include <simgear/structure/exception.hxx>
32 #include <simgear/debug/logstream.hxx>
33 #include <simgear/sg_inlines.h>
34 #include <simgear/props/props.hxx>
37 #include <Navaids/navrecord.hxx>
38 #include <Navaids/navdb.hxx>
39 #include <Airports/runways.hxx>
40 #include <Airports/airport.hxx>
41 #include <Airports/xmlloader.hxx>
42 #include <Main/fg_props.hxx>
44 FGNavRecord::FGNavRecord(PositionedID aGuid, Type aTy, const std::string& aIdent,
45 const std::string& aName, const SGGeod& aPos,
46 int aFreq, int aRange, double aMultiuse, PositionedID aRunway) :
47 FGPositioned(aGuid, aTy, aIdent, aPos),
58 FGRunwayRef FGNavRecord::runway() const
60 return loadById<FGRunway>(mRunway);
63 double FGNavRecord::localizerWidth() const
69 FGRunway* rwy = runway();
70 SGVec3d thresholdCart(SGVec3d::fromGeod(rwy->threshold()));
71 double axisLength = dist(cart(), thresholdCart);
72 double landingLength = dist(thresholdCart, SGVec3d::fromGeod(rwy->end()));
74 // Reference: http://dcaa.slv.dk:8000/icaodocs/
75 // ICAO standard width at threshold is 210 m = 689 feet = approx 700 feet.
76 // ICAO 3.1.1 half course = DDM = 0.0775
77 // ICAO 3.1.3.7.1 Sensitivity 0.00145 DDM/m at threshold
78 // implies peg-to-peg of 214 m ... we will stick with 210.
79 // ICAO 3.1.3.7.1 "Course sector angle shall not exceed 6 degrees."
81 // Very short runway: less than 1200 m (4000 ft) landing length:
82 if (landingLength < 1200.0) {
83 // ICAO fudges localizer sensitivity for very short runways.
84 // This produces a non-monotonic sensitivity-versus length relation.
88 // Example: very short: San Diego KMYF (Montgomery Field) ILS RWY 28R
89 // Example: short: Tom's River KMJX (Robert J. Miller) ILS RWY 6
90 // Example: very long: Denver KDEN (Denver) ILS RWY 16R
91 double raw_width = 210.0 / axisLength * SGD_RADIANS_TO_DEGREES;
92 return raw_width < 6.0? raw_width : 6.0;
96 bool FGNavRecord::hasDME()
98 return (mColocated > 0);
101 void FGNavRecord::setColocatedDME(PositionedID other)
106 void FGNavRecord::updateFromXML(const SGGeod& geod, double heading)
108 modifyPosition(geod);
112 //------------------------------------------------------------------------------
113 FGMobileNavRecord::FGMobileNavRecord( PositionedID aGuid,
115 const std::string& ident,
116 const std::string& name,
121 PositionedID aRunway ):
122 FGNavRecord(aGuid, type, ident, name, aPos, freq, range, multiuse, aRunway)
127 //------------------------------------------------------------------------------
128 const SGGeod& FGMobileNavRecord::geod() const
130 const_cast<FGMobileNavRecord*>(this)->updatePos();
131 return FGNavRecord::geod();
134 //------------------------------------------------------------------------------
135 const SGVec3d& FGMobileNavRecord::cart() const
137 const_cast<FGMobileNavRecord*>(this)->updatePos();
138 return FGNavRecord::cart();
141 //------------------------------------------------------------------------------
142 void FGMobileNavRecord::updatePos()
144 SGTimeStamp now = SGTimeStamp::now();
145 if( (now - _last_position_update).toSecs() < 1 )
147 _last_position_update = now;
149 SGPropertyNode* ai_branch = fgGetNode("ai/models");
154 "Can not update mobile navaid position (no ai/models branch)" );
159 const std::string& nav_name = name();
161 // Try any aircraft carriers first
162 simgear::PropertyList carrier = ai_branch->getChildren("carrier");
163 for(size_t i = 0; i < carrier.size(); ++i)
165 const std::string carrier_name = carrier[i]->getStringValue("name");
167 if( carrier_name.empty()
168 || nav_name.find(carrier_name) == std::string::npos )
171 modifyPosition(SGGeod::fromDegFt(
172 carrier[i]->getDoubleValue("position/longitude-deg"),
173 carrier[i]->getDoubleValue("position/latitude-deg"),
180 const std::string tanker_branches[] = {
183 // And finally mp tankers
187 for(size_t i = 0; i < sizeof(tanker_branches)/sizeof(tanker_branches[0]); ++i)
189 simgear::PropertyList tanker = ai_branch->getChildren(tanker_branches[i]);
190 for(size_t j = 0; j < tanker.size(); ++j)
192 const std::string callsign = tanker[j]->getStringValue("callsign");
195 || nav_name.find(callsign) == std::string::npos )
198 modifyPosition(SGGeod::fromDegFt(
199 tanker[j]->getDoubleValue("position/longitude-deg"),
200 tanker[j]->getDoubleValue("position/latitude-deg"),
201 tanker[j]->getDoubleValue("position/altitude-ft")
207 // If no match was found set 'invalid' position (lat = lon = alt = 0)
208 modifyPosition(SGGeod());
210 // It's mobile but we do not know where it is...
214 FGTACANRecord::FGTACANRecord(void) :
222 operator >> ( std::istream& in, FGTACANRecord& n )
224 in >> n.channel >> n.freq ;
225 //getline( in, n.name );