2000-04-24 23:50:59 +00:00
|
|
|
// radiostack.cxx -- class to manage an instance of the radio stack
|
|
|
|
//
|
|
|
|
// 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-03-21 23:16:21 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
2001-03-09 23:35:21 +00:00
|
|
|
#include <simgear/math/sg_random.h>
|
|
|
|
|
2000-05-04 01:18:45 +00:00
|
|
|
#include <Aircraft/aircraft.hxx>
|
2000-06-15 18:36:13 +00:00
|
|
|
#include <Main/bfi.hxx>
|
2000-04-24 23:50:59 +00:00
|
|
|
#include <Navaids/ilslist.hxx>
|
2001-03-16 23:59:02 +00:00
|
|
|
#include <Navaids/mkrbeacons.hxx>
|
2000-04-24 23:50:59 +00:00
|
|
|
#include <Navaids/navlist.hxx>
|
2001-01-11 22:44:18 +00:00
|
|
|
#include <Time/event.hxx>
|
2000-04-24 23:50:59 +00:00
|
|
|
|
|
|
|
#include "radiostack.hxx"
|
|
|
|
|
2001-03-09 23:35:21 +00:00
|
|
|
static int nav1_play_count = 0;
|
2001-03-14 23:37:50 +00:00
|
|
|
static int nav2_play_count = 0;
|
|
|
|
static int adf_play_count = 0;
|
2001-03-09 23:35:21 +00:00
|
|
|
static time_t nav1_last_time = 0;
|
2001-03-14 23:37:50 +00:00
|
|
|
static time_t nav2_last_time = 0;
|
|
|
|
static time_t adf_last_time = 0;
|
2001-03-09 23:35:21 +00:00
|
|
|
|
|
|
|
|
2001-03-14 01:31:04 +00:00
|
|
|
FGRadioStack *current_radiostack;
|
|
|
|
|
|
|
|
|
2000-05-30 16:49:44 +00:00
|
|
|
/**
|
|
|
|
* Boy, this is ugly! Make the VOR range vary by altitude difference.
|
|
|
|
*/
|
2001-03-14 01:31:04 +00:00
|
|
|
static double kludgeRange ( double stationElev, double aircraftElev,
|
|
|
|
double nominalRange)
|
2000-05-30 16:49:44 +00:00
|
|
|
{
|
|
|
|
// Assume that the nominal range (usually
|
|
|
|
// 50nm) applies at a 5,000 ft difference.
|
|
|
|
// Just a wild guess!
|
2001-03-14 01:31:04 +00:00
|
|
|
double factor = ((aircraftElev*METER_TO_FEET) - stationElev) / 5000.0;
|
2000-05-30 16:49:44 +00:00
|
|
|
double range = fabs(nominalRange * factor);
|
|
|
|
|
|
|
|
// Clamp the range to keep it sane; for
|
|
|
|
// now, never less than 25% or more than
|
|
|
|
// 500% of nominal range.
|
|
|
|
if (range < nominalRange/4.0) {
|
|
|
|
range = nominalRange/4.0;
|
|
|
|
} else if (range > nominalRange*5.0) {
|
|
|
|
range = nominalRange*5.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
2000-04-24 23:50:59 +00:00
|
|
|
|
2001-01-11 22:44:18 +00:00
|
|
|
// periodic radio station search wrapper
|
|
|
|
static void fgRadioSearch( void ) {
|
|
|
|
current_radiostack->search();
|
|
|
|
}
|
|
|
|
|
2000-04-24 23:50:59 +00:00
|
|
|
// Constructor
|
|
|
|
FGRadioStack::FGRadioStack() {
|
2001-01-05 17:38:58 +00:00
|
|
|
nav1_radial = 0.0;
|
2000-05-12 20:07:51 +00:00
|
|
|
nav1_dme_dist = 0.0;
|
2001-01-05 17:38:58 +00:00
|
|
|
nav2_radial = 0.0;
|
|
|
|
nav2_dme_dist = 0.0;
|
2000-04-24 23:50:59 +00:00
|
|
|
need_update = true;
|
2001-01-13 22:06:39 +00:00
|
|
|
longitudeVal = fgGetValue("/position/longitude");
|
|
|
|
latitudeVal = fgGetValue("/position/latitude");
|
|
|
|
altitudeVal = fgGetValue("/position/altitude");
|
2000-04-24 23:50:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Destructor
|
2001-01-11 22:44:18 +00:00
|
|
|
FGRadioStack::~FGRadioStack()
|
|
|
|
{
|
|
|
|
unbind(); // FIXME: should be called externally
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
FGRadioStack::init ()
|
|
|
|
{
|
2001-03-09 02:41:04 +00:00
|
|
|
morse.init();
|
|
|
|
|
2001-01-11 22:44:18 +00:00
|
|
|
search();
|
|
|
|
update();
|
|
|
|
|
2001-03-14 07:25:14 +00:00
|
|
|
FGPath path( globals->get_fg_root() );
|
|
|
|
FGPath term = path;
|
|
|
|
term.append( "Navaids/range.term" );
|
|
|
|
FGPath low = path;
|
|
|
|
low.append( "Navaids/range.low" );
|
|
|
|
FGPath high = path;
|
|
|
|
high.append( "Navaids/range.high" );
|
|
|
|
|
|
|
|
term_tbl = new SGInterpTable( term.str() );
|
|
|
|
low_tbl = new SGInterpTable( low.str() );
|
|
|
|
high_tbl = new SGInterpTable( high.str() );
|
|
|
|
|
2001-01-11 22:44:18 +00:00
|
|
|
// Search radio database once per second
|
|
|
|
global_events.Register( "fgRadioSearch()", fgRadioSearch,
|
|
|
|
fgEVENT::FG_EVENT_READY, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGRadioStack::bind ()
|
|
|
|
{
|
|
|
|
// User inputs
|
|
|
|
fgTie("/radios/nav1/frequencies/selected", this,
|
|
|
|
&FGRadioStack::get_nav1_freq, &FGRadioStack::set_nav1_freq);
|
|
|
|
fgTie("/radios/nav1/frequencies/standby", this,
|
|
|
|
&FGRadioStack::get_nav1_alt_freq, &FGRadioStack::set_nav1_alt_freq);
|
|
|
|
fgTie("/radios/nav1/radials/selected", this,
|
|
|
|
&FGRadioStack::get_nav1_sel_radial,
|
|
|
|
&FGRadioStack::set_nav1_sel_radial);
|
2001-03-16 05:33:04 +00:00
|
|
|
fgTie("/radios/nav1/volume", this,
|
|
|
|
&FGRadioStack::get_nav1_vol_btn,
|
|
|
|
&FGRadioStack::set_nav1_vol_btn);
|
2001-03-09 02:41:04 +00:00
|
|
|
fgTie("/radios/nav1/ident", this,
|
|
|
|
&FGRadioStack::get_nav1_ident_btn,
|
|
|
|
&FGRadioStack::set_nav1_ident_btn);
|
2001-01-11 22:44:18 +00:00
|
|
|
|
|
|
|
// Radio outputs
|
|
|
|
fgTie("/radios/nav1/radials/actual", this, &FGRadioStack::get_nav1_radial);
|
|
|
|
fgTie("/radios/nav1/to-flag", this, &FGRadioStack::get_nav1_to_flag);
|
|
|
|
fgTie("/radios/nav1/from-flag", this, &FGRadioStack::get_nav1_from_flag);
|
|
|
|
fgTie("/radios/nav1/in-range", this, &FGRadioStack::get_nav1_inrange);
|
|
|
|
fgTie("/radios/nav1/dme/distance", this, &FGRadioStack::get_nav1_dme_dist);
|
|
|
|
fgTie("/radios/nav1/dme/in-range", this,
|
|
|
|
&FGRadioStack::get_nav1_dme_inrange);
|
2001-02-25 04:45:26 +00:00
|
|
|
fgTie("/radios/nav1/heading-needle-deflection", this,
|
|
|
|
&FGRadioStack::get_nav1_heading_needle_deflection);
|
|
|
|
fgTie("/radios/nav1/gs-needle-deflection", this,
|
|
|
|
&FGRadioStack::get_nav1_gs_needle_deflection);
|
2001-01-11 22:44:18 +00:00
|
|
|
|
|
|
|
// User inputs
|
|
|
|
fgTie("/radios/nav2/frequencies/selected", this,
|
|
|
|
&FGRadioStack::get_nav2_freq, &FGRadioStack::set_nav2_freq);
|
|
|
|
fgTie("/radios/nav2/frequencies/standby", this,
|
|
|
|
&FGRadioStack::get_nav2_alt_freq, &FGRadioStack::set_nav2_alt_freq);
|
|
|
|
fgTie("/radios/nav2/radials/selected", this,
|
|
|
|
&FGRadioStack::get_nav2_sel_radial,
|
|
|
|
&FGRadioStack::set_nav2_sel_radial);
|
2001-03-16 05:33:04 +00:00
|
|
|
fgTie("/radios/nav2/volume", this,
|
|
|
|
&FGRadioStack::get_nav2_vol_btn,
|
|
|
|
&FGRadioStack::set_nav2_vol_btn);
|
2001-03-09 02:41:04 +00:00
|
|
|
fgTie("/radios/nav2/ident", this,
|
|
|
|
&FGRadioStack::get_nav2_ident_btn,
|
|
|
|
&FGRadioStack::set_nav2_ident_btn);
|
2001-01-11 22:44:18 +00:00
|
|
|
|
|
|
|
// Radio outputs
|
|
|
|
fgTie("/radios/nav2/radials/actual", this, &FGRadioStack::get_nav2_radial);
|
|
|
|
fgTie("/radios/nav2/to-flag", this, &FGRadioStack::get_nav2_to_flag);
|
|
|
|
fgTie("/radios/nav2/from-flag", this, &FGRadioStack::get_nav2_from_flag);
|
|
|
|
fgTie("/radios/nav2/in-range", this, &FGRadioStack::get_nav2_inrange);
|
|
|
|
fgTie("/radios/nav2/dme/distance", this, &FGRadioStack::get_nav2_dme_dist);
|
|
|
|
fgTie("/radios/nav2/dme/in-range", this,
|
|
|
|
&FGRadioStack::get_nav2_dme_inrange);
|
2001-02-25 16:26:48 +00:00
|
|
|
fgTie("/radios/nav2/heading-needle-deflection", this,
|
2001-02-25 04:45:26 +00:00
|
|
|
&FGRadioStack::get_nav2_heading_needle_deflection);
|
2001-02-25 16:26:48 +00:00
|
|
|
fgTie("/radios/nav2/gs-needle-deflection", this,
|
2001-02-25 04:45:26 +00:00
|
|
|
&FGRadioStack::get_nav2_gs_needle_deflection);
|
2001-01-11 22:44:18 +00:00
|
|
|
|
|
|
|
// User inputs
|
|
|
|
fgTie("/radios/adf/frequencies/selected", this,
|
|
|
|
&FGRadioStack::get_adf_freq, &FGRadioStack::set_adf_freq);
|
|
|
|
fgTie("/radios/adf/frequencies/standby", this,
|
|
|
|
&FGRadioStack::get_adf_alt_freq, &FGRadioStack::set_adf_alt_freq);
|
|
|
|
fgTie("/radios/adf/rotation", this,
|
|
|
|
&FGRadioStack::get_adf_rotation, &FGRadioStack::set_adf_rotation);
|
2001-03-16 05:33:04 +00:00
|
|
|
fgTie("/radios/adf/volume", this,
|
|
|
|
&FGRadioStack::get_adf_vol_btn,
|
|
|
|
&FGRadioStack::set_adf_vol_btn);
|
2001-03-14 23:37:50 +00:00
|
|
|
fgTie("/radios/adf/ident", this,
|
|
|
|
&FGRadioStack::get_adf_ident_btn,
|
|
|
|
&FGRadioStack::set_adf_ident_btn);
|
2000-04-24 23:50:59 +00:00
|
|
|
}
|
|
|
|
|
2001-01-11 22:44:18 +00:00
|
|
|
void
|
|
|
|
FGRadioStack::unbind ()
|
|
|
|
{
|
|
|
|
fgUntie("/radios/nav1/frequencies/selected");
|
|
|
|
fgUntie("/radios/nav1/frequencies/standby");
|
|
|
|
fgUntie("/radios/nav1/radials/actual");
|
|
|
|
fgUntie("/radios/nav1/radials/selected");
|
2001-03-09 02:41:04 +00:00
|
|
|
fgUntie("/radios/nav1/on");
|
|
|
|
fgUntie("/radios/nav1/ident");
|
2001-01-11 22:44:18 +00:00
|
|
|
fgUntie("/radios/nav1/to-flag");
|
|
|
|
fgUntie("/radios/nav1/from-flag");
|
|
|
|
fgUntie("/radios/nav1/in-range");
|
|
|
|
fgUntie("/radios/nav1/dme/distance");
|
|
|
|
fgUntie("/radios/nav1/dme/in-range");
|
2001-02-25 04:45:26 +00:00
|
|
|
fgUntie("/radios/nav1/heading-needle-deflection");
|
|
|
|
fgUntie("/radios/nav1/gs-needle-deflection");
|
2001-01-11 22:44:18 +00:00
|
|
|
|
|
|
|
fgUntie("/radios/nav2/frequencies/selected");
|
|
|
|
fgUntie("/radios/nav2/frequencies/standby");
|
|
|
|
fgUntie("/radios/nav2/radials/actual");
|
|
|
|
fgUntie("/radios/nav2/radials/selected");
|
2001-03-09 02:41:04 +00:00
|
|
|
fgUntie("/radios/nav2/on");
|
|
|
|
fgUntie("/radios/nav2/ident");
|
2001-01-11 22:44:18 +00:00
|
|
|
fgUntie("/radios/nav2/to-flag");
|
|
|
|
fgUntie("/radios/nav2/from-flag");
|
|
|
|
fgUntie("/radios/nav2/in-range");
|
|
|
|
fgUntie("/radios/nav2/dme/distance");
|
|
|
|
fgUntie("/radios/nav2/dme/in-range");
|
2001-02-25 04:45:26 +00:00
|
|
|
fgUntie("/radios/nav2/heading-needle-deflection");
|
|
|
|
fgUntie("/radios/nav2/gs-needle-deflection");
|
2001-01-11 22:44:18 +00:00
|
|
|
|
|
|
|
fgUntie("/radios/adf/frequencies/selected");
|
|
|
|
fgUntie("/radios/adf/frequencies/standby");
|
|
|
|
fgUntie("/radios/adf/rotation");
|
2001-03-14 23:37:50 +00:00
|
|
|
fgUntie("/radios/adf/on");
|
|
|
|
fgUntie("/radios/adf/ident");
|
2001-01-11 22:44:18 +00:00
|
|
|
}
|
2000-04-24 23:50:59 +00:00
|
|
|
|
2001-03-14 07:25:14 +00:00
|
|
|
|
|
|
|
// model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
|
|
|
|
double FGRadioStack::adjustNavRange( double stationElev, double aircraftElev,
|
|
|
|
double nominalRange )
|
|
|
|
{
|
2001-03-14 23:37:50 +00:00
|
|
|
// extend out actual usable range to be 1.3x the published safe range
|
|
|
|
const double usability_factor = 1.3;
|
|
|
|
|
2001-03-14 07:25:14 +00:00
|
|
|
// assumptions we model the standard service volume, plus
|
|
|
|
// ... rather than specifying a cylinder, we model a cone that
|
|
|
|
// contains the cylinder. Then we put an upside down cone on top
|
|
|
|
// to model diminishing returns at too-high altitudes.
|
|
|
|
|
|
|
|
// altitude difference
|
|
|
|
double alt = ( aircraftElev * METER_TO_FEET - stationElev );
|
|
|
|
// cout << "aircraft elev = " << aircraftElev * METER_TO_FEET
|
|
|
|
// << " station elev = " << stationElev << endl;
|
|
|
|
|
2001-03-24 00:18:01 +00:00
|
|
|
if ( nominalRange < 25.0 + SG_EPSILON ) {
|
2001-03-14 07:25:14 +00:00
|
|
|
// Standard Terminal Service Volume
|
2001-03-14 23:37:50 +00:00
|
|
|
return term_tbl->interpolate( alt ) * usability_factor;
|
2001-03-24 00:18:01 +00:00
|
|
|
} else if ( nominalRange < 50.0 + SG_EPSILON ) {
|
2001-03-14 07:25:14 +00:00
|
|
|
// Standard Low Altitude Service Volume
|
|
|
|
// table is based on range of 40, scale to actual range
|
2001-03-14 23:37:50 +00:00
|
|
|
return low_tbl->interpolate( alt ) * nominalRange / 40.0
|
|
|
|
* usability_factor;
|
2001-03-14 07:25:14 +00:00
|
|
|
} else {
|
|
|
|
// Standard High Altitude Service Volume
|
|
|
|
// table is based on range of 130, scale to actual range
|
2001-03-14 23:37:50 +00:00
|
|
|
return high_tbl->interpolate( alt ) * nominalRange / 130.0
|
|
|
|
* usability_factor;
|
2001-03-14 07:25:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// model standard ILS service volumes as per AIM 1-1-9
|
|
|
|
double FGRadioStack::adjustILSRange( double stationElev, double aircraftElev,
|
|
|
|
double offsetDegrees, double distance )
|
|
|
|
{
|
|
|
|
// assumptions we model the standard service volume, plus
|
|
|
|
|
|
|
|
// altitude difference
|
|
|
|
// double alt = ( aircraftElev * METER_TO_FEET - stationElev );
|
|
|
|
double offset = fabs( offsetDegrees );
|
|
|
|
|
|
|
|
if ( offset < 10 ) {
|
|
|
|
return FG_ILS_DEFAULT_RANGE;
|
|
|
|
} else if ( offset < 35 ) {
|
|
|
|
return 10 + (35 - offset) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
|
|
|
|
} else if ( offset < 45 ) {
|
|
|
|
return (45 - offset);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-09 02:41:04 +00:00
|
|
|
// Update the various nav values based on position and valid tuned in navs
|
2001-01-11 22:44:18 +00:00
|
|
|
void
|
|
|
|
FGRadioStack::update()
|
|
|
|
{
|
|
|
|
double lon = longitudeVal->getDoubleValue() * DEG_TO_RAD;
|
|
|
|
double lat = latitudeVal->getDoubleValue() * DEG_TO_RAD;
|
|
|
|
double elev = altitudeVal->getDoubleValue() * FEET_TO_METER;
|
|
|
|
|
2000-04-24 23:50:59 +00:00
|
|
|
need_update = false;
|
|
|
|
|
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 az1, az2, s;
|
|
|
|
|
|
|
|
if ( nav1_valid ) {
|
2000-05-12 22:17:09 +00:00
|
|
|
station = Point3D( nav1_x, nav1_y, nav1_z );
|
|
|
|
nav1_loc_dist = aircraft.distance3D( station );
|
|
|
|
|
|
|
|
if ( nav1_has_dme ) {
|
|
|
|
// staightline distance
|
|
|
|
station = Point3D( nav1_dme_x, nav1_dme_y, nav1_dme_z );
|
|
|
|
nav1_dme_dist = aircraft.distance3D( station );
|
|
|
|
} else {
|
|
|
|
nav1_dme_dist = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( nav1_has_gs ) {
|
2000-05-12 20:07:51 +00:00
|
|
|
station = Point3D( nav1_gs_x, nav1_gs_y, nav1_gs_z );
|
|
|
|
nav1_gs_dist = aircraft.distance3D( station );
|
2000-05-12 22:17:09 +00:00
|
|
|
} else {
|
|
|
|
nav1_gs_dist = 0.0;
|
2000-05-12 20:07:51 +00:00
|
|
|
}
|
2000-05-04 01:18:45 +00:00
|
|
|
|
2001-03-14 07:25:14 +00:00
|
|
|
// wgs84 heading
|
|
|
|
geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG,
|
|
|
|
nav1_loclat, nav1_loclon,
|
|
|
|
&az1, &az2, &s );
|
|
|
|
// cout << "az1 = " << az1 << " magvar = " << nav1_magvar << endl;
|
|
|
|
nav1_heading = az1 - nav1_magvar;
|
|
|
|
// cout << " heading = " << nav1_heading
|
|
|
|
// << " dist = " << nav1_dist << endl;
|
|
|
|
|
|
|
|
if ( nav1_loc ) {
|
|
|
|
double offset = nav1_heading - nav1_radial;
|
|
|
|
while ( offset < -180.0 ) { offset += 360.0; }
|
|
|
|
while ( offset > 180.0 ) { offset -= 360.0; }
|
2001-03-14 23:37:50 +00:00
|
|
|
// cout << "ils offset = " << offset << endl;
|
2001-03-14 07:25:14 +00:00
|
|
|
nav1_effective_range = adjustILSRange(nav1_elev, elev, offset,
|
|
|
|
nav1_loc_dist * METER_TO_NM );
|
|
|
|
} else {
|
|
|
|
nav1_effective_range = adjustNavRange(nav1_elev, elev, nav1_range);
|
|
|
|
}
|
2001-03-14 23:37:50 +00:00
|
|
|
// cout << "nav1 range = " << nav1_effective_range
|
|
|
|
// << " (" << nav1_range << ")" << endl;
|
2001-03-14 07:25:14 +00:00
|
|
|
|
2000-05-15 16:33:42 +00:00
|
|
|
if ( nav1_loc_dist < nav1_effective_range * NM_TO_METER ) {
|
2000-05-04 01:18:45 +00:00
|
|
|
nav1_inrange = true;
|
2001-03-14 07:25:14 +00:00
|
|
|
} else if ( nav1_loc_dist < 2 * nav1_effective_range * NM_TO_METER ) {
|
|
|
|
nav1_inrange = sg_random() <
|
|
|
|
( 2 * nav1_effective_range * NM_TO_METER - nav1_loc_dist ) /
|
|
|
|
(nav1_effective_range * NM_TO_METER);
|
2000-05-04 01:18:45 +00:00
|
|
|
} else {
|
|
|
|
nav1_inrange = false;
|
|
|
|
}
|
|
|
|
|
2001-03-14 07:25:14 +00:00
|
|
|
if ( !nav1_loc ) {
|
2000-05-04 01:18:45 +00:00
|
|
|
nav1_radial = nav1_sel_radial;
|
|
|
|
}
|
2001-03-12 12:40:18 +00:00
|
|
|
} else {
|
|
|
|
nav1_inrange = false;
|
|
|
|
nav1_dme_dist = 0.0;
|
|
|
|
// cout << "not picking up vor. :-(" << endl;
|
|
|
|
}
|
2001-03-09 02:41:04 +00:00
|
|
|
|
2001-03-12 12:40:18 +00:00
|
|
|
if ( nav1_valid && nav1_inrange ) {
|
2001-03-09 02:41:04 +00:00
|
|
|
// play station ident via audio system if on + ident,
|
|
|
|
// otherwise turn it off
|
2001-03-16 05:33:04 +00:00
|
|
|
if ( nav1_vol_btn > 0.1 && nav1_ident_btn ) {
|
|
|
|
FGSimpleSound *sound;
|
|
|
|
sound = globals->get_soundmgr()->find( "nav1-vor-ident" );
|
|
|
|
sound->set_volume( nav1_vol_btn * 0.3 );
|
|
|
|
sound = globals->get_soundmgr()->find( "nav1-dme-ident" );
|
|
|
|
sound->set_volume( nav1_vol_btn * 0.3 );
|
2001-03-09 23:35:21 +00:00
|
|
|
if ( nav1_last_time <
|
|
|
|
globals->get_time_params()->get_cur_time() - 30 ) {
|
|
|
|
nav1_last_time = globals->get_time_params()->get_cur_time();
|
|
|
|
nav1_play_count = 0;
|
|
|
|
}
|
|
|
|
if ( nav1_play_count < 4 ) {
|
|
|
|
// play VOR ident
|
|
|
|
if ( !globals->get_soundmgr()->is_playing("nav1-vor-ident") ) {
|
|
|
|
globals->get_soundmgr()->play_once( "nav1-vor-ident" );
|
|
|
|
++nav1_play_count;
|
|
|
|
}
|
2001-03-10 00:06:39 +00:00
|
|
|
} else if ( nav1_play_count < 5 && nav1_has_dme ) {
|
2001-03-09 23:35:21 +00:00
|
|
|
// play DME ident
|
|
|
|
if ( !globals->get_soundmgr()->is_playing("nav1-vor-ident") &&
|
|
|
|
!globals->get_soundmgr()->is_playing("nav1-dme-ident") ) {
|
|
|
|
globals->get_soundmgr()->play_once( "nav1-dme-ident" );
|
|
|
|
++nav1_play_count;
|
|
|
|
}
|
2001-03-09 02:41:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
2001-03-09 23:35:21 +00:00
|
|
|
globals->get_soundmgr()->stop( "nav1-vor-ident" );
|
|
|
|
globals->get_soundmgr()->stop( "nav1-dme-ident" );
|
2001-03-09 02:41:04 +00:00
|
|
|
}
|
2000-05-04 01:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( nav2_valid ) {
|
2000-05-12 22:17:09 +00:00
|
|
|
station = Point3D( nav2_x, nav2_y, nav2_z );
|
|
|
|
nav2_loc_dist = aircraft.distance3D( station );
|
|
|
|
|
|
|
|
if ( nav2_has_dme ) {
|
|
|
|
// staightline distance
|
|
|
|
station = Point3D( nav2_dme_x, nav2_dme_y, nav2_dme_z );
|
|
|
|
nav2_dme_dist = aircraft.distance3D( station );
|
|
|
|
} else {
|
|
|
|
nav2_dme_dist = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( nav2_has_gs ) {
|
2000-05-12 20:07:51 +00:00
|
|
|
station = Point3D( nav2_gs_x, nav2_gs_y, nav2_gs_z );
|
|
|
|
nav2_gs_dist = aircraft.distance3D( station );
|
2000-05-12 22:17:09 +00:00
|
|
|
} else {
|
|
|
|
nav2_gs_dist = 0.0;
|
2000-05-12 20:07:51 +00:00
|
|
|
}
|
2000-05-04 01:18:45 +00:00
|
|
|
|
2001-03-14 07:25:14 +00:00
|
|
|
// wgs84 heading
|
|
|
|
geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG,
|
|
|
|
nav2_loclat, nav2_loclon,
|
|
|
|
&az1, &az2, &s );
|
|
|
|
nav2_heading = az1 - nav2_magvar;
|
|
|
|
// cout << " heading = " << nav2_heading
|
|
|
|
// << " dist = " << nav2_dist << endl;
|
|
|
|
|
|
|
|
if ( nav2_loc ) {
|
|
|
|
double offset = nav2_heading - nav2_radial;
|
|
|
|
while ( offset < -180.0 ) { offset += 360.0; }
|
|
|
|
while ( offset > 180.0 ) { offset -= 360.0; }
|
2001-03-14 23:37:50 +00:00
|
|
|
// cout << "ils offset = " << offset << endl;
|
2001-03-14 07:25:14 +00:00
|
|
|
nav2_effective_range = adjustILSRange(nav2_elev, elev, offset,
|
|
|
|
nav2_loc_dist * METER_TO_NM );
|
|
|
|
} else {
|
|
|
|
nav2_effective_range = adjustNavRange(nav2_elev, elev, nav2_range);
|
|
|
|
}
|
2001-03-14 23:37:50 +00:00
|
|
|
// cout << "nav2 range = " << nav2_effective_range
|
|
|
|
// << " (" << nav2_range << ")" << endl;
|
2001-03-14 07:25:14 +00:00
|
|
|
|
2000-05-15 16:33:42 +00:00
|
|
|
if ( nav2_loc_dist < nav2_effective_range * NM_TO_METER ) {
|
2000-05-04 01:18:45 +00:00
|
|
|
nav2_inrange = true;
|
2001-03-14 07:25:14 +00:00
|
|
|
} else if ( nav2_loc_dist < 2 * nav2_effective_range * NM_TO_METER ) {
|
|
|
|
nav2_inrange = sg_random() <
|
|
|
|
( 2 * nav2_effective_range * NM_TO_METER - nav2_loc_dist ) /
|
|
|
|
(nav2_effective_range * NM_TO_METER);
|
2000-05-04 01:18:45 +00:00
|
|
|
} else {
|
|
|
|
nav2_inrange = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !nav2_loc ) {
|
|
|
|
nav2_radial = nav2_sel_radial;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nav2_inrange = false;
|
2001-03-14 07:25:14 +00:00
|
|
|
nav2_dme_dist = 0.0;
|
2000-05-04 01:18:45 +00:00
|
|
|
// cout << "not picking up vor. :-(" << endl;
|
|
|
|
}
|
|
|
|
|
2001-03-14 23:37:50 +00:00
|
|
|
if ( nav2_valid && nav2_inrange ) {
|
|
|
|
// play station ident via audio system if on + ident,
|
|
|
|
// otherwise turn it off
|
2001-03-16 05:33:04 +00:00
|
|
|
if ( nav2_vol_btn > 0.1 && nav2_ident_btn ) {
|
|
|
|
FGSimpleSound *sound;
|
|
|
|
sound = globals->get_soundmgr()->find( "nav2-vor-ident" );
|
|
|
|
sound->set_volume( nav2_vol_btn * 0.3 );
|
|
|
|
sound = globals->get_soundmgr()->find( "nav2-dme-ident" );
|
|
|
|
sound->set_volume( nav2_vol_btn * 0.3 );
|
2001-03-14 23:37:50 +00:00
|
|
|
if ( nav2_last_time <
|
|
|
|
globals->get_time_params()->get_cur_time() - 30 ) {
|
|
|
|
nav2_last_time = globals->get_time_params()->get_cur_time();
|
|
|
|
nav2_play_count = 0;
|
|
|
|
}
|
|
|
|
if ( nav2_play_count < 4 ) {
|
|
|
|
// play VOR ident
|
|
|
|
if ( !globals->get_soundmgr()->is_playing("nav2-vor-ident") ) {
|
|
|
|
globals->get_soundmgr()->play_once( "nav2-vor-ident" );
|
|
|
|
++nav2_play_count;
|
|
|
|
}
|
|
|
|
} else if ( nav2_play_count < 5 && nav2_has_dme ) {
|
|
|
|
// play DME ident
|
|
|
|
if ( !globals->get_soundmgr()->is_playing("nav2-vor-ident") &&
|
|
|
|
!globals->get_soundmgr()->is_playing("nav2-dme-ident") ) {
|
|
|
|
globals->get_soundmgr()->play_once( "nav2-dme-ident" );
|
|
|
|
++nav2_play_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
globals->get_soundmgr()->stop( "nav2-vor-ident" );
|
|
|
|
globals->get_soundmgr()->stop( "nav2-dme-ident" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-04 01:18:45 +00:00
|
|
|
// adf
|
|
|
|
if ( adf_valid ) {
|
|
|
|
// staightline distance
|
|
|
|
station = Point3D( adf_x, adf_y, adf_z );
|
|
|
|
adf_dist = aircraft.distance3D( station );
|
|
|
|
|
2001-03-14 07:25:14 +00:00
|
|
|
// wgs84 heading
|
|
|
|
geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG,
|
|
|
|
adf_lat, adf_lon,
|
|
|
|
&az1, &az2, &s );
|
|
|
|
adf_heading = az1;
|
|
|
|
// cout << " heading = " << nav2_heading
|
|
|
|
// << " dist = " << nav2_dist << endl;
|
|
|
|
|
2001-03-12 15:07:49 +00:00
|
|
|
adf_effective_range = kludgeRange(adf_elev, elev, adf_range);
|
2000-05-04 01:18:45 +00:00
|
|
|
if ( adf_dist < adf_effective_range * NM_TO_METER ) {
|
|
|
|
adf_inrange = true;
|
2001-03-14 07:25:14 +00:00
|
|
|
} else if ( adf_dist < 2 * adf_effective_range * NM_TO_METER ) {
|
|
|
|
adf_inrange = sg_random() <
|
|
|
|
( 2 * adf_effective_range * NM_TO_METER - adf_dist ) /
|
|
|
|
(adf_effective_range * NM_TO_METER);
|
2000-05-04 01:18:45 +00:00
|
|
|
} else {
|
|
|
|
adf_inrange = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
adf_inrange = false;
|
|
|
|
}
|
2001-03-14 23:37:50 +00:00
|
|
|
|
|
|
|
if ( adf_valid && adf_inrange ) {
|
|
|
|
// play station ident via audio system if on + ident,
|
|
|
|
// otherwise turn it off
|
2001-03-16 05:33:04 +00:00
|
|
|
if ( adf_vol_btn > 0.1 && adf_ident_btn ) {
|
|
|
|
FGSimpleSound *sound;
|
|
|
|
sound = globals->get_soundmgr()->find( "adf-ident" );
|
|
|
|
sound->set_volume( adf_vol_btn * 0.3 );
|
2001-03-14 23:37:50 +00:00
|
|
|
if ( adf_last_time <
|
|
|
|
globals->get_time_params()->get_cur_time() - 30 ) {
|
|
|
|
adf_last_time = globals->get_time_params()->get_cur_time();
|
|
|
|
adf_play_count = 0;
|
|
|
|
}
|
|
|
|
if ( adf_play_count < 4 ) {
|
|
|
|
// play ADF ident
|
|
|
|
if ( !globals->get_soundmgr()->is_playing("adf-ident") ) {
|
|
|
|
globals->get_soundmgr()->play_once( "adf-ident" );
|
|
|
|
++adf_play_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
globals->get_soundmgr()->stop( "adf-ident" );
|
|
|
|
}
|
|
|
|
}
|
2000-05-04 01:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update current nav/adf radio stations based on current postition
|
2001-03-09 02:41:04 +00:00
|
|
|
void FGRadioStack::search()
|
2001-01-11 22:44:18 +00:00
|
|
|
{
|
|
|
|
double lon = longitudeVal->getDoubleValue() * DEG_TO_RAD;
|
|
|
|
double lat = latitudeVal->getDoubleValue() * DEG_TO_RAD;
|
|
|
|
double elev = altitudeVal->getDoubleValue() * FEET_TO_METER;
|
|
|
|
|
2000-04-24 23:50:59 +00:00
|
|
|
// nav1
|
2000-04-25 03:09:26 +00:00
|
|
|
FGILS ils;
|
User-visible
- knobs now continue to rotate when you hold down the mouse
- the middle mouse button makes knobs rotate much faster
- there are NAV1, NAV2, and ADF radios that can be tuned using the mouse
- there are standby frequencies for NAV1 and NAV2, and buttons to swap
- there is a crude, rather silly-looking DME, hard-wired to NAV1
- there is a crude, rather silly-looking autopilot that can lock
the heading (to the bug on the gyro), can lock to NAV1, and can lock
the current altitude
- the knobs for changing the radials on NAV1 and NAV2 look much better
and are in the right place
- tuning into an ILS frequency doesn't change the displayed radial for
NAV1
Code
- I've created a new module, sp_panel.[ch]xx, that constructs the
default single-prop panel; this works entirely outside of FGPanel,
so it is possible to construct similar modules for other sorts of
panels; all code specific to the default panel has been removed from
panel.cxx
- current_panel is now a pointer
- radiostack.[ch]xx keeps track both of the actual radial and of the
selected radial (they will differ with ILS); the NAV gauges should
not spin around automatically to show the actual radial (we need to
do something similar with the autopilot)
- the panel is initialized fairly early
- make sure that standby frequencies also get initialized
- I've started combining and clipping small textures to save texture
memory; there's a lot more to do, but at least I've made a start
2000-05-02 18:26:00 +00:00
|
|
|
FGNav nav;
|
|
|
|
|
2001-03-09 02:41:04 +00:00
|
|
|
static string last_nav1_ident = "";
|
|
|
|
static string last_nav2_ident = "";
|
2001-03-14 23:37:50 +00:00
|
|
|
static string last_adf_ident = "";
|
2001-03-12 13:42:32 +00:00
|
|
|
static bool last_nav1_vor = false;
|
|
|
|
static bool last_nav2_vor = false;
|
2000-05-04 01:18:45 +00:00
|
|
|
if ( current_ilslist->query( lon, lat, elev, nav1_freq, &ils ) ) {
|
2001-03-09 02:41:04 +00:00
|
|
|
nav1_ident = ils.get_locident();
|
2001-03-14 23:37:50 +00:00
|
|
|
nav1_valid = true;
|
2001-03-12 13:42:32 +00:00
|
|
|
if ( last_nav1_ident != nav1_ident || last_nav1_vor ) {
|
2001-03-12 12:40:18 +00:00
|
|
|
nav1_trans_ident = ils.get_trans_ident();
|
2001-03-09 02:41:04 +00:00
|
|
|
last_nav1_ident = nav1_ident;
|
2001-03-12 13:42:32 +00:00
|
|
|
last_nav1_vor = false;
|
2001-03-09 02:41:04 +00:00
|
|
|
nav1_loc = true;
|
|
|
|
nav1_has_dme = ils.get_has_dme();
|
|
|
|
nav1_has_gs = ils.get_has_gs();
|
|
|
|
|
|
|
|
nav1_loclon = ils.get_loclon();
|
|
|
|
nav1_loclat = ils.get_loclat();
|
|
|
|
nav1_gslon = ils.get_gslon();
|
|
|
|
nav1_gslat = ils.get_gslat();
|
|
|
|
nav1_dmelon = ils.get_dmelon();
|
|
|
|
nav1_dmelat = ils.get_dmelat();
|
|
|
|
nav1_elev = ils.get_gselev();
|
|
|
|
nav1_magvar = 0;
|
2001-03-12 15:07:49 +00:00
|
|
|
nav1_range = FG_ILS_DEFAULT_RANGE;
|
|
|
|
nav1_effective_range = nav1_range;
|
2001-03-09 02:41:04 +00:00
|
|
|
nav1_target_gs = ils.get_gsangle();
|
|
|
|
nav1_radial = ils.get_locheading();
|
|
|
|
while ( nav1_radial < 0.0 ) { nav1_radial += 360.0; }
|
|
|
|
while ( nav1_radial > 360.0 ) { nav1_radial -= 360.0; }
|
|
|
|
nav1_x = ils.get_x();
|
|
|
|
nav1_y = ils.get_y();
|
|
|
|
nav1_z = ils.get_z();
|
|
|
|
nav1_gs_x = ils.get_gs_x();
|
|
|
|
nav1_gs_y = ils.get_gs_y();
|
|
|
|
nav1_gs_z = ils.get_gs_z();
|
|
|
|
nav1_dme_x = ils.get_dme_x();
|
|
|
|
nav1_dme_y = ils.get_dme_y();
|
|
|
|
nav1_dme_z = ils.get_dme_z();
|
|
|
|
|
2001-03-09 23:35:21 +00:00
|
|
|
if ( globals->get_soundmgr()->exists( "nav1-vor-ident" ) ) {
|
|
|
|
globals->get_soundmgr()->remove( "nav1-vor-ident" );
|
|
|
|
}
|
|
|
|
FGSimpleSound *sound;
|
2001-03-12 12:40:18 +00:00
|
|
|
sound = morse.make_ident( nav1_trans_ident, LO_FREQUENCY );
|
2001-03-09 23:35:21 +00:00
|
|
|
sound->set_volume( 0.3 );
|
|
|
|
globals->get_soundmgr()->add( sound, "nav1-vor-ident" );
|
|
|
|
|
|
|
|
if ( globals->get_soundmgr()->exists( "nav1-dme-ident" ) ) {
|
|
|
|
globals->get_soundmgr()->remove( "nav1-dme-ident" );
|
2001-03-09 02:41:04 +00:00
|
|
|
}
|
2001-03-12 12:40:18 +00:00
|
|
|
sound = morse.make_ident( nav1_trans_ident, HI_FREQUENCY );
|
2001-03-09 02:41:04 +00:00
|
|
|
sound->set_volume( 0.3 );
|
2001-03-09 23:35:21 +00:00
|
|
|
globals->get_soundmgr()->add( sound, "nav1-dme-ident" );
|
|
|
|
|
|
|
|
int offset = (int)(sg_random() * 30.0);
|
|
|
|
nav1_play_count = offset / 4;
|
|
|
|
nav1_last_time = globals->get_time_params()->get_cur_time() -
|
|
|
|
offset;
|
2001-03-14 23:37:50 +00:00
|
|
|
// cout << "offset = " << offset << " play_count = "
|
|
|
|
// << nav1_play_count
|
|
|
|
// << " nav1_last_time = " << nav1_last_time
|
|
|
|
// << " current time = "
|
|
|
|
// << globals->get_time_params()->get_cur_time() << endl;
|
2001-03-09 02:41:04 +00:00
|
|
|
|
2001-03-14 23:37:50 +00:00
|
|
|
// cout << "Found an ils station in range" << endl;
|
|
|
|
// cout << " id = " << ils.get_locident() << endl;
|
2001-03-09 02:41:04 +00:00
|
|
|
}
|
2000-05-04 01:18:45 +00:00
|
|
|
} else if ( current_navlist->query( lon, lat, elev, nav1_freq, &nav ) ) {
|
2001-03-09 02:41:04 +00:00
|
|
|
nav1_ident = nav.get_ident();
|
2001-03-14 23:37:50 +00:00
|
|
|
nav1_valid = true;
|
2001-03-12 13:42:32 +00:00
|
|
|
if ( last_nav1_ident != nav1_ident || !last_nav1_vor ) {
|
2001-03-09 02:41:04 +00:00
|
|
|
last_nav1_ident = nav1_ident;
|
2001-03-12 13:42:32 +00:00
|
|
|
last_nav1_vor = true;
|
2001-03-12 12:40:18 +00:00
|
|
|
nav1_trans_ident = nav.get_trans_ident();
|
2001-03-09 02:41:04 +00:00
|
|
|
nav1_loc = false;
|
|
|
|
nav1_has_dme = nav.get_has_dme();
|
|
|
|
nav1_has_gs = false;
|
|
|
|
nav1_loclon = nav.get_lon();
|
|
|
|
nav1_loclat = nav.get_lat();
|
|
|
|
nav1_elev = nav.get_elev();
|
|
|
|
nav1_magvar = nav.get_magvar();
|
2001-03-12 15:07:49 +00:00
|
|
|
nav1_range = nav.get_range();
|
2001-03-14 07:25:14 +00:00
|
|
|
nav1_effective_range = adjustNavRange(nav1_elev, elev, nav1_range);
|
2001-03-09 02:41:04 +00:00
|
|
|
nav1_target_gs = 0.0;
|
|
|
|
nav1_radial = nav1_sel_radial;
|
|
|
|
nav1_x = nav1_dme_x = nav.get_x();
|
|
|
|
nav1_y = nav1_dme_y = nav.get_y();
|
|
|
|
nav1_z = nav1_dme_z = nav.get_z();
|
|
|
|
|
2001-03-09 23:35:21 +00:00
|
|
|
if ( globals->get_soundmgr()->exists( "nav1-vor-ident" ) ) {
|
|
|
|
globals->get_soundmgr()->remove( "nav1-vor-ident" );
|
|
|
|
}
|
|
|
|
FGSimpleSound *sound;
|
2001-03-12 12:40:18 +00:00
|
|
|
sound = morse.make_ident( nav1_trans_ident, LO_FREQUENCY );
|
2001-03-09 23:35:21 +00:00
|
|
|
sound->set_volume( 0.3 );
|
|
|
|
globals->get_soundmgr()->add( sound, "nav1-vor-ident" );
|
|
|
|
|
|
|
|
if ( globals->get_soundmgr()->exists( "nav1-dme-ident" ) ) {
|
|
|
|
globals->get_soundmgr()->remove( "nav1-dme-ident" );
|
2001-03-09 02:41:04 +00:00
|
|
|
}
|
2001-03-12 12:40:18 +00:00
|
|
|
sound = morse.make_ident( nav1_trans_ident, HI_FREQUENCY );
|
2001-03-09 02:41:04 +00:00
|
|
|
sound->set_volume( 0.3 );
|
2001-03-09 23:35:21 +00:00
|
|
|
globals->get_soundmgr()->add( sound, "nav1-dme-ident" );
|
|
|
|
|
|
|
|
int offset = (int)(sg_random() * 30.0);
|
|
|
|
nav1_play_count = offset / 4;
|
|
|
|
nav1_last_time = globals->get_time_params()->get_cur_time() -
|
|
|
|
offset;
|
2001-03-14 23:37:50 +00:00
|
|
|
// cout << "offset = " << offset << " play_count = "
|
|
|
|
// << nav1_play_count << " nav1_last_time = "
|
|
|
|
// << nav1_last_time << " current time = "
|
|
|
|
// << globals->get_time_params()->get_cur_time() << endl;
|
2001-03-09 02:41:04 +00:00
|
|
|
|
2001-03-14 23:37:50 +00:00
|
|
|
// cout << "Found a vor station in range" << endl;
|
|
|
|
// cout << " id = " << nav.get_ident() << endl;
|
2001-03-09 02:41:04 +00:00
|
|
|
}
|
2000-04-24 23:50:59 +00:00
|
|
|
} else {
|
2000-05-04 01:18:45 +00:00
|
|
|
nav1_valid = false;
|
2001-03-09 02:41:04 +00:00
|
|
|
nav1_ident = "";
|
2001-01-05 17:38:58 +00:00
|
|
|
nav1_radial = 0;
|
2001-01-11 22:44:18 +00:00
|
|
|
nav1_dme_dist = 0;
|
2001-03-14 23:37:50 +00:00
|
|
|
nav1_trans_ident = "";
|
|
|
|
last_nav1_ident = "";
|
2001-03-09 23:35:21 +00:00
|
|
|
globals->get_soundmgr()->remove( "nav1-vor-ident" );
|
|
|
|
globals->get_soundmgr()->remove( "nav1-dme-ident" );
|
2001-03-14 23:37:50 +00:00
|
|
|
// cout << "not picking up vor1. :-(" << endl;
|
2000-04-24 23:50:59 +00:00
|
|
|
}
|
|
|
|
|
2000-05-04 01:18:45 +00:00
|
|
|
if ( current_ilslist->query( lon, lat, elev, nav2_freq, &ils ) ) {
|
2001-03-09 02:41:04 +00:00
|
|
|
nav2_ident = ils.get_locident();
|
2001-03-14 23:37:50 +00:00
|
|
|
nav2_valid = true;
|
2001-03-12 13:42:32 +00:00
|
|
|
if ( last_nav2_ident != nav2_ident || last_nav2_vor ) {
|
2001-03-09 02:41:04 +00:00
|
|
|
last_nav2_ident = nav2_ident;
|
2001-03-12 13:42:32 +00:00
|
|
|
last_nav2_vor = false;
|
2001-03-12 12:40:18 +00:00
|
|
|
nav2_trans_ident = ils.get_trans_ident();
|
2001-03-09 02:41:04 +00:00
|
|
|
nav2_loc = true;
|
|
|
|
nav2_has_dme = ils.get_has_dme();
|
|
|
|
nav2_has_gs = ils.get_has_gs();
|
|
|
|
|
|
|
|
nav2_loclon = ils.get_loclon();
|
|
|
|
nav2_loclat = ils.get_loclat();
|
|
|
|
nav2_elev = ils.get_gselev();
|
|
|
|
nav2_magvar = 0;
|
2001-03-12 15:07:49 +00:00
|
|
|
nav2_range = FG_ILS_DEFAULT_RANGE;
|
|
|
|
nav2_effective_range = nav2_range;
|
2001-03-09 02:41:04 +00:00
|
|
|
nav2_target_gs = ils.get_gsangle();
|
|
|
|
nav2_radial = ils.get_locheading();
|
|
|
|
while ( nav2_radial < 0.0 ) { nav2_radial += 360.0; }
|
|
|
|
while ( nav2_radial > 360.0 ) { nav2_radial -= 360.0; }
|
|
|
|
nav2_x = ils.get_x();
|
|
|
|
nav2_y = ils.get_y();
|
|
|
|
nav2_z = ils.get_z();
|
|
|
|
nav2_gs_x = ils.get_gs_x();
|
|
|
|
nav2_gs_y = ils.get_gs_y();
|
|
|
|
nav2_gs_z = ils.get_gs_z();
|
|
|
|
nav2_dme_x = ils.get_dme_x();
|
|
|
|
nav2_dme_y = ils.get_dme_y();
|
|
|
|
nav2_dme_z = ils.get_dme_z();
|
2001-03-14 23:37:50 +00:00
|
|
|
|
|
|
|
if ( globals->get_soundmgr()->exists( "nav2-vor-ident" ) ) {
|
|
|
|
globals->get_soundmgr()->remove( "nav2-vor-ident" );
|
|
|
|
}
|
|
|
|
FGSimpleSound *sound;
|
|
|
|
sound = morse.make_ident( nav2_trans_ident, LO_FREQUENCY );
|
|
|
|
sound->set_volume( 0.3 );
|
|
|
|
globals->get_soundmgr()->add( sound, "nav2-vor-ident" );
|
|
|
|
|
|
|
|
if ( globals->get_soundmgr()->exists( "nav2-dme-ident" ) ) {
|
|
|
|
globals->get_soundmgr()->remove( "nav2-dme-ident" );
|
|
|
|
}
|
|
|
|
sound = morse.make_ident( nav2_trans_ident, HI_FREQUENCY );
|
|
|
|
sound->set_volume( 0.3 );
|
|
|
|
globals->get_soundmgr()->add( sound, "nav2-dme-ident" );
|
|
|
|
|
|
|
|
int offset = (int)(sg_random() * 30.0);
|
|
|
|
nav2_play_count = offset / 4;
|
|
|
|
nav2_last_time = globals->get_time_params()->get_cur_time() -
|
|
|
|
offset;
|
|
|
|
// cout << "offset = " << offset << " play_count = "
|
|
|
|
// << nav2_play_count << " nav2_last_time = "
|
|
|
|
// << nav2_last_time << " current time = "
|
|
|
|
// << globals->get_time_params()->get_cur_time() << endl;
|
|
|
|
|
2001-03-09 02:41:04 +00:00
|
|
|
// cout << "Found an ils station in range" << endl;
|
|
|
|
// cout << " id = " << ils.get_locident() << endl;
|
|
|
|
}
|
2000-05-04 01:18:45 +00:00
|
|
|
} else if ( current_navlist->query( lon, lat, elev, nav2_freq, &nav ) ) {
|
2001-03-09 02:41:04 +00:00
|
|
|
nav2_ident = nav.get_ident();
|
2001-03-14 23:37:50 +00:00
|
|
|
nav2_valid = true;
|
2001-03-12 13:42:32 +00:00
|
|
|
if ( last_nav2_ident != nav2_ident || !last_nav2_vor ) {
|
2001-03-09 02:41:04 +00:00
|
|
|
last_nav2_ident = nav2_ident;
|
2001-03-12 13:42:32 +00:00
|
|
|
last_nav2_vor = true;
|
2001-03-12 12:40:18 +00:00
|
|
|
nav2_trans_ident = nav.get_trans_ident();
|
2001-03-09 02:41:04 +00:00
|
|
|
nav2_loc = false;
|
|
|
|
nav2_has_dme = nav.get_has_dme();
|
|
|
|
nav2_has_dme = false;
|
|
|
|
nav2_loclon = nav.get_lon();
|
|
|
|
nav2_loclat = nav.get_lat();
|
|
|
|
nav2_elev = nav.get_elev();
|
|
|
|
nav2_magvar = nav.get_magvar();
|
2001-03-12 15:07:49 +00:00
|
|
|
nav2_range = nav.get_range();
|
2001-03-14 07:25:14 +00:00
|
|
|
nav2_effective_range = adjustNavRange(nav2_elev, elev, nav2_range);
|
2001-03-09 02:41:04 +00:00
|
|
|
nav2_target_gs = 0.0;
|
|
|
|
nav2_radial = nav2_sel_radial;
|
|
|
|
nav2_x = nav2_dme_x = nav.get_x();
|
|
|
|
nav2_y = nav2_dme_y = nav.get_y();
|
|
|
|
nav2_z = nav2_dme_z = nav.get_z();
|
2001-03-14 23:37:50 +00:00
|
|
|
|
|
|
|
if ( globals->get_soundmgr()->exists( "nav2-vor-ident" ) ) {
|
|
|
|
globals->get_soundmgr()->remove( "nav2-vor-ident" );
|
|
|
|
}
|
|
|
|
FGSimpleSound *sound;
|
|
|
|
sound = morse.make_ident( nav2_trans_ident, LO_FREQUENCY );
|
|
|
|
sound->set_volume( 0.3 );
|
|
|
|
globals->get_soundmgr()->add( sound, "nav2-vor-ident" );
|
|
|
|
|
|
|
|
if ( globals->get_soundmgr()->exists( "nav2-dme-ident" ) ) {
|
|
|
|
globals->get_soundmgr()->remove( "nav2-dme-ident" );
|
|
|
|
}
|
|
|
|
sound = morse.make_ident( nav2_trans_ident, HI_FREQUENCY );
|
|
|
|
sound->set_volume( 0.3 );
|
|
|
|
globals->get_soundmgr()->add( sound, "nav2-dme-ident" );
|
|
|
|
|
|
|
|
int offset = (int)(sg_random() * 30.0);
|
|
|
|
nav2_play_count = offset / 4;
|
|
|
|
nav2_last_time = globals->get_time_params()->get_cur_time() -
|
|
|
|
offset;
|
|
|
|
// cout << "offset = " << offset << " play_count = "
|
|
|
|
// << nav2_play_count << " nav2_last_time = "
|
|
|
|
// << nav2_last_time << " current time = "
|
|
|
|
// << globals->get_time_params()->get_cur_time() << endl;
|
|
|
|
|
2001-03-09 02:41:04 +00:00
|
|
|
// cout << "Found a vor station in range" << endl;
|
|
|
|
// cout << " id = " << nav.get_ident() << endl;
|
|
|
|
}
|
2000-04-24 23:50:59 +00:00
|
|
|
} else {
|
2000-05-04 01:18:45 +00:00
|
|
|
nav2_valid = false;
|
2001-03-09 02:41:04 +00:00
|
|
|
nav2_ident = "";
|
2001-01-05 17:38:58 +00:00
|
|
|
nav2_radial = 0;
|
|
|
|
nav2_dme_dist = 0;
|
2001-03-14 23:37:50 +00:00
|
|
|
nav2_trans_ident = "";
|
|
|
|
last_nav2_ident = "";
|
|
|
|
globals->get_soundmgr()->remove( "nav2-vor-ident" );
|
|
|
|
globals->get_soundmgr()->remove( "nav2-dme-ident" );
|
|
|
|
// cout << "not picking up vor1. :-(" << endl;
|
2000-04-24 23:50:59 +00:00
|
|
|
}
|
|
|
|
|
2001-03-16 23:59:02 +00:00
|
|
|
FGBeacon::fgMkrBeacType beacon_type
|
|
|
|
= current_beacons->query( lon * RAD_TO_DEG, lat * RAD_TO_DEG, elev );
|
|
|
|
|
|
|
|
outer_marker = middle_marker = inner_marker = false;
|
|
|
|
|
|
|
|
if ( beacon_type == FGBeacon::OUTER ) {
|
|
|
|
outer_marker = true;
|
|
|
|
cout << "OUTER MARKER" << endl;
|
|
|
|
} else if ( beacon_type == FGBeacon::MIDDLE ) {
|
|
|
|
middle_marker = true;
|
|
|
|
cout << "MIDDLE MARKER" << endl;
|
|
|
|
} else if ( beacon_type == FGBeacon::INNER ) {
|
|
|
|
inner_marker = true;
|
|
|
|
cout << "INNER MARKER" << endl;
|
|
|
|
}
|
|
|
|
|
2000-04-24 23:50:59 +00:00
|
|
|
// adf
|
2000-05-04 01:18:45 +00:00
|
|
|
if ( current_navlist->query( lon, lat, elev, adf_freq, &nav ) ) {
|
2001-03-14 23:37:50 +00:00
|
|
|
char freq[128];
|
2001-03-21 23:16:21 +00:00
|
|
|
#if defined( _MSC_VER )
|
|
|
|
_snprintf( freq, 10, "%.0f", adf_freq );
|
|
|
|
#else
|
2001-03-14 23:37:50 +00:00
|
|
|
snprintf( freq, 10, "%.0f", adf_freq );
|
2001-03-21 23:16:21 +00:00
|
|
|
#endif
|
2001-03-14 23:37:50 +00:00
|
|
|
adf_ident = freq;
|
|
|
|
adf_ident += nav.get_ident();
|
|
|
|
// cout << "adf ident = " << adf_ident << endl;
|
2000-05-04 01:18:45 +00:00
|
|
|
adf_valid = true;
|
2001-03-14 23:37:50 +00:00
|
|
|
if ( last_adf_ident != adf_ident ) {
|
|
|
|
last_adf_ident = adf_ident;
|
|
|
|
|
|
|
|
adf_trans_ident = nav.get_trans_ident();
|
|
|
|
adf_lon = nav.get_lon();
|
|
|
|
adf_lat = nav.get_lat();
|
|
|
|
adf_elev = nav.get_elev();
|
|
|
|
adf_range = nav.get_range();
|
|
|
|
adf_effective_range = kludgeRange(adf_elev, elev, adf_range);
|
|
|
|
adf_x = nav.get_x();
|
|
|
|
adf_y = nav.get_y();
|
|
|
|
adf_z = nav.get_z();
|
|
|
|
|
|
|
|
if ( globals->get_soundmgr()->exists( "adf-ident" ) ) {
|
|
|
|
globals->get_soundmgr()->remove( "adf-ident" );
|
|
|
|
}
|
|
|
|
FGSimpleSound *sound;
|
|
|
|
sound = morse.make_ident( adf_trans_ident, LO_FREQUENCY );
|
|
|
|
sound->set_volume( 0.3 );
|
|
|
|
globals->get_soundmgr()->add( sound, "adf-ident" );
|
2000-05-04 01:18:45 +00:00
|
|
|
|
2001-03-14 23:37:50 +00:00
|
|
|
int offset = (int)(sg_random() * 30.0);
|
|
|
|
adf_play_count = offset / 4;
|
|
|
|
adf_last_time = globals->get_time_params()->get_cur_time() -
|
|
|
|
offset;
|
|
|
|
// cout << "offset = " << offset << " play_count = "
|
|
|
|
// << adf_play_count << " adf_last_time = "
|
|
|
|
// << adf_last_time << " current time = "
|
|
|
|
// << globals->get_time_params()->get_cur_time() << endl;
|
|
|
|
|
|
|
|
// cout << "Found an adf station in range" << endl;
|
|
|
|
// cout << " id = " << nav.get_ident() << endl;
|
|
|
|
}
|
2000-04-24 23:50:59 +00:00
|
|
|
} else {
|
2000-05-04 01:18:45 +00:00
|
|
|
adf_valid = false;
|
2001-03-14 23:37:50 +00:00
|
|
|
adf_ident = "";
|
|
|
|
adf_trans_ident = "";
|
|
|
|
globals->get_soundmgr()->remove( "adf-ident" );
|
|
|
|
last_adf_ident = "";
|
2000-04-27 03:26:36 +00:00
|
|
|
// cout << "not picking up adf. :-(" << endl;
|
2000-04-24 23:50:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-04 01:18:45 +00:00
|
|
|
|
2001-02-25 04:45:26 +00:00
|
|
|
// return the amount of heading needle deflection, returns a value
|
|
|
|
// clamped to the range of ( -10 , 10 )
|
|
|
|
double FGRadioStack::get_nav1_heading_needle_deflection() const {
|
|
|
|
double r;
|
|
|
|
|
|
|
|
if ( nav1_inrange ) {
|
|
|
|
r = nav1_heading - nav1_radial;
|
|
|
|
// cout << "Radial = " << nav1_radial
|
|
|
|
// << " Bearing = " << nav1_heading << endl;
|
|
|
|
|
2001-02-27 23:52:52 +00:00
|
|
|
while ( r > 180.0 ) { r -= 360.0;}
|
|
|
|
while ( r < -180.0 ) { r += 360.0;}
|
|
|
|
if ( fabs(r) > 90.0 ) {
|
2001-02-25 04:45:26 +00:00
|
|
|
r = ( r<0.0 ? -r-180.0 : -r+180.0 );
|
2001-02-27 23:52:52 +00:00
|
|
|
if ( nav1_loc ) {
|
|
|
|
r = -r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-25 04:45:26 +00:00
|
|
|
// According to Robin Peel, the ILS is 4x more sensitive than a vor
|
2001-02-27 23:52:52 +00:00
|
|
|
if ( nav1_loc ) { r *= 4.0; }
|
|
|
|
if ( r < -10.0 ) { r = -10.0; }
|
|
|
|
if ( r > 10.0 ) { r = 10.0; }
|
2001-02-25 04:45:26 +00:00
|
|
|
} else {
|
|
|
|
r = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the amount of heading needle deflection, returns a value
|
|
|
|
// clamped to the range of ( -10 , 10 )
|
|
|
|
double FGRadioStack::get_nav2_heading_needle_deflection() const {
|
|
|
|
double r;
|
|
|
|
|
|
|
|
if ( nav2_inrange ) {
|
|
|
|
r = nav2_heading - nav2_radial;
|
2001-02-25 16:26:48 +00:00
|
|
|
// cout << "Radial = " << nav2_radial
|
|
|
|
// << " Bearing = " << nav2_heading << endl;
|
2001-02-25 04:45:26 +00:00
|
|
|
|
|
|
|
while (r> 180.0) r-=360.0;
|
|
|
|
while (r<-180.0) r+=360.0;
|
|
|
|
if ( fabs(r) > 90.0 )
|
|
|
|
r = ( r<0.0 ? -r-180.0 : -r+180.0 );
|
|
|
|
// According to Robin Peel, the ILS is 4x more sensitive than a vor
|
2001-02-25 16:26:48 +00:00
|
|
|
if ( nav2_loc ) r *= 4.0;
|
2001-02-25 04:45:26 +00:00
|
|
|
if ( r < -10.0 ) r = -10.0;
|
|
|
|
if ( r > 10.0 ) r = 10.0;
|
|
|
|
} else {
|
|
|
|
r = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the amount of glide slope needle deflection (.i.e. the
|
|
|
|
// number of degrees we are off the glide slope * 5.0
|
|
|
|
double FGRadioStack::get_nav1_gs_needle_deflection() const {
|
|
|
|
if ( nav1_inrange && nav1_has_gs ) {
|
|
|
|
double x = nav1_gs_dist;
|
|
|
|
double y = (FGBFI::getAltitude() - nav1_elev) * FEET_TO_METER;
|
|
|
|
double angle = atan2( y, x ) * RAD_TO_DEG;
|
|
|
|
return (nav1_target_gs - angle) * 5.0;
|
|
|
|
} else {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return the amount of glide slope needle deflection (.i.e. the
|
|
|
|
// number of degrees we are off the glide slope * 5.0
|
|
|
|
double FGRadioStack::get_nav2_gs_needle_deflection() const {
|
|
|
|
if ( nav2_inrange && nav2_has_gs ) {
|
|
|
|
double x = nav2_gs_dist;
|
|
|
|
double y = (FGBFI::getAltitude() - nav2_elev) * FEET_TO_METER;
|
|
|
|
double angle = atan2( y, x ) * RAD_TO_DEG;
|
|
|
|
return (nav2_target_gs - angle) * 5.0;
|
|
|
|
} else {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-11 22:44:18 +00:00
|
|
|
/**
|
|
|
|
* Return true if the NAV1 TO flag should be active.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
FGRadioStack::get_nav1_to_flag () const
|
|
|
|
{
|
|
|
|
if (nav1_inrange) {
|
|
|
|
double offset = fabs(nav1_heading - nav1_radial);
|
|
|
|
if (nav1_loc)
|
2001-02-25 16:26:48 +00:00
|
|
|
return true;
|
2001-01-11 22:44:18 +00:00
|
|
|
else
|
2001-02-25 04:45:26 +00:00
|
|
|
return (offset <= 90.0 || offset >= 270.0);
|
2001-01-11 22:44:18 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2000-05-04 01:18:45 +00:00
|
|
|
}
|
2001-01-11 22:44:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the NAV1 FROM flag should be active.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
FGRadioStack::get_nav1_from_flag () const
|
|
|
|
{
|
|
|
|
if (nav1_inrange) {
|
|
|
|
double offset = fabs(nav1_heading - nav1_radial);
|
|
|
|
if (nav1_loc)
|
2001-02-25 16:26:48 +00:00
|
|
|
return false;
|
2001-01-11 22:44:18 +00:00
|
|
|
else
|
2001-02-25 04:45:26 +00:00
|
|
|
return (offset > 90.0 && offset < 270.0);
|
2001-01-11 22:44:18 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the NAV2 TO flag should be active.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
FGRadioStack::get_nav2_to_flag () const
|
|
|
|
{
|
|
|
|
if (nav2_inrange) {
|
|
|
|
double offset = fabs(nav2_heading - nav2_radial);
|
|
|
|
if (nav2_loc)
|
2001-02-25 16:26:48 +00:00
|
|
|
return true;
|
2001-01-11 22:44:18 +00:00
|
|
|
else
|
2001-02-25 04:45:26 +00:00
|
|
|
return (offset <= 90.0 || offset >= 270.0);
|
2001-01-11 22:44:18 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the NAV2 FROM flag should be active.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
FGRadioStack::get_nav2_from_flag () const
|
|
|
|
{
|
|
|
|
if (nav2_inrange) {
|
|
|
|
double offset = fabs(nav2_heading - nav2_radial);
|
|
|
|
if (nav2_loc)
|
2001-02-25 16:26:48 +00:00
|
|
|
return false;
|
2001-01-11 22:44:18 +00:00
|
|
|
else
|
2001-02-25 04:45:26 +00:00
|
|
|
return (offset > 90.0 && offset < 270.0);
|
2001-01-11 22:44:18 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|