From 7827e28ff3ab9e2d90634fb119cb3c0b68737678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20de=20l=27Hamaide?= Date: Mon, 19 Aug 2013 16:08:29 +0200 Subject: [PATCH] Fix range calculation for special frequencies Range for special freq was computed with previous freq, now they are always in range Use a global variable (_currentFreqKhz) in order to avoid a in main loop; now it's only on frequency change Fix a .size() > 0 for !.empty() --- src/Network/fgcom.cxx | 20 ++++++++++++++------ src/Network/fgcom.hxx | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Network/fgcom.cxx b/src/Network/fgcom.cxx index e3cb98f4d..5d9319c20 100644 --- a/src/Network/fgcom.cxx +++ b/src/Network/fgcom.cxx @@ -259,8 +259,9 @@ void FGCom::postinit() // Do the first call at start const double freq = _comm0_node->getDoubleValue(); + _currentFreqKhz = 10 * static_cast(freq * 100 + 0.25); std::string num = computePhoneNumber(freq, getAirportCode(freq)); - if( num.size() > 0 ) { + if( !num.empty() ) { SG_LOG( SG_IO, SG_INFO, "FGCom comm[0] number=" << num ); _callComm0 = iaxc_call(num.c_str()); } @@ -272,6 +273,9 @@ void FGCom::postinit() void FGCom::updateCall(bool& changed, int& callNo, double freqMHz) { + + _currentFreqKhz = 10 * static_cast(freqMHz * 100 + 0.25); + if (!changed) { if( !isInRange(freqMHz) ) { iaxc_dump_call_number(callNo); @@ -479,16 +483,14 @@ std::string FGCom::getAirportCode(const double& freq) { SGGeod aircraftPos = globals->get_aircraft_position(); - int freqKhz = 10 * static_cast(freq * 100 + 0.25); - for(size_t i=0; iget_aircraft_position(); double distNm = SGGeodesy::distanceNm(_aptPos, acftPos); double delta_elevation_ft = fabs(acftPos.getElevationFt() - _aptPos.getElevationFt()); diff --git a/src/Network/fgcom.hxx b/src/Network/fgcom.hxx index 0025d3f27..535e825ca 100644 --- a/src/Network/fgcom.hxx +++ b/src/Network/fgcom.hxx @@ -79,6 +79,7 @@ class FGCom : public SGSubsystem, public SGPropertyChangeListener int _callComm0; //int _callComm1; int _listener_active; + int _currentFreqKhz; std::string _server; std::string _callsign; std::string _username;