# include <config.h>
#endif
+#include <stdio.h> // snprintf
+
#include <simgear/compiler.h>
#include <simgear/math/sg_random.h>
#include <Navaids/ilslist.hxx>
#include <Navaids/mkrbeacons.hxx>
#include <Navaids/navlist.hxx>
-#include <Time/event.hxx>
+#include <Time/FGEventMgr.hxx>
#include "radiostack.hxx"
+#include <string>
+SG_USING_STD(string);
+
static int nav1_play_count = 0;
static int nav2_play_count = 0;
-static int adf_play_count = 0;
static time_t nav1_last_time = 0;
static time_t nav2_last_time = 0;
-static time_t adf_last_time = 0;
FGRadioStack *current_radiostack;
}
-// periodic radio station search wrapper
-static void fgRadioSearch( void ) {
- current_radiostack->search();
-}
-
// Constructor
FGRadioStack::FGRadioStack() :
lon_node(fgGetNode("/position/longitude-deg", true)),
lat_node(fgGetNode("/position/latitude-deg", true)),
alt_node(fgGetNode("/position/altitude-ft", true)),
need_update(true),
+ comm1_freq(0.0),
+ comm1_alt_freq(0.0),
+ comm1_vol_btn(0.0),
+ comm2_freq(0.0),
+ comm2_alt_freq(0.0),
+ comm2_vol_btn(0.0),
+ nav1_freq(0.0),
+ nav1_alt_freq(0.0),
nav1_radial(0.0),
+ nav1_vol_btn(0.0),
+ nav2_freq(0.0),
+ nav2_alt_freq(0.0),
nav2_radial(0.0),
+ nav2_vol_btn(0.0),
dme_freq(0.0),
dme_dist(0.0),
dme_prev_dist(0.0),
dme_spd(0.0),
- dme_ete(0.0)
+ dme_ete(0.0),
+ outer_blink(false),
+ middle_blink(false),
+ inner_blink(false)
{
SGPath path( globals->get_fg_root() );
SGPath term = path;
// Destructor
FGRadioStack::~FGRadioStack()
{
+ adf.unbind();
+ xponder.unbind();
unbind(); // FIXME: should be called externally
delete term_tbl;
void
FGRadioStack::init ()
{
+ adf.init();
+ xponder.init();
+
morse.init();
beacon.init();
blink.stamp();
search();
- update();
+ adf.search();
+ xponder.search();
+
+ update(0); // FIXME: use dt
+ adf.update(0);
+ xponder.update(0);
// Search radio database once per second
- global_events.Register( "fgRadioSearch()", fgRadioSearch,
- fgEVENT::FG_EVENT_READY, 1000);
+ global_events.Register( "fgRadioSearch()",
+ current_radiostack, &FGRadioStack::search,
+ 1000 );
}
void
FGRadioStack::bind ()
{
// User inputs
+ fgTie("/radios/comm[0]/frequencies/selected-mhz", this,
+ &FGRadioStack::get_comm1_freq, &FGRadioStack::set_comm1_freq);
+ fgSetArchivable("/radios/comm[0]/frequencies/selected-mhz");
+ fgTie("/radios/comm[0]/frequencies/standby-mhz", this,
+ &FGRadioStack::get_comm1_alt_freq, &FGRadioStack::set_comm1_alt_freq);
+ fgSetArchivable("/radios/comm[0]/frequencies/standby-mhz");
+ fgTie("/radios/comm[0]/volume", this,
+ &FGRadioStack::get_comm1_vol_btn,
+ &FGRadioStack::set_comm1_vol_btn);
+ fgSetArchivable("/radios/comm[0]/volume");
+ fgTie("/radios/comm[0]/ident", this,
+ &FGRadioStack::get_comm1_ident_btn,
+ &FGRadioStack::set_comm1_ident_btn);
+ fgSetArchivable("/radios/comm[0]/ident");
+
+ fgTie("/radios/comm[1]/frequencies/selected-mhz", this,
+ &FGRadioStack::get_comm2_freq, &FGRadioStack::set_comm2_freq);
+ fgSetArchivable("/radios/comm[0]/frequencies/selected-mhz");
+ fgTie("/radios/comm[1]/frequencies/standby-mhz", this,
+ &FGRadioStack::get_comm2_alt_freq, &FGRadioStack::set_comm2_alt_freq);
+ fgSetArchivable("/radios/comm[0]/frequencies/standby-mhz");
+ fgTie("/radios/comm[1]/volume", this,
+ &FGRadioStack::get_comm2_vol_btn,
+ &FGRadioStack::set_comm2_vol_btn);
+ fgSetArchivable("/radios/comm[0]/volume");
+ fgTie("/radios/comm[1]/ident", this,
+ &FGRadioStack::get_comm2_ident_btn,
+ &FGRadioStack::set_comm2_ident_btn);
+ fgSetArchivable("/radios/comm[1]/ident");
+
fgTie("/radios/nav[0]/frequencies/selected-mhz", this,
&FGRadioStack::get_nav1_freq, &FGRadioStack::set_nav1_freq);
fgSetArchivable("/radios/nav[0]/frequencies/selected-mhz");
// User inputs
fgTie("/radios/dme/frequencies/selected-khz", this,
- &FGRadioStack::get_dme_freq, &FGRadioStack::set_adf_freq);
+ &FGRadioStack::get_dme_freq, &FGRadioStack::set_dme_freq);
// Radio outputs
fgTie("/radios/dme/in-range", this, &FGRadioStack::get_dme_inrange);
fgTie("/radios/dme/speed-kt", this, &FGRadioStack::get_dme_spd);
fgTie("/radios/dme/ete-min", this, &FGRadioStack::get_dme_ete);
- // User inputs
- fgTie("/radios/adf/frequencies/selected-khz", this,
- &FGRadioStack::get_adf_freq, &FGRadioStack::set_adf_freq);
- fgSetArchivable("/radios/adf/frequencies/selected-khz");
- fgTie("/radios/adf/frequencies/standby-khz", this,
- &FGRadioStack::get_adf_alt_freq, &FGRadioStack::set_adf_alt_freq);
- fgSetArchivable("/radios/adf/frequencies/standby-khz");
- fgTie("/radios/adf/rotation-deg", this,
- &FGRadioStack::get_adf_rotation, &FGRadioStack::set_adf_rotation);
- fgSetArchivable("/radios/adf/rotation-deg");
- fgTie("/radios/adf/volume", this,
- &FGRadioStack::get_adf_vol_btn,
- &FGRadioStack::set_adf_vol_btn);
- fgSetArchivable("/radios/adf/volume");
- fgTie("/radios/adf/ident", this,
- &FGRadioStack::get_adf_ident_btn,
- &FGRadioStack::set_adf_ident_btn);
- fgSetArchivable("/radios/adf/ident");
-
fgTie("/radios/marker-beacon/inner", this,
&FGRadioStack::get_inner_blink);
fgTie("/radios/marker-beacon/middle", this,
&FGRadioStack::get_middle_blink);
fgTie("/radios/marker-beacon/outer", this,
&FGRadioStack::get_outer_blink);
+
+ adf.bind();
+ xponder.bind();
}
void
FGRadioStack::unbind ()
{
+ fgUntie("/radios/comm[0]/frequencies/selected-mhz");
+ fgUntie("/radios/comm[0]/frequencies/standby-mhz");
+ fgUntie("/radios/comm[0]/on");
+ fgUntie("/radios/comm[0]/ident");
+
+ fgUntie("/radios/comm[1]/frequencies/selected-mhz");
+ fgUntie("/radios/comm[1]/frequencies/standby-mhz");
+ fgUntie("/radios/comm[1]/on");
+ fgUntie("/radios/comm[1]/ident");
+
fgUntie("/radios/nav[0]/frequencies/selected-mhz");
fgUntie("/radios/nav[0]/frequencies/standby-mhz");
fgUntie("/radios/nav[0]/radials/actual-deg");
fgUntie("/radios/dme/speed-kt");
fgUntie("/radios/dme/ete-min");
- fgUntie("/radios/adf/frequencies/selected-khz");
- fgUntie("/radios/adf/frequencies/standby-khz");
- fgUntie("/radios/adf/rotation-deg");
- fgUntie("/radios/adf/on");
- fgUntie("/radios/adf/ident");
-
fgUntie("/radios/marker-beacon/inner");
fgUntie("/radios/marker-beacon/middle");
fgUntie("/radios/marker-beacon/outer");
+
+ adf.unbind();
+ xponder.unbind();
}
return 10 + (35 - offset) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
} else if ( offset < 45 ) {
return (45 - offset);
+ } else if ( offset > 170 ) {
+ return FG_ILS_DEFAULT_RANGE;
+ } else if ( offset > 145 ) {
+ return 10 + (offset - 145) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
+ } else if ( offset > 135 ) {
+ return (offset - 135);
} else {
return 0;
}
// Update the various nav values based on position and valid tuned in navs
void
-FGRadioStack::update()
+FGRadioStack::update(double dt)
{
double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
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 );
+ if ( sound != NULL ) {
+ sound->set_volume( nav1_vol_btn );
+ } else {
+ SG_LOG( SG_COCKPIT, SG_ALERT,
+ "Can't find nav1-vor-ident sound" );
+ }
sound = globals->get_soundmgr()->find( "nav1-dme-ident" );
- sound->set_volume( nav1_vol_btn * 0.3 );
+ if ( sound != NULL ) {
+ sound->set_volume( nav1_vol_btn );
+ } else {
+ SG_LOG( SG_COCKPIT, SG_ALERT,
+ "Can't find nav1-dme-ident sound" );
+ }
+ // cout << "nav1_last_time = " << nav1_last_time << " ";
+ // cout << "cur_time = " << globals->get_time_params()->get_cur_time();
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;
}
+ // cout << " nav1_play_count = " << nav1_play_count << endl;
+ // cout << "playing = "
+ // << globals->get_soundmgr()->is_playing("nav1-vor-ident")
+ // << endl;
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;
- }
+ }
} else if ( nav1_play_count < 5 && nav1_has_dme ) {
// play DME ident
if ( !globals->get_soundmgr()->is_playing("nav1-vor-ident") &&
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 );
+ if ( sound != NULL ) {
+ sound->set_volume( nav2_vol_btn );
+ } else {
+ SG_LOG( SG_COCKPIT, SG_ALERT,
+ "Can't find nav2-vor-ident sound" );
+ }
sound = globals->get_soundmgr()->find( "nav2-dme-ident" );
- sound->set_volume( nav2_vol_btn * 0.3 );
- if ( nav2_last_time <
+ if ( sound != NULL ) {
+ sound->set_volume( nav2_vol_btn );
+ } else {
+ SG_LOG( SG_COCKPIT, SG_ALERT,
+ "Can't find nav2-dme-ident sound" );
+ }
+ 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;
dme_prev_dist = 0.0;
}
-
- ////////////////////////////////////////////////////////////////////////
- // ADF
- ////////////////////////////////////////////////////////////////////////
-
- if ( adf_valid ) {
- // staightline distance
- station = Point3D( adf_x, adf_y, adf_z );
- adf_dist = aircraft.distance3D( station );
-
- // wgs84 heading
- geo_inverse_wgs_84( elev, lat * SGD_RADIANS_TO_DEGREES, lon * SGD_RADIANS_TO_DEGREES,
- adf_lat, adf_lon,
- &az1, &az2, &s );
- adf_heading = az1;
- // cout << " heading = " << nav2_heading
- // << " dist = " << nav2_dist << endl;
-
- adf_effective_range = kludgeRange(adf_elev, elev, adf_range);
- if ( adf_dist < adf_effective_range * SG_NM_TO_METER ) {
- adf_inrange = true;
- } else if ( adf_dist < 2 * adf_effective_range * SG_NM_TO_METER ) {
- adf_inrange = sg_random() <
- ( 2 * adf_effective_range * SG_NM_TO_METER - adf_dist ) /
- (adf_effective_range * SG_NM_TO_METER);
- } else {
- adf_inrange = false;
- }
- } else {
- adf_inrange = false;
- }
-
-#ifdef ENABLE_AUDIO_SUPPORT
- if ( adf_valid && adf_inrange ) {
- // play station ident via audio system if on + ident,
- // otherwise turn it off
- 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 );
- 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" );
- }
- }
-#endif
-
// marker beacon blinking
bool light_on = ( outer_blink || middle_blink || inner_blink );
SGTimeStamp current;
}
// cout << outer_blink << " " << middle_blink << " " << inner_blink << endl;
+
+ adf.update( dt );
+ xponder.update( dt );
}
// FIXME: the panel should handle this
// don't worry about overhead for now,
// since this is handled only periodically
- int dme_switch_pos = fgGetInt("/panel/dme/switch-position");
+ int dme_switch_pos = fgGetInt("/radios/dme/switch-position");
if (dme_switch_pos == 0) {
dme_freq = 0;
dme_inrange = false;
static string last_nav1_ident = "";
static string last_nav2_ident = "";
- static string last_adf_ident = "";
static bool last_nav1_vor = false;
static bool last_nav2_vor = false;
-
////////////////////////////////////////////////////////////////////////
// Nav1.
////////////////////////////////////////////////////////////////////////
FGSimpleSound *sound;
sound = morse.make_ident( nav1_trans_ident, LO_FREQUENCY );
sound->set_volume( 0.3 );
- globals->get_soundmgr()->add( sound, "nav1-vor-ident" );
+ if ( globals->get_soundmgr()->add( sound, "nav1-vor-ident" ) ) {
+ // cout << "Added nav1-vor-ident sound" << endl;
+ } else {
+ // cout << "Failed to add v1-vor-ident sound" << endl;
+ }
if ( globals->get_soundmgr()->exists( "nav1-dme-ident" ) ) {
globals->get_soundmgr()->remove( "nav1-dme-ident" );
nav1_trans_ident = "";
last_nav1_ident = "";
#ifdef ENABLE_AUDIO_SUPPORT
- globals->get_soundmgr()->remove( "nav1-vor-ident" );
+ if ( ! globals->get_soundmgr()->remove( "nav1-vor-ident" ) ) {
+ // cout << "Failed to remove nav1-vor-ident sound" << endl;
+ }
globals->get_soundmgr()->remove( "nav1-dme-ident" );
#endif
// cout << "not picking up vor1. :-(" << endl;
}
last_beacon = beacon_type;
-
- ////////////////////////////////////////////////////////////////////////
- // ADF.
- ////////////////////////////////////////////////////////////////////////
-
- if ( current_navlist->query( lon, lat, elev, adf_freq, &nav ) ) {
- char freq[128];
-#if defined( _MSC_VER )
- _snprintf( freq, 10, "%.0f", adf_freq );
-#else
- snprintf( freq, 10, "%.0f", adf_freq );
-#endif
- adf_ident = freq;
- adf_ident += nav.get_ident();
- // cout << "adf ident = " << adf_ident << endl;
- adf_valid = true;
- 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();
-
-#ifdef ENABLE_AUDIO_SUPPORT
- 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" );
-
- 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;
-#endif
-
- // cout << "Found an adf station in range" << endl;
- // cout << " id = " << nav.get_ident() << endl;
- }
- } else {
- adf_valid = false;
- adf_ident = "";
- adf_trans_ident = "";
-#ifdef ENABLE_AUDIO_SUPPORT
- globals->get_soundmgr()->remove( "adf-ident" );
-#endif
- last_adf_ident = "";
- // cout << "not picking up adf. :-(" << endl;
- }
+ adf.search();
+ xponder.search();
}
return false;
}
}
-