From 7961f12e81af3f41c9bd0f5793bd7d608c59e496 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 23 Feb 2021 13:51:27 +0000 Subject: [PATCH] CommRadio: capture current behaviour for EPLL --- .../Instrumentation/test_commRadio.cxx | 76 ++++++++++++++++--- .../Instrumentation/test_commRadio.hxx | 8 ++ 2 files changed, 75 insertions(+), 9 deletions(-) diff --git a/test_suite/unit_tests/Instrumentation/test_commRadio.cxx b/test_suite/unit_tests/Instrumentation/test_commRadio.cxx index 7b4e04280..2df1204e2 100644 --- a/test_suite/unit_tests/Instrumentation/test_commRadio.cxx +++ b/test_suite/unit_tests/Instrumentation/test_commRadio.cxx @@ -38,19 +38,14 @@ void CommRadioTests::tearDown() // return buf; // } -void CommRadioTests::testBasic() -{ -} - -void CommRadioTests::testEightPointThree() +SGSubsystemRef CommRadioTests::setupStandardRadio(const std::string& name, int index, bool enable833) { SGPropertyNode_ptr configNode(new SGPropertyNode); - configNode->setStringValue("name", "commtest"); - configNode->setIntValue("number", 2); - configNode->setBoolValue("eight-point-three", true); + configNode->setStringValue("name", name); + configNode->setIntValue("number", index); + configNode->setBoolValue("eight-point-three", enable833); auto r = Instrumentation::CommRadio::createInstance(configNode); - fgSetBool("/sim/atis/enabled", false); r->bind(); @@ -58,6 +53,18 @@ void CommRadioTests::testEightPointThree() globals->add_subsystem("comm-radio", r); + return r; +} + +void CommRadioTests::testBasic() +{ +} + +void CommRadioTests::testEightPointThree() +{ + auto r = setupStandardRadio("commtest", 2, true); + + FGAirportRef apt = FGAirport::getByIdent("EGKK"); FGTestApi::setPositionAndStabilise(apt->geod()); @@ -104,6 +111,7 @@ void CommRadioTests::testEightPointThree() CPPUNIT_ASSERT_EQUAL(326, n->getIntValue("frequencies/selected-channel")); CPPUNIT_ASSERT_DOUBLES_EQUAL(120.03333, n->getDoubleValue("frequencies/selected-real-frequency-mhz"), 1e-6); + // under-run the permitted frequency range n->setDoubleValue("frequencies/selected-mhz", 117.99); r->update(1.0); CPPUNIT_ASSERT_DOUBLES_EQUAL(25.0, n->getDoubleValue("frequencies/selected-channel-width-khz"), 1e-3); @@ -115,4 +123,54 @@ void CommRadioTests::testEightPointThree() CPPUNIT_ASSERT_EQUAL("118.705"s, string{n->getStringValue("frequencies/selected-mhz-fmt")}); CPPUNIT_ASSERT_EQUAL(113, n->getIntValue("frequencies/selected-channel")); CPPUNIT_ASSERT_DOUBLES_EQUAL(118.700, n->getDoubleValue("frequencies/selected-real-frequency-mhz"), 1e-6); + + // over-run the frequency range + n->setDoubleValue("frequencies/selected-mhz", 137.000); + r->update(1.0); + CPPUNIT_ASSERT_DOUBLES_EQUAL(8.33, n->getDoubleValue("frequencies/selected-channel-width-khz"), 1e-3); + CPPUNIT_ASSERT_EQUAL("136.990"s, string{n->getStringValue("frequencies/selected-mhz-fmt")}); + CPPUNIT_ASSERT_EQUAL(3039, n->getIntValue("frequencies/selected-channel")); + CPPUNIT_ASSERT_DOUBLES_EQUAL(136.99166, n->getDoubleValue("frequencies/selected-real-frequency-mhz"), 1e-6); +} + +void CommRadioTests::testEPLLTuning833() +{ + auto r = setupStandardRadio("commtest", 2, true); + + FGAirportRef apt = FGAirport::getByIdent("EPLL"); + FGTestApi::setPositionAndStabilise(apt->geod()); + + SGPropertyNode_ptr n = globals->get_props()->getNode("instrumentation/commtest[2]"); + // should be EPLL TWR + n->setDoubleValue("frequencies/selected-mhz", 124.23); + r->update(1.0); + + CPPUNIT_ASSERT_EQUAL("EPLL"s, string{n->getStringValue("airport-id")}); + CPPUNIT_ASSERT_EQUAL("Lodz TOWER"s, string{n->getStringValue("station-name")}); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, n->getDoubleValue("slant-distance-m"), 1e-6); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, n->getDoubleValue("signal-quality-norm"), 1e-6); +} + +void CommRadioTests::testEPLLTuning25() +{ + auto r = setupStandardRadio("commtest", 2, false); + + FGAirportRef apt = FGAirport::getByIdent("EPLL"); + FGTestApi::setPositionAndStabilise(apt->geod()); + + SGPropertyNode_ptr n = globals->get_props()->getNode("instrumentation/commtest[2]"); + // should be EPLL TWR + n->setDoubleValue("frequencies/selected-mhz", 124.23); + r->update(1.0); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(124.23, n->getDoubleValue("frequencies/selected-mhz"), 1e-6); + CPPUNIT_ASSERT_EQUAL("124.22"s, string{n->getStringValue("frequencies/selected-mhz-fmt")}); + + // fail for now +#if 0 + CPPUNIT_ASSERT_EQUAL("EPLL"s, string{n->getStringValue("airport-id")}); + CPPUNIT_ASSERT_EQUAL("Lodz TOWER"s, string{n->getStringValue("station-name")}); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, n->getDoubleValue("slant-distance-m"), 1e-6); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, n->getDoubleValue("signal-quality-norm"), 1e-6); +#endif } diff --git a/test_suite/unit_tests/Instrumentation/test_commRadio.hxx b/test_suite/unit_tests/Instrumentation/test_commRadio.hxx index 3b3cd7af3..ac7c3382e 100644 --- a/test_suite/unit_tests/Instrumentation/test_commRadio.hxx +++ b/test_suite/unit_tests/Instrumentation/test_commRadio.hxx @@ -24,6 +24,8 @@ #include #include +#include + class FGNavRadio; class SGGeod; @@ -35,9 +37,13 @@ class CommRadioTests : public CppUnit::TestFixture CPPUNIT_TEST(testBasic); CPPUNIT_TEST(testEightPointThree); + CPPUNIT_TEST(testEPLLTuning833); + CPPUNIT_TEST(testEPLLTuning25); CPPUNIT_TEST_SUITE_END(); + SGSubsystemRef setupStandardRadio(const std::string& name, int index, bool enable833); + public: // Set up function for each test. void setUp(); @@ -50,4 +56,6 @@ public: // The tests. void testBasic(); void testEightPointThree(); + void testEPLLTuning833(); + void testEPLLTuning25(); };