diff --git a/test_suite/unit_tests/Instrumentation/test_navRadio.cxx b/test_suite/unit_tests/Instrumentation/test_navRadio.cxx index c7ab1cd7a..03b1ebd92 100644 --- a/test_suite/unit_tests/Instrumentation/test_navRadio.cxx +++ b/test_suite/unit_tests/Instrumentation/test_navRadio.cxx @@ -1,11 +1,14 @@ #include "test_navRadio.hxx" +#include #include +#include #include #include "test_suite/FGTestApi/testGlobals.hxx" #include "test_suite/FGTestApi/NavDataCache.hxx" +#include
#include #include #include @@ -837,3 +840,92 @@ void NavRadioTests::testGlideslopeLongDistance() CPPUNIT_ASSERT_EQUAL(false, node->getBoolValue("gs-in-range")); CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("in-range")); } + +void NavRadioTests::testVORSignalQuality() +{ + std::unique_ptr r = testVORSignalQuality_setup("navtest", 2); + SGPropertyNode* node = fgGetNode("/instrumentation/navtest[2]"); + + SGGeod pos = SGGeod::fromDegFt(-3.35277800, 55.499167, 20000); + setPositionAndStabilise(r.get(), pos); + // The signal quality should be good here + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, + node->getDoubleValue("signal-quality-norm"), + 0.01); + + // 2786 feet is the navaid altitude above sea level, according to nav.dat. + // I believe 150000 is high enough, however I'm not knowledgeable in this + // field. + pos = SGGeod::fromDegFt(-3.35277800, 55.499167, 2786 + 150000); + setPositionAndStabilise(r.get(), pos); + // Too high for a good signal here + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, + node->getDoubleValue("signal-quality-norm"), + 0.01); + r.reset(); + + // Test that changing the standby frequency doesn't affect the rate of + // change of signal quality (it has no reason to disable the low-pass + // filter). + double rate1 = testVORSignalQuality_maxRateOfChange(false); + double rate2 = testVORSignalQuality_maxRateOfChange(true); + // At the time of this writing, rate1 == rate2, however randomness, signal + // quality affected by weather... might be added in the future. + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, rate2 / rate1, 0.01); +} + +std::unique_ptr +NavRadioTests::testVORSignalQuality_setup(const std::string& name, int index) +{ + SGPropertyNode_ptr configNode(new SGPropertyNode); + configNode->setStringValue("name", name); + configNode->setIntValue("number", index); + auto r = std::make_unique(configNode); + r->bind(); + r->init(); + + SGPropertyNode* node = fgGetNode("/instrumentation/" + name, index); + node->setBoolValue("serviceable", true); + // Needed for the radio to power up + fgSetDouble("/systems/electrical/outputs/nav", 6.0); + node->setDoubleValue("frequencies/selected-mhz", 113.8); + node->setDoubleValue("frequencies/standby-mhz", 112.4); // whatever + + return r; +} + +// Rise above the selected VOR station and measure how quickly the signal +// quality diminishes. Return the largest variation seen between two +// consecutive positions. +// +// When the low-pass filter is disabled, the return value is larger (by a +// factor of approximately four with the FG code from November 2022). +double +NavRadioTests::testVORSignalQuality_maxRateOfChange(bool changeStandbyFreq) +{ + std::unique_ptr r = testVORSignalQuality_setup("navtest", 2); + SGPropertyNode* node = fgGetNode("/instrumentation/navtest[2]"); + + double currAlt = 2786 + 65000; // in feet, above MSL + double maxChange = 0.0; + double signalQuality, lastSignalQuality = 1.0; + + for (int i = 0; i < 1000; i++) { + currAlt += 20; + SGGeod pos = SGGeod::fromDegFt(-3.35277800, 55.499167, currAlt); + FGTestApi::setPosition(pos); + + if (changeStandbyFreq) { + node->setDoubleValue("frequencies/standby-mhz", + (i % 2) ? 112.2 : 112.5); + } + r->update(0.01); + + signalQuality = node->getDoubleValue("signal-quality-norm"); + maxChange = std::max(maxChange, + std::abs(signalQuality - lastSignalQuality)); + lastSignalQuality = signalQuality; + } + + return maxChange; +} diff --git a/test_suite/unit_tests/Instrumentation/test_navRadio.hxx b/test_suite/unit_tests/Instrumentation/test_navRadio.hxx index 438d2ef3c..119f30acc 100644 --- a/test_suite/unit_tests/Instrumentation/test_navRadio.hxx +++ b/test_suite/unit_tests/Instrumentation/test_navRadio.hxx @@ -21,6 +21,8 @@ #ifndef _FG_NAVRADIO_UNIT_TESTS_HXX #define _FG_NAVRADIO_UNIT_TESTS_HXX +#include +#include #include #include @@ -48,9 +50,14 @@ class NavRadioTests : public CppUnit::TestFixture CPPUNIT_TEST(testILSAdjacentPaired); CPPUNIT_TEST(testGlideslopeLongDistance); + CPPUNIT_TEST(testVORSignalQuality); + CPPUNIT_TEST_SUITE_END(); void setPositionAndStabilise(FGNavRadio* r, const SGGeod& g); + std::unique_ptr testVORSignalQuality_setup( + const std::string& name, int index); + double testVORSignalQuality_maxRateOfChange(bool changeStandbyFreq); public: // Set up function for each test. @@ -76,6 +83,8 @@ public: void testILSPaired(); void testILSAdjacentPaired(); void testGlideslopeLongDistance(); + + void testVORSignalQuality(); };