X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Ftacan.cxx;h=b17c8bb346386e06a01cc995085621808b966d48;hb=db85ebff95b5e7bcb469d99ae25e062b733d090b;hp=a6781d7d3477ca1a93b1e0582b1556a5f9a42049;hpb=d90922fe1ed1064ea408255f50723454e00268b6;p=flightgear.git diff --git a/src/Instrumentation/tacan.cxx b/src/Instrumentation/tacan.cxx old mode 100755 new mode 100644 index a6781d7d3..b17c8bb34 --- a/src/Instrumentation/tacan.cxx +++ b/src/Instrumentation/tacan.cxx @@ -17,7 +17,7 @@ #include "tacan.hxx" -SG_USING_STD(vector); +using std::vector; /** @@ -58,6 +58,8 @@ TACAN::TACAN ( SGPropertyNode *node ) : _transmitter_pos(SGGeod::fromDeg(0, 0)), _transmitter_range_nm(0), _transmitter_bias(0.0), + _mobile_lat(0.0), + _mobile_lon(0.0), _listener_active(0) { } @@ -125,6 +127,9 @@ TACAN::init () void TACAN::update (double delta_time_sec) { + // don't do anything when paused + if (delta_time_sec == 0) return; + if (!_serviceable_node->getBoolValue() || !_electrical_node->getBoolValue()) { _last_distance_nm = 0; _in_range_node->setBoolValue(false); @@ -154,10 +159,10 @@ TACAN::update (double delta_time_sec) double mobile_bearing = 0; double mobile_distance = 0; - SG_LOG( SG_INSTR, SG_DEBUG, "carrier_lat " << _mobile_lat); - SG_LOG( SG_INSTR, SG_DEBUG, "carrier_lon " << _mobile_lon); - SG_LOG( SG_INSTR, SG_DEBUG, "carrier_name " << _mobile_name); - SG_LOG( SG_INSTR, SG_DEBUG, "carrier_valid " << _mobile_valid); + SG_LOG( SG_INSTR, SG_DEBUG, "mobile_lat " << _mobile_lat); + SG_LOG( SG_INSTR, SG_DEBUG, "mobile_lon " << _mobile_lon); + SG_LOG( SG_INSTR, SG_DEBUG, "mobile_name " << _mobile_name); + SG_LOG( SG_INSTR, SG_DEBUG, "mobile_valid " << _mobile_valid); geo_inverse_wgs_84(altitude_m, latitude_deg, longitude_deg, @@ -235,7 +240,7 @@ TACAN::update (double delta_time_sec) } _distance_node->setDoubleValue( tmp_dist ); _speed_node->setDoubleValue(speed_kt); - _time_node->setDoubleValue(distance_nm/speed_kt*60.0); + _time_node->setDoubleValue(speed_kt > 0 ? (distance_nm/speed_kt*60.0) : 0); _bearing_node->setDoubleValue(bearing); _x_shift_node->setDoubleValue(x_shift); _y_shift_node->setDoubleValue(y_shift); @@ -276,6 +281,7 @@ TACAN::search (double frequency_mhz, double longitude_rad, double latitude_rad, double altitude_m) { int number, i; + _mobile_valid = false; SG_LOG( SG_INSTR, SG_DEBUG, "tacan freq " << frequency_mhz ); @@ -290,7 +296,7 @@ TACAN::search (double frequency_mhz, double longitude_rad, if ( freq_valid ) { - string str1( mobile_tacan->get_name() ); + string str1( mobile_tacan->name() ); SGPropertyNode * branch = fgGetNode("ai/models", true); vector carrier = branch->getChildren("carrier"); @@ -298,78 +304,65 @@ TACAN::search (double frequency_mhz, double longitude_rad, number = carrier.size(); SG_LOG( SG_INSTR, SG_DEBUG, "carrier " << number ); - if ( number > 0 ) { // don't do this if there are no carriers - for ( i = 0; i < number; ++i ) { - string str2 ( carrier[i]->getStringValue("name", "")); - SG_LOG( SG_INSTR, SG_DEBUG, "carrier name " << str2 ); - - SG_LOG( SG_INSTR, SG_DEBUG, "strings 1 " << str1 << " 2 " << str2 ); - string::size_type loc1= str1.find( str2, 0 ); - if ( loc1 != string::npos && str2 != "" ) { - SG_LOG( SG_INSTR, SG_DEBUG, " string found" ); - _mobile_lat = carrier[i]->getDoubleValue("position/latitude-deg"); - _mobile_lon = carrier[i]->getDoubleValue("position/longitude-deg"); - _mobile_elevation_ft = mobile_tacan->get_elev_ft(); - _mobile_range_nm = mobile_tacan->get_range(); - _mobile_bias = mobile_tacan->get_multiuse(); - _mobile_name = mobile_tacan->get_name(); - _mobile_ident = mobile_tacan->get_trans_ident(); - _mobile_valid = true; - SG_LOG( SG_INSTR, SG_DEBUG, " carrier transmitter valid " << _mobile_valid ); - break; - } else { - _mobile_valid = false; - SG_LOG( SG_INSTR, SG_DEBUG, " carrier transmitter invalid " << _mobile_valid ); - } + for ( i = 0; i < number; ++i ) { + string str2 ( carrier[i]->getStringValue("name", "")); + SG_LOG( SG_INSTR, SG_DEBUG, "carrier name " << str2 ); + + SG_LOG( SG_INSTR, SG_DEBUG, "strings 1 " << str1 << " 2 " << str2 ); + string::size_type loc1= str1.find( str2, 0 ); + if ( loc1 != string::npos && str2 != "" ) { + SG_LOG( SG_INSTR, SG_DEBUG, " string found" ); + _mobile_lat = carrier[i]->getDoubleValue("position/latitude-deg"); + _mobile_lon = carrier[i]->getDoubleValue("position/longitude-deg"); + _mobile_elevation_ft = mobile_tacan->get_elev_ft(); + _mobile_range_nm = mobile_tacan->get_range(); + _mobile_bias = mobile_tacan->get_multiuse(); + _mobile_name = mobile_tacan->name(); + _mobile_ident = mobile_tacan->get_trans_ident(); + _mobile_valid = true; + SG_LOG( SG_INSTR, SG_DEBUG, " carrier transmitter valid " << _mobile_valid ); + break; + } else { + _mobile_valid = false; + SG_LOG( SG_INSTR, SG_DEBUG, " carrier transmitter invalid " << _mobile_valid ); } } - SG_LOG( SG_INSTR, SG_DEBUG, "name " << _mobile_name); - SG_LOG( SG_INSTR, SG_DEBUG, "lat " << _mobile_lat << "lon " << _mobile_lon); - SG_LOG( SG_INSTR, SG_DEBUG, "elev " << _mobile_elevation_ft); - //try any AI tankers second if ( !_mobile_valid) { SG_LOG( SG_INSTR, SG_DEBUG, "tanker transmitter valid start " << _mobile_valid ); SGPropertyNode * branch = fgGetNode("ai/models", true); - vector tanker = branch->getChildren("aircraft"); + vector tanker = branch->getChildren("tanker"); number = tanker.size(); SG_LOG( SG_INSTR, SG_DEBUG, "tanker number " << number ); - if ( number > 0 ) { // don't do this if there are no AI aircraft - for ( i = 0; i < number; ++i ) { - string str4 ( tanker[i]->getStringValue("callsign", "")); - SG_LOG( SG_INSTR, SG_DEBUG, "tanker callsign " << str4 ); - - SG_LOG( SG_INSTR, SG_DEBUG, "strings 1 " << str1 << " 4 " << str4 ); - string::size_type loc1= str1.find( str4, 0 ); - if ( loc1 != string::npos && str4 != "" ) { - SG_LOG( SG_INSTR, SG_DEBUG, " string found" ); - _mobile_lat = tanker[i]->getDoubleValue("position/latitude-deg"); - _mobile_lon = tanker[i]->getDoubleValue("position/longitude-deg"); - _mobile_elevation_ft = tanker[i]->getDoubleValue("position/altitude-ft"); - _mobile_range_nm = mobile_tacan->get_range(); - _mobile_bias = mobile_tacan->get_multiuse(); - _mobile_name = mobile_tacan->get_name(); - _mobile_ident = mobile_tacan->get_trans_ident(); - _mobile_valid = true; - SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter valid " << _mobile_valid ); - break; - } else { - _mobile_valid = false; - SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter invalid " << _mobile_valid ); - } + for ( i = 0; i < number; ++i ) { + string str4 ( tanker[i]->getStringValue("callsign", "")); + SG_LOG( SG_INSTR, SG_DEBUG, "tanker callsign " << str4 ); + + SG_LOG( SG_INSTR, SG_DEBUG, "strings 1 " << str1 << " 4 " << str4 ); + string::size_type loc1= str1.find( str4, 0 ); + if ( loc1 != string::npos && str4 != "" ) { + SG_LOG( SG_INSTR, SG_DEBUG, " string found" ); + _mobile_lat = tanker[i]->getDoubleValue("position/latitude-deg"); + _mobile_lon = tanker[i]->getDoubleValue("position/longitude-deg"); + _mobile_elevation_ft = tanker[i]->getDoubleValue("position/altitude-ft"); + _mobile_range_nm = mobile_tacan->get_range(); + _mobile_bias = mobile_tacan->get_multiuse(); + _mobile_name = mobile_tacan->name(); + _mobile_ident = mobile_tacan->get_trans_ident(); + _mobile_valid = true; + SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter valid " << _mobile_valid ); + break; + } else { + _mobile_valid = false; + SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter invalid " << _mobile_valid ); } } - - SG_LOG( SG_INSTR, SG_DEBUG, "tanker name " << _mobile_name); - SG_LOG( SG_INSTR, SG_DEBUG, "lat " << _mobile_lat << "lon " << _mobile_lon); - SG_LOG( SG_INSTR, SG_DEBUG, "elev " << _mobile_elevation_ft); - SG_LOG( SG_INSTR, SG_DEBUG, "range " << _mobile_range_nm); } //try any mp tankers third, if we haven't found the tanker in the ai aircraft @@ -398,7 +391,7 @@ TACAN::search (double frequency_mhz, double longitude_rad, _mobile_elevation_ft = mp_tanker[i]->getDoubleValue("position/altitude-ft"); _mobile_range_nm = mobile_tacan->get_range(); _mobile_bias = mobile_tacan->get_multiuse(); - _mobile_name = mobile_tacan->get_name(); + _mobile_name = mobile_tacan->name(); _mobile_ident = mobile_tacan->get_trans_ident(); _mobile_valid = true; @@ -421,19 +414,18 @@ TACAN::search (double frequency_mhz, double longitude_rad, } // try the TACAN/VORTAC list next - FGNavRecord *tacan - = globals->get_tacanlist()->findByFreq( frequency_mhz, longitude_rad, - latitude_rad, altitude_m); + FGNavRecord *tacan = globals->get_tacanlist()->findByFreq( frequency_mhz, + SGGeod::fromRadM(longitude_rad, latitude_rad, altitude_m)); _transmitter_valid = (tacan != NULL); if ( _transmitter_valid ) { SG_LOG( SG_INSTR, SG_DEBUG, "transmitter valid " << _transmitter_valid ); - _transmitter_pos = tacan->get_pos(); + _transmitter_pos = tacan->geod(); _transmitter_range_nm = tacan->get_range(); _transmitter_bias = tacan->get_multiuse(); - _transmitter_name = tacan->get_name(); + _transmitter_name = tacan->name(); _name_node->setStringValue(_transmitter_name.c_str()); _transmitter_ident = tacan->get_trans_ident(); _ident_node->setStringValue(_transmitter_ident.c_str());