]> git.mxchange.org Git - flightgear.git/commitdiff
Fix range calculation for special frequencies
authorClément de l'Hamaide <clemaez@hotmail.fr>
Mon, 19 Aug 2013 14:08:29 +0000 (16:08 +0200)
committerClément de l'Hamaide <clemaez@hotmail.fr>
Mon, 19 Aug 2013 14:08:29 +0000 (16:08 +0200)
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 <static_cast> in main loop; now it's only on frequency change
Fix a .size() > 0 for !.empty()

src/Network/fgcom.cxx
src/Network/fgcom.hxx

index e3cb98f4d420a28400181eca98794a0d841b34cc..5d9319c2053139b9eaf2d7a94354ec2858200205 100644 (file)
@@ -259,8 +259,9 @@ void FGCom::postinit()
 
     // Do the first call at start
     const double freq = _comm0_node->getDoubleValue();
+    _currentFreqKhz = 10 * static_cast<int>(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<int>(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<int>(freq * 100 + 0.25);
-
   for(size_t i=0; i<sizeof(special_freq)/sizeof(special_freq[0]); i++) { // Check if it's a special freq
-    if(special_freq[i] == freqKhz) {
-      SG_LOG( SG_IO, SG_INFO, "FGCom getAirportCode: " << freqKhz << " is specially associated to " << NULL_ICAO );
+    if(special_freq[i] == _currentFreqKhz) {
+      SG_LOG( SG_IO, SG_INFO, "FGCom getAirportCode: " << freq << " is specially associated to " << NULL_ICAO );
       return NULL_ICAO;
     }
   }
 
-  flightgear::CommStation* apt = flightgear::CommStation::findByFreq(freqKhz, aircraftPos);
+  flightgear::CommStation* apt = flightgear::CommStation::findByFreq(_currentFreqKhz, aircraftPos);
   if( !apt ) {
     SG_LOG( SG_IO, SG_INFO, "FGCom getAirportCode: not found" );
     return std::string();
@@ -571,6 +573,12 @@ std::string FGCom::computePhoneNumber(const double& freq, const std::string& ica
 
 bool FGCom::isInRange(const double &freq) const
 {
+    for(size_t i=0; i<sizeof(special_freq)/sizeof(special_freq[0]); i++) { // Check if it's a special freq
+      if( (special_freq[i]) == _currentFreqKhz ) {
+        return 1;
+      }
+    }
+
     SGGeod acftPos = globals->get_aircraft_position();
     double distNm = SGGeodesy::distanceNm(_aptPos, acftPos);
     double delta_elevation_ft = fabs(acftPos.getElevationFt() - _aptPos.getElevationFt());
index 0025d3f270d2d7a2ea405507990da217cd9f3039..535e825caf65b8b6d1f6fd522860c7a3b2367bc0 100644 (file)
@@ -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;