#include "adf.hxx"
+#include <iostream>
+#include <string>
+#include <sstream>
+
// Use a bigger number to be more responsive, or a smaller number
// to be more sluggish.
}
+ADF::ADF (SGPropertyNode *node )
+ :
+ _time_before_search_sec(0),
+ _last_frequency_khz(-1),
+ _transmitter_valid(false),
+ _transmitter_elevation_ft(0),
+ _transmitter_range_nm(0),
+ _ident_count(0),
+ _last_ident_time(0),
+ _last_volume(-1),
+ name("adf"),
+ num(0)
+{
+ int i;
+ for ( i = 0; i < node->nChildren(); ++i ) {
+ SGPropertyNode *child = node->getChild(i);
+ string cname = child->getName();
+ string cval = child->getStringValue();
+ if ( cname == "name" ) {
+ name = cval;
+ } else if ( cname == "number" ) {
+ num = child->getIntValue();
+ } else {
+ SG_LOG( SG_INSTR, SG_WARN, "Error in adf config logic" );
+ if ( name.length() ) {
+ SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
+ }
+ }
+ }
+}
+
+
ADF::ADF ()
: _time_before_search_sec(0),
_last_frequency_khz(-1),
_transmitter_valid(false),
_transmitter_elevation_ft(0),
- _transmitter_range_nm(0)
+ _transmitter_range_nm(0),
+ _ident_count(0),
+ _last_ident_time(0),
+ _last_volume(-1),
+ name("adf"),
+ num(0)
{
}
void
ADF::init ()
{
+ string branch;
+ branch = "/instrumentation/" + name;
+
+ SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
_longitude_node = fgGetNode("/position/longitude-deg", true);
_latitude_node = fgGetNode("/position/latitude-deg", true);
_altitude_node = fgGetNode("/position/altitude-ft", true);
_heading_node = fgGetNode("/orientation/heading-deg", true);
- _serviceable_node = fgGetNode("/instrumentation/adf/serviceable", true);
- _error_node = fgGetNode("/instrumentation/adf/error-deg", true);
+ _serviceable_node = node->getChild("serviceable", 0, true);
+ _error_node = node->getChild("error-deg", 0, true);
_electrical_node = fgGetNode("/systems/electrical/outputs/adf", true);
- _frequency_node =
- fgGetNode("/instrumentation/adf/frequencies/selected-khz", true);
- _mode_node = fgGetNode("/instrumentation/adf/mode", true);
-
- _in_range_node = fgGetNode("/instrumentation/adf/in-range", true);
- _bearing_node =
- fgGetNode("/instrumentation/adf/indicated-bearing-deg", true);
- _ident_node = fgGetNode("/instrumentation/adf/ident", true);
+ branch = branch + "/frequencies";
+ SGPropertyNode *fnode = node->getChild("frequencies", 0, true);
+ _frequency_node = fnode->getChild("selected-khz", 0, true);
+ _mode_node = node->getChild("mode", 0, true);
+ _volume_node = node->getChild("volume-norm", 0, true);
+ _in_range_node = node->getChild("in-range", 0, true);
+ _bearing_node = node->getChild("indicated-bearing-deg", 0, true);
+ _ident_node = node->getChild("ident", 0, true);
+ _ident_audible_node = node->getChild("ident-audible", 0, true);
+
+ morse.init();
+
+ std::ostringstream temp;
+ temp << name << num;
+ adf_ident = temp.str();
+
+ _serviceable_node->setBoolValue(true);
}
void
if (bearing < 0)
bearing += 360;
set_bearing(delta_time_sec, bearing);
+
+ // adf ident sound
+ double volume;
+ if ( _ident_audible_node->getBoolValue() )
+ volume = _volume_node->getDoubleValue();
+ else
+ volume = 0.0;
+
+ if ( volume != _last_volume ) {
+ _last_volume = volume;
+
+ SGSoundSample *sound;
+ sound = globals->get_soundmgr()->find( adf_ident );
+ if ( sound != NULL )
+ sound->set_volume( volume );
+ else
+ SG_LOG( SG_GENERAL, SG_ALERT, "Can't find adf-ident sound" );
+ }
+
+ time_t cur_time = globals->get_time_params()->get_cur_time();
+ if ( _last_ident_time < cur_time - 30 ) {
+ _last_ident_time = cur_time;
+ _ident_count = 0;
+ }
+
+ if ( _ident_count < 4 ) {
+ if ( !globals->get_soundmgr()->is_playing(adf_ident) ) {
+ globals->get_soundmgr()->play_once( adf_ident );
+ ++_ident_count;
+ }
+ }
} else {
_in_range_node->setBoolValue(false);
set_bearing(delta_time_sec, 90);
_ident_node->setStringValue("");
+ globals->get_soundmgr()->stop( adf_ident );
}
}
double latitude_rad, double altitude_m)
{
string ident = "";
-
// reset search time
_time_before_search_sec = 1.0;
// try the ILS list first
- FGNav * nav =
- current_navlist->findByFreq(frequency_khz, longitude_rad,
- latitude_rad, altitude_m);
+ FGNavRecord *nav =
+ globals->get_navlist()->findByFreq(frequency_khz, longitude_rad,
+ latitude_rad, altitude_m);
- if (nav !=0) {
- _transmitter_valid = true;
+ _transmitter_valid = (nav != NULL);
+ if ( _transmitter_valid ) {
ident = nav->get_trans_ident();
- if (ident !=_last_ident) {
+ if ( ident != _last_ident ) {
_transmitter_lon_deg = nav->get_lon();
_transmitter_lat_deg = nav->get_lat();
_transmitter = Point3D(nav->get_x(), nav->get_y(), nav->get_z());
_transmitter_elevation_ft = nav->get_elev_ft();
_transmitter_range_nm = nav->get_range();
}
- } else {
- _transmitter_valid = false;
}
- _last_ident = ident;
- _ident_node->setStringValue(ident.c_str());
+
+ if ( _last_ident != ident ) {
+ _last_ident = ident;
+ _ident_node->setStringValue(ident.c_str());
+
+ if ( globals->get_soundmgr()->exists( adf_ident ) ) {
+ // stop is required! -- remove alone wouldn't stop immediately
+ globals->get_soundmgr()->stop( adf_ident );
+ globals->get_soundmgr()->remove( adf_ident );
+ }
+
+ SGSoundSample *sound;
+ sound = morse.make_ident( ident, LO_FREQUENCY );
+ sound->set_volume(_last_volume = 0);
+ globals->get_soundmgr()->add( sound, adf_ident );
+
+ int offset = (int)(sg_random() * 30.0);
+ _ident_count = offset / 4;
+ _last_ident_time = globals->get_time_params()->get_cur_time() -
+ offset;
+ }
}
void