2000-04-21 18:00:47 +00:00
|
|
|
// ilslist.cxx -- ils management class
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started April 2000.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
2001-05-15 22:30:39 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2000-04-21 18:00:47 +00:00
|
|
|
#include <simgear/debug/logstream.hxx>
|
2001-03-25 14:20:12 +00:00
|
|
|
#include <simgear/misc/sgstream.hxx>
|
2000-09-27 20:16:22 +00:00
|
|
|
#include <simgear/math/sg_geodesy.hxx>
|
2000-04-21 18:00:47 +00:00
|
|
|
|
2001-03-16 23:57:38 +00:00
|
|
|
#include "mkrbeacons.hxx"
|
2000-04-21 18:00:47 +00:00
|
|
|
#include "ilslist.hxx"
|
|
|
|
|
|
|
|
|
2000-04-24 23:51:56 +00:00
|
|
|
FGILSList *current_ilslist;
|
|
|
|
|
|
|
|
|
2000-04-21 18:00:47 +00:00
|
|
|
// Constructor
|
|
|
|
FGILSList::FGILSList( void ) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
FGILSList::~FGILSList( void ) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// load the navaids and build the map
|
2001-03-25 14:20:12 +00:00
|
|
|
bool FGILSList::init( SGPath path ) {
|
2000-04-21 18:00:47 +00:00
|
|
|
FGILS ils;
|
|
|
|
|
|
|
|
ilslist.erase( ilslist.begin(), ilslist.end() );
|
|
|
|
|
2001-03-25 14:20:12 +00:00
|
|
|
sg_gzifstream in( path.str() );
|
2000-04-21 18:00:47 +00:00
|
|
|
if ( !in.is_open() ) {
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
|
2000-04-21 18:00:47 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// read in each line of the file
|
|
|
|
|
|
|
|
in >> skipeol;
|
|
|
|
in >> skipcomment;
|
|
|
|
|
|
|
|
#ifdef __MWERKS__
|
|
|
|
|
|
|
|
char c = 0;
|
2000-09-13 21:51:07 +00:00
|
|
|
while ( in.get(c) && c != '\0' && ils.get_ilstype() != '[' ) {
|
2000-04-21 18:00:47 +00:00
|
|
|
in.putback(c);
|
|
|
|
in >> ils;
|
2000-09-13 21:51:07 +00:00
|
|
|
if ( ils.get_ilstype() != '[' ) {
|
2000-04-21 18:00:47 +00:00
|
|
|
ilslist[ils.get_locfreq()].push_back(ils);
|
|
|
|
}
|
|
|
|
in >> skipcomment;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2000-04-25 17:33:13 +00:00
|
|
|
double min = 1000000.0;
|
|
|
|
double max = 0.0;
|
|
|
|
|
2000-04-21 18:00:47 +00:00
|
|
|
while ( ! in.eof() && ils.get_ilstype() != '[' ) {
|
|
|
|
in >> ils;
|
|
|
|
/* cout << "id = " << n.get_ident() << endl;
|
|
|
|
cout << " type = " << n.get_type() << endl;
|
|
|
|
cout << " lon = " << n.get_lon() << endl;
|
|
|
|
cout << " lat = " << n.get_lat() << endl;
|
|
|
|
cout << " elev = " << n.get_elev() << endl;
|
|
|
|
cout << " freq = " << n.get_freq() << endl;
|
|
|
|
cout << " range = " << n.get_range() << endl; */
|
|
|
|
if ( ils.get_ilstype() != '[' ) {
|
|
|
|
ilslist[ils.get_locfreq()].push_back(ils);
|
|
|
|
}
|
|
|
|
in >> skipcomment;
|
2000-04-25 17:33:13 +00:00
|
|
|
|
|
|
|
if ( ils.get_locfreq() < min ) {
|
|
|
|
min = ils.get_locfreq();
|
|
|
|
}
|
|
|
|
if ( ils.get_locfreq() > max ) {
|
|
|
|
max = ils.get_locfreq();
|
|
|
|
}
|
2001-03-16 23:57:38 +00:00
|
|
|
|
|
|
|
// update the marker beacon list
|
2001-03-24 00:18:01 +00:00
|
|
|
if ( fabs(ils.get_omlon()) > SG_EPSILON ||
|
|
|
|
fabs(ils.get_omlat()) > SG_EPSILON ) {
|
2001-03-16 23:57:38 +00:00
|
|
|
current_beacons->add( ils.get_omlon(), ils.get_omlat(),
|
2001-03-28 07:12:11 +00:00
|
|
|
ils.get_gselev(), FGMkrBeacon::OUTER );
|
2001-03-16 23:57:38 +00:00
|
|
|
}
|
2001-03-24 00:18:01 +00:00
|
|
|
if ( fabs(ils.get_mmlon()) > SG_EPSILON ||
|
|
|
|
fabs(ils.get_mmlat()) > SG_EPSILON ) {
|
2001-03-16 23:57:38 +00:00
|
|
|
current_beacons->add( ils.get_mmlon(), ils.get_mmlat(),
|
2001-03-28 07:12:11 +00:00
|
|
|
ils.get_gselev(), FGMkrBeacon::MIDDLE );
|
2001-03-16 23:57:38 +00:00
|
|
|
}
|
2001-03-24 00:18:01 +00:00
|
|
|
if ( fabs(ils.get_imlon()) > SG_EPSILON ||
|
|
|
|
fabs(ils.get_imlat()) > SG_EPSILON ) {
|
2001-03-16 23:57:38 +00:00
|
|
|
current_beacons->add( ils.get_imlon(), ils.get_imlat(),
|
2001-03-28 07:12:11 +00:00
|
|
|
ils.get_gselev(), FGMkrBeacon::INNER );
|
2001-03-16 23:57:38 +00:00
|
|
|
}
|
2000-04-21 18:00:47 +00:00
|
|
|
}
|
|
|
|
|
2000-05-04 01:18:45 +00:00
|
|
|
// cout << "min freq = " << min << endl;
|
|
|
|
// cout << "max freq = " << max << endl;
|
2000-04-25 17:33:13 +00:00
|
|
|
|
2000-04-21 18:00:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// query the database for the specified frequency, lon and lat are in
|
|
|
|
// degrees, elev is in meters
|
|
|
|
bool FGILSList::query( double lon, double lat, double elev, double freq,
|
2000-05-04 01:18:45 +00:00
|
|
|
FGILS *ils )
|
2000-04-21 18:00:47 +00:00
|
|
|
{
|
2000-04-24 23:51:56 +00:00
|
|
|
ils_list_type stations = ilslist[(int)(freq*100.0 + 0.5)];
|
2000-04-21 18:00:47 +00:00
|
|
|
|
|
|
|
ils_list_iterator current = stations.begin();
|
|
|
|
ils_list_iterator last = stations.end();
|
|
|
|
|
2000-05-04 01:18:45 +00:00
|
|
|
// double az1, az2, s;
|
2000-09-27 20:16:22 +00:00
|
|
|
Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
|
2000-05-04 01:18:45 +00:00
|
|
|
Point3D station;
|
|
|
|
double d;
|
2000-04-21 18:00:47 +00:00
|
|
|
for ( ; current != last ; ++current ) {
|
2000-05-04 01:18:45 +00:00
|
|
|
// cout << " testing " << current->get_locident() << endl;
|
2000-05-12 22:17:09 +00:00
|
|
|
station = Point3D(current->get_x(),
|
|
|
|
current->get_y(),
|
|
|
|
current->get_z());
|
2000-05-04 01:18:45 +00:00
|
|
|
// cout << " aircraft = " << aircraft << " station = " << station
|
|
|
|
// << endl;
|
|
|
|
|
|
|
|
d = aircraft.distance3Dsquared( station );
|
|
|
|
// cout << " distance = " << d << " ("
|
2001-03-24 04:56:46 +00:00
|
|
|
// << FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER
|
|
|
|
// * FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER
|
2000-05-04 01:18:45 +00:00
|
|
|
// << ")" << endl;
|
|
|
|
|
2000-04-21 18:00:47 +00:00
|
|
|
// cout << " dist = " << s << endl;
|
2001-03-14 07:25:14 +00:00
|
|
|
|
|
|
|
// match up to twice the published range so we can model
|
|
|
|
// reduced signal strength
|
2001-03-24 04:56:46 +00:00
|
|
|
if ( d < (2* FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER
|
|
|
|
* 2 * FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER) ) {
|
2001-10-30 17:45:11 +00:00
|
|
|
|
|
|
|
// Get our bearing from this station.
|
|
|
|
double reciprocal_bearing, dummy;
|
|
|
|
double a_lat_deg = lat * SGD_RADIANS_TO_DEGREES;
|
|
|
|
double a_lon_deg = lon * SGD_RADIANS_TO_DEGREES;
|
|
|
|
// Locator beam direction
|
|
|
|
double s_ils_deg = current->get_locheading() - 180.0;
|
|
|
|
if ( s_ils_deg < 0.0 ) { s_ils_deg += 360.0; }
|
|
|
|
double angle_to_beam_deg;
|
|
|
|
|
|
|
|
// printf("**ALI geting geo_inverse_wgs_84 with elev = %.2f, a.lat = %.2f, a.lon = %.2f,
|
|
|
|
// s.lat = %.2f, s.lon = %.2f\n", elev,a_lat_deg,a_lon_deg,current->get_loclat(),current->get_loclon());
|
|
|
|
|
|
|
|
geo_inverse_wgs_84( elev, current->get_loclat(),
|
|
|
|
current->get_loclon(), a_lat_deg, a_lon_deg,
|
|
|
|
&reciprocal_bearing, &dummy, &dummy );
|
|
|
|
angle_to_beam_deg = fabs(reciprocal_bearing - s_ils_deg);
|
|
|
|
if ( angle_to_beam_deg < 90.0 ) {
|
|
|
|
*ils = *current;
|
|
|
|
return true;
|
|
|
|
}
|
2000-04-21 18:00:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|