#include <Aircraft/aircraft.hxx>
#include <Navaids/ilslist.hxx>
-#include <Navaids/mkrbeacons.hxx>
#include <Navaids/navlist.hxx>
#include <Time/FGEventMgr.hxx>
SG_USING_STD(string);
-/**
- * Boy, this is ugly! Make the VOR range vary by altitude difference.
- */
-static double kludgeRange ( double stationElev, double aircraftElev,
- double nominalRange)
-{
- // Assume that the nominal range (usually 50nm) applies at a 5,000
- // ft difference. Just a wild guess!
- double factor = ((aircraftElev*SG_METER_TO_FEET) - stationElev) / 5000.0;
- 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;
-}
-
-
// Constructor
FGNavCom::FGNavCom() :
lon_node(fgGetNode("/position/longitude-deg", true)),
lat_node(fgGetNode("/position/latitude-deg", true)),
alt_node(fgGetNode("/position/altitude-ft", true)),
- last_nav_ident(""),
+ last_nav_id(""),
last_nav_vor(false),
nav_play_count(0),
nav_last_time(0),
need_update(true),
+ power_btn(true),
comm_freq(0.0),
comm_alt_freq(0.0),
comm_vol_btn(0.0),
nav_freq(0.0),
nav_alt_freq(0.0),
nav_radial(0.0),
- nav_vol_btn(0.0)
+ nav_vol_btn(0.0),
+ nav_ident_btn(true)
{
SGPath path( globals->get_fg_root() );
SGPath term = path;
// Destructor
FGNavCom::~FGNavCom()
{
- unbind(); // FIXME: should be called externally
-
delete term_tbl;
delete low_tbl;
delete high_tbl;
FGNavCom::init ()
{
morse.init();
- beacon.init();
search();
char propname[256];
// User inputs
+ sprintf( propname, "/radios/comm[%d]/inputs/power-btn", index );
+ fgTie( propname, this,
+ &FGNavCom::get_power_btn, &FGNavCom::set_power_btn );
+ fgSetArchivable( propname );
+
sprintf( propname, "/radios/comm[%d]/frequencies/selected-mhz", index );
fgTie( propname, this, &FGNavCom::get_comm_freq, &FGNavCom::set_comm_freq );
fgSetArchivable( propname );
&FGNavCom::get_comm_vol_btn, &FGNavCom::set_comm_vol_btn );
fgSetArchivable( propname );
- sprintf( propname, "/radios/comm[%d]/ident", index );
- fgTie( propname, this,
- &FGNavCom::get_comm_ident_btn, &FGNavCom::set_comm_ident_btn );
- fgSetArchivable( propname );
-
sprintf( propname, "/radios/nav[%d]/frequencies/selected-mhz", index );
fgTie( propname, this,
&FGNavCom::get_nav_freq, &FGNavCom::set_nav_freq );
sprintf( propname, "/radios/nav[%d]/gs-needle-deflection", index );
fgTie( propname, this, &FGNavCom::get_nav_gs_needle_deflection );
+
+ // end of binding
+
+ // We know index is valid now so lets bind to the bus property
+ // here.
+ sprintf( propname, "/systems/electrical/outputs/navcom[%d]", index );
+ // default to true in case no electrical system defined.
+ fgSetDouble( propname, 60.0 );
+ bus_power = fgGetNode( propname, true );
}
{
char propname[256];
+ sprintf( propname, "/radios/comm[%d]/inputs/power-btn", index );
+ fgUntie( propname );
sprintf( propname, "/radios/comm[%d]/frequencies/selected-mhz", index );
fgUntie( propname );
sprintf( propname, "/radios/comm[%d]/frequencies/standby-mhz", index );
fgUntie( propname );
- sprintf( propname, "/radios/comm[%d]/on", index );
- fgUntie( propname );
- sprintf( propname, "/radios/comm[%d]/ident", index );
- fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/frequencies/selected-mhz", index );
fgUntie( propname );
fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/radials/selected-deg", index );
fgUntie( propname );
- sprintf( propname, "/radios/nav[%d]/on", index );
- fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/ident", index );
fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/to-flag", index );
// Nav.
////////////////////////////////////////////////////////////////////////
- if ( nav_valid ) {
+ if ( nav_valid && power_btn && (bus_power->getDoubleValue() > 1.0) ) {
station = Point3D( nav_x, nav_y, nav_z );
nav_loc_dist = aircraft.distance3D( station );
if ( nav_valid && nav_inrange ) {
// play station ident via audio system if on + ident,
// otherwise turn it off
- if ( nav_vol_btn > 0.1 && nav_ident_btn ) {
+ if ( power_btn && (bus_power->getDoubleValue() > 1.0)
+ && nav_ident_btn )
+ {
FGSimpleSound *sound;
sound = globals->get_soundmgr()->find( nav_fx_name );
if ( sound != NULL ) {
SG_LOG( SG_COCKPIT, SG_ALERT,
"Can't find nav-dme-ident sound" );
}
- cout << "nav_last_time = " << nav_last_time << " ";
- cout << "cur_time = " << globals->get_time_params()->get_cur_time();
+ // cout << "nav_last_time = " << nav_last_time << " ";
+ // cout << "cur_time = "
+ // << globals->get_time_params()->get_cur_time();
if ( nav_last_time <
globals->get_time_params()->get_cur_time() - 30 ) {
nav_last_time = globals->get_time_params()->get_cur_time();
nav_play_count = 0;
}
- cout << " nav_play_count = " << nav_play_count << endl;
- cout << "playing = "
- << globals->get_soundmgr()->is_playing(nav_fx_name)
- << endl;
+ // cout << " nav_play_count = " << nav_play_count << endl;
+ // cout << "playing = "
+ // << globals->get_soundmgr()->is_playing(nav_fx_name)
+ // << endl;
if ( nav_play_count < 4 ) {
// play VOR ident
if ( !globals->get_soundmgr()->is_playing(nav_fx_name) ) {
////////////////////////////////////////////////////////////////////////
if ( current_ilslist->query( lon, lat, elev, nav_freq, &ils ) ) {
- nav_ident = ils.get_locident();
+ nav_id = ils.get_locident();
nav_valid = true;
- if ( last_nav_ident != nav_ident || last_nav_vor ) {
+ if ( last_nav_id != nav_id || last_nav_vor ) {
nav_trans_ident = ils.get_trans_ident();
- last_nav_ident = nav_ident;
+ last_nav_id = nav_id;
last_nav_vor = false;
nav_loc = true;
nav_has_dme = ils.get_has_dme();
nav_play_count = offset / 4;
nav_last_time = globals->get_time_params()->get_cur_time() -
offset;
- cout << "offset = " << offset << " play_count = "
- << nav_play_count
- << " nav_last_time = " << nav_last_time
- << " current time = "
- << globals->get_time_params()->get_cur_time() << endl;
+ // cout << "offset = " << offset << " play_count = "
+ // << nav_play_count
+ // << " nav_last_time = " << nav_last_time
+ // << " current time = "
+ // << globals->get_time_params()->get_cur_time() << endl;
#endif
// cout << "Found an ils station in range" << endl;
// cout << " id = " << ils.get_locident() << endl;
}
} else if ( current_navlist->query( lon, lat, elev, nav_freq, &nav ) ) {
- nav_ident = nav.get_ident();
+ nav_id = nav.get_ident();
nav_valid = true;
- if ( last_nav_ident != nav_ident || !last_nav_vor ) {
- last_nav_ident = nav_ident;
+ if ( last_nav_id != nav_id || !last_nav_vor ) {
+ last_nav_id = nav_id;
last_nav_vor = true;
nav_trans_ident = nav.get_trans_ident();
nav_loc = false;
sound = morse.make_ident( nav_trans_ident, LO_FREQUENCY );
sound->set_volume( 0.3 );
if ( globals->get_soundmgr()->add( sound, nav_fx_name ) ) {
- cout << "Added nav-vor-ident sound" << endl;
+ // cout << "Added nav-vor-ident sound" << endl;
} else {
cout << "Failed to add v1-vor-ident sound" << endl;
}
nav_play_count = offset / 4;
nav_last_time = globals->get_time_params()->get_cur_time() -
offset;
- cout << "offset = " << offset << " play_count = "
- << nav_play_count << " nav_last_time = "
- << nav_last_time << " current time = "
- << globals->get_time_params()->get_cur_time() << endl;
+ // cout << "offset = " << offset << " play_count = "
+ // << nav_play_count << " nav_last_time = "
+ // << nav_last_time << " current time = "
+ // << globals->get_time_params()->get_cur_time() << endl;
#endif
// cout << "Found a vor station in range" << endl;
}
} else {
nav_valid = false;
- nav_ident = "";
+ nav_id = "";
nav_radial = 0;
nav_trans_ident = "";
- last_nav_ident = "";
+ last_nav_id = "";
#ifdef ENABLE_AUDIO_SUPPORT
if ( ! globals->get_soundmgr()->remove( nav_fx_name ) ) {
cout << "Failed to remove nav-vor-ident sound" << endl;