diff --git a/Source/Components/DataSources/NI9157/CounterChecker.cpp b/Source/Components/DataSources/NI9157/CounterChecker.cpp index 5b5e61e54029934cb2ab27e41e3e36979c279af1..bdda922fd664c2e5169a56b8495cb286591ae5ea 100644 --- a/Source/Components/DataSources/NI9157/CounterChecker.cpp +++ b/Source/Components/DataSources/NI9157/CounterChecker.cpp @@ -91,7 +91,7 @@ bool CounterChecker::Initialise(StructuredDataI &data) { if (ret) { ret = ((checkCounterAfterNSteps % counterStep) == 0u); if (!ret) { - REPORT_ERROR(ErrorManagement::InitialisationError, "CounterChecker::Initialise CheckCounterAfterNPackets=%d must divide exactly CounterStep=%d", checkCounterAfterNSteps, counterStep); + REPORT_ERROR(ErrorManagement::InitialisationError, "CounterChecker::Initialise CheckCounterAfterNPackets=%d must be divided exactly by CounterStep=%d", checkCounterAfterNSteps, counterStep); } else { ret = (((acquireFromCounter - packetCounter) % counterStep) == 0u); @@ -115,28 +115,27 @@ bool CounterChecker::Check(uint8 *sample, bool &write) { bool ret = true; - write = true; if (packetCounter == nextPacketCheck) { ret = (MemoryOperationsHelper::Compare(&packetCounter, sample, sampleSize) == 0); + nextPacketCheck = (packetCounter + checkCounterAfterNSteps); } if (ret) { - nextPacketCheck = (packetCounter + checkCounterAfterNSteps); packetCounter += counterStep; //before the first packet, check each packet if (acquireFromCounter > 0ull) { /*lint -e{340} -e{928} -e{927} -e{826} -e{740} Allowed cast from pointer to pointer*/ /*lint -e{613} NULL pointer checked*/ - if (MemoryOperationsHelper::Compare(&(sample[0]), reinterpret_cast<uint8*>((&acquireFromCounter)), sampleSize) != 0) { + if (MemoryOperationsHelper::Compare(sample, reinterpret_cast<uint8*>((&acquireFromCounter)), sampleSize) != 0) { nextPacketCheck = packetCounter; - //return without adding nothing to the circular buffer - write = false; + //return without adding nothing to the circular buffer (write=false) } else { acquireFromCounter = 0ull; } } } + write = (acquireFromCounter == 0ull); return ret; } diff --git a/Source/Components/DataSources/NI9157/CounterChecker.h b/Source/Components/DataSources/NI9157/CounterChecker.h index 4607241ac802dc5971f75a47786e86caf4ce9d4c..92fc452c85ce88240e4d62a3f8b4eb67fffe30b1 100644 --- a/Source/Components/DataSources/NI9157/CounterChecker.h +++ b/Source/Components/DataSources/NI9157/CounterChecker.h @@ -77,7 +77,7 @@ public: * CounterStep: The step used in the counter interations. Default is value * is 1 and the user set value must be greater than zero. \n * CheckCounterAfterNSteps: After how many counts should the check be - * perfromed. If not defined, the default value is the CounterStep value. + * performed. If not defined, the default value is the CounterStep value. */ virtual bool Initialise(StructuredDataI &data); diff --git a/Source/Components/DataSources/NI9157/NI9157CircularFifoReader.cpp b/Source/Components/DataSources/NI9157/NI9157CircularFifoReader.cpp index 82a508dc2f3e12271b74ddc52dfbf868834d3a84..de080c767846d4fb20e709aeea49ebe049b7c1e7 100644 --- a/Source/Components/DataSources/NI9157/NI9157CircularFifoReader.cpp +++ b/Source/Components/DataSources/NI9157/NI9157CircularFifoReader.cpp @@ -281,7 +281,7 @@ bool NI9157CircularFifoReader::PrepareNextState(const char8 * const currentState bool NI9157CircularFifoReader::DriverRead(char8 * const bufferToFill, uint32 &sizeToRead, const uint32 signalIdx) { bool ret = true; - bool writeMemory = false; + bool writeMemory = true; //REPORT_ERROR(ErrorManagement::Information, "NI9157CircularFifoReader::DriverRead"); if (runNi == 1u) { diff --git a/Test/Components/DataSources/NI9157/CounterCheckerGTest.cpp b/Test/Components/DataSources/NI9157/CounterCheckerGTest.cpp index 2fec6b5860e4ca2fda3fcb87a2d4bd4e111e1e4c..4518c6f6b03863287c7a7cf67cec66eb25527e36 100644 --- a/Test/Components/DataSources/NI9157/CounterCheckerGTest.cpp +++ b/Test/Components/DataSources/NI9157/CounterCheckerGTest.cpp @@ -115,6 +115,11 @@ TEST(CounterCheckerGTest,TestCheck_ConsecutiveCalls) { ASSERT_TRUE(test.TestCheck_ConsecutiveCalls()); } +TEST(CounterCheckerGTest,TestCheck_ConsecutiveCalls_NSteps) { + CounterCheckerTest test; + ASSERT_TRUE(test.TestCheck_ConsecutiveCalls_NSteps()); +} + TEST(CounterCheckerGTest,TestSynchronise) { CounterCheckerTest test; ASSERT_TRUE(test.TestSynchronise()); diff --git a/Test/Components/DataSources/NI9157/CounterCheckerTest.cpp b/Test/Components/DataSources/NI9157/CounterCheckerTest.cpp index 37b3da11a3d7425eddda47108c99676aecdc385b..448d630fa58922b618dafec9016ca9bc119c2455 100644 --- a/Test/Components/DataSources/NI9157/CounterCheckerTest.cpp +++ b/Test/Components/DataSources/NI9157/CounterCheckerTest.cpp @@ -563,7 +563,7 @@ bool CounterCheckerTest::TestCheck_ReturnFalse() { bool aWrite = false; uint64 aSample = 128ull; ret = !aCounterChecker->Check(reinterpret_cast<uint8 *>(&aSample), aWrite); - ret &= aWrite; + ret &= !aWrite; } if (ret) { ret = (aCounterChecker->GetAcquireFromCounter() == 1ull); @@ -622,6 +622,57 @@ bool CounterCheckerTest::TestCheck_ConsecutiveCalls() { return ret; } + +bool CounterCheckerTest::TestCheck_ConsecutiveCalls_NSteps() { + + HeapManager::AddHeap(GlobalObjectsDatabase::Instance()->GetStandardHeap()); + ConfigurationDatabase cdb; + StreamString configStream = counterCheckerTestconfig0; + configStream.Seek(0); + StandardParser parser(configStream, cdb); + bool ret = parser.Parse(); + + if (ret) { + ret = cdb.MoveAbsolute("+ACounterChecker"); + ret &= cdb.Write("AcquireFromCounter", "0"); + ret &= cdb.Write("CounterStep", "2"); + ret &= cdb.Write("CheckCounterAfterNSteps", "8"); + ret &= cdb.MoveToRoot(); + } + + ObjectRegistryDatabase *god = ObjectRegistryDatabase::Instance(); + if (ret) { + god->Purge(); + ret = god->Initialise(cdb); + } + ReferenceT<CounterCheckerTestHelper> aCounterChecker; + if (ret) { + aCounterChecker = ObjectRegistryDatabase::Instance()->Find("ACounterChecker"); + ret = aCounterChecker.IsValid(); + } + if (ret) { + ret = (aCounterChecker->GetPacketCounter() == 2ull); + ret &= (aCounterChecker->GetAcquireFromCounter() == 0ull); + ret &= (aCounterChecker->GetCounterStep() == 2u); + ret &= (aCounterChecker->GetCheckCounterAfterNSteps() == 8u); + ret &= (aCounterChecker->GetNextPacketCheck() == 2ull); + ret &= (aCounterChecker->GetSampleSize() == 8u); + ret &= (aCounterChecker->GetNFrameForSync() == 2u); + } + uint64 aSample = 0ull; + bool aWrite = false; + uint32 runs = 13u; + for (uint32 i = 0u; (i < runs) && (ret) ; i++) { + aSample += aCounterChecker->GetCounterStep(); + ret = aCounterChecker->Check(reinterpret_cast<uint8 *>(&aSample), aWrite); + ret &= aWrite; + } + + ObjectRegistryDatabase::Instance()->Purge(); + return ret; +} + + bool CounterCheckerTest::TestSynchronise() { HeapManager::AddHeap(GlobalObjectsDatabase::Instance()->GetStandardHeap()); diff --git a/Test/Components/DataSources/NI9157/CounterCheckerTest.h b/Test/Components/DataSources/NI9157/CounterCheckerTest.h index 94e8b78260180326bc6c1f400a30d35c55df9f2f..ebded2c21c9da48732069b3d79eac20185eb6186 100644 --- a/Test/Components/DataSources/NI9157/CounterCheckerTest.h +++ b/Test/Components/DataSources/NI9157/CounterCheckerTest.h @@ -147,6 +147,12 @@ public: */ bool TestCheck_ConsecutiveCalls(); + /** + * @brief Tests the CounterChecker::Check method which retruns true and + * with argument write true upon consecutive calls (increments) and check every N steps. + */ + bool TestCheck_ConsecutiveCalls_NSteps(); + /** * @brief Tests the CounterChecker::Synchronise method. */