# 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;
}
-// 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),
+ outer_blink(false),
+ middle_blink(false),
+ inner_blink(false),
adf_freq(0.0),
- adf_alt_freq(0.0)
+ adf_alt_freq(0.0),
+ adf_vol_btn(0.0)
{
SGPath path( globals->get_fg_root() );
SGPath term = path;
blink.stamp();
search();
- update();
+ update(1); // FIXME: use dt
// 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);
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");
// Update the various nav values based on position and valid tuned in navs
void
-FGRadioStack::update()
+FGRadioStack::update(int 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;
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 ( sound != NULL ) {
+ sound->set_volume( adf_vol_btn );
+ } else {
+ SG_LOG( SG_COCKPIT, SG_ALERT, "Can't find adf-ident sound" );
+ }
if ( adf_last_time <
globals->get_time_params()->get_cur_time() - 30 ) {
adf_last_time = globals->get_time_params()->get_cur_time();
// 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 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;
return false;
}
}
-