diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml index c159b7ed63..f553b04b78 100644 --- a/.github/workflows/format-check.yml +++ b/.github/workflows/format-check.yml @@ -31,11 +31,16 @@ jobs: env: # Svc is currently listing all but Svc/FpySequencer CHECKED_DIRS: >- + CFDP + default Drv FppTestProject Fw Os + Ref Svc + TestUtils + Utils run: | fprime-util format --check --dirs $CHECKED_DIRS diff --git a/CFDP/Checksum/Checksum.cpp b/CFDP/Checksum/Checksum.cpp index 193acf508b..0ce10e845e 100644 --- a/CFDP/Checksum/Checksum.cpp +++ b/CFDP/Checksum/Checksum.cpp @@ -14,133 +14,83 @@ #include "Fw/Types/Assert.hpp" static U32 min(const U32 a, const U32 b) { - return (a < b) ? a : b; + return (a < b) ? a : b; } namespace CFDP { - Checksum :: - Checksum() : m_value(0) - { +Checksum ::Checksum() : m_value(0) {} - } +Checksum ::Checksum(const U32 value) : m_value(value) {} - Checksum :: - Checksum(const U32 value) : m_value(value) - { - - } - - Checksum :: - Checksum(const Checksum &original) - { +Checksum ::Checksum(const Checksum& original) { this->m_value = original.getValue(); - } +} - Checksum :: - ~Checksum() - { +Checksum ::~Checksum() {} - } - - Checksum& Checksum :: - operator=(const Checksum& checksum) - { +Checksum& Checksum ::operator=(const Checksum& checksum) { this->m_value = checksum.m_value; return *this; - } +} - bool Checksum :: - operator==(const Checksum& checksum) const - { +bool Checksum ::operator==(const Checksum& checksum) const { return this->m_value == checksum.m_value; - } +} - bool Checksum :: - operator!=(const Checksum& checksum) const - { - return not (*this == checksum); - } +bool Checksum ::operator!=(const Checksum& checksum) const { + return not(*this == checksum); +} - U32 Checksum :: - getValue() const - { +U32 Checksum ::getValue() const { return this->m_value; - } +} - void Checksum :: - update( - const U8 *const data, - const U32 offset, - const U32 length - ) - { +void Checksum ::update(const U8* const data, const U32 offset, const U32 length) { U32 index = 0; // Add the first word unaligned if necessary const U32 offsetMod4 = offset % 4; if (offsetMod4 != 0) { - const U8 wordLength = static_cast(min(length, 4 - offsetMod4)); - this->addWordUnaligned( - &data[index], - static_cast(offset + index), - wordLength - ); - index += wordLength; + const U8 wordLength = static_cast(min(length, 4 - offsetMod4)); + this->addWordUnaligned(&data[index], static_cast(offset + index), wordLength); + index += wordLength; } // Add the middle words aligned - for ( ; index + 4 <= length; index += 4) { - addWordAligned(&data[index]); + for (; index + 4 <= length; index += 4) { + addWordAligned(&data[index]); } // Add the last word unaligned if necessary if (index < length) { - const U8 wordLength = static_cast(length - index); - this->addWordUnaligned( - &data[index], - static_cast(offset + index), - wordLength - ); + const U8 wordLength = static_cast(length - index); + this->addWordUnaligned(&data[index], static_cast(offset + index), wordLength); } +} - } - - void Checksum :: - addWordAligned(const U8 *const word) - { +void Checksum ::addWordAligned(const U8* const word) { for (U8 i = 0; i < 4; ++i) { - addByteAtOffset(word[i], i); + addByteAtOffset(word[i], i); } - } +} - void Checksum :: - addWordUnaligned( - const U8 *word, - const U8 position, - const U8 length - ) - { +void Checksum ::addWordUnaligned(const U8* word, const U8 position, const U8 length) { FW_ASSERT(length < 4); U8 offset = position % 4; for (U8 i = 0; i < length; ++i) { - addByteAtOffset(word[i], offset); - ++offset; - if (offset == 4) { - offset = 0; - } + addByteAtOffset(word[i], offset); + ++offset; + if (offset == 4) { + offset = 0; + } } - } - - void Checksum :: - addByteAtOffset( - const U8 byte, - const U8 offset - ) - { - FW_ASSERT(offset < 4); - const U32 addend = static_cast(byte) << (8*(3-offset)); - this->m_value += addend; - } - } + +void Checksum ::addByteAtOffset(const U8 byte, const U8 offset) { + FW_ASSERT(offset < 4); + const U32 addend = static_cast(byte) << (8 * (3 - offset)); + this->m_value += addend; +} + +} // namespace CFDP diff --git a/CFDP/Checksum/Checksum.hpp b/CFDP/Checksum/Checksum.hpp index 9b47d45c00..a2a032171b 100644 --- a/CFDP/Checksum/Checksum.hpp +++ b/CFDP/Checksum/Checksum.hpp @@ -17,130 +17,120 @@ namespace CFDP { - //! \class Checksum - //! \brief Class representing a 32-bit checksum as mandated by the CCSDS File - //! Delivery Protocol. - //! - //! This checksum is calculated by update of an existing 32-bit value - //! with the "next" 32-bit string drawn from the file data. Beginning - //! at the start of the file, a 4-byte window moves up the file by four - //! bytes per update. The update itself replaces the existing checksum - //! with the byte-wise sum of the existing checksum and the file data - //! contained in the window. Overflows in the addition are permitted - //! and the carry discarded. - //! - //! If an update is to be made beginning at an offset into the file - //! which is not aligned to a 4-byte boundary, the window is treated - //! as beginning at the last 4-byte boundary, but is left-zero-padded. - //! Similarly, where the file data for an update ends on an unaligned - //! byte, the window extends up to the next boundary and is - //! right-zero-padded. - //! - //! ## Example - //! - //! For buffer 0xDE 0xAD 0xBE 0xEF 0xCA 0xFE and initial zero checksum: - //! - //! ------------------------------------ Update 1 - //! Window 0xDE 0xAD 0xBE 0xEF - //! Checksum 0xDEADBEEF - //! - //! ------------------------------------ Update 2 - //! Window 0xCA 0xFE - //! Checksum 0xDEADBEEF+ - //! 0xCAFE0000 - //! ---------- - //! 0xA8ABBEEF <- Final value - class Checksum { +//! \class Checksum +//! \brief Class representing a 32-bit checksum as mandated by the CCSDS File +//! Delivery Protocol. +//! +//! This checksum is calculated by update of an existing 32-bit value +//! with the "next" 32-bit string drawn from the file data. Beginning +//! at the start of the file, a 4-byte window moves up the file by four +//! bytes per update. The update itself replaces the existing checksum +//! with the byte-wise sum of the existing checksum and the file data +//! contained in the window. Overflows in the addition are permitted +//! and the carry discarded. +//! +//! If an update is to be made beginning at an offset into the file +//! which is not aligned to a 4-byte boundary, the window is treated +//! as beginning at the last 4-byte boundary, but is left-zero-padded. +//! Similarly, where the file data for an update ends on an unaligned +//! byte, the window extends up to the next boundary and is +//! right-zero-padded. +//! +//! ## Example +//! +//! For buffer 0xDE 0xAD 0xBE 0xEF 0xCA 0xFE and initial zero checksum: +//! +//! ------------------------------------ Update 1 +//! Window 0xDE 0xAD 0xBE 0xEF +//! Checksum 0xDEADBEEF +//! +//! ------------------------------------ Update 2 +//! Window 0xCA 0xFE +//! Checksum 0xDEADBEEF+ +//! 0xCAFE0000 +//! ---------- +//! 0xA8ABBEEF <- Final value +class Checksum { + public: + // ---------------------------------------------------------------------- + // Types + // ---------------------------------------------------------------------- - public: + public: + // ---------------------------------------------------------------------- + // Construction and destruction + // ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Types - // ---------------------------------------------------------------------- + //! Construct a fresh Checksum object. + Checksum(); - public: + //! Construct a Checksum object and initialize it with a value. + Checksum(const U32 value); - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- + //! Copy a Checksum object. + Checksum(const Checksum& original); - //! Construct a fresh Checksum object. - Checksum(); + //! Destroy a Checksum object. + ~Checksum(); - //! Construct a Checksum object and initialize it with a value. - Checksum(const U32 value); + public: + // ---------------------------------------------------------------------- + // Public instance methods + // ---------------------------------------------------------------------- - //! Copy a Checksum object. - Checksum(const Checksum &original); + //! Assign checksum to this. + Checksum& operator=(const Checksum& checksum); - //! Destroy a Checksum object. - ~Checksum(); + //! Compare checksum and this for equality. + bool operator==(const Checksum& checksum) const; - public: + //! Compare checksum and this for inequality. + bool operator!=(const Checksum& checksum) const; - // ---------------------------------------------------------------------- - // Public instance methods - // ---------------------------------------------------------------------- + //! Update the checksum value by accumulating words in the given data. + //! + //! \important The data and data-length passed to this method are specifically + //! those over which the update is made, rather than the entire + //! file. Typically, therefore, `data` will be a pointer to the + //! byte given by the offset, e.g. `&file_buffer[offset]`. + //! + void update(const U8* const data, //!< Beginning of the data over which to update. + const U32 offset, //!< Offset into the file at which the data begins. + const U32 length //!< Length of the update data in bytes. + ); - //! Assign checksum to this. - Checksum& operator=(const Checksum& checksum); + //! Get the checksum value + U32 getValue() const; - //! Compare checksum and this for equality. - bool operator==(const Checksum& checksum) const; + private: + // ---------------------------------------------------------------------- + // Private instance methods + // ---------------------------------------------------------------------- - //! Compare checksum and this for inequality. - bool operator!=(const Checksum& checksum) const; + //! Add a four-byte aligned word to the checksum value + void addWordAligned(const U8* const word //! The word + ); - //! Update the checksum value by accumulating words in the given data. - //! - //! \important The data and data-length passed to this method are specifically - //! those over which the update is made, rather than the entire - //! file. Typically, therefore, `data` will be a pointer to the - //! byte given by the offset, e.g. `&file_buffer[offset]`. - //! - void update(const U8* const data, //!< Beginning of the data over which to update. - const U32 offset, //!< Offset into the file at which the data begins. - const U32 length //!< Length of the update data in bytes. - ); + //! Add a four-byte unaligned word to the checksum value + void addWordUnaligned(const U8* const word, //! The word + const U8 position, //! The position of the word relative to the start of the file + const U8 length //! The number of valid bytes in the word + ); - //! Get the checksum value - U32 getValue() const; + //! Add byte to value at offset in word + void addByteAtOffset(const U8 byte, //! The byte + const U8 offset //! The offset + ); - private: + private: + // ---------------------------------------------------------------------- + // Private member variables + // ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Private instance methods - // ---------------------------------------------------------------------- + //! The accumulated checksum value + U32 m_value; +}; - //! Add a four-byte aligned word to the checksum value - void addWordAligned( - const U8 *const word //! The word - ); - - //! Add a four-byte unaligned word to the checksum value - void addWordUnaligned( - const U8 *const word, //! The word - const U8 position, //! The position of the word relative to the start of the file - const U8 length //! The number of valid bytes in the word - ); - - //! Add byte to value at offset in word - void addByteAtOffset( - const U8 byte, //! The byte - const U8 offset //! The offset - ); - - private: - - // ---------------------------------------------------------------------- - // Private member variables - // ---------------------------------------------------------------------- - - //! The accumulated checksum value - U32 m_value; - - }; - -} +} // namespace CFDP #endif diff --git a/CFDP/Checksum/GTest/Checksums.cpp b/CFDP/Checksum/GTest/Checksums.cpp index 6887ba56a7..ddfaa601e7 100644 --- a/CFDP/Checksum/GTest/Checksums.cpp +++ b/CFDP/Checksum/GTest/Checksums.cpp @@ -1,4 +1,4 @@ -// ====================================================================== +// ====================================================================== // \title CFDP/Checksum/GTest/Checksums.cpp // \author bocchino // \brief cpp file for CFDP Checksum gtest utilities @@ -7,26 +7,21 @@ // Copyright (C) 2016, California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. -// -// ====================================================================== +// +// ====================================================================== #include "CFDP/Checksum/GTest/Checksums.hpp" namespace CFDP { - namespace GTest { - - void Checksums :: - compare( - const CFDP::Checksum& expected, - const CFDP::Checksum& actual - ) - { - const U32 expectedValue = expected.getValue(); - const U32 actualValue = actual.getValue(); - ASSERT_EQ(expectedValue, actualValue); - } - - } +namespace GTest { +void Checksums ::compare(const CFDP::Checksum& expected, const CFDP::Checksum& actual) { + const U32 expectedValue = expected.getValue(); + const U32 actualValue = actual.getValue(); + ASSERT_EQ(expectedValue, actualValue); } + +} // namespace GTest + +} // namespace CFDP diff --git a/CFDP/Checksum/GTest/Checksums.hpp b/CFDP/Checksum/GTest/Checksums.hpp index 6f4f7f91de..f3eee9ff48 100644 --- a/CFDP/Checksum/GTest/Checksums.hpp +++ b/CFDP/Checksum/GTest/Checksums.hpp @@ -1,4 +1,4 @@ -// ====================================================================== +// ====================================================================== // \title CFDP/Checksum/GTest/Checksums.hpp // \author bocchino // \brief hpp file for CFDP Checksum gtest utilities @@ -7,8 +7,8 @@ // Copyright (C) 2016 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. -// -// ====================================================================== +// +// ====================================================================== #ifndef GTest_CFDP_Checksums_HPP #define GTest_CFDP_Checksums_HPP @@ -19,21 +19,20 @@ namespace CFDP { - namespace GTest { +namespace GTest { - //! Utilities for testing Checksum operations - //! - namespace Checksums { +//! Utilities for testing Checksum operations +//! +namespace Checksums { - void compare( - const CFDP::Checksum& expected, //!< Expected value - const CFDP::Checksum& actual //!< Actual value - ); - - } - - } +void compare(const CFDP::Checksum& expected, //!< Expected value + const CFDP::Checksum& actual //!< Actual value +); } +} // namespace GTest + +} // namespace CFDP + #endif diff --git a/CFDP/Checksum/test/ut/ChecksumMain.cpp b/CFDP/Checksum/test/ut/ChecksumMain.cpp index 5d40099c4a..47cf16ddc3 100644 --- a/CFDP/Checksum/test/ut/ChecksumMain.cpp +++ b/CFDP/Checksum/test/ut/ChecksumMain.cpp @@ -1,5 +1,5 @@ // ---------------------------------------------------------------------- -// Main.cpp +// Main.cpp // ---------------------------------------------------------------------- #include "gtest/gtest.h" @@ -8,49 +8,47 @@ using namespace CFDP; -const U8 data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; +const U8 data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; -const U32 expectedValue = - (data[0] << 3*8) + (data[1] << 2*8) + (data[2] << 1*8) + data[3] + - (data[4] << 3*8) + (data[5] << 2*8) + (data[6] << 1*8) + data[7]; +const U32 expectedValue = (data[0] << 3 * 8) + (data[1] << 2 * 8) + (data[2] << 1 * 8) + data[3] + (data[4] << 3 * 8) + + (data[5] << 2 * 8) + (data[6] << 1 * 8) + data[7]; TEST(Checksum, OnePacket) { - Checksum checksum; - checksum.update(data, 0, 8); - ASSERT_EQ(expectedValue, checksum.getValue()); + Checksum checksum; + checksum.update(data, 0, 8); + ASSERT_EQ(expectedValue, checksum.getValue()); } TEST(Checksum, TwoPacketsAligned) { - Checksum checksum; - checksum.update(&data[0], 0, 4); - checksum.update(&data[4], 4, 4); - ASSERT_EQ(expectedValue, checksum.getValue()); + Checksum checksum; + checksum.update(&data[0], 0, 4); + checksum.update(&data[4], 4, 4); + ASSERT_EQ(expectedValue, checksum.getValue()); } TEST(Checksum, TwoPacketsUnaligned1) { - Checksum checksum; - checksum.update(&data[0], 0, 3); - checksum.update(&data[3], 3, 5); - ASSERT_EQ(expectedValue, checksum.getValue()); + Checksum checksum; + checksum.update(&data[0], 0, 3); + checksum.update(&data[3], 3, 5); + ASSERT_EQ(expectedValue, checksum.getValue()); } TEST(Checksum, TwoPacketsUnaligned2) { - Checksum checksum; - checksum.update(&data[0], 0, 5); - checksum.update(&data[5], 5, 3); - ASSERT_EQ(expectedValue, checksum.getValue()); + Checksum checksum; + checksum.update(&data[0], 0, 5); + checksum.update(&data[5], 5, 3); + ASSERT_EQ(expectedValue, checksum.getValue()); } TEST(Checksum, ThreePackets) { - Checksum checksum; - checksum.update(&data[0], 0, 2); - checksum.update(&data[2], 2, 3); - checksum.update(&data[5], 5, 3); - ASSERT_EQ(expectedValue, checksum.getValue()); + Checksum checksum; + checksum.update(&data[0], 0, 2); + checksum.update(&data[2], 2, 3); + checksum.update(&data[5], 5, 3); + ASSERT_EQ(expectedValue, checksum.getValue()); } -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } - diff --git a/Ref/BlockDriver/BlockDriver.cpp b/Ref/BlockDriver/BlockDriver.cpp index 43358c8e21..80261a952b 100644 --- a/Ref/BlockDriver/BlockDriver.cpp +++ b/Ref/BlockDriver/BlockDriver.cpp @@ -1,31 +1,25 @@ -#include #include #include +#include namespace Ref { - BlockDriver::BlockDriver(const char* compName) : - BlockDriverComponentBase(compName), m_cycles(0) - {} +BlockDriver::BlockDriver(const char* compName) : BlockDriverComponentBase(compName), m_cycles(0) {} - BlockDriver::~BlockDriver() {} - - void BlockDriver::BufferIn_handler(FwIndexType portNum, Drv::DataBuffer& buffer) { - // just a pass-through - this->BufferOut_out(0,buffer); - } - - void BlockDriver::Sched_handler(FwIndexType portNum, U32 context) { - this->tlmWrite_BD_Cycles(this->m_cycles++); - } - - void BlockDriver::PingIn_handler( - const FwIndexType portNum, - U32 key - ) - { - // call ping output port - this->PingOut_out(0,key); - } +BlockDriver::~BlockDriver() {} +void BlockDriver::BufferIn_handler(FwIndexType portNum, Drv::DataBuffer& buffer) { + // just a pass-through + this->BufferOut_out(0, buffer); } + +void BlockDriver::Sched_handler(FwIndexType portNum, U32 context) { + this->tlmWrite_BD_Cycles(this->m_cycles++); +} + +void BlockDriver::PingIn_handler(const FwIndexType portNum, U32 key) { + // call ping output port + this->PingOut_out(0, key); +} + +} // namespace Ref diff --git a/Ref/BlockDriver/BlockDriver.hpp b/Ref/BlockDriver/BlockDriver.hpp index 5c982a19c9..266f2f379e 100644 --- a/Ref/BlockDriver/BlockDriver.hpp +++ b/Ref/BlockDriver/BlockDriver.hpp @@ -5,31 +5,26 @@ namespace Ref { - class BlockDriver final : public BlockDriverComponentBase { +class BlockDriver final : public BlockDriverComponentBase { + public: + // Only called by derived class + BlockDriver(const char* compName); - public: + ~BlockDriver(); - // Only called by derived class - BlockDriver(const char* compName); + private: + // downcalls for input ports + void BufferIn_handler(FwIndexType portNum, Drv::DataBuffer& buffer); + void Sched_handler(FwIndexType portNum, U32 context); + //! Handler implementation for PingIn + //! + void PingIn_handler(const FwIndexType portNum, /*!< The port number*/ + U32 key /*!< Value to return to pinger*/ + ); - ~BlockDriver(); - - private: - - // downcalls for input ports - void BufferIn_handler(FwIndexType portNum, Drv::DataBuffer& buffer); - void Sched_handler(FwIndexType portNum, U32 context); - //! Handler implementation for PingIn - //! - void PingIn_handler( - const FwIndexType portNum, /*!< The port number*/ - U32 key /*!< Value to return to pinger*/ - ); - - // cycle count - U32 m_cycles; - - }; -} + // cycle count + U32 m_cycles; +}; +} // namespace Ref #endif diff --git a/Ref/BlockDriver/test/ut/BlockDriverTestMain.cpp b/Ref/BlockDriver/test/ut/BlockDriverTestMain.cpp index bfaed74ed3..9af10346e0 100644 --- a/Ref/BlockDriver/test/ut/BlockDriverTestMain.cpp +++ b/Ref/BlockDriver/test/ut/BlockDriverTestMain.cpp @@ -7,21 +7,21 @@ #include "BlockDriverTester.hpp" TEST(Nominal, testDataLoopBack) { - Ref::BlockDriverTester tester; - tester.testDataLoopBack(); + Ref::BlockDriverTester tester; + tester.testDataLoopBack(); } TEST(Nominal, testPing) { - Ref::BlockDriverTester tester; - tester.testPing(); + Ref::BlockDriverTester tester; + tester.testPing(); } TEST(Nominal, testCycleIncrement) { - Ref::BlockDriverTester tester; - tester.testCycleIncrement(); + Ref::BlockDriverTester tester; + tester.testCycleIncrement(); } int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/Ref/BlockDriver/test/ut/BlockDriverTester.cpp b/Ref/BlockDriver/test/ut/BlockDriverTester.cpp index 3c8eb74bd7..70cfc7daa5 100644 --- a/Ref/BlockDriver/test/ut/BlockDriverTester.cpp +++ b/Ref/BlockDriver/test/ut/BlockDriverTester.cpp @@ -8,32 +8,23 @@ namespace Ref { - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- +// ---------------------------------------------------------------------- +// Construction and destruction +// ---------------------------------------------------------------------- - BlockDriverTester :: - BlockDriverTester() : - BlockDriverGTestBase("BlockDriverTester", BlockDriverTester::MAX_HISTORY_SIZE), - component("BlockDriver") - { +BlockDriverTester ::BlockDriverTester() + : BlockDriverGTestBase("BlockDriverTester", BlockDriverTester::MAX_HISTORY_SIZE), component("BlockDriver") { this->initComponents(); this->connectPorts(); - } +} - BlockDriverTester :: - ~BlockDriverTester() - { +BlockDriverTester ::~BlockDriverTester() {} - } +// ---------------------------------------------------------------------- +// Tests +// ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- - - void BlockDriverTester :: - testDataLoopBack() - { +void BlockDriverTester ::testDataLoopBack() { const U8 data[] = {1, 2, 3, 4, 5, 6, 7}; Drv::DataBuffer dataBuffer(data, 7); @@ -47,11 +38,9 @@ namespace Ref { // verify data output ASSERT_from_BufferOut_SIZE(1); ASSERT_from_BufferOut(0, dataBuffer); - } +} - void BlockDriverTester :: - testPing() - { +void BlockDriverTester ::testPing() { const U32 key = 42; this->clearHistory(); @@ -64,15 +53,13 @@ namespace Ref { // verify Ping output ASSERT_from_PingOut_SIZE(1); ASSERT_from_PingOut(0, key); - } +} - void BlockDriverTester :: - testCycleIncrement() - { +void BlockDriverTester ::testCycleIncrement() { this->clearHistory(); // call ISR - this->invoke_to_Sched(0,0); + this->invoke_to_Sched(0, 0); this->component.doDispatch(); // there shall be one report with 0 cycle @@ -81,13 +68,13 @@ namespace Ref { ASSERT_TLM_BD_Cycles(0, 0); // call ISR once again - this->invoke_to_Sched(0,0); + this->invoke_to_Sched(0, 0); this->component.doDispatch(); // there shall be one more report with 1 cycle ASSERT_TLM_SIZE(2); ASSERT_TLM_BD_Cycles_SIZE(2); ASSERT_TLM_BD_Cycles(1, 1); - } - } + +} // namespace Ref diff --git a/Ref/BlockDriver/test/ut/BlockDriverTester.hpp b/Ref/BlockDriver/test/ut/BlockDriverTester.hpp index 99c662a297..5bec47f19f 100644 --- a/Ref/BlockDriver/test/ut/BlockDriverTester.hpp +++ b/Ref/BlockDriver/test/ut/BlockDriverTester.hpp @@ -7,80 +7,71 @@ #ifndef Ref_BlockDriverTester_HPP #define Ref_BlockDriverTester_HPP -#include "Ref/BlockDriver/BlockDriverGTestBase.hpp" #include "Ref/BlockDriver/BlockDriver.hpp" +#include "Ref/BlockDriver/BlockDriverGTestBase.hpp" namespace Ref { - class BlockDriverTester final : - public BlockDriverGTestBase - { +class BlockDriverTester final : public BlockDriverGTestBase { + public: + // ---------------------------------------------------------------------- + // Constants + // ---------------------------------------------------------------------- - public: + // Maximum size of histories storing events, telemetry, and port outputs + static const FwSizeType MAX_HISTORY_SIZE = 10; - // ---------------------------------------------------------------------- - // Constants - // ---------------------------------------------------------------------- + // Instance ID supplied to the component instance under test + static const FwEnumStoreType TEST_INSTANCE_ID = 0; - // Maximum size of histories storing events, telemetry, and port outputs - static const FwSizeType MAX_HISTORY_SIZE = 10; + // Queue depth supplied to the component instance under test + static const FwSizeType TEST_INSTANCE_QUEUE_DEPTH = 10; - // Instance ID supplied to the component instance under test - static const FwEnumStoreType TEST_INSTANCE_ID = 0; + public: + // ---------------------------------------------------------------------- + // Construction and destruction + // ---------------------------------------------------------------------- - // Queue depth supplied to the component instance under test - static const FwSizeType TEST_INSTANCE_QUEUE_DEPTH = 10; + //! Construct object BlockDriverTester + BlockDriverTester(); - public: + //! Destroy object BlockDriverTester + ~BlockDriverTester(); - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- + public: + // ---------------------------------------------------------------------- + // Tests + // ---------------------------------------------------------------------- - //! Construct object BlockDriverTester - BlockDriverTester(); + //! Test data loop back port + void testDataLoopBack(); - //! Destroy object BlockDriverTester - ~BlockDriverTester(); + //! Test Ping port + void testPing(); - public: + //! Test ISR cycle increment + void testCycleIncrement(); - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- + private: + // ---------------------------------------------------------------------- + // Helper functions + // ---------------------------------------------------------------------- - //! Test data loop back port - void testDataLoopBack(); + //! Connect ports + void connectPorts(); - //! Test Ping port - void testPing(); + //! Initialize components + void initComponents(); - //! Test ISR cycle increment - void testCycleIncrement(); + private: + // ---------------------------------------------------------------------- + // Member variables + // ---------------------------------------------------------------------- - private: + //! The component under test + BlockDriver component; +}; - // ---------------------------------------------------------------------- - // Helper functions - // ---------------------------------------------------------------------- - - //! Connect ports - void connectPorts(); - - //! Initialize components - void initComponents(); - - private: - - // ---------------------------------------------------------------------- - // Member variables - // ---------------------------------------------------------------------- - - //! The component under test - BlockDriver component; - - }; - -} +} // namespace Ref #endif diff --git a/Ref/DpDemo/DpDemo.cpp b/Ref/DpDemo/DpDemo.cpp index d4ec0977fd..23229fde1b 100644 --- a/Ref/DpDemo/DpDemo.cpp +++ b/Ref/DpDemo/DpDemo.cpp @@ -8,239 +8,166 @@ namespace Ref { - // ---------------------------------------------------------------------- - // Component construction and destruction - // ---------------------------------------------------------------------- +// ---------------------------------------------------------------------- +// Component construction and destruction +// ---------------------------------------------------------------------- - DpDemo ::DpDemo(const char* const compName) : DpDemoComponentBase(compName) { - this->selectedColor = DpDemo_ColorEnum::RED; - this->numRecords = 0; - this->dpPriority = 0; +DpDemo ::DpDemo(const char* const compName) : DpDemoComponentBase(compName) { + this->selectedColor = DpDemo_ColorEnum::RED; + this->numRecords = 0; + this->dpPriority = 0; +} + +DpDemo ::~DpDemo() {} + +// ---------------------------------------------------------------------- +// Handler implementations for typed input ports +// ---------------------------------------------------------------------- + +void DpDemo ::run_handler(FwIndexType portNum, U32 context) { + // If a Data product is being generated, store records + if (this->dpInProgress) { + this->dpContainer.serializeRecord_StringRecord(Fw::String("Test string")); + this->dpContainer.serializeRecord_BooleanRecord(true); + this->dpContainer.serializeRecord_I32Record(-100); + this->dpContainer.serializeRecord_F64Record(1.25); + this->dpContainer.serializeRecord_U32ArrayRecord(DpDemo_U32Array({1, 2, 3, 4, 5})); + this->dpContainer.serializeRecord_F32ArrayRecord(DpDemo_F32Array({1.1f, 2.2f, 3.3f})); + this->dpContainer.serializeRecord_BooleanArrayRecord(DpDemo_BooleanArray({true, false})); + // Array Records + // Array record of strings + Fw::String str0("String array element 0"); + Fw::String str1("String array element 1"); + Fw::String str2("String array element 2"); + const Fw::StringBase* strings[3] = {&str0, &str1, &str2}; + this->dpContainer.serializeRecord_StringArrayRecord(strings, 3); + // Array record of arrays + const DpDemo_StringArray arrayArray[1] = {DpDemo_StringArray( + {Fw::String("0 - String array record element 0"), Fw::String("0 - String array record element 1")})}; + this->dpContainer.serializeRecord_ArrayArrayRecord(arrayArray, 1); + // Array record of structs + const DpDemo_StructWithStringMembers structArray[2] = { + DpDemo_StructWithStringMembers(Fw::String("0 - String member"), + DpDemo_StringArray({Fw::String("0 - String array element 0"), + Fw::String("0 - String array element 1")})), + DpDemo_StructWithStringMembers(Fw::String("1 - String member"), + DpDemo_StringArray({Fw::String("1 - String array element 0"), + Fw::String("1 - String array element 1")}))}; + this->dpContainer.serializeRecord_StructArrayRecord(structArray, 2); + this->dpContainer.serializeRecord_ArrayOfStringArrayRecord(DpDemo_ArrayOfStringArray( + {DpDemo_StringArray({Fw::String("0 - String array element 0"), Fw::String("0 - String array element 1")}), + DpDemo_StringArray({Fw::String("1 - String array element 0"), Fw::String("1 - String array element 1")}), + DpDemo_StringArray( + {Fw::String("2 - String array element 0"), Fw::String("2 - String array element 1")})})); + this->dpContainer.serializeRecord_ArrayOfStructsRecord(DpDemo_ArrayOfStructs( + {DpDemo_StructWithStringMembers(Fw::String("0 - String member"), + DpDemo_StringArray({Fw::String("0 - String array element 0"), + Fw::String("0 - String array element 1")})), + DpDemo_StructWithStringMembers(Fw::String("1 - String member"), + DpDemo_StringArray({Fw::String("1 - String array element 0"), + Fw::String("1 - String array element 1")})), + DpDemo_StructWithStringMembers(Fw::String("2 - String member"), + DpDemo_StringArray({Fw::String("2 - String array element 0"), + Fw::String("2 - String array element 1")}))})); + this->dpContainer.serializeRecord_EnumArrayRecord( + DpDemo_EnumArray({DpDemo_ColorEnum::RED, DpDemo_ColorEnum::GREEN, DpDemo_ColorEnum::BLUE})); + this->dpContainer.serializeRecord_StructWithEverythingRecord(DpDemo_StructWithEverything( + -1, 2.5, Fw::String("String Member"), false, this->selectedColor, + {DpDemo_U32Array({1, 2, 3, 4, 5}), DpDemo_U32Array({6, 7, 8, 9, 10})}, DpDemo_F32Array({4.4f, 5.5f, 6.6f}), + DpDemo_U32Array({6, 7, 8, 9, 10}), + DpDemo_EnumArray({DpDemo_ColorEnum::RED, DpDemo_ColorEnum::GREEN, DpDemo_ColorEnum::BLUE}), + DpDemo_StringArray({Fw::String("String array element 0"), Fw::String("String array element 1")}), + DpDemo_BooleanArray({true, false}), + DpDemo_StructWithStringMembers( + Fw::String("String member"), + DpDemo_StringArray({Fw::String("String array element 0"), Fw::String("String array element 1")})), + DpDemo_ArrayOfStringArray({DpDemo_StringArray({Fw::String("0 - String array element 0"), + Fw::String("0 - String array element 1")}), + DpDemo_StringArray({Fw::String("1 - String array element 0"), + Fw::String("1 - String array element 1")}), + DpDemo_StringArray({Fw::String("2 - String array element 0"), + Fw::String("2 - String array element 1")})}))); + this->log_ACTIVITY_LO_DpComplete(this->numRecords); + this->cleanupAndSendDp(); + } +} + +// ---------------------------------------------------------------------- +// Handler implementations for commands +// ---------------------------------------------------------------------- + +void DpDemo ::SelectColor_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, Ref::DpDemo_ColorEnum color) { + this->selectedColor = color; + log_ACTIVITY_HI_ColorSelected(color); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); +} + +void DpDemo ::Dp_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, DpDemo_DpReqType reqType, U32 priority) { + // make sure DPs are available + if (!this->isConnected_productGetOut_OutputPort(0) || !this->isConnected_productRequestOut_OutputPort(0)) { + this->log_WARNING_HI_DpsNotConnected(); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); + return; } - DpDemo ::~DpDemo() {} + this->numRecords = 15; // 15 records in current demo + FwSizeType dpSize = DpDemo_StringAlias::SERIALIZED_SIZE + sizeof(DpDemo_BoolAlias) + sizeof(DpDemo_I32Alias) + + sizeof(DpDemo_F64Alias) + DpDemo_U32Array::SERIALIZED_SIZE + DpDemo_F32Array::SERIALIZED_SIZE + + DpDemo_BooleanArray::SERIALIZED_SIZE + DpDemo_EnumArray::SERIALIZED_SIZE + + DpDemo_StringArray::SERIALIZED_SIZE + DpDemo_StructWithEverything::SERIALIZED_SIZE + + DpDemo_StructWithStringMembers::SERIALIZED_SIZE + (DpDemo_StringArray::SERIALIZED_SIZE * 3) + + (DpDemo_StringArray::SERIALIZED_SIZE * 1) + + (DpDemo_StructWithStringMembers::SERIALIZED_SIZE * 2) + + DpDemo_ArrayOfStringArray::SERIALIZED_SIZE + (numRecords * sizeof(FwDpIdType)); - // ---------------------------------------------------------------------- - // Handler implementations for typed input ports - // ---------------------------------------------------------------------- - - void DpDemo ::run_handler(FwIndexType portNum, U32 context) { - // If a Data product is being generated, store records - if (this->dpInProgress) { - this->dpContainer.serializeRecord_StringRecord(Fw::String("Test string")); - this->dpContainer.serializeRecord_BooleanRecord(true); - this->dpContainer.serializeRecord_I32Record(-100); - this->dpContainer.serializeRecord_F64Record(1.25); - this->dpContainer.serializeRecord_U32ArrayRecord(DpDemo_U32Array({1, 2, 3, 4, 5})); - this->dpContainer.serializeRecord_F32ArrayRecord(DpDemo_F32Array({1.1f, 2.2f, 3.3f})); - this->dpContainer.serializeRecord_BooleanArrayRecord(DpDemo_BooleanArray({true, false})); - // Array Records - // Array record of strings - Fw::String str0("String array element 0"); - Fw::String str1("String array element 1"); - Fw::String str2("String array element 2"); - const Fw::StringBase* strings[3] = { &str0, &str1, &str2 }; - this->dpContainer.serializeRecord_StringArrayRecord(strings, 3); - // Array record of arrays - const DpDemo_StringArray arrayArray[1] = { - DpDemo_StringArray({ - Fw::String("0 - String array record element 0"), - Fw::String("0 - String array record element 1") - }) - }; - this->dpContainer.serializeRecord_ArrayArrayRecord(arrayArray, 1); - // Array record of structs - const DpDemo_StructWithStringMembers structArray[2] = { - DpDemo_StructWithStringMembers( - Fw::String("0 - String member"), - DpDemo_StringArray({ - Fw::String("0 - String array element 0"), - Fw::String("0 - String array element 1") - }) - ), - DpDemo_StructWithStringMembers( - Fw::String("1 - String member"), - DpDemo_StringArray({ - Fw::String("1 - String array element 0"), - Fw::String("1 - String array element 1") - }) - ) - }; - this->dpContainer.serializeRecord_StructArrayRecord(structArray, 2); - this->dpContainer.serializeRecord_ArrayOfStringArrayRecord( - DpDemo_ArrayOfStringArray({ - DpDemo_StringArray({ - Fw::String("0 - String array element 0"), - Fw::String("0 - String array element 1") - }), - DpDemo_StringArray({ - Fw::String("1 - String array element 0"), - Fw::String("1 - String array element 1") - }), - DpDemo_StringArray({ - Fw::String("2 - String array element 0"), - Fw::String("2 - String array element 1") - }) - }) - ); - this->dpContainer.serializeRecord_ArrayOfStructsRecord( - DpDemo_ArrayOfStructs({ - DpDemo_StructWithStringMembers( - Fw::String("0 - String member"), - DpDemo_StringArray({ - Fw::String("0 - String array element 0"), - Fw::String("0 - String array element 1") - }) - ), - DpDemo_StructWithStringMembers( - Fw::String("1 - String member"), - DpDemo_StringArray({ - Fw::String("1 - String array element 0"), - Fw::String("1 - String array element 1") - }) - ), - DpDemo_StructWithStringMembers( - Fw::String("2 - String member"), - DpDemo_StringArray({ - Fw::String("2 - String array element 0"), - Fw::String("2 - String array element 1") - }) - ) - }) - ); - this->dpContainer.serializeRecord_EnumArrayRecord(DpDemo_EnumArray({DpDemo_ColorEnum::RED, DpDemo_ColorEnum::GREEN, DpDemo_ColorEnum::BLUE})); - this->dpContainer.serializeRecord_StructWithEverythingRecord(DpDemo_StructWithEverything( - -1, - 2.5, - Fw::String("String Member"), - false, - this->selectedColor, - { - DpDemo_U32Array({1, 2, 3, 4, 5}), - DpDemo_U32Array({6, 7, 8, 9, 10}) - }, - DpDemo_F32Array({4.4f, 5.5f, 6.6f}), - DpDemo_U32Array({6, 7, 8, 9, 10}), - DpDemo_EnumArray({DpDemo_ColorEnum::RED, DpDemo_ColorEnum::GREEN, DpDemo_ColorEnum::BLUE}), - DpDemo_StringArray({ - Fw::String("String array element 0"), - Fw::String("String array element 1") - }), - DpDemo_BooleanArray({true, false}), - DpDemo_StructWithStringMembers( - Fw::String("String member"), - DpDemo_StringArray({ - Fw::String("String array element 0"), - Fw::String("String array element 1") - }) - ), - DpDemo_ArrayOfStringArray({ - DpDemo_StringArray({ - Fw::String("0 - String array element 0"), - Fw::String("0 - String array element 1") - }), - DpDemo_StringArray({ - Fw::String("1 - String array element 0"), - Fw::String("1 - String array element 1") - }), - DpDemo_StringArray({ - Fw::String("2 - String array element 0"), - Fw::String("2 - String array element 1") - }) - }) - )); - this->log_ACTIVITY_LO_DpComplete(this->numRecords); - this->cleanupAndSendDp(); - } - } - - // ---------------------------------------------------------------------- - // Handler implementations for commands - // ---------------------------------------------------------------------- - - void DpDemo ::SelectColor_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, Ref::DpDemo_ColorEnum color) { - this->selectedColor = color; - log_ACTIVITY_HI_ColorSelected(color); - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); - } - - void DpDemo ::Dp_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, DpDemo_DpReqType reqType, U32 priority) { - - // make sure DPs are available - if (!this->isConnected_productGetOut_OutputPort(0) || !this->isConnected_productRequestOut_OutputPort(0)) { - this->log_WARNING_HI_DpsNotConnected(); - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); - return; - } - - this->numRecords = 15; // 15 records in current demo - FwSizeType dpSize = DpDemo_StringAlias::SERIALIZED_SIZE + - sizeof(DpDemo_BoolAlias) + - sizeof(DpDemo_I32Alias) + - sizeof(DpDemo_F64Alias) + - DpDemo_U32Array::SERIALIZED_SIZE + - DpDemo_F32Array::SERIALIZED_SIZE + - DpDemo_BooleanArray::SERIALIZED_SIZE + - DpDemo_EnumArray::SERIALIZED_SIZE + - DpDemo_StringArray::SERIALIZED_SIZE + - DpDemo_StructWithEverything::SERIALIZED_SIZE + - DpDemo_StructWithStringMembers::SERIALIZED_SIZE + - (DpDemo_StringArray::SERIALIZED_SIZE * 3) + - (DpDemo_StringArray::SERIALIZED_SIZE * 1) + - (DpDemo_StructWithStringMembers::SERIALIZED_SIZE * 2) + - DpDemo_ArrayOfStringArray::SERIALIZED_SIZE + - (numRecords * sizeof(FwDpIdType)); - - this->dpPriority = static_cast(priority); - this->log_ACTIVITY_LO_DpMemRequested(dpSize); - if(reqType == DpDemo_DpReqType::IMMEDIATE) { - Fw::Success stat = this->dpGet_DpDemoContainer(dpSize, this->dpContainer); - // make sure we got the memory we wanted - if (Fw::Success::FAILURE == stat) { - this->log_WARNING_HI_DpMemoryFail(); - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); - } else { - this->dpInProgress = true; - this->log_ACTIVITY_LO_DpStarted(numRecords); - this->log_ACTIVITY_LO_DpMemReceived(this->dpContainer.getBuffer().getSize()); - // override priority with requested priority - this->dpContainer.setPriority(priority); - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); - } - } - else if (reqType == DpDemo_DpReqType::ASYNC) { - this->dpRequest_DpDemoContainer(dpSize); - } - else { - // should never get here - FW_ASSERT(0, reqType.e); - } - } - - // ---------------------------------------------------------------------- - // Handler implementations for data products - // ---------------------------------------------------------------------- - - void DpDemo ::dpRecv_DpDemoContainer_handler(DpContainer& container, Fw::Success::T status) { - // Make sure we got the buffer we wanted or quit - if (Fw::Success::SUCCESS == status) { - this->dpContainer = container; - this->dpInProgress = true; - // set previously requested priority - this->dpContainer.setPriority(this->dpPriority); - this->log_ACTIVITY_LO_DpStarted(this->numRecords); - } else { + this->dpPriority = static_cast(priority); + this->log_ACTIVITY_LO_DpMemRequested(dpSize); + if (reqType == DpDemo_DpReqType::IMMEDIATE) { + Fw::Success stat = this->dpGet_DpDemoContainer(dpSize, this->dpContainer); + // make sure we got the memory we wanted + if (Fw::Success::FAILURE == stat) { this->log_WARNING_HI_DpMemoryFail(); - // cleanup - this->dpInProgress = false; - this->numRecords = 0; + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); + } else { + this->dpInProgress = true; + this->log_ACTIVITY_LO_DpStarted(numRecords); + this->log_ACTIVITY_LO_DpMemReceived(this->dpContainer.getBuffer().getSize()); + // override priority with requested priority + this->dpContainer.setPriority(priority); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } + } else if (reqType == DpDemo_DpReqType::ASYNC) { + this->dpRequest_DpDemoContainer(dpSize); + } else { + // should never get here + FW_ASSERT(0, reqType.e); } +} - void DpDemo ::cleanupAndSendDp() { - this->dpSend(this->dpContainer); +// ---------------------------------------------------------------------- +// Handler implementations for data products +// ---------------------------------------------------------------------- + +void DpDemo ::dpRecv_DpDemoContainer_handler(DpContainer& container, Fw::Success::T status) { + // Make sure we got the buffer we wanted or quit + if (Fw::Success::SUCCESS == status) { + this->dpContainer = container; + this->dpInProgress = true; + // set previously requested priority + this->dpContainer.setPriority(this->dpPriority); + this->log_ACTIVITY_LO_DpStarted(this->numRecords); + } else { + this->log_WARNING_HI_DpMemoryFail(); + // cleanup this->dpInProgress = false; this->numRecords = 0; } +} + +void DpDemo ::cleanupAndSendDp() { + this->dpSend(this->dpContainer); + this->dpInProgress = false; + this->numRecords = 0; +} } // namespace Ref diff --git a/Ref/Main.cpp b/Ref/Main.cpp index 1b41c76a9f..7ead81b1af 100644 --- a/Ref/Main.cpp +++ b/Ref/Main.cpp @@ -19,7 +19,6 @@ // Used to get the Os::Console #include - /** * \brief print commandline help message * diff --git a/Ref/PingReceiver/PingReceiver.hpp b/Ref/PingReceiver/PingReceiver.hpp index f37d67e31d..4ef1a3df38 100644 --- a/Ref/PingReceiver/PingReceiver.hpp +++ b/Ref/PingReceiver/PingReceiver.hpp @@ -10,7 +10,7 @@ namespace Ref { - typedef PingReceiverComponentImpl PingReceiver; +typedef PingReceiverComponentImpl PingReceiver; } diff --git a/Ref/PingReceiver/PingReceiverComponentImpl.cpp b/Ref/PingReceiver/PingReceiverComponentImpl.cpp index 364900ca79..0a7fde5f57 100644 --- a/Ref/PingReceiver/PingReceiverComponentImpl.cpp +++ b/Ref/PingReceiver/PingReceiverComponentImpl.cpp @@ -10,53 +10,37 @@ // // ====================================================================== - -#include #include +#include namespace Ref { - // ---------------------------------------------------------------------- - // Construction, initialization, and destruction - // ---------------------------------------------------------------------- +// ---------------------------------------------------------------------- +// Construction, initialization, and destruction +// ---------------------------------------------------------------------- - PingReceiverComponentImpl :: - PingReceiverComponentImpl( - const char *const compName - ) : PingReceiverComponentBase(compName), m_inhibitPings(false), m_pingsRecvd(0) - { +PingReceiverComponentImpl ::PingReceiverComponentImpl(const char* const compName) + : PingReceiverComponentBase(compName), m_inhibitPings(false), m_pingsRecvd(0) {} - } +PingReceiverComponentImpl ::~PingReceiverComponentImpl() {} - PingReceiverComponentImpl :: - ~PingReceiverComponentImpl() - { +// ---------------------------------------------------------------------- +// Handler implementations for user-defined typed input ports +// ---------------------------------------------------------------------- - } - - // ---------------------------------------------------------------------- - // Handler implementations for user-defined typed input ports - // ---------------------------------------------------------------------- - - void PingReceiverComponentImpl :: - PingIn_handler( - const FwIndexType portNum, - U32 key - ) - { - //this->log_DIAGNOSTIC_PR_PingReceived(key); +void PingReceiverComponentImpl ::PingIn_handler(const FwIndexType portNum, U32 key) { + // this->log_DIAGNOSTIC_PR_PingReceived(key); this->tlmWrite_PR_NumPings(this->m_pingsRecvd++); if (not this->m_inhibitPings) { - PingOut_out(0,key); + PingOut_out(0, key); } - } +} - void PingReceiverComponentImpl::PR_StopPings_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq /*!< The command sequence number*/ - ) { - this->m_inhibitPings = true; - this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK); - } +void PingReceiverComponentImpl::PR_StopPings_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq /*!< The command sequence number*/ +) { + this->m_inhibitPings = true; + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); +} -} // end namespace Ref +} // end namespace Ref diff --git a/Ref/PingReceiver/PingReceiverComponentImpl.hpp b/Ref/PingReceiver/PingReceiverComponentImpl.hpp index 53aa2b6ad8..8edf14d9d6 100644 --- a/Ref/PingReceiver/PingReceiverComponentImpl.hpp +++ b/Ref/PingReceiver/PingReceiverComponentImpl.hpp @@ -17,50 +17,40 @@ namespace Ref { - class PingReceiverComponentImpl final : - public PingReceiverComponentBase - { +class PingReceiverComponentImpl final : public PingReceiverComponentBase { + public: + // ---------------------------------------------------------------------- + // Construction, initialization, and destruction + // ---------------------------------------------------------------------- - public: + //! Construct object PingReceiver + //! + PingReceiverComponentImpl(const char* const compName /*!< The component name*/ + ); - // ---------------------------------------------------------------------- - // Construction, initialization, and destruction - // ---------------------------------------------------------------------- + //! Destroy object PingReceiver + //! + ~PingReceiverComponentImpl(); - //! Construct object PingReceiver - //! - PingReceiverComponentImpl( - const char *const compName /*!< The component name*/ - ); + private: + // ---------------------------------------------------------------------- + // Handler implementations for user-defined typed input ports + // ---------------------------------------------------------------------- - //! Destroy object PingReceiver - //! - ~PingReceiverComponentImpl(); + //! Handler implementation for PingIn + //! + void PingIn_handler(const FwIndexType portNum, /*!< The port number*/ + U32 key /*!< Value to return to pinger*/ + ); - private: + void PR_StopPings_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq /*!< The command sequence number*/ + ); - // ---------------------------------------------------------------------- - // Handler implementations for user-defined typed input ports - // ---------------------------------------------------------------------- + bool m_inhibitPings; + U32 m_pingsRecvd; +}; - //! Handler implementation for PingIn - //! - void PingIn_handler( - const FwIndexType portNum, /*!< The port number*/ - U32 key /*!< Value to return to pinger*/ - ); - - void PR_StopPings_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq /*!< The command sequence number*/ - ); - - bool m_inhibitPings; - U32 m_pingsRecvd; - - - }; - -} // end namespace Ref +} // end namespace Ref #endif diff --git a/Ref/RecvBuffApp/RecvBuff.hpp b/Ref/RecvBuffApp/RecvBuff.hpp index c80930042e..314dd5d251 100644 --- a/Ref/RecvBuffApp/RecvBuff.hpp +++ b/Ref/RecvBuffApp/RecvBuff.hpp @@ -10,7 +10,7 @@ namespace Ref { - typedef RecvBuffImpl RecvBuff; +typedef RecvBuffImpl RecvBuff; } diff --git a/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp b/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp index 0550f013fe..500ef8ba3e 100644 --- a/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp +++ b/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp @@ -1,7 +1,7 @@ -#include #include -#include #include +#include +#include #include @@ -9,87 +9,82 @@ namespace Ref { - RecvBuffImpl::RecvBuffImpl(const char* compName) : - RecvBuffComponentBase(compName) { - this->m_firstBuffReceived = 0; - this->m_sensor1 = 1000.0; - this->m_sensor2 = 10.0; - this->m_stats.set_BuffRecv(0); - this->m_stats.set_BuffErr(0); - this->m_stats.set_PacketStatus(PacketRecvStatus::PACKET_STATE_NO_PACKETS); - } - - RecvBuffImpl::~RecvBuffImpl() { - - } - - void RecvBuffImpl::Data_handler(FwIndexType portNum, Drv::DataBuffer &buff) { - - this->m_stats.set_BuffRecv(++this->m_buffsReceived); - // reset deserialization of buffer - buff.resetDeser(); - // deserialize packet ID - U32 id = 0; - Fw::SerializeStatus stat = buff.deserializeTo(id); - FW_ASSERT(stat == Fw::FW_SERIALIZE_OK,static_cast(stat)); - // deserialize data - U8 testData[24] = {0}; - FwSizeType size = sizeof(testData); - stat = buff.deserializeTo(testData,size); - FW_ASSERT(stat == Fw::FW_SERIALIZE_OK,static_cast(stat)); - // deserialize checksum - U32 csum = 0; - stat = buff.deserializeTo(csum); - FW_ASSERT(stat == Fw::FW_SERIALIZE_OK,static_cast(stat)); - // if first packet, send event - if (not this->m_firstBuffReceived) { - this->log_ACTIVITY_LO_FirstPacketReceived(id); - this->m_stats.set_PacketStatus(PacketRecvStatus::PACKET_STATE_OK); - this->m_firstBuffReceived = true; - } - - // compute checksum - U32 sum = 0; - for (U32 byte = 0; byte < size; byte++) { - sum += testData[byte]; - } - // check checksum - if (sum != csum) { - // increment error count - this->m_stats.set_BuffErr(++this->m_errBuffs); - // send error event - this->log_WARNING_HI_PacketChecksumError(id); - // update stats - this->m_stats.set_PacketStatus(PacketRecvStatus::PACKET_STATE_ERRORS); - } - // update sensor values - this->m_sensor1 += 5.0; - this->m_sensor2 += 1.2; - // update channels - this->tlmWrite_Sensor1(this->m_sensor1); - this->tlmWrite_Sensor2(this->m_sensor2); - this->tlmWrite_PktState(this->m_stats); - - } - - void RecvBuffImpl::parameterUpdated(FwPrmIdType id) { - this->log_ACTIVITY_LO_BuffRecvParameterUpdated(id); - Fw::ParamValid valid; - switch(id) { - case PARAMID_PARAMETER1: { - U32 val = this->paramGet_parameter1(valid); - this->tlmWrite_Parameter1(val); - break; - } - case PARAMID_PARAMETER2: { - I16 val = this->paramGet_parameter2(valid); - this->tlmWrite_Parameter2(val); - break; - } - default: - FW_ASSERT(0,id); - break; - } - } - +RecvBuffImpl::RecvBuffImpl(const char* compName) : RecvBuffComponentBase(compName) { + this->m_firstBuffReceived = 0; + this->m_sensor1 = 1000.0; + this->m_sensor2 = 10.0; + this->m_stats.set_BuffRecv(0); + this->m_stats.set_BuffErr(0); + this->m_stats.set_PacketStatus(PacketRecvStatus::PACKET_STATE_NO_PACKETS); } + +RecvBuffImpl::~RecvBuffImpl() {} + +void RecvBuffImpl::Data_handler(FwIndexType portNum, Drv::DataBuffer& buff) { + this->m_stats.set_BuffRecv(++this->m_buffsReceived); + // reset deserialization of buffer + buff.resetDeser(); + // deserialize packet ID + U32 id = 0; + Fw::SerializeStatus stat = buff.deserializeTo(id); + FW_ASSERT(stat == Fw::FW_SERIALIZE_OK, static_cast(stat)); + // deserialize data + U8 testData[24] = {0}; + FwSizeType size = sizeof(testData); + stat = buff.deserializeTo(testData, size); + FW_ASSERT(stat == Fw::FW_SERIALIZE_OK, static_cast(stat)); + // deserialize checksum + U32 csum = 0; + stat = buff.deserializeTo(csum); + FW_ASSERT(stat == Fw::FW_SERIALIZE_OK, static_cast(stat)); + // if first packet, send event + if (not this->m_firstBuffReceived) { + this->log_ACTIVITY_LO_FirstPacketReceived(id); + this->m_stats.set_PacketStatus(PacketRecvStatus::PACKET_STATE_OK); + this->m_firstBuffReceived = true; + } + + // compute checksum + U32 sum = 0; + for (U32 byte = 0; byte < size; byte++) { + sum += testData[byte]; + } + // check checksum + if (sum != csum) { + // increment error count + this->m_stats.set_BuffErr(++this->m_errBuffs); + // send error event + this->log_WARNING_HI_PacketChecksumError(id); + // update stats + this->m_stats.set_PacketStatus(PacketRecvStatus::PACKET_STATE_ERRORS); + } + // update sensor values + this->m_sensor1 += 5.0; + this->m_sensor2 += 1.2; + // update channels + this->tlmWrite_Sensor1(this->m_sensor1); + this->tlmWrite_Sensor2(this->m_sensor2); + this->tlmWrite_PktState(this->m_stats); +} + +void RecvBuffImpl::parameterUpdated(FwPrmIdType id) { + this->log_ACTIVITY_LO_BuffRecvParameterUpdated(id); + Fw::ParamValid valid; + switch (id) { + case PARAMID_PARAMETER1: { + U32 val = this->paramGet_parameter1(valid); + this->tlmWrite_Parameter1(val); + break; + } + case PARAMID_PARAMETER2: { + I16 val = this->paramGet_parameter2(valid); + this->tlmWrite_Parameter2(val); + break; + } + default: + FW_ASSERT(0, id); + break; + } +} + +} // namespace Ref diff --git a/Ref/RecvBuffApp/RecvBuffComponentImpl.hpp b/Ref/RecvBuffApp/RecvBuffComponentImpl.hpp index be71854eec..49cd7c3e29 100644 --- a/Ref/RecvBuffApp/RecvBuffComponentImpl.hpp +++ b/Ref/RecvBuffApp/RecvBuffComponentImpl.hpp @@ -5,30 +5,27 @@ namespace Ref { - class RecvBuffImpl final : public RecvBuffComponentBase { - public: +class RecvBuffImpl final : public RecvBuffComponentBase { + public: + // Only called by derived class + RecvBuffImpl(const char* compName); - // Only called by derived class - RecvBuffImpl(const char* compName); + ~RecvBuffImpl(); - ~RecvBuffImpl(); + private: + // downcall for input port + void Data_handler(FwIndexType portNum, Drv::DataBuffer& buff); + Ref::PacketStat m_stats; + U32 m_buffsReceived; // !< number of buffers received + bool m_firstBuffReceived; // !< first buffer received or not + U32 m_errBuffs; // !< number of buffers with errors received + F32 m_sensor1; + F32 m_sensor2; - private: + // parameter update notification + void parameterUpdated(FwPrmIdType id); +}; - // downcall for input port - void Data_handler(FwIndexType portNum, Drv::DataBuffer &buff); - Ref::PacketStat m_stats; - U32 m_buffsReceived; // !< number of buffers received - bool m_firstBuffReceived; // !< first buffer received or not - U32 m_errBuffs; // !< number of buffers with errors received - F32 m_sensor1; - F32 m_sensor2; - - // parameter update notification - void parameterUpdated(FwPrmIdType id); - - }; - -} +} // namespace Ref #endif diff --git a/Ref/SendBuffApp/SendBuff.hpp b/Ref/SendBuffApp/SendBuff.hpp index 1a2d69441a..b8a70da35e 100644 --- a/Ref/SendBuffApp/SendBuff.hpp +++ b/Ref/SendBuffApp/SendBuff.hpp @@ -10,7 +10,7 @@ namespace Ref { - typedef SendBuffImpl SendBuff; +typedef SendBuffImpl SendBuff; } diff --git a/Ref/SendBuffApp/SendBuffComponentImpl.cpp b/Ref/SendBuffApp/SendBuffComponentImpl.cpp index 9cd8817bfe..bbf38bf700 100644 --- a/Ref/SendBuffApp/SendBuffComponentImpl.cpp +++ b/Ref/SendBuffApp/SendBuffComponentImpl.cpp @@ -1,7 +1,7 @@ -#include #include #include #include +#include #include #include @@ -10,138 +10,131 @@ namespace Ref { - SendBuffImpl::SendBuffImpl(const char* compName) : - SendBuffComponentBase(compName) { - this->m_currPacketId = 0; - this->m_invocations = 0; - this->m_buffsSent = 0; - this->m_errorsInjected = 0; - this->m_injectError = false; - this->m_sendPackets = false; - this->m_currPacketId = 0; - this->m_firstPacketSent = false; - this->m_state = SendBuff_ActiveState::SEND_IDLE; +SendBuffImpl::SendBuffImpl(const char* compName) : SendBuffComponentBase(compName) { + this->m_currPacketId = 0; + this->m_invocations = 0; + this->m_buffsSent = 0; + this->m_errorsInjected = 0; + this->m_injectError = false; + this->m_sendPackets = false; + this->m_currPacketId = 0; + this->m_firstPacketSent = false; + this->m_state = SendBuff_ActiveState::SEND_IDLE; +} + +SendBuffImpl::~SendBuffImpl() {} + +void SendBuffImpl::SchedIn_handler(FwIndexType portNum, U32 context) { + // first, dequeue any messages + + MsgDispatchStatus stat = MSG_DISPATCH_OK; + + while (MSG_DISPATCH_OK == stat) { + stat = this->doDispatch(); + FW_ASSERT(stat != MSG_DISPATCH_ERROR); } - SendBuffImpl::~SendBuffImpl() { - - } - - void SendBuffImpl::SchedIn_handler(FwIndexType portNum, U32 context) { - - // first, dequeue any messages - - MsgDispatchStatus stat = MSG_DISPATCH_OK; - - while (MSG_DISPATCH_OK == stat) { - stat = this->doDispatch(); - FW_ASSERT(stat != MSG_DISPATCH_ERROR); + if (this->m_sendPackets) { + // check to see if first + if (this->m_firstPacketSent) { + this->m_firstPacketSent = false; + this->log_ACTIVITY_HI_FirstPacketSent(this->m_currPacketId); + this->tlmWrite_NumErrorsInjected(this->m_errorsInjected); } - - if (this->m_sendPackets) { - // check to see if first - if (this->m_firstPacketSent) { - this->m_firstPacketSent = false; - this->log_ACTIVITY_HI_FirstPacketSent(this->m_currPacketId); - this->tlmWrite_NumErrorsInjected(this->m_errorsInjected); - } - // reset buffer - this->m_testBuff.resetSer(); - // serialize packet id - Fw::SerializeStatus serStat = this->m_testBuff.serialize(this->m_currPacketId); - FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK); - // increment packet id - this->m_currPacketId++; - this->m_buffsSent++; - // set telemetry - this->tlmWrite_PacketsSent(this->m_buffsSent); - // write data - U8 testData[24]; - FwSizeType dataSize = static_cast(sizeof(testData)); - memset(testData,0xFF,static_cast(dataSize)); - // compute checksum - U32 csum = 0; - for (U32 byte = 0; byte < dataSize; byte++) { - csum += testData[byte]; - } - // inject error, if requested - if (this->m_injectError) { - this->m_injectError = false; - this->m_errorsInjected++; - testData[5] = 0; - this->log_WARNING_HI_PacketErrorInserted(this->m_currPacketId-1); - } - // serialize data - serStat = this->m_testBuff.serialize(testData,dataSize); - FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK); - // serialize checksum - serStat = this->m_testBuff.serialize(csum); - FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK); - // send data - this->Data_out(0,this->m_testBuff); - + // reset buffer + this->m_testBuff.resetSer(); + // serialize packet id + Fw::SerializeStatus serStat = this->m_testBuff.serialize(this->m_currPacketId); + FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK); + // increment packet id + this->m_currPacketId++; + this->m_buffsSent++; + // set telemetry + this->tlmWrite_PacketsSent(this->m_buffsSent); + // write data + U8 testData[24]; + FwSizeType dataSize = static_cast(sizeof(testData)); + memset(testData, 0xFF, static_cast(dataSize)); + // compute checksum + U32 csum = 0; + for (U32 byte = 0; byte < dataSize; byte++) { + csum += testData[byte]; } - - this->m_invocations++; - - this->tlmWrite_SendState(this->m_state); - } - - void SendBuffImpl::SB_START_PKTS_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { - this->m_sendPackets = true; - this->m_state = SendBuff_ActiveState::SEND_ACTIVE; - this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK); - } - - void SendBuffImpl::SB_INJECT_PKT_ERROR_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { - this->m_injectError = true; - this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK); - } - - void SendBuffImpl::SB_GEN_FATAL_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq, /*!< The command sequence number*/ - U32 arg1, /*!< First FATAL Argument*/ - U32 arg2, /*!< Second FATAL Argument*/ - U32 arg3 /*!< Third FATAL Argument*/ - ) { - this->log_FATAL_SendBuffFatal(arg1,arg2,arg3); - this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK); - } - - //! Handler for command SB_GEN_ASSERT - /* Generate an ASSERT */ - void SendBuffImpl::SB_GEN_ASSERT_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq, /*!< The command sequence number*/ - U32 arg1, /*!< First ASSERT Argument*/ - U32 arg2, /*!< Second ASSERT Argument*/ - U32 arg3, /*!< Third ASSERT Argument*/ - U32 arg4, /*!< Fourth ASSERT Argument*/ - U32 arg5, /*!< Fifth ASSERT Argument*/ - U32 arg6 /*!< Sixth ASSERT Argument*/ - ) { - FW_ASSERT(0,arg1,arg2,arg3,arg4,arg5,arg6); - this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK); - } - - void SendBuffImpl::parameterUpdated(FwPrmIdType id) { - this->log_ACTIVITY_LO_BuffSendParameterUpdated(id); - Fw::ParamValid valid; - switch(id) { - case PARAMID_PARAMETER3: { - U8 val = this->paramGet_parameter3(valid); - this->tlmWrite_Parameter3(val); - break; - } - case PARAMID_PARAMETER4: { - F32 val = this->paramGet_parameter4(valid); - this->tlmWrite_Parameter4(val); - break; - } - default: - FW_ASSERT(0,id); - break; + // inject error, if requested + if (this->m_injectError) { + this->m_injectError = false; + this->m_errorsInjected++; + testData[5] = 0; + this->log_WARNING_HI_PacketErrorInserted(this->m_currPacketId - 1); } + // serialize data + serStat = this->m_testBuff.serialize(testData, dataSize); + FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK); + // serialize checksum + serStat = this->m_testBuff.serialize(csum); + FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK); + // send data + this->Data_out(0, this->m_testBuff); + } + + this->m_invocations++; + + this->tlmWrite_SendState(this->m_state); +} + +void SendBuffImpl::SB_START_PKTS_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { + this->m_sendPackets = true; + this->m_state = SendBuff_ActiveState::SEND_ACTIVE; + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); +} + +void SendBuffImpl::SB_INJECT_PKT_ERROR_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { + this->m_injectError = true; + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); +} + +void SendBuffImpl::SB_GEN_FATAL_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq, /*!< The command sequence number*/ + U32 arg1, /*!< First FATAL Argument*/ + U32 arg2, /*!< Second FATAL Argument*/ + U32 arg3 /*!< Third FATAL Argument*/ +) { + this->log_FATAL_SendBuffFatal(arg1, arg2, arg3); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); +} + +//! Handler for command SB_GEN_ASSERT +/* Generate an ASSERT */ +void SendBuffImpl::SB_GEN_ASSERT_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq, /*!< The command sequence number*/ + U32 arg1, /*!< First ASSERT Argument*/ + U32 arg2, /*!< Second ASSERT Argument*/ + U32 arg3, /*!< Third ASSERT Argument*/ + U32 arg4, /*!< Fourth ASSERT Argument*/ + U32 arg5, /*!< Fifth ASSERT Argument*/ + U32 arg6 /*!< Sixth ASSERT Argument*/ +) { + FW_ASSERT(0, arg1, arg2, arg3, arg4, arg5, arg6); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); +} + +void SendBuffImpl::parameterUpdated(FwPrmIdType id) { + this->log_ACTIVITY_LO_BuffSendParameterUpdated(id); + Fw::ParamValid valid; + switch (id) { + case PARAMID_PARAMETER3: { + U8 val = this->paramGet_parameter3(valid); + this->tlmWrite_Parameter3(val); + break; + } + case PARAMID_PARAMETER4: { + F32 val = this->paramGet_parameter4(valid); + this->tlmWrite_Parameter4(val); + break; + } + default: + FW_ASSERT(0, id); + break; } } +} // namespace Ref diff --git a/Ref/SendBuffApp/SendBuffComponentImpl.hpp b/Ref/SendBuffApp/SendBuffComponentImpl.hpp index 1094c7defa..2f07b5ff21 100644 --- a/Ref/SendBuffApp/SendBuffComponentImpl.hpp +++ b/Ref/SendBuffApp/SendBuffComponentImpl.hpp @@ -5,58 +5,54 @@ namespace Ref { - /// This component sends a data buffer to a driver each time it is invoked by a scheduler +/// This component sends a data buffer to a driver each time it is invoked by a scheduler - class SendBuffImpl final : public SendBuffComponentBase { - public: +class SendBuffImpl final : public SendBuffComponentBase { + public: + // Only called by derived class + SendBuffImpl(const char* compName); //!< constructor + ~SendBuffImpl(); //!< destructor - // Only called by derived class - SendBuffImpl(const char* compName); //!< constructor - ~SendBuffImpl(); //!< destructor + private: + void SchedIn_handler(FwIndexType portNum, U32 context); //!< downcall for input port + void SB_START_PKTS_cmdHandler(FwOpcodeType opcode, U32 cmdSeq); //!< START_PKTS command handler + void SB_INJECT_PKT_ERROR_cmdHandler(FwOpcodeType opcode, U32 cmdSeq); //!< START_PKTS command handler + void SB_GEN_FATAL_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq, /*!< The command sequence number*/ + U32 arg1, /*!< First FATAL Argument*/ + U32 arg2, /*!< Second FATAL Argument*/ + U32 arg3 /*!< Third FATAL Argument*/ + ); - private: + //! Handler for command SB_GEN_ASSERT + /* Generate an ASSERT */ + void SB_GEN_ASSERT_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq, /*!< The command sequence number*/ + U32 arg1, /*!< First ASSERT Argument*/ + U32 arg2, /*!< Second ASSERT Argument*/ + U32 arg3, /*!< Third ASSERT Argument*/ + U32 arg4, /*!< Fourth ASSERT Argument*/ + U32 arg5, /*!< Fifth ASSERT Argument*/ + U32 arg6 /*!< Sixth ASSERT Argument*/ + ); + U32 m_invocations; //!< number of times component has been called by the scheduler + U32 m_buffsSent; //!< number of buffers sent + U32 m_errorsInjected; //!< number of errors injected + bool m_injectError; //!< flag to inject error on next packet + bool m_sendPackets; //!< If true, send packets + U32 m_currPacketId; //!< current packet ID to be sent + bool m_firstPacketSent; //!< set if first packet - void SchedIn_handler(FwIndexType portNum, U32 context); //!< downcall for input port - void SB_START_PKTS_cmdHandler(FwOpcodeType opcode, U32 cmdSeq); //!< START_PKTS command handler - void SB_INJECT_PKT_ERROR_cmdHandler(FwOpcodeType opcode, U32 cmdSeq); //!< START_PKTS command handler - void SB_GEN_FATAL_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq, /*!< The command sequence number*/ - U32 arg1, /*!< First FATAL Argument*/ - U32 arg2, /*!< Second FATAL Argument*/ - U32 arg3 /*!< Third FATAL Argument*/ - ); + // buffer data + Drv::DataBuffer m_testBuff; //!< data buffer to send - //! Handler for command SB_GEN_ASSERT - /* Generate an ASSERT */ - void SB_GEN_ASSERT_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq, /*!< The command sequence number*/ - U32 arg1, /*!< First ASSERT Argument*/ - U32 arg2, /*!< Second ASSERT Argument*/ - U32 arg3, /*!< Third ASSERT Argument*/ - U32 arg4, /*!< Fourth ASSERT Argument*/ - U32 arg5, /*!< Fifth ASSERT Argument*/ - U32 arg6 /*!< Sixth ASSERT Argument*/ - ); - U32 m_invocations; //!< number of times component has been called by the scheduler - U32 m_buffsSent; //!< number of buffers sent - U32 m_errorsInjected; //!< number of errors injected - bool m_injectError; //!< flag to inject error on next packet - bool m_sendPackets; //!< If true, send packets - U32 m_currPacketId; //!< current packet ID to be sent - bool m_firstPacketSent; //!< set if first packet + // parameter update notification + void parameterUpdated(FwPrmIdType id); //!< Notification function for changed parameters - // buffer data - Drv::DataBuffer m_testBuff; //!< data buffer to send - - // parameter update notification - void parameterUpdated(FwPrmIdType id); //!< Notification function for changed parameters - - // send state - SendBuff_ActiveState m_state; + // send state + SendBuff_ActiveState m_state; }; -} +} // namespace Ref #endif diff --git a/Ref/SignalGen/SignalGen.cpp b/Ref/SignalGen/SignalGen.cpp index 73ffe72167..c397bf589e 100644 --- a/Ref/SignalGen/SignalGen.cpp +++ b/Ref/SignalGen/SignalGen.cpp @@ -17,280 +17,252 @@ // TKC - don't know why it's undefined in VxWorks #ifdef TGT_OS_TYPE_VXWORKS -#define M_PI (22.0/7.0) +#define M_PI (22.0 / 7.0) #endif namespace Ref { - // ---------------------------------------------------------------------- - // Construction, initialization, and destruction - // ---------------------------------------------------------------------- +// ---------------------------------------------------------------------- +// Construction, initialization, and destruction +// ---------------------------------------------------------------------- - SignalGen :: - SignalGen(const char* name) : - SignalGenComponentBase(name), - sampleFrequency(25), - signalFrequency(1), - signalAmplitude(0.0f), - signalPhase(0.0f), - ticks(0), - sigType(SignalType::SINE), - sigHistory(), - sigPairHistory(), - running(false), - skipOne(false), - m_dpInProgress(false), - m_numDps(0), - m_currDp(0), - m_dpPriority(0) - {} +SignalGen ::SignalGen(const char* name) + : SignalGenComponentBase(name), + sampleFrequency(25), + signalFrequency(1), + signalAmplitude(0.0f), + signalPhase(0.0f), + ticks(0), + sigType(SignalType::SINE), + sigHistory(), + sigPairHistory(), + running(false), + skipOne(false), + m_dpInProgress(false), + m_numDps(0), + m_currDp(0), + m_dpPriority(0) {} +SignalGen ::~SignalGen() {} - SignalGen :: ~SignalGen() { } +// ---------------------------------------------------------------------- +// Handler implementations +// ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Handler implementations - // ---------------------------------------------------------------------- - - F32 SignalGen::generateSample(U32 ticks) { - F32 val = 0.0f; - if (this->skipOne) { - return val; - } - // Samples per period - F32 samplesPerPeriod = static_cast(this->sampleFrequency) / static_cast(this->signalFrequency); - U32 halfSamplesPerPeriod = samplesPerPeriod / 2; - /* Signals courtesy of the open source Aquila DSP Library */ - switch (this->sigType.e) { - case SignalType::TRIANGLE: - { +F32 SignalGen::generateSample(U32 ticks) { + F32 val = 0.0f; + if (this->skipOne) { + return val; + } + // Samples per period + F32 samplesPerPeriod = static_cast(this->sampleFrequency) / static_cast(this->signalFrequency); + U32 halfSamplesPerPeriod = samplesPerPeriod / 2; + /* Signals courtesy of the open source Aquila DSP Library */ + switch (this->sigType.e) { + case SignalType::TRIANGLE: { F32 m = this->signalAmplitude / static_cast(halfSamplesPerPeriod); val = m * static_cast(ticks % halfSamplesPerPeriod); break; } - case SignalType::SINE: - { + case SignalType::SINE: { F32 normalizedFrequency = 1.0f / samplesPerPeriod; - val = this->signalAmplitude * std::sin((2.0 * M_PI * normalizedFrequency * - static_cast(ticks)) + (this->signalPhase * 2.0 * M_PI)); + val = this->signalAmplitude * std::sin((2.0 * M_PI * normalizedFrequency * static_cast(ticks)) + + (this->signalPhase * 2.0 * M_PI)); break; } - case SignalType::SQUARE: - { - val = this->signalAmplitude * ((ticks % static_cast(samplesPerPeriod) < halfSamplesPerPeriod) ? 1.0f : -1.0f); + case SignalType::SQUARE: { + val = this->signalAmplitude * + ((ticks % static_cast(samplesPerPeriod) < halfSamplesPerPeriod) ? 1.0f : -1.0f); break; } - case SignalType::NOISE: - { + case SignalType::NOISE: { val = this->signalAmplitude * (std::rand() / static_cast(RAND_MAX)); break; } default: - FW_ASSERT(0); // Should never happen + FW_ASSERT(0); // Should never happen + } + return val; +} + +void SignalGen::schedIn_handler(FwIndexType portNum, /*!< The port number*/ + U32 context /*!< The call order*/ +) { + F32 value = 0.0f; + // This is a queued component, so it must intentionally run the dispatch of commands and queue processing on this + // synchronous scheduled call + this->doDispatch(); + + // This short-circuits when the signal generator is not running + if (not this->running) { + return; + } + // Allows for skipping a single reading of the signal + if (not this->skipOne) { + value = this->generateSample(this->ticks); + } + this->skipOne = false; + + // Build our new types + SignalPair pair = SignalPair(this->ticks, value); + + // Shift and assign our array types + for (U32 i = 1; i < this->sigHistory.SIZE; i++) { + this->sigHistory[i - 1] = this->sigHistory[i]; + this->sigPairHistory[i - 1] = this->sigPairHistory[i]; + } + this->sigHistory[this->sigHistory.SIZE - 1] = value; + this->sigPairHistory[this->sigPairHistory.SIZE - 1] = pair; + + // Composite structure + SignalInfo sigInfo(this->sigType, this->sigHistory, this->sigPairHistory); + + // Write all signals + this->tlmWrite_Type(this->sigType); + this->tlmWrite_Output(value); + this->tlmWrite_PairOutput(pair); + this->tlmWrite_History(this->sigHistory); + this->tlmWrite_PairHistory(this->sigPairHistory); + this->tlmWrite_Info(sigInfo); + + // if a Data product is being generated, store a record + if (this->m_dpInProgress) { + Fw::SerializeStatus stat = this->m_dpContainer.serializeRecord_DataRecord(sigInfo); + this->m_currDp++; + this->m_dpBytes += SignalInfo::SERIALIZED_SIZE; + // check for full data product + if (Fw::SerializeStatus::FW_SERIALIZE_NO_ROOM_LEFT == stat) { + this->log_WARNING_LO_DpRecordFull(this->m_currDp, this->m_dpBytes); + this->cleanupAndSendDp(); + } else if (this->m_currDp == this->m_numDps) { // if we reached the target number of DPs + this->log_ACTIVITY_LO_DpComplete(this->m_numDps, this->m_dpBytes); + this->cleanupAndSendDp(); } - return val; + + this->tlmWrite_DpBytes(this->m_dpBytes); + this->tlmWrite_DpRecords(this->m_currDp); } - void SignalGen::schedIn_handler( - FwIndexType portNum, /*!< The port number*/ - U32 context /*!< The call order*/ - ) - { - F32 value = 0.0f; - // This is a queued component, so it must intentionally run the dispatch of commands and queue processing on this - // synchronous scheduled call - this->doDispatch(); + this->ticks += 1; +} - // This short-circuits when the signal generator is not running - if (not this->running) { - return; - } - // Allows for skipping a single reading of the signal - if (not this->skipOne) { - value = this->generateSample(this->ticks); - } - this->skipOne = false; +void SignalGen::Settings_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq, /*!< The command sequence number*/ + U32 Frequency, + F32 Amplitude, + F32 Phase, + Ref::SignalType SigType) { + this->signalFrequency = Frequency; + this->signalAmplitude = Amplitude; + this->signalPhase = Phase; + this->sigType = SigType; - // Build our new types - SignalPair pair = SignalPair(this->ticks, value); + // When the settings change, reset the history values + for (U32 i = 0; i < SignalSet::SIZE; i++) { + this->sigHistory[i] = 0.0f; + } + for (U32 i = 0; i < SignalPairSet::SIZE; i++) { + this->sigPairHistory[i].set_time(0.0f); + this->sigPairHistory[i].set_value(0.0f); + } + this->log_ACTIVITY_LO_SettingsChanged(this->signalFrequency, this->signalAmplitude, this->signalPhase, + this->sigType); + this->tlmWrite_Type(SigType); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); +} - // Shift and assign our array types - for (U32 i = 1; i < this->sigHistory.SIZE; i++) { - this->sigHistory[i - 1] = this->sigHistory[i]; - this->sigPairHistory[i - 1] = this->sigPairHistory[i]; - } - this->sigHistory[this->sigHistory.SIZE - 1] = value; - this->sigPairHistory[this->sigPairHistory.SIZE - 1] = pair; +void SignalGen::Toggle_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq /*!< The command sequence number*/ +) { + this->running = !this->running; + this->ticks = 0; + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); +} - // Composite structure - SignalInfo sigInfo(this->sigType, this->sigHistory, this->sigPairHistory); +void SignalGen::Skip_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq /*!< The command sequence number*/ +) { + this->skipOne = true; + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); +} - // Write all signals - this->tlmWrite_Type(this->sigType); - this->tlmWrite_Output(value); - this->tlmWrite_PairOutput(pair); - this->tlmWrite_History(this->sigHistory); - this->tlmWrite_PairHistory(this->sigPairHistory); - this->tlmWrite_Info(sigInfo); - - // if a Data product is being generated, store a record - if (this->m_dpInProgress) { - Fw::SerializeStatus stat = this->m_dpContainer.serializeRecord_DataRecord(sigInfo); - this->m_currDp++; - this->m_dpBytes += SignalInfo::SERIALIZED_SIZE; - // check for full data product - if (Fw::SerializeStatus::FW_SERIALIZE_NO_ROOM_LEFT == stat) { - this->log_WARNING_LO_DpRecordFull(this->m_currDp,this->m_dpBytes); - this->cleanupAndSendDp(); - } else if (this->m_currDp == this->m_numDps) { // if we reached the target number of DPs - this->log_ACTIVITY_LO_DpComplete(this->m_numDps,this->m_dpBytes); - this->cleanupAndSendDp(); - } - - this->tlmWrite_DpBytes(this->m_dpBytes); - this->tlmWrite_DpRecords(this->m_currDp); - } - - this->ticks += 1; +void SignalGen::Dp_cmdHandler(FwOpcodeType opCode, + U32 cmdSeq, + Ref::SignalGen_DpReqType reqType, + U32 records, + U32 priority) { + // at least one record + if (0 == records) { + this->log_WARNING_HI_InSufficientDpRecords(); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR); + return; } - void SignalGen::Settings_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq, /*!< The command sequence number*/ - U32 Frequency, - F32 Amplitude, - F32 Phase, - Ref::SignalType SigType - ) - { - this->signalFrequency = Frequency; - this->signalAmplitude = Amplitude; - this->signalPhase = Phase; - this->sigType = SigType; - - // When the settings change, reset the history values - for (U32 i = 0; i < SignalSet::SIZE; i++) { - this->sigHistory[i] = 0.0f; - } - for (U32 i = 0; i < SignalPairSet::SIZE; i++) { - this->sigPairHistory[i].set_time(0.0f); - this->sigPairHistory[i].set_value(0.0f); - } - this->log_ACTIVITY_LO_SettingsChanged(this->signalFrequency, this->signalAmplitude, this->signalPhase, this->sigType); - this->tlmWrite_Type(SigType); - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + // make sure DPs are available + if (not this->isConnected_productGetOut_OutputPort(0)) { + this->log_WARNING_HI_DpsNotConnected(); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); + return; } - void SignalGen::Toggle_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq /*!< The command sequence number*/ - ) - { - this->running = !this->running; - this->ticks = 0; - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); - } - - void SignalGen::Skip_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq /*!< The command sequence number*/ - ) - { - this->skipOne = true; - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); - } - - void SignalGen::Dp_cmdHandler( - FwOpcodeType opCode, - U32 cmdSeq, - Ref::SignalGen_DpReqType reqType, - U32 records, - U32 priority - ) - { - // at least one record - if (0 == records) { - this->log_WARNING_HI_InSufficientDpRecords(); - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR); - return; - } - - // make sure DPs are available - if ( - not this->isConnected_productGetOut_OutputPort(0) - ) { - this->log_WARNING_HI_DpsNotConnected(); + // get DP buffer. Use sync or async request depending on + // requested type + FwSizeType dpSize = records * (SignalInfo::SERIALIZED_SIZE + sizeof(FwDpIdType)); + this->m_numDps = records; + this->m_currDp = 0; + this->m_dpPriority = static_cast(priority); + this->log_ACTIVITY_LO_DpMemRequested(dpSize); + if (Ref::SignalGen_DpReqType::IMMEDIATE == reqType) { + Fw::Success stat = this->dpGet_DataContainer(dpSize, this->m_dpContainer); + // make sure we got the memory we wanted + if (Fw::Success::FAILURE == stat) { + this->log_WARNING_HI_DpMemoryFail(); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); - return; - } - - // get DP buffer. Use sync or async request depending on - // requested type - FwSizeType dpSize = records*(SignalInfo::SERIALIZED_SIZE + sizeof(FwDpIdType)); - this->m_numDps = records; - this->m_currDp = 0; - this->m_dpPriority = static_cast(priority); - this->log_ACTIVITY_LO_DpMemRequested(dpSize); - if (Ref::SignalGen_DpReqType::IMMEDIATE == reqType) { - Fw::Success stat = this->dpGet_DataContainer(dpSize,this->m_dpContainer); - // make sure we got the memory we wanted - if (Fw::Success::FAILURE == stat) { - this->log_WARNING_HI_DpMemoryFail(); - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); - } else { - this->m_dpInProgress = true; - this->log_ACTIVITY_LO_DpStarted(records); - this->log_ACTIVITY_LO_DpMemReceived(this->m_dpContainer.getBuffer().getSize()); - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); - // override priority with requested priority - this->m_dpContainer.setPriority(this->m_dpPriority); - } - } else if (Ref::SignalGen_DpReqType::ASYNC == reqType) { - this->dpRequest_DataContainer(dpSize); - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } else { - // should never get here - FW_ASSERT(0,reqType.e); + this->m_dpInProgress = true; + this->log_ACTIVITY_LO_DpStarted(records); + this->log_ACTIVITY_LO_DpMemReceived(this->m_dpContainer.getBuffer().getSize()); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + // override priority with requested priority + this->m_dpContainer.setPriority(this->m_dpPriority); } - + } else if (Ref::SignalGen_DpReqType::ASYNC == reqType) { + this->dpRequest_DataContainer(dpSize); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + } else { + // should never get here + FW_ASSERT(0, reqType.e); } +} - void SignalGen::cleanupAndSendDp() { - this->dpSend(this->m_dpContainer); +void SignalGen::cleanupAndSendDp() { + this->dpSend(this->m_dpContainer); + this->m_dpInProgress = false; + this->m_dpBytes = 0; + this->m_numDps = 0; + this->m_currDp = 0; +} + +// ---------------------------------------------------------------------- +// Handler implementations for data products +// ---------------------------------------------------------------------- + +void SignalGen ::dpRecv_DataContainer_handler(DpContainer& container, Fw::Success::T status) { + // Make sure we got the buffer we wanted or quit + if (Fw::Success::SUCCESS == status) { + this->m_dpContainer = container; + this->m_dpInProgress = true; + // set previously requested priority + this->m_dpContainer.setPriority(this->m_dpPriority); + this->log_ACTIVITY_LO_DpStarted(this->m_numDps); + } else { + this->log_WARNING_HI_DpMemoryFail(); + // cleanup this->m_dpInProgress = false; this->m_dpBytes = 0; this->m_numDps = 0; this->m_currDp = 0; } - - - - // ---------------------------------------------------------------------- - // Handler implementations for data products - // ---------------------------------------------------------------------- - - void SignalGen :: - dpRecv_DataContainer_handler( - DpContainer& container, - Fw::Success::T status - ) - { - - // Make sure we got the buffer we wanted or quit - if (Fw::Success::SUCCESS == status) { - this->m_dpContainer = container; - this->m_dpInProgress = true; - // set previously requested priority - this->m_dpContainer.setPriority(this->m_dpPriority); - this->log_ACTIVITY_LO_DpStarted(this->m_numDps); - } else { - this->log_WARNING_HI_DpMemoryFail(); - // cleanup - this->m_dpInProgress = false; - this->m_dpBytes = 0; - this->m_numDps = 0; - this->m_currDp = 0; - } - } - } + +} // namespace Ref diff --git a/Ref/SignalGen/SignalGen.hpp b/Ref/SignalGen/SignalGen.hpp index 8a3d983222..c61caa359e 100644 --- a/Ref/SignalGen/SignalGen.hpp +++ b/Ref/SignalGen/SignalGen.hpp @@ -22,92 +22,77 @@ namespace Ref { - class SignalGen final : - public SignalGenComponentBase - { +class SignalGen final : public SignalGenComponentBase { + private: + void schedIn_handler(FwIndexType portNum, /*!< The port number*/ + U32 context /*!< The call order*/ + ) final; - private: + void Settings_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq, /*!< The command sequence number*/ + U32 Frequency, + F32 Amplitude, + F32 Phase, + Ref::SignalType SigType) final; - void schedIn_handler( - FwIndexType portNum, /*!< The port number*/ - U32 context /*!< The call order*/ - ) final; + void Toggle_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq /*!< The command sequence number*/ + ) final; - void Settings_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq, /*!< The command sequence number*/ - U32 Frequency, - F32 Amplitude, - F32 Phase, - Ref::SignalType SigType - ) final; + void Skip_cmdHandler(FwOpcodeType opCode, /*!< The opcode*/ + U32 cmdSeq /*!< The command sequence number*/ + ) final; - void Toggle_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq /*!< The command sequence number*/ - ) final; + //! Handler implementation for command Dp + //! + //! Signal Generator Settings + void Dp_cmdHandler(FwOpcodeType opCode, //!< The opcode + U32 cmdSeq, //!< The command sequence number + Ref::SignalGen_DpReqType reqType, + U32 records, + U32 priority) final; - void Skip_cmdHandler( - FwOpcodeType opCode, /*!< The opcode*/ - U32 cmdSeq /*!< The command sequence number*/ - ) final; + // ---------------------------------------------------------------------- + // Handler implementations for data products + // ---------------------------------------------------------------------- - //! Handler implementation for command Dp - //! - //! Signal Generator Settings - void Dp_cmdHandler( - FwOpcodeType opCode, //!< The opcode - U32 cmdSeq, //!< The command sequence number - Ref::SignalGen_DpReqType reqType, - U32 records, - U32 priority - ) final; + //! Receive a container of type DataContainer + void dpRecv_DataContainer_handler(DpContainer& container, //!< The container + Fw::Success::T status //!< The container status + ) final; - // ---------------------------------------------------------------------- - // Handler implementations for data products - // ---------------------------------------------------------------------- + public: + //! Construct a SignalGen + SignalGen(const char* compName //!< The component name + ); - //! Receive a container of type DataContainer - void dpRecv_DataContainer_handler( - DpContainer& container, //!< The container - Fw::Success::T status //!< The container status - ) final; + //! Destroy a SignalGen + ~SignalGen(); + private: + // Generate the next sample internal helper + F32 generateSample(U32 ticks); - public: - //! Construct a SignalGen - SignalGen( - const char* compName //!< The component name - ); + // DP cleanup helper + void cleanupAndSendDp(); - //! Destroy a SignalGen - ~SignalGen(); - - private: - // Generate the next sample internal helper - F32 generateSample(U32 ticks); - - // DP cleanup helper - void cleanupAndSendDp(); - - // Member variables - U32 sampleFrequency; - U32 signalFrequency; - F32 signalAmplitude; - F32 signalPhase; - U32 ticks; - SignalType sigType; - SignalSet sigHistory; - SignalPairSet sigPairHistory; - bool running; - bool skipOne; - DpContainer m_dpContainer; - bool m_dpInProgress; //!< flag to indicate data products are being generated - U32 m_numDps; //!< number of DPs to store - U32 m_currDp; //!< current DP number - U32 m_dpBytes; //!< currently serialized records - FwDpPriorityType m_dpPriority; //!< stored priority for current DP - - }; -} + // Member variables + U32 sampleFrequency; + U32 signalFrequency; + F32 signalAmplitude; + F32 signalPhase; + U32 ticks; + SignalType sigType; + SignalSet sigHistory; + SignalPairSet sigPairHistory; + bool running; + bool skipOne; + DpContainer m_dpContainer; + bool m_dpInProgress; //!< flag to indicate data products are being generated + U32 m_numDps; //!< number of DPs to store + U32 m_currDp; //!< current DP number + U32 m_dpBytes; //!< currently serialized records + FwDpPriorityType m_dpPriority; //!< stored priority for current DP +}; +} // namespace Ref #endif diff --git a/Ref/SignalGen/test/ut/SignalGenTestMain.cpp b/Ref/SignalGen/test/ut/SignalGenTestMain.cpp index 42a37ff91d..aedd25148b 100644 --- a/Ref/SignalGen/test/ut/SignalGenTestMain.cpp +++ b/Ref/SignalGen/test/ut/SignalGenTestMain.cpp @@ -9,7 +9,7 @@ TEST(Nominal, TestStart) { tester.test_start(); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/Ref/SignalGen/test/ut/SignalGenTester.cpp b/Ref/SignalGen/test/ut/SignalGenTester.cpp index daa9a61c35..6bec78c3f1 100644 --- a/Ref/SignalGen/test/ut/SignalGenTester.cpp +++ b/Ref/SignalGen/test/ut/SignalGenTester.cpp @@ -14,74 +14,54 @@ namespace Ref { - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- +// ---------------------------------------------------------------------- +// Construction and destruction +// ---------------------------------------------------------------------- - SignalGenTester :: - SignalGenTester() : - SignalGenGTestBase("Tester", MAX_HISTORY_SIZE), - component("SignalGen") - { +SignalGenTester ::SignalGenTester() : SignalGenGTestBase("Tester", MAX_HISTORY_SIZE), component("SignalGen") { this->initComponents(); this->connectPorts(); - this->m_reqDpBuff.set(this->m_dpBuff,sizeof(this->m_dpBuff)); - } + this->m_reqDpBuff.set(this->m_dpBuff, sizeof(this->m_dpBuff)); +} - SignalGenTester :: - ~SignalGenTester() - { +SignalGenTester ::~SignalGenTester() {} - } +// ---------------------------------------------------------------------- +// Tests +// ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- +void SignalGenTester ::test_start() { + ASSERT_TLM_Output_SIZE(0); + sendCmd_Toggle(0, 0); + component.doDispatch(); + invoke_to_schedIn(0, 0); + component.doDispatch(); + ASSERT_TLM_Output_SIZE(1); + sendCmd_Dp(0, 10, Ref::SignalGen_DpReqType::IMMEDIATE, 1, 1); + component.doDispatch(); + // verify request for data product buffer + ASSERT_PRODUCT_GET_SIZE(1); + // run 2 cycles, should output data product on second + invoke_to_schedIn(0, 0); + ASSERT_PRODUCT_SEND_SIZE(1); +} - void SignalGenTester :: - test_start() - { - ASSERT_TLM_Output_SIZE(0); - sendCmd_Toggle(0, 0); - component.doDispatch(); - invoke_to_schedIn(0, 0); - component.doDispatch(); - ASSERT_TLM_Output_SIZE(1); - sendCmd_Dp(0,10,Ref::SignalGen_DpReqType::IMMEDIATE,1,1); - component.doDispatch(); - // verify request for data product buffer - ASSERT_PRODUCT_GET_SIZE(1); - // run 2 cycles, should output data product on second - invoke_to_schedIn(0, 0); - ASSERT_PRODUCT_SEND_SIZE(1); +//! Handle a text event +void SignalGenTester::textLogIn(FwEventIdType id, //!< The event ID + const Fw::Time& timeTag, //!< The time + const Fw::LogSeverity severity, //!< The severity + const Fw::TextLogString& text //!< The event string +) { + TextLogEntry e = {id, timeTag, severity, text}; - } + printTextLogHistoryEntry(e, stdout); +} - //! Handle a text event - void SignalGenTester::textLogIn( - FwEventIdType id, //!< The event ID - const Fw::Time& timeTag, //!< The time - const Fw::LogSeverity severity, //!< The severity - const Fw::TextLogString& text //!< The event string - ) { - TextLogEntry e = { id, timeTag, severity, text }; - - printTextLogHistoryEntry(e, stdout); - - } - - Fw::Success::T SignalGenTester :: - productGet_handler( - FwDpIdType id, - FwSizeType dataSize, - Fw::Buffer& buffer - ) - { - printf ("Component requested %" PRI_FwSizeType " bytes.\n",dataSize); - buffer.set(this->m_dpBuff,dataSize); +Fw::Success::T SignalGenTester ::productGet_handler(FwDpIdType id, FwSizeType dataSize, Fw::Buffer& buffer) { + printf("Component requested %" PRI_FwSizeType " bytes.\n", dataSize); + buffer.set(this->m_dpBuff, dataSize); this->pushProductGetEntry(id, dataSize); return Fw::Success::SUCCESS; - } +} - -} // end namespace Ref +} // end namespace Ref diff --git a/Ref/SignalGen/test/ut/SignalGenTester.hpp b/Ref/SignalGen/test/ut/SignalGenTester.hpp index d86cb14363..48554cb571 100644 --- a/Ref/SignalGen/test/ut/SignalGenTester.hpp +++ b/Ref/SignalGen/test/ut/SignalGenTester.hpp @@ -13,92 +13,83 @@ #ifndef TESTER_HPP #define TESTER_HPP -#include "SignalGenGTestBase.hpp" #include "Ref/SignalGen/SignalGen.hpp" +#include "SignalGenGTestBase.hpp" namespace Ref { - class SignalGenTester : - public SignalGenGTestBase - { - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- +class SignalGenTester : public SignalGenGTestBase { + // ---------------------------------------------------------------------- + // Construction and destruction + // ---------------------------------------------------------------------- - public: - // Maximum size of histories storing events, telemetry, and port outputs - static const U32 MAX_HISTORY_SIZE = 10; - // Instance ID supplied to the component instance under test - static const FwEnumStoreType TEST_INSTANCE_ID = 0; - // Queue depth supplied to component instance under test - static const FwSizeType TEST_INSTANCE_QUEUE_DEPTH = 10; + public: + // Maximum size of histories storing events, telemetry, and port outputs + static const U32 MAX_HISTORY_SIZE = 10; + // Instance ID supplied to the component instance under test + static const FwEnumStoreType TEST_INSTANCE_ID = 0; + // Queue depth supplied to component instance under test + static const FwSizeType TEST_INSTANCE_QUEUE_DEPTH = 10; - //! Construct object SignalGenTester - //! - SignalGenTester(); + //! Construct object SignalGenTester + //! + SignalGenTester(); - //! Destroy object SignalGenTester - //! - ~SignalGenTester(); + //! Destroy object SignalGenTester + //! + ~SignalGenTester(); - public: + public: + // ---------------------------------------------------------------------- + // Tests + // ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- + //! To do + //! + void test_start(); - //! To do - //! - void test_start(); + private: + // ---------------------------------------------------------------------- + // Helper methods + // ---------------------------------------------------------------------- - private: + //! Connect ports + //! + void connectPorts(); - // ---------------------------------------------------------------------- - // Helper methods - // ---------------------------------------------------------------------- + //! Initialize components + //! + void initComponents(); - //! Connect ports - //! - void connectPorts(); + private: + //! Handle a data product get from the component under test + //! + //! By default, (1) call pushProductGetEntry; (2) do not allocate a buffer + //! and return FAILURE. You can override this behavior, e.g., to call + //! pushProductGetEntry, allocate a buffer and return SUCCESS. + Fw::Success::T productGet_handler(FwDpIdType id, //!< The container ID (input) + FwSizeType dataSize, //!< The data size of the requested buffer (input) + Fw::Buffer& buffer //!< The buffer (output) + ) override; - //! Initialize components - //! - void initComponents(); + // ---------------------------------------------------------------------- + // Variables + // ---------------------------------------------------------------------- - private: + //! The component under test + //! + SignalGen component; - //! Handle a data product get from the component under test - //! - //! By default, (1) call pushProductGetEntry; (2) do not allocate a buffer - //! and return FAILURE. You can override this behavior, e.g., to call - //! pushProductGetEntry, allocate a buffer and return SUCCESS. - Fw::Success::T productGet_handler ( - FwDpIdType id, //!< The container ID (input) - FwSizeType dataSize, //!< The data size of the requested buffer (input) - Fw::Buffer& buffer //!< The buffer (output) - ) override; + void textLogIn(FwEventIdType id, //!< The event ID + const Fw::Time& timeTag, //!< The time + const Fw::LogSeverity severity, //!< The severity + const Fw::TextLogString& text //!< The event string + ) override; + U8 m_dpBuff[1024]; + Fw::Buffer m_reqDpBuff; +}; - // ---------------------------------------------------------------------- - // Variables - // ---------------------------------------------------------------------- - - //! The component under test - //! - SignalGen component; - - void textLogIn( - FwEventIdType id, //!< The event ID - const Fw::Time& timeTag, //!< The time - const Fw::LogSeverity severity, //!< The severity - const Fw::TextLogString& text //!< The event string - ) override; - - U8 m_dpBuff[1024]; - Fw::Buffer m_reqDpBuff; - - }; - -} // end namespace Ref +} // end namespace Ref #endif diff --git a/Ref/Top/RefTopology.cpp b/Ref/Top/RefTopology.cpp index 7d88746ed5..81d0e51680 100644 --- a/Ref/Top/RefTopology.cpp +++ b/Ref/Top/RefTopology.cpp @@ -15,7 +15,6 @@ // Necessary project-specified types #include - // Allows easy reference to objects in FPP/autocoder required namespaces using namespace Ref; @@ -78,7 +77,7 @@ void setupTopology(const TopologyState& state) { loadParameters(); // Autocoded task kick-off (active components). Function provided by autocoder. startTasks(state); - //Initialize socket client communication if and only if there is a valid specification + // Initialize socket client communication if and only if there is a valid specification if (state.hostname != nullptr && state.port != 0) { Os::TaskString name("ReceiveTask"); comDriver.start(name, COMM_PRIORITY, Default::STACK_SIZE); @@ -102,7 +101,7 @@ void teardownTopology(const TopologyState& state) { stopTasks(state); freeThreads(state); - //Stop the comDriver component, free thread + // Stop the comDriver component, free thread comDriver.stop(); (void)comDriver.join(); diff --git a/Ref/Top/RefTopology.hpp b/Ref/Top/RefTopology.hpp index f083a0ca28..b66a2053ac 100644 --- a/Ref/Top/RefTopology.hpp +++ b/Ref/Top/RefTopology.hpp @@ -67,12 +67,13 @@ void teardownTopology(const TopologyState& state); /** * \brief cycle the rate group driver based in a system timer * - * In order to be a portable demonstration, the reference topology does not have a direct hardware timer that is typically used - * in embedded applications. Instead, a linux system timer is used to drive the rate groups at 1Hz. The slower rate groups are - * derived from this fundamental rate using the RateGroupDriver component to divide the rate down to slower rates. - * - * For embedded Linux, this could be used to drive the system rate groups. For other embedded systems, projects should write components - * that implement whatever timers are available for that platform in place of Svc/LinuxTimer. + * In order to be a portable demonstration, the reference topology does not have a direct hardware timer that is + * typically used in embedded applications. Instead, a linux system timer is used to drive the rate groups at 1Hz. The + * slower rate groups are derived from this fundamental rate using the RateGroupDriver component to divide the rate down + * to slower rates. + * + * For embedded Linux, this could be used to drive the system rate groups. For other embedded systems, projects should + * write components that implement whatever timers are available for that platform in place of Svc/LinuxTimer. * * This loop is stopped via a stopRateGroups call. * @@ -80,11 +81,11 @@ void teardownTopology(const TopologyState& state); void startRateGroups(const Fw::TimeInterval& interval); /** - * \brief stop the rate groups + * \brief stop the rate groups * * This stops the cycle started by startRateGroups. */ void stopRateGroups(); -} // namespace Ref +} // namespace Ref #endif diff --git a/Utils/CRCChecker.cpp b/Utils/CRCChecker.cpp index 449d18e201..8f388c4394 100644 --- a/Utils/CRCChecker.cpp +++ b/Utils/CRCChecker.cpp @@ -10,19 +10,18 @@ // ====================================================================== #include -#include #include +#include #include #include +#include #include -#include namespace Utils { static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING, - "Cannot use CRC checker without full string formatting"); + "Cannot use CRC checker without full string formatting"); - crc_stat_t create_checksum_file(const char* const fname) - { +crc_stat_t create_checksum_file(const char* const fname) { FW_ASSERT(fname != nullptr); FwSizeType i; @@ -40,45 +39,39 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING, U8 block_data[CRC_FILE_READ_BLOCK]; fs_stat = Os::FileSystem::getFileSize(fname, filesize); - if(fs_stat != Os::FileSystem::OP_OK) - { - return FAILED_FILE_SIZE; + if (fs_stat != Os::FileSystem::OP_OK) { + return FAILED_FILE_SIZE; } // Open file stat = f.open(fname, Os::File::OPEN_READ); - if(stat != Os::File::OP_OK) - { - return FAILED_FILE_OPEN; + if (stat != Os::File::OP_OK) { + return FAILED_FILE_OPEN; } // Read file bytes_to_read = CRC_FILE_READ_BLOCK; blocks = filesize / CRC_FILE_READ_BLOCK; - for(i = 0; i < blocks; i++) - { - stat = f.read(block_data, bytes_to_read); - if(stat != Os::File::OP_OK || bytes_to_read != CRC_FILE_READ_BLOCK) - { - f.close(); - return FAILED_FILE_READ; - } + for (i = 0; i < blocks; i++) { + stat = f.read(block_data, bytes_to_read); + if (stat != Os::File::OP_OK || bytes_to_read != CRC_FILE_READ_BLOCK) { + f.close(); + return FAILED_FILE_READ; + } - hash.update(block_data, bytes_to_read); + hash.update(block_data, bytes_to_read); } remaining_bytes = filesize % CRC_FILE_READ_BLOCK; bytes_to_read = remaining_bytes; - if(remaining_bytes > 0) - { - stat = f.read(block_data, bytes_to_read); - if(stat != Os::File::OP_OK || bytes_to_read != remaining_bytes) - { - f.close(); - return FAILED_FILE_READ; - } + if (remaining_bytes > 0) { + stat = f.read(block_data, bytes_to_read); + if (stat != Os::File::OP_OK || bytes_to_read != remaining_bytes) { + f.close(); + return FAILED_FILE_READ; + } - hash.update(block_data, remaining_bytes); + hash.update(block_data, remaining_bytes); } // close file @@ -92,57 +85,52 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING, FW_ASSERT(formatStatus == Fw::FormatStatus::SUCCESS); stat = f.open(hashFilename.toChar(), Os::File::OPEN_WRITE); - if(stat != Os::File::OP_OK) - { - return FAILED_FILE_CRC_OPEN; + if (stat != Os::File::OP_OK) { + return FAILED_FILE_CRC_OPEN; } // Write checksum file bytes_to_write = sizeof(checksum); stat = f.write(reinterpret_cast(&checksum), bytes_to_write); - if(stat != Os::File::OP_OK || sizeof(checksum) != bytes_to_write) - { - f.close(); - return FAILED_FILE_CRC_WRITE; + if (stat != Os::File::OP_OK || sizeof(checksum) != bytes_to_write) { + f.close(); + return FAILED_FILE_CRC_WRITE; } // close checksum file f.close(); return PASSED_FILE_CRC_WRITE; - } +} - crc_stat_t read_crc32_from_file(const char* const fname, U32 &checksum_from_file) { - Os::File f; - Os::File::Status stat; - Fw::FileNameString hashFilename; - FW_ASSERT(fname != nullptr); - // open checksum file - Fw::FormatStatus formatStatus = hashFilename.format("%s%s", fname, HASH_EXTENSION_STRING); - FW_ASSERT(formatStatus == Fw::FormatStatus::SUCCESS); +crc_stat_t read_crc32_from_file(const char* const fname, U32& checksum_from_file) { + Os::File f; + Os::File::Status stat; + Fw::FileNameString hashFilename; + FW_ASSERT(fname != nullptr); + // open checksum file + Fw::FormatStatus formatStatus = hashFilename.format("%s%s", fname, HASH_EXTENSION_STRING); + FW_ASSERT(formatStatus == Fw::FormatStatus::SUCCESS); - stat = f.open(hashFilename.toChar(), Os::File::OPEN_READ); - if(stat != Os::File::OP_OK) - { + stat = f.open(hashFilename.toChar(), Os::File::OPEN_READ); + if (stat != Os::File::OP_OK) { return FAILED_FILE_CRC_OPEN; - } + } - // Read checksum file - FwSizeType checksum_from_file_size = static_cast(sizeof(checksum_from_file)); - stat = f.read(reinterpret_cast(&checksum_from_file), checksum_from_file_size); - if(stat != Os::File::OP_OK || checksum_from_file_size != sizeof(checksum_from_file)) - { + // Read checksum file + FwSizeType checksum_from_file_size = static_cast(sizeof(checksum_from_file)); + stat = f.read(reinterpret_cast(&checksum_from_file), checksum_from_file_size); + if (stat != Os::File::OP_OK || checksum_from_file_size != sizeof(checksum_from_file)) { f.close(); return FAILED_FILE_CRC_READ; - } + } - // close checksum file - f.close(); - return PASSED_FILE_CRC_CHECK; - } + // close checksum file + f.close(); + return PASSED_FILE_CRC_CHECK; +} - crc_stat_t verify_checksum(const char* const fname, U32 &expected, U32 &actual) - { +crc_stat_t verify_checksum(const char* const fname, U32& expected, U32& actual) { FW_ASSERT(fname != nullptr); FwSizeType i; @@ -159,45 +147,39 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING, U8 block_data[CRC_FILE_READ_BLOCK]; fs_stat = Os::FileSystem::getFileSize(fname, filesize); - if(fs_stat != Os::FileSystem::OP_OK) - { - return FAILED_FILE_SIZE; + if (fs_stat != Os::FileSystem::OP_OK) { + return FAILED_FILE_SIZE; } // Open file stat = f.open(fname, Os::File::OPEN_READ); - if(stat != Os::File::OP_OK) - { - return FAILED_FILE_OPEN; + if (stat != Os::File::OP_OK) { + return FAILED_FILE_OPEN; } // Read file bytes_to_read = CRC_FILE_READ_BLOCK; blocks = filesize / CRC_FILE_READ_BLOCK; - for(i = 0; i < blocks; i++) - { - stat = f.read(block_data, bytes_to_read); - if(stat != Os::File::OP_OK || bytes_to_read != CRC_FILE_READ_BLOCK) - { - f.close(); - return FAILED_FILE_READ; - } + for (i = 0; i < blocks; i++) { + stat = f.read(block_data, bytes_to_read); + if (stat != Os::File::OP_OK || bytes_to_read != CRC_FILE_READ_BLOCK) { + f.close(); + return FAILED_FILE_READ; + } - hash.update(block_data, static_cast(bytes_to_read)); + hash.update(block_data, static_cast(bytes_to_read)); } remaining_bytes = filesize % CRC_FILE_READ_BLOCK; bytes_to_read = remaining_bytes; - if(remaining_bytes > 0) - { - stat = f.read(block_data, bytes_to_read); - if(stat != Os::File::OP_OK || bytes_to_read != remaining_bytes) - { - f.close(); - return FAILED_FILE_READ; - } + if (remaining_bytes > 0) { + stat = f.read(block_data, bytes_to_read); + if (stat != Os::File::OP_OK || bytes_to_read != remaining_bytes) { + f.close(); + return FAILED_FILE_READ; + } - hash.update(block_data, remaining_bytes); + hash.update(block_data, remaining_bytes); } // close file @@ -211,16 +193,15 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING, } // compare checksums - if(checksum != checksum_from_file) - { - expected = checksum_from_file; - actual = checksum; - return FAILED_FILE_CRC_CHECK; + if (checksum != checksum_from_file) { + expected = checksum_from_file; + actual = checksum; + return FAILED_FILE_CRC_CHECK; } expected = checksum_from_file; actual = checksum; return PASSED_FILE_CRC_CHECK; - } - } + +} // namespace Utils diff --git a/Utils/CRCChecker.hpp b/Utils/CRCChecker.hpp index 0593e542b2..023852dd51 100644 --- a/Utils/CRCChecker.hpp +++ b/Utils/CRCChecker.hpp @@ -1,4 +1,4 @@ -// ====================================================================== +// ====================================================================== // \title CRCChecker.hpp // \author ortega // \brief hpp file for a crc32 checker @@ -7,7 +7,7 @@ // Copyright 2009-2020, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. -// ====================================================================== +// ====================================================================== #ifndef CRC_CHECKER_HPP #define CRC_CHECKER_HPP @@ -17,11 +17,9 @@ namespace Utils { - static const FwSignedSizeType CRC_FILE_READ_BLOCK = CONFIG_CRC_FILE_READ_BLOCK ; - +static const FwSignedSizeType CRC_FILE_READ_BLOCK = CONFIG_CRC_FILE_READ_BLOCK; - typedef enum - { +typedef enum { PASSED_FILE_CRC_CHECK = 0, PASSED_FILE_CRC_WRITE, FAILED_FILE_SIZE, @@ -32,12 +30,12 @@ namespace Utils { FAILED_FILE_CRC_READ, FAILED_FILE_CRC_WRITE, FAILED_FILE_CRC_CHECK - } crc_stat_t; +} crc_stat_t; - crc_stat_t create_checksum_file(const char* const filename); - crc_stat_t read_crc32_from_file(const char* const fname, U32 &checksum_from_file); - crc_stat_t verify_checksum(const char* const filename, U32 &expected, U32 &actual); +crc_stat_t create_checksum_file(const char* const filename); +crc_stat_t read_crc32_from_file(const char* const fname, U32& checksum_from_file); +crc_stat_t verify_checksum(const char* const filename, U32& expected, U32& actual); -} +} // namespace Utils #endif diff --git a/Utils/Hash/Hash.hpp b/Utils/Hash/Hash.hpp index 2fc6672073..699be5a5c5 100644 --- a/Utils/Hash/Hash.hpp +++ b/Utils/Hash/Hash.hpp @@ -13,113 +13,96 @@ #ifndef UTILS_HASH_HPP #define UTILS_HASH_HPP -#include "Fw/Types/StringType.hpp" #include +#include "Fw/Types/StringType.hpp" namespace Utils { - //! \class Hash - //! \brief A generic interface for creating and comparing hash values - //! - class Hash { +//! \class Hash +//! \brief A generic interface for creating and comparing hash values +//! +class Hash { + public: + // ---------------------------------------------------------------------- + // Types + // ---------------------------------------------------------------------- + public: + // ---------------------------------------------------------------------- + // Construction and destruction + // ---------------------------------------------------------------------- - public: + //! Construct a Hash object + //! + Hash(); - // ---------------------------------------------------------------------- - // Types - // ---------------------------------------------------------------------- - public: + //! Destroy a Hash object + //! + ~Hash(); - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- + public: + // ---------------------------------------------------------------------- + // Public static methods + // ---------------------------------------------------------------------- - //! Construct a Hash object - //! - Hash(); + //! Create a hash value all at once from raw data + //! \param data: pointer to start of data + //! \param len: length of the data + //! \param buffer: filled with resulting hash value + static void hash(const void* data, const FwSizeType len, HashBuffer& buffer); - //! Destroy a Hash object - //! - ~Hash(); + public: + // ---------------------------------------------------------------------- + // Public instance methods + // ---------------------------------------------------------------------- - public: + //! Initialize a Hash object for incremental hash computation + //! + void init(); - // ---------------------------------------------------------------------- - // Public static methods - // ---------------------------------------------------------------------- + //! Set hash value to specified value + //! + void setHashValue(HashBuffer& value //! Hash value + ); - //! Create a hash value all at once from raw data - //! \param data: pointer to start of data - //! \param len: length of the data - //! \param buffer: filled with resulting hash value - static void hash( - const void *data, - const FwSizeType len, - HashBuffer& buffer - ); + //! Update an incremental computation with new data + //! \param data: pointer to start of data to add to hash calculation + //! \param len: length of data to add to hash calculation + void update(const void* const data, const FwSizeType len); - public: + //! Finalize an incremental computation and return the result + //! + void final(HashBuffer& buffer //! The result + ); - // ---------------------------------------------------------------------- - // Public instance methods - // ---------------------------------------------------------------------- + //! Finalize an incremental computation and return the result + //! + void final(U32& hashvalue); - //! Initialize a Hash object for incremental hash computation - //! - void init(); + //! Get the file extension for the supported hash type + //! E.g., could return "SHA256" + //! + static const char* getFileExtensionString(); - //! Set hash value to specified value - //! - void setHashValue( - HashBuffer &value //! Hash value - ); + //! Add the extension for the supported hash type + //! + static void addFileExtension(const Fw::StringBase& baseName, //!< The base name + Fw::StringBase& extendedName //!< The extended name + ); - //! Update an incremental computation with new data - //! \param data: pointer to start of data to add to hash calculation - //! \param len: length of data to add to hash calculation - void update( - const void *const data, - const FwSizeType len - ); + //! Get the length of the file extension string + //! + static FwSizeType getFileExtensionLength(); - //! Finalize an incremental computation and return the result - //! - void final( - HashBuffer& buffer //! The result - ); + private: + // ---------------------------------------------------------------------- + // Private member variables + // ---------------------------------------------------------------------- - //! Finalize an incremental computation and return the result - //! - void final(U32 &hashvalue); + //! The hash handle + //! + HASH_HANDLE_TYPE hash_handle; +}; - //! Get the file extension for the supported hash type - //! E.g., could return "SHA256" - //! - static const char* getFileExtensionString(); - - //! Add the extension for the supported hash type - //! - static void addFileExtension( - const Fw::StringBase& baseName, //!< The base name - Fw::StringBase& extendedName //!< The extended name - ); - - //! Get the length of the file extension string - //! - static FwSizeType getFileExtensionLength(); - - private: - - // ---------------------------------------------------------------------- - // Private member variables - // ---------------------------------------------------------------------- - - //! The hash handle - //! - HASH_HANDLE_TYPE hash_handle; - - }; - -} +} // namespace Utils #endif diff --git a/Utils/Hash/HashCommon.cpp b/Utils/Hash/HashCommon.cpp index 897cad54cf..3582cd1f59 100644 --- a/Utils/Hash/HashCommon.cpp +++ b/Utils/Hash/HashCommon.cpp @@ -2,26 +2,18 @@ namespace Utils { - const char* Hash :: - getFileExtensionString() - { - return HASH_EXTENSION_STRING; - } - - void Hash :: - addFileExtension( - const Fw::StringBase& baseName, - Fw::StringBase& extendedName - ) { - extendedName.format("%s%s", baseName.toChar(), HASH_EXTENSION_STRING); - } - - FwSizeType Hash :: - getFileExtensionLength() - { - // Size of returns the size including the '\0' character. - // We want to return just the size of the string. - return sizeof(HASH_EXTENSION_STRING) - 1; - } - +const char* Hash ::getFileExtensionString() { + return HASH_EXTENSION_STRING; } + +void Hash ::addFileExtension(const Fw::StringBase& baseName, Fw::StringBase& extendedName) { + extendedName.format("%s%s", baseName.toChar(), HASH_EXTENSION_STRING); +} + +FwSizeType Hash ::getFileExtensionLength() { + // Size of returns the size including the '\0' character. + // We want to return just the size of the string. + return sizeof(HASH_EXTENSION_STRING) - 1; +} + +} // namespace Utils diff --git a/Utils/Hash/libcrc/CRC32.cpp b/Utils/Hash/libcrc/CRC32.cpp index 3e5f569860..7da903f312 100644 --- a/Utils/Hash/libcrc/CRC32.cpp +++ b/Utils/Hash/libcrc/CRC32.cpp @@ -14,80 +14,62 @@ static_assert(sizeof(unsigned long) >= sizeof(U32), "CRC32 cannot fit in CRC32 library chosen types"); - namespace Utils { - Hash :: - Hash() - { - this->init(); - } +Hash ::Hash() { + this->init(); +} - Hash :: - ~Hash() - { - } +Hash ::~Hash() {} - void Hash :: - hash(const void *const data, const FwSizeType len, HashBuffer& buffer) - { - HASH_HANDLE_TYPE local_hash_handle; - local_hash_handle = 0xffffffffL; - FW_ASSERT(data); - char c; - for(FwSizeType index = 0; index < len; index++) { - c = static_cast(data)[index]; - local_hash_handle = static_cast(update_crc_32(local_hash_handle, c)); - } - HashBuffer bufferOut; - // For CRC32 we need to return the one's complement of the result: - Fw::SerializeStatus status = bufferOut.serialize(~(local_hash_handle)); - FW_ASSERT( Fw::FW_SERIALIZE_OK == status ); - buffer = bufferOut; +void Hash ::hash(const void* const data, const FwSizeType len, HashBuffer& buffer) { + HASH_HANDLE_TYPE local_hash_handle; + local_hash_handle = 0xffffffffL; + FW_ASSERT(data); + char c; + for (FwSizeType index = 0; index < len; index++) { + c = static_cast(data)[index]; + local_hash_handle = static_cast(update_crc_32(local_hash_handle, c)); } + HashBuffer bufferOut; + // For CRC32 we need to return the one's complement of the result: + Fw::SerializeStatus status = bufferOut.serialize(~(local_hash_handle)); + FW_ASSERT(Fw::FW_SERIALIZE_OK == status); + buffer = bufferOut; +} - void Hash :: - init() - { - this->hash_handle = 0xffffffffL; - } +void Hash ::init() { + this->hash_handle = 0xffffffffL; +} - void Hash :: - update(const void *const data, FwSizeType len) - { - FW_ASSERT(data); - char c; - for(FwSizeType index = 0; index < len; index++) { - c = static_cast(data)[index]; - this->hash_handle = static_cast(update_crc_32(this->hash_handle, c)); - } - } - - void Hash :: - final(HashBuffer& buffer) - { - HashBuffer bufferOut; - // For CRC32 we need to return the one's complement of the result: - Fw::SerializeStatus status = bufferOut.serialize(~(this->hash_handle)); - FW_ASSERT( Fw::FW_SERIALIZE_OK == status ); - buffer = bufferOut; - } - - void Hash :: - final(U32 &hashvalue) - { - FW_ASSERT(sizeof(this->hash_handle) == sizeof(U32)); - // For CRC32 we need to return the one's complement of the result: - hashvalue = ~(this->hash_handle); - } - - void Hash :: - setHashValue(HashBuffer &value) - { - Fw::SerializeStatus status = value.deserialize(this->hash_handle); - FW_ASSERT( Fw::FW_SERIALIZE_OK == status ); - // Expecting `value` to already be one's complement; so doing one's complement - // here for correct hash updates - this->hash_handle = ~this->hash_handle; +void Hash ::update(const void* const data, FwSizeType len) { + FW_ASSERT(data); + char c; + for (FwSizeType index = 0; index < len; index++) { + c = static_cast(data)[index]; + this->hash_handle = static_cast(update_crc_32(this->hash_handle, c)); } } + +void Hash ::final(HashBuffer& buffer) { + HashBuffer bufferOut; + // For CRC32 we need to return the one's complement of the result: + Fw::SerializeStatus status = bufferOut.serialize(~(this->hash_handle)); + FW_ASSERT(Fw::FW_SERIALIZE_OK == status); + buffer = bufferOut; +} + +void Hash ::final(U32& hashvalue) { + FW_ASSERT(sizeof(this->hash_handle) == sizeof(U32)); + // For CRC32 we need to return the one's complement of the result: + hashvalue = ~(this->hash_handle); +} + +void Hash ::setHashValue(HashBuffer& value) { + Fw::SerializeStatus status = value.deserialize(this->hash_handle); + FW_ASSERT(Fw::FW_SERIALIZE_OK == status); + // Expecting `value` to already be one's complement; so doing one's complement + // here for correct hash updates + this->hash_handle = ~this->hash_handle; +} +} // namespace Utils diff --git a/Utils/Hash/libcrc/CRC32.hpp b/Utils/Hash/libcrc/CRC32.hpp index ff1de448c7..262e256c6b 100644 --- a/Utils/Hash/libcrc/CRC32.hpp +++ b/Utils/Hash/libcrc/CRC32.hpp @@ -3,10 +3,10 @@ // Include the lic crc c library: extern "C" { - #include +#include } -//! Define the hash handle type for this +//! Define the hash handle type for this //! implementation. This is required. #ifndef HASH_HANDLE_TYPE #define HASH_HANDLE_TYPE U32 @@ -18,7 +18,7 @@ extern "C" { #define HASH_DIGEST_LENGTH (4) #endif -//! Define the string to be used as a filename +//! Define the string to be used as a filename //! extension (ie. file.txt.SHA256) for this //! implementation. This is required. #ifndef HASH_EXTENSION_STRING diff --git a/Utils/Hash/libcrc/lib_crc.c b/Utils/Hash/libcrc/lib_crc.c index 54d6b269f6..327edb0bfe 100644 --- a/Utils/Hash/libcrc/lib_crc.c +++ b/Utils/Hash/libcrc/lib_crc.c @@ -1,3 +1,4 @@ +// clang-format off #include "lib_crc.h" diff --git a/Utils/Hash/libcrc/lib_crc.h b/Utils/Hash/libcrc/lib_crc.h index e84f1693f7..33aad01b8c 100644 --- a/Utils/Hash/libcrc/lib_crc.h +++ b/Utils/Hash/libcrc/lib_crc.h @@ -1,3 +1,4 @@ +// clang-format off /*******************************************************************\ * * * Library : lib_crc * diff --git a/Utils/Hash/libcrc/tst_crc.c b/Utils/Hash/libcrc/tst_crc.c index 3003cfd32d..e4e4ab5aed 100644 --- a/Utils/Hash/libcrc/tst_crc.c +++ b/Utils/Hash/libcrc/tst_crc.c @@ -1,3 +1,4 @@ +// clang-format off #include #include #include diff --git a/Utils/Hash/openssl/SHA256.cpp b/Utils/Hash/openssl/SHA256.cpp index 0bc9c9ff1e..e79f1f9be5 100644 --- a/Utils/Hash/openssl/SHA256.cpp +++ b/Utils/Hash/openssl/SHA256.cpp @@ -14,49 +14,36 @@ namespace Utils { - Hash :: - Hash() - { - this->init(); - } - - Hash :: - ~Hash() - { - } - - void Hash :: - hash(const void *const data, const FwSizeType len, HashBuffer& buffer) - { - U8 out[SHA256_DIGEST_LENGTH]; - U8* ret = SHA256(static_cast(data), len, out); - FW_ASSERT(ret != nullptr); - HashBuffer bufferOut(out, sizeof(out)); - buffer = bufferOut; - } - - void Hash :: - init() - { - int ret = SHA256_Init(&this->hash_handle); - FW_ASSERT(ret == 1); - } - - void Hash :: - update(const void *const data, FwSizeType len) - { - int ret = SHA256_Update(&this->hash_handle, static_cast(data), len); - FW_ASSERT(ret == 1); - } - - void Hash :: - final(HashBuffer& buffer) - { - U8 out[SHA256_DIGEST_LENGTH]; - int ret = SHA256_Final(out, &this->hash_handle); - FW_ASSERT(ret == 1); - HashBuffer bufferOut(out, sizeof(out)); - buffer = bufferOut; - } - +Hash ::Hash() { + this->init(); } + +Hash ::~Hash() {} + +void Hash ::hash(const void* const data, const FwSizeType len, HashBuffer& buffer) { + U8 out[SHA256_DIGEST_LENGTH]; + U8* ret = SHA256(static_cast(data), len, out); + FW_ASSERT(ret != nullptr); + HashBuffer bufferOut(out, sizeof(out)); + buffer = bufferOut; +} + +void Hash ::init() { + int ret = SHA256_Init(&this->hash_handle); + FW_ASSERT(ret == 1); +} + +void Hash ::update(const void* const data, FwSizeType len) { + int ret = SHA256_Update(&this->hash_handle, static_cast(data), len); + FW_ASSERT(ret == 1); +} + +void Hash ::final(HashBuffer& buffer) { + U8 out[SHA256_DIGEST_LENGTH]; + int ret = SHA256_Final(out, &this->hash_handle); + FW_ASSERT(ret == 1); + HashBuffer bufferOut(out, sizeof(out)); + buffer = bufferOut; +} + +} // namespace Utils diff --git a/Utils/Hash/openssl/SHA256.hpp b/Utils/Hash/openssl/SHA256.hpp index 974315bb58..39799a028e 100644 --- a/Utils/Hash/openssl/SHA256.hpp +++ b/Utils/Hash/openssl/SHA256.hpp @@ -4,7 +4,7 @@ // Include the sha library: #include -//! Define the hash handle type for this +//! Define the hash handle type for this //! implementation. This is required. #ifndef HASH_HANDLE_TYPE #define HASH_HANDLE_TYPE SHA256_CTX @@ -16,7 +16,7 @@ #define HASH_DIGEST_LENGTH (SHA256_DIGEST_LENGTH) #endif -//! Define the string to be used as a filename +//! Define the string to be used as a filename //! extension (ie. file.txt.SHA256) for this //! implementation. This is required. #ifndef HASH_EXTENSION_STRING diff --git a/Utils/Hash/openssl/sha.h b/Utils/Hash/openssl/sha.h index a31359f23e..6086d09c9b 100644 --- a/Utils/Hash/openssl/sha.h +++ b/Utils/Hash/openssl/sha.h @@ -1,3 +1,4 @@ +// clang-format off /* crypto/sha/sha.h */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. diff --git a/Utils/RateLimiter.cpp b/Utils/RateLimiter.cpp index ff874434df..905bc67447 100644 --- a/Utils/RateLimiter.cpp +++ b/Utils/RateLimiter.cpp @@ -1,4 +1,4 @@ -// ====================================================================== +// ====================================================================== // \title RateLimiter.cpp // \author vwong // \brief cpp file for a rate limiter utility class @@ -7,89 +7,52 @@ // Copyright (C) 2009-2020 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. -// ====================================================================== +// ====================================================================== #include namespace Utils { - RateLimiter :: - RateLimiter ( - U32 counterCycle, - U32 timeCycle - ) : - m_counterCycle(counterCycle), - m_timeCycle(timeCycle) - { +RateLimiter ::RateLimiter(U32 counterCycle, U32 timeCycle) : m_counterCycle(counterCycle), m_timeCycle(timeCycle) { this->reset(); - } +} - RateLimiter :: - RateLimiter () : - m_counterCycle(0), - m_timeCycle(0) - { +RateLimiter ::RateLimiter() : m_counterCycle(0), m_timeCycle(0) { this->reset(); - } +} - void RateLimiter :: - setCounterCycle( - U32 counterCycle - ) - { +void RateLimiter ::setCounterCycle(U32 counterCycle) { this->m_counterCycle = counterCycle; - } +} - void RateLimiter :: - setTimeCycle( - U32 timeCycle - ) - { +void RateLimiter ::setTimeCycle(U32 timeCycle) { this->m_timeCycle = timeCycle; - } +} - void RateLimiter :: - reset() - { +void RateLimiter ::reset() { this->resetCounter(); this->resetTime(); - } +} - void RateLimiter :: - resetCounter() - { +void RateLimiter ::resetCounter() { this->m_counter = 0; - } +} - void RateLimiter :: - resetTime() - { +void RateLimiter ::resetTime() { this->m_time = Fw::Time(); this->m_timeAtNegativeInfinity = true; - } +} - void RateLimiter :: - setCounter( - U32 counter - ) - { +void RateLimiter ::setCounter(U32 counter) { this->m_counter = counter; - } +} - void RateLimiter :: - setTime( - Fw::Time time - ) - { +void RateLimiter ::setTime(Fw::Time time) { this->m_time = time; this->m_timeAtNegativeInfinity = false; - } +} - bool RateLimiter :: - trigger( - Fw::Time time - ) - { +bool RateLimiter ::trigger(Fw::Time time) { // NB: this implements a 4-bit decision, logically equivalent to this pseudo-code // // A = HAS_COUNTER, B = HAS_TIME, C = COUNTER_TRIGGER, D = TIME_TRIGGER @@ -101,50 +64,44 @@ namespace Utils { // false // if (this->m_counterCycle == 0 && this->m_timeCycle == 0) { - return true; + return true; } // evaluate trigger criteria bool shouldTrigger = false; if (this->m_counterCycle > 0) { - shouldTrigger = shouldTrigger || this->shouldCounterTrigger(); + shouldTrigger = shouldTrigger || this->shouldCounterTrigger(); } if (this->m_timeCycle > 0) { - shouldTrigger = shouldTrigger || this->shouldTimeTrigger(time); + shouldTrigger = shouldTrigger || this->shouldTimeTrigger(time); } // update states if (this->m_counterCycle > 0) { - this->updateCounter(shouldTrigger); + this->updateCounter(shouldTrigger); } if (this->m_timeCycle > 0) { - this->updateTime(shouldTrigger, time); + this->updateTime(shouldTrigger, time); } return shouldTrigger; - } +} - bool RateLimiter :: - trigger() - { +bool RateLimiter ::trigger() { FW_ASSERT(this->m_timeCycle == 0); return trigger(Fw::Time::zero()); - } +} - bool RateLimiter :: - shouldCounterTrigger() - { +bool RateLimiter ::shouldCounterTrigger() { FW_ASSERT(this->m_counterCycle > 0); // trigger at 0 bool shouldTrigger = (this->m_counter == 0); return shouldTrigger; - } +} - bool RateLimiter :: - shouldTimeTrigger(Fw::Time time) - { +bool RateLimiter ::shouldTimeTrigger(Fw::Time time) { FW_ASSERT(this->m_timeCycle > 0); // trigger at prev trigger time + time cycle seconds OR when time is at negative infinity @@ -153,35 +110,31 @@ namespace Utils { bool shouldTrigger = (time >= nextTrigger) || this->m_timeAtNegativeInfinity; return shouldTrigger; - } +} - void RateLimiter :: - updateCounter(bool triggered) - { +void RateLimiter ::updateCounter(bool triggered) { FW_ASSERT(this->m_counterCycle > 0); if (triggered) { - // triggered, set to next state - this->m_counter = 1; + // triggered, set to next state + this->m_counter = 1; } else { - // otherwise, just increment and maybe wrap - if (++this->m_counter >= this->m_counterCycle) { - this->m_counter = 0; - } + // otherwise, just increment and maybe wrap + if (++this->m_counter >= this->m_counterCycle) { + this->m_counter = 0; + } } - } +} - void RateLimiter :: - updateTime(bool triggered, Fw::Time time) - { +void RateLimiter ::updateTime(bool triggered, Fw::Time time) { FW_ASSERT(this->m_timeCycle > 0); if (triggered) { - // mark time of trigger - this->m_time = time; + // mark time of trigger + this->m_time = time; } this->m_timeAtNegativeInfinity = false; - } +} -} // end namespace Utils +} // end namespace Utils diff --git a/Utils/RateLimiter.hpp b/Utils/RateLimiter.hpp index 7c3ecba863..b5ab343809 100644 --- a/Utils/RateLimiter.hpp +++ b/Utils/RateLimiter.hpp @@ -1,4 +1,4 @@ -// ====================================================================== +// ====================================================================== // \title RateLimiter.hpp // \author vwong // \brief hpp file for a rate limiter utility class @@ -8,7 +8,7 @@ // // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. -// ====================================================================== +// ====================================================================== #ifndef RateLimiter_HPP #define RateLimiter_HPP @@ -18,65 +18,59 @@ namespace Utils { - class RateLimiter - { +class RateLimiter { + public: + // Construct with defined cycles + RateLimiter(U32 counterCycle, U32 timeCycle); - public: + // Construct with cycles set to 0 + RateLimiter(); - // Construct with defined cycles - RateLimiter(U32 counterCycle, U32 timeCycle); + public: + // Adjust cycles at run-time + void setCounterCycle(U32 counterCycle); + void setTimeCycle(U32 timeCycle); - // Construct with cycles set to 0 - RateLimiter(); + // Main point of entry + // + // It will only factor in counter or time, whichever one has a cycle defined + // + // If both are defined, then satisfying _either_ one will work + // e.g. I want to trigger only once every X times or once every Y + // seconds, whichever comes first + // + // The argument-less version is a shorthand for counter-only RateLimiters + // If a time cycle is defined but the argument-less version is called, + // RateLimiter assumes the client forgot to supply a time, and asserts + // + bool trigger(Fw::Time time); + bool trigger(); - public: + // Manual state adjustments, if necessary + void reset(); + void resetCounter(); + void resetTime(); + void setCounter(U32); + void setTime(Fw::Time time); - // Adjust cycles at run-time - void setCounterCycle(U32 counterCycle); - void setTimeCycle(U32 timeCycle); + private: + // Helper functions to update each independently + bool shouldCounterTrigger(); + bool shouldTimeTrigger(Fw::Time time); + void updateCounter(bool triggered); + void updateTime(bool triggered, Fw::Time time); - // Main point of entry - // - // It will only factor in counter or time, whichever one has a cycle defined - // - // If both are defined, then satisfying _either_ one will work - // e.g. I want to trigger only once every X times or once every Y - // seconds, whichever comes first - // - // The argument-less version is a shorthand for counter-only RateLimiters - // If a time cycle is defined but the argument-less version is called, - // RateLimiter assumes the client forgot to supply a time, and asserts - // - bool trigger(Fw::Time time); - bool trigger(); + private: + // parameters + U32 m_counterCycle; + U32 m_timeCycle; - // Manual state adjustments, if necessary - void reset(); - void resetCounter(); - void resetTime(); - void setCounter(U32); - void setTime(Fw::Time time); + // state + U32 m_counter; + Fw::Time m_time; + bool m_timeAtNegativeInfinity; +}; - private: - - // Helper functions to update each independently - bool shouldCounterTrigger(); - bool shouldTimeTrigger(Fw::Time time); - void updateCounter(bool triggered); - void updateTime(bool triggered, Fw::Time time); - - private: - - // parameters - U32 m_counterCycle; - U32 m_timeCycle; - - // state - U32 m_counter; - Fw::Time m_time; - bool m_timeAtNegativeInfinity; - }; - -} // end namespace Utils +} // end namespace Utils #endif diff --git a/Utils/TestUtils.hpp b/Utils/TestUtils.hpp index b8a83bcf72..c9aadd2df1 100644 --- a/Utils/TestUtils.hpp +++ b/Utils/TestUtils.hpp @@ -36,7 +36,6 @@ // // See below for detailed descriptions - // SEND_CMD // // Send a command and expect a response status. This command essentially calls @@ -50,13 +49,12 @@ // SEND_CMD(PWR_SW_MGR_SET_DUTY_CYCLE, Fw::CmdResponse::OK, channel, dutyCycle); // SEND_CMD(PWR_SW_MGR_PWR_ON, Fw::COMMAND_EXECUTION_ERROR, illegalChannel); // -#define SEND_CMD(cmd, status, ...) \ - SEND_CMD_COMP(TEST_COMP, cmd, status, ## __VA_ARGS__) +#define SEND_CMD(cmd, status, ...) SEND_CMD_COMP(TEST_COMP, cmd, status, ##__VA_ARGS__) -#define SEND_CMD_COMP(comp, cmd, status, ...) \ - this->sendCmd_ ## cmd(INSTANCE, CMD_SEQ, ## __VA_ARGS__); \ - this->component.doDispatch(); \ - ASSERT_LAST_CMD(cmd, status); +#define SEND_CMD_COMP(comp, cmd, status, ...) \ + this->sendCmd_##cmd(INSTANCE, CMD_SEQ, ##__VA_ARGS__); \ + this->component.doDispatch(); \ + ASSERT_LAST_CMD(cmd, status); // SEND_CMD_NO_EXPECT // @@ -67,12 +65,11 @@ // SEND_CMD_NO_EXPECT(FILE_DWN_SEND_APID, 100, 0, 0, 0); // // ... // -#define SEND_CMD_NO_EXPECT(cmd, ...) \ - SEND_CMD_COMP_NO_EXPECT(TEST_COMP, cmd, ## __VA_ARGS__) +#define SEND_CMD_NO_EXPECT(cmd, ...) SEND_CMD_COMP_NO_EXPECT(TEST_COMP, cmd, ##__VA_ARGS__) -#define SEND_CMD_COMP_NO_EXPECT(comp, cmd, ...) \ - this->sendCmd_ ## cmd(INSTANCE, CMD_SEQ, ## __VA_ARGS__); \ - this->component.doDispatch(); +#define SEND_CMD_COMP_NO_EXPECT(comp, cmd, ...) \ + this->sendCmd_##cmd(INSTANCE, CMD_SEQ, ##__VA_ARGS__); \ + this->component.doDispatch(); // ASSERT_LAST_CMD // @@ -86,12 +83,11 @@ // // ... // ASSERT_LAST_CMD(FILE_DWN_SEND_APID, Fw::CmdResponse::OK); // -#define ASSERT_LAST_CMD(cmd, status) \ - ASSERT_LAST_CMD_COMP(TEST_COMP, cmd, status) +#define ASSERT_LAST_CMD(cmd, status) ASSERT_LAST_CMD_COMP(TEST_COMP, cmd, status) -#define ASSERT_LAST_CMD_COMP(comp, cmd, status) \ - ASSERT_GT(this->cmdResponseHistory->size(), 0); \ - ASSERT_CMD_RESPONSE(this->cmdResponseHistory->size()-1, comp::OPCODE_ ## cmd, CMD_SEQ, status); +#define ASSERT_LAST_CMD_COMP(comp, cmd, status) \ + ASSERT_GT(this->cmdResponseHistory->size(), 0); \ + ASSERT_CMD_RESPONSE(this->cmdResponseHistory->size() - 1, comp::OPCODE_##cmd, CMD_SEQ, status); // ASSERT_LAST_TLM // @@ -102,9 +98,9 @@ // ASSERT_LAST_TLM(NeaCamManager_ImageDataSize, dataSize); // ASSERT_LAST_TLM(NeaCamManager_PatternDataSize, 0); // -#define ASSERT_LAST_TLM(name, value) \ - ASSERT_GT(this->tlmHistory_ ## name->size(), 0); \ - ASSERT_TLM_ ## name(this->tlmHistory_ ## name->size()-1, value); +#define ASSERT_LAST_TLM(name, value) \ + ASSERT_GT(this->tlmHistory_##name->size(), 0); \ + ASSERT_TLM_##name(this->tlmHistory_##name->size() - 1, value); // ASSERT_LAST_EVENT // @@ -115,9 +111,9 @@ // SEND_CMD(PWR_SW_MGR_SET_DUTY_CYCLE, Fw::COMMAND_VALIDATION_ERROR, 0, 0); // ASSERT_LAST_EVENT(PwrSwitchManager_DutyCyclingNotEnabled, i); // -#define ASSERT_LAST_EVENT(name, ...) \ - ASSERT_GT(this->eventHistory_ ## name->size(), 0); \ - ASSERT_EVENTS_ ## name(this->eventHistory_ ## name->size()-1, ## __VA_ARGS__); +#define ASSERT_LAST_EVENT(name, ...) \ + ASSERT_GT(this->eventHistory_##name->size(), 0); \ + ASSERT_EVENTS_##name(this->eventHistory_##name->size() - 1, ##__VA_ARGS__); // ASSERT_LAST_PORT_OUT // @@ -129,9 +125,8 @@ // this->component.doDispatch(); // ASSERT_LAST_PORT_OUT(PingResponse, 0, 0xDEADBEEF); // -#define ASSERT_LAST_PORT_OUT(port, ...) \ - ASSERT_GT(this->fromPortHistory_ ## port->size(), 0); \ - ASSERT_from_ ## port(__VA_ARGS__); - +#define ASSERT_LAST_PORT_OUT(port, ...) \ + ASSERT_GT(this->fromPortHistory_##port->size(), 0); \ + ASSERT_from_##port(__VA_ARGS__); #endif diff --git a/Utils/TokenBucket.cpp b/Utils/TokenBucket.cpp index 15037e6644..f8d06552c4 100644 --- a/Utils/TokenBucket.cpp +++ b/Utils/TokenBucket.cpp @@ -15,120 +15,80 @@ namespace Utils { - TokenBucket :: - TokenBucket ( - U32 replenishInterval, - U32 maxTokens, - U32 replenishRate, - U32 startTokens, - Fw::Time startTime - ) : - m_replenishInterval(replenishInterval), +TokenBucket ::TokenBucket(U32 replenishInterval, U32 maxTokens, U32 replenishRate, U32 startTokens, Fw::Time startTime) + : m_replenishInterval(replenishInterval), m_maxTokens(maxTokens), m_replenishRate(replenishRate), m_tokens(startTokens), - m_time(startTime) - { - } + m_time(startTime) {} - TokenBucket :: - TokenBucket ( - U32 replenishInterval, - U32 maxTokens - ) : - m_replenishInterval(replenishInterval), +TokenBucket ::TokenBucket(U32 replenishInterval, U32 maxTokens) + : m_replenishInterval(replenishInterval), m_maxTokens(maxTokens), m_replenishRate(1), m_tokens(maxTokens), - m_time(0, 0) - { + m_time(0, 0) { FW_ASSERT(this->m_maxTokens <= MAX_TOKEN_BUCKET_TOKENS, static_cast(this->m_maxTokens)); - } +} - void TokenBucket :: - setReplenishInterval( - U32 replenishInterval - ) - { +void TokenBucket ::setReplenishInterval(U32 replenishInterval) { this->m_replenishInterval = replenishInterval; - } +} - void TokenBucket :: - setMaxTokens( - U32 maxTokens - ) - { +void TokenBucket ::setMaxTokens(U32 maxTokens) { this->m_maxTokens = maxTokens; - } +} - void TokenBucket :: - setReplenishRate( - U32 replenishRate - ) - { +void TokenBucket ::setReplenishRate(U32 replenishRate) { this->m_replenishRate = replenishRate; - } +} - void TokenBucket :: - replenish() - { +void TokenBucket ::replenish() { if (this->m_tokens < this->m_maxTokens) { - this->m_tokens = this->m_maxTokens; + this->m_tokens = this->m_maxTokens; } - } +} - U32 TokenBucket :: - getReplenishInterval() const - { +U32 TokenBucket ::getReplenishInterval() const { return this->m_replenishInterval; - } +} - U32 TokenBucket :: - getMaxTokens() const - { +U32 TokenBucket ::getMaxTokens() const { return this->m_maxTokens; - } +} - U32 TokenBucket :: - getReplenishRate() const - { +U32 TokenBucket ::getReplenishRate() const { return this->m_replenishRate; - } +} - U32 TokenBucket :: - getTokens() const - { +U32 TokenBucket ::getTokens() const { return this->m_tokens; - } +} - bool TokenBucket :: - trigger( - const Fw::Time time - ) - { +bool TokenBucket ::trigger(const Fw::Time time) { // attempt replenishing if (this->m_replenishRate > 0) { - Fw::Time replenishInterval = Fw::Time(this->m_replenishInterval / 1000000, this->m_replenishInterval % 1000000); - Fw::Time nextTime = Fw::Time::add(this->m_time, replenishInterval); - while (this->m_tokens < this->m_maxTokens && nextTime <= time) { - // replenish by replenish rate, or up to maxTokens - this->m_tokens += FW_MIN(this->m_replenishRate, this->m_maxTokens - this->m_tokens); - this->m_time = nextTime; - nextTime = Fw::Time::add(this->m_time, replenishInterval); - } - if (this->m_tokens >= this->m_maxTokens && this->m_time < time) { - this->m_time = time; - } + Fw::Time replenishInterval = Fw::Time(this->m_replenishInterval / 1000000, this->m_replenishInterval % 1000000); + Fw::Time nextTime = Fw::Time::add(this->m_time, replenishInterval); + while (this->m_tokens < this->m_maxTokens && nextTime <= time) { + // replenish by replenish rate, or up to maxTokens + this->m_tokens += FW_MIN(this->m_replenishRate, this->m_maxTokens - this->m_tokens); + this->m_time = nextTime; + nextTime = Fw::Time::add(this->m_time, replenishInterval); + } + if (this->m_tokens >= this->m_maxTokens && this->m_time < time) { + this->m_time = time; + } } // attempt consuming token if (this->m_tokens > 0) { - this->m_tokens--; - return true; + this->m_tokens--; + return true; } else { - return false; + return false; } - } +} -} // end namespace Utils +} // end namespace Utils diff --git a/Utils/TokenBucket.hpp b/Utils/TokenBucket.hpp index 28901e7a0b..85fe6908bb 100644 --- a/Utils/TokenBucket.hpp +++ b/Utils/TokenBucket.hpp @@ -1,4 +1,4 @@ -// ====================================================================== +// ====================================================================== // \title TokenBucket.hpp // \author vwong // \brief hpp file for a rate limiter utility class @@ -9,7 +9,7 @@ // // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. -// ====================================================================== +// ====================================================================== #ifndef TokenBucket_HPP #define TokenBucket_HPP @@ -21,57 +21,52 @@ namespace Utils { - class TokenBucket - { +class TokenBucket { + public: + // Full constructor + // + // replenishInterval is in microseconds + // + TokenBucket(U32 replenishInterval, U32 maxTokens, U32 replenishRate, U32 startTokens, Fw::Time startTime); - public: + // replenishRate=1, startTokens=maxTokens, startTime=0 + TokenBucket(U32 replenishInterval, U32 maxTokens); - // Full constructor - // - // replenishInterval is in microseconds - // - TokenBucket(U32 replenishInterval, U32 maxTokens, U32 replenishRate, U32 startTokens, Fw::Time startTime); + public: + // Adjust settings at runtime + void setMaxTokens(U32 maxTokens); + void setReplenishInterval(U32 replenishInterval); + void setReplenishRate(U32 replenishRate); - // replenishRate=1, startTokens=maxTokens, startTime=0 - TokenBucket(U32 replenishInterval, U32 maxTokens); + U32 getMaxTokens() const; + U32 getReplenishInterval() const; + U32 getReplenishRate() const; + U32 getTokens() const; - public: + // Manual replenish + void replenish(); - // Adjust settings at runtime - void setMaxTokens(U32 maxTokens); - void setReplenishInterval(U32 replenishInterval); - void setReplenishRate(U32 replenishRate); + // Main point of entry + // + // Evaluates time since last trigger to determine number of tokens to + // replenish. If time moved backwards, always returns false. + // + // If number of tokens is not zero, consumes one and returns true. + // Otherwise, returns false. + // + bool trigger(const Fw::Time time); - U32 getMaxTokens() const; - U32 getReplenishInterval() const; - U32 getReplenishRate() const; - U32 getTokens() const; + private: + // parameters + U32 m_replenishInterval; + U32 m_maxTokens; + U32 m_replenishRate; - // Manual replenish - void replenish(); + // state + U32 m_tokens; + Fw::Time m_time; +}; - // Main point of entry - // - // Evaluates time since last trigger to determine number of tokens to - // replenish. If time moved backwards, always returns false. - // - // If number of tokens is not zero, consumes one and returns true. - // Otherwise, returns false. - // - bool trigger(const Fw::Time time); - - private: - - // parameters - U32 m_replenishInterval; - U32 m_maxTokens; - U32 m_replenishRate; - - // state - U32 m_tokens; - Fw::Time m_time; - }; - -} // end namespace Utils +} // end namespace Utils #endif diff --git a/Utils/Types/CircularBuffer.cpp b/Utils/Types/CircularBuffer.cpp index 820050ef3d..51076c00a2 100644 --- a/Utils/Types/CircularBuffer.cpp +++ b/Utils/Types/CircularBuffer.cpp @@ -18,30 +18,18 @@ namespace Types { -CircularBuffer :: CircularBuffer() : - m_store(nullptr), - m_store_size(0), - m_head_idx(0), - m_allocated_size(0), - m_high_water_mark(0) -{ +CircularBuffer ::CircularBuffer() + : m_store(nullptr), m_store_size(0), m_head_idx(0), m_allocated_size(0), m_high_water_mark(0) {} -} - -CircularBuffer :: CircularBuffer(U8* const buffer, const FwSizeType size) : - m_store(nullptr), - m_store_size(0), - m_head_idx(0), - m_allocated_size(0), - m_high_water_mark(0) -{ +CircularBuffer ::CircularBuffer(U8* const buffer, const FwSizeType size) + : m_store(nullptr), m_store_size(0), m_head_idx(0), m_allocated_size(0), m_high_water_mark(0) { setup(buffer, size); } -void CircularBuffer :: setup(U8* const buffer, const FwSizeType size) { +void CircularBuffer ::setup(U8* const buffer, const FwSizeType size) { FW_ASSERT(size > 0); FW_ASSERT(buffer != nullptr); - FW_ASSERT(m_store == nullptr && m_store_size == 0); // Not already setup + FW_ASSERT(m_store == nullptr && m_store_size == 0); // Not already setup // Initialize buffer data m_store = buffer; @@ -51,23 +39,23 @@ void CircularBuffer :: setup(U8* const buffer, const FwSizeType size) { m_high_water_mark = 0; } -FwSizeType CircularBuffer :: get_allocated_size() const { +FwSizeType CircularBuffer ::get_allocated_size() const { return m_allocated_size; } -FwSizeType CircularBuffer :: get_free_size() const { - FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called +FwSizeType CircularBuffer ::get_free_size() const { + FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called FW_ASSERT(m_allocated_size <= m_store_size, static_cast(m_allocated_size)); return m_store_size - m_allocated_size; } -FwSizeType CircularBuffer :: advance_idx(FwSizeType idx, FwSizeType amount) const { +FwSizeType CircularBuffer ::advance_idx(FwSizeType idx, FwSizeType amount) const { FW_ASSERT(idx < m_store_size, static_cast(idx)); return (idx + amount) % m_store_size; } -Fw::SerializeStatus CircularBuffer :: serialize(const U8* const buffer, const FwSizeType size) { - FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called +Fw::SerializeStatus CircularBuffer ::serialize(const U8* const buffer, const FwSizeType size) { + FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called FW_ASSERT(buffer != nullptr); // Check there is sufficient space if (size > get_free_size()) { @@ -86,13 +74,13 @@ Fw::SerializeStatus CircularBuffer :: serialize(const U8* const buffer, const Fw return Fw::FW_SERIALIZE_OK; } -Fw::SerializeStatus CircularBuffer :: peek(char& value, FwSizeType offset) const { - FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called +Fw::SerializeStatus CircularBuffer ::peek(char& value, FwSizeType offset) const { + FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called return peek(reinterpret_cast(value), offset); } -Fw::SerializeStatus CircularBuffer :: peek(U8& value, FwSizeType offset) const { - FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called +Fw::SerializeStatus CircularBuffer ::peek(U8& value, FwSizeType offset) const { + FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called // Check there is sufficient data if ((sizeof(U8) + offset) > m_allocated_size) { return Fw::FW_DESERIALIZE_BUFFER_EMPTY; @@ -103,8 +91,8 @@ Fw::SerializeStatus CircularBuffer :: peek(U8& value, FwSizeType offset) const { return Fw::FW_SERIALIZE_OK; } -Fw::SerializeStatus CircularBuffer :: peek(U32& value, FwSizeType offset) const { - FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called +Fw::SerializeStatus CircularBuffer ::peek(U32& value, FwSizeType offset) const { + FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called // Check there is sufficient data if ((sizeof(U32) + offset) > m_allocated_size) { return Fw::FW_DESERIALIZE_BUFFER_EMPTY; @@ -121,8 +109,8 @@ Fw::SerializeStatus CircularBuffer :: peek(U32& value, FwSizeType offset) const return Fw::FW_SERIALIZE_OK; } -Fw::SerializeStatus CircularBuffer :: peek(U8* buffer, FwSizeType size, FwSizeType offset) const { - FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called +Fw::SerializeStatus CircularBuffer ::peek(U8* buffer, FwSizeType size, FwSizeType offset) const { + FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called FW_ASSERT(buffer != nullptr); // Check there is sufficient data if ((size + offset) > m_allocated_size) { @@ -138,8 +126,8 @@ Fw::SerializeStatus CircularBuffer :: peek(U8* buffer, FwSizeType size, FwSizeTy return Fw::FW_SERIALIZE_OK; } -Fw::SerializeStatus CircularBuffer :: rotate(FwSizeType amount) { - FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called +Fw::SerializeStatus CircularBuffer ::rotate(FwSizeType amount) { + FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called // Check there is sufficient data if (amount > m_allocated_size) { return Fw::FW_DESERIALIZE_BUFFER_EMPTY; @@ -150,7 +138,7 @@ Fw::SerializeStatus CircularBuffer :: rotate(FwSizeType amount) { } FwSizeType CircularBuffer ::get_capacity() const { - FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called + FW_ASSERT(m_store != nullptr && m_store_size != 0); // setup method was called return m_store_size; } @@ -162,4 +150,4 @@ void CircularBuffer ::clear_high_water_mark() { m_high_water_mark = 0; } -} //End Namespace Types +} // End Namespace Types diff --git a/Utils/Types/CircularBuffer.hpp b/Utils/Types/CircularBuffer.hpp index 278fa05b78..fc1c662a2a 100644 --- a/Utils/Types/CircularBuffer.hpp +++ b/Utils/Types/CircularBuffer.hpp @@ -23,138 +23,136 @@ namespace Types { class CircularBuffer { - friend class CircularBufferTester; - public: - /** - * Circular buffer constructor. Wraps the supplied buffer as the new data store. Buffer - * size is supplied in the 'size' argument. - * - * Note: specification of storage buffer must be done using `setup` before use. - */ - CircularBuffer(); + public: + /** + * Circular buffer constructor. Wraps the supplied buffer as the new data store. Buffer + * size is supplied in the 'size' argument. + * + * Note: specification of storage buffer must be done using `setup` before use. + */ + CircularBuffer(); - /** - * Circular buffer constructor. Wraps the supplied buffer as the new data store. Buffer - * size is supplied in the 'size' argument. This is equivalent to calling the no-argument constructor followed - * by setup(buffer, size). - * - * Note: ownership of the supplied buffer is held until the circular buffer is deallocated - * - * \param buffer: supplied buffer used as a data store. - * \param size: the of the supplied data store. - */ - CircularBuffer(U8* const buffer, const FwSizeType size); + /** + * Circular buffer constructor. Wraps the supplied buffer as the new data store. Buffer + * size is supplied in the 'size' argument. This is equivalent to calling the no-argument constructor followed + * by setup(buffer, size). + * + * Note: ownership of the supplied buffer is held until the circular buffer is deallocated + * + * \param buffer: supplied buffer used as a data store. + * \param size: the of the supplied data store. + */ + CircularBuffer(U8* const buffer, const FwSizeType size); - /** - * Wraps the supplied buffer as the new data store. Buffer size is supplied in the 'size' argument. Cannot be - * called after successful setup. - * - * Note: ownership of the supplied buffer is held until the circular buffer is deallocated - * - * \param buffer: supplied buffer used as a data store. - * \param size: the of the supplied data store. - */ - void setup(U8* const buffer, const FwSizeType size); + /** + * Wraps the supplied buffer as the new data store. Buffer size is supplied in the 'size' argument. Cannot be + * called after successful setup. + * + * Note: ownership of the supplied buffer is held until the circular buffer is deallocated + * + * \param buffer: supplied buffer used as a data store. + * \param size: the of the supplied data store. + */ + void setup(U8* const buffer, const FwSizeType size); - /** - * Serialize a given buffer into this circular buffer. Will not accept more data than - * space available. This means it will not overwrite existing data. - * \param buffer: supplied buffer to be serialized. - * \param size: size of the supplied buffer. - * \return Fw::FW_SERIALIZE_OK on success or something else on error - */ - Fw::SerializeStatus serialize(const U8* const buffer, const FwSizeType size); + /** + * Serialize a given buffer into this circular buffer. Will not accept more data than + * space available. This means it will not overwrite existing data. + * \param buffer: supplied buffer to be serialized. + * \param size: size of the supplied buffer. + * \return Fw::FW_SERIALIZE_OK on success or something else on error + */ + Fw::SerializeStatus serialize(const U8* const buffer, const FwSizeType size); - /** - * Deserialize data into the given variable without moving the head index - * \param value: value to fill - * \param offset: offset from head to start peak. Default: 0 - * \return Fw::FW_SERIALIZE_OK on success or something else on error - */ - Fw::SerializeStatus peek(char& value, FwSizeType offset = 0) const; - /** - * Deserialize data into the given variable without moving the head index - * \param value: value to fill - * \param offset: offset from head to start peak. Default: 0 - * \return Fw::FW_SERIALIZE_OK on success or something else on error - */ - Fw::SerializeStatus peek(U8& value, FwSizeType offset = 0) const; - /** - * Deserialize data into the given variable without moving the head index - * \param value: value to fill - * \param offset: offset from head to start peak. Default: 0 - * \return Fw::FW_SERIALIZE_OK on success or something else on error - */ - Fw::SerializeStatus peek(U32& value, FwSizeType offset = 0) const; + /** + * Deserialize data into the given variable without moving the head index + * \param value: value to fill + * \param offset: offset from head to start peak. Default: 0 + * \return Fw::FW_SERIALIZE_OK on success or something else on error + */ + Fw::SerializeStatus peek(char& value, FwSizeType offset = 0) const; + /** + * Deserialize data into the given variable without moving the head index + * \param value: value to fill + * \param offset: offset from head to start peak. Default: 0 + * \return Fw::FW_SERIALIZE_OK on success or something else on error + */ + Fw::SerializeStatus peek(U8& value, FwSizeType offset = 0) const; + /** + * Deserialize data into the given variable without moving the head index + * \param value: value to fill + * \param offset: offset from head to start peak. Default: 0 + * \return Fw::FW_SERIALIZE_OK on success or something else on error + */ + Fw::SerializeStatus peek(U32& value, FwSizeType offset = 0) const; - /** - * Deserialize data into the given buffer without moving the head variable. - * \param buffer: buffer to fill with data of the peek - * \param size: size in bytes to peek at - * \param offset: offset from head to start peak. Default: 0 - * \return Fw::FW_SERIALIZE_OK on success or something else on error - */ - Fw::SerializeStatus peek(U8* buffer, FwSizeType size, FwSizeType offset = 0) const; + /** + * Deserialize data into the given buffer without moving the head variable. + * \param buffer: buffer to fill with data of the peek + * \param size: size in bytes to peek at + * \param offset: offset from head to start peak. Default: 0 + * \return Fw::FW_SERIALIZE_OK on success or something else on error + */ + Fw::SerializeStatus peek(U8* buffer, FwSizeType size, FwSizeType offset = 0) const; - /** - * Rotate the head index, deleting data from the circular buffer and making - * space. Cannot rotate more than the available space. - * \param amount: amount to rotate by (in bytes) - * \return Fw::FW_SERIALIZE_OK on success or something else on error - */ - Fw::SerializeStatus rotate(FwSizeType amount); + /** + * Rotate the head index, deleting data from the circular buffer and making + * space. Cannot rotate more than the available space. + * \param amount: amount to rotate by (in bytes) + * \return Fw::FW_SERIALIZE_OK on success or something else on error + */ + Fw::SerializeStatus rotate(FwSizeType amount); - /** - * Get the number of bytes allocated in the buffer - * \return number of bytes - */ - FwSizeType get_allocated_size() const; + /** + * Get the number of bytes allocated in the buffer + * \return number of bytes + */ + FwSizeType get_allocated_size() const; - /** - * Get the number of free bytes, i.e., the number - * of bytes that may be stored in the buffer without - * deleting data and without exceeding the buffer capacity - */ - FwSizeType get_free_size() const; + /** + * Get the number of free bytes, i.e., the number + * of bytes that may be stored in the buffer without + * deleting data and without exceeding the buffer capacity + */ + FwSizeType get_free_size() const; - /** - * Get the logical capacity of the buffer, i.e., the number of available - * bytes when the buffer is empty - */ - FwSizeType get_capacity() const; + /** + * Get the logical capacity of the buffer, i.e., the number of available + * bytes when the buffer is empty + */ + FwSizeType get_capacity() const; - /** - * Return the largest tracked allocated size - */ - FwSizeType get_high_water_mark() const; + /** + * Return the largest tracked allocated size + */ + FwSizeType get_high_water_mark() const; - /** - * Clear tracking of the largest allocated size - */ - void clear_high_water_mark(); + /** + * Clear tracking of the largest allocated size + */ + void clear_high_water_mark(); - private: - /** - * Returns a wrap-advanced index into the store. - * \param idx: index to advance and wrap. - * \param amount: amount to advance - * \return: new index value - */ - FwSizeType advance_idx(FwSizeType idx, FwSizeType amount = 1) const; - //! Physical store backing this circular buffer - U8* m_store; - //! Size of the physical store - FwSizeType m_store_size; - //! Index into m_store of byte zero in the logical store. - //! When memory is deallocated, this index moves forward and wraps around. - FwSizeType m_head_idx; - //! Allocated size (size of the logical store) - FwSizeType m_allocated_size; - //! Maximum allocated size - FwSizeType m_high_water_mark; + private: + /** + * Returns a wrap-advanced index into the store. + * \param idx: index to advance and wrap. + * \param amount: amount to advance + * \return: new index value + */ + FwSizeType advance_idx(FwSizeType idx, FwSizeType amount = 1) const; + //! Physical store backing this circular buffer + U8* m_store; + //! Size of the physical store + FwSizeType m_store_size; + //! Index into m_store of byte zero in the logical store. + //! When memory is deallocated, this index moves forward and wraps around. + FwSizeType m_head_idx; + //! Allocated size (size of the logical store) + FwSizeType m_allocated_size; + //! Maximum allocated size + FwSizeType m_high_water_mark; }; -} //End Namespace Types +} // End Namespace Types #endif - diff --git a/Utils/Types/Queue.cpp b/Utils/Types/Queue.cpp index 125449ac0b..da5903f25e 100644 --- a/Utils/Types/Queue.cpp +++ b/Utils/Types/Queue.cpp @@ -14,33 +14,29 @@ namespace Types { Queue::Queue() : m_internal(), m_message_size(0) {} -void Queue::setup(U8* const storage, const FwSizeType storage_size, const FwSizeType depth, const FwSizeType message_size) { +void Queue::setup(U8* const storage, + const FwSizeType storage_size, + const FwSizeType depth, + const FwSizeType message_size) { // Ensure that enough storage was supplied const FwSizeType total_needed_size = depth * message_size; - FW_ASSERT( - storage_size >= total_needed_size, - static_cast(storage_size), - static_cast(depth), - static_cast(message_size)); + FW_ASSERT(storage_size >= total_needed_size, static_cast(storage_size), + static_cast(depth), static_cast(message_size)); m_internal.setup(storage, total_needed_size); m_message_size = message_size; } Fw::SerializeStatus Queue::enqueue(const U8* const message, const FwSizeType size) { - FW_ASSERT(m_message_size > 0, static_cast(m_message_size)); // Ensure initialization - FW_ASSERT( - m_message_size == size, - static_cast(size), - static_cast(m_message_size)); // Message size is as expected + FW_ASSERT(m_message_size > 0, static_cast(m_message_size)); // Ensure initialization + FW_ASSERT(m_message_size == size, static_cast(size), + static_cast(m_message_size)); // Message size is as expected return m_internal.serialize(message, m_message_size); } Fw::SerializeStatus Queue::dequeue(U8* const message, const FwSizeType size) { - FW_ASSERT(m_message_size > 0); // Ensure initialization - FW_ASSERT( - m_message_size <= size, - static_cast(size), - static_cast(m_message_size)); // Sufficient storage space for read message + FW_ASSERT(m_message_size > 0); // Ensure initialization + FW_ASSERT(m_message_size <= size, static_cast(size), + static_cast(m_message_size)); // Sufficient storage space for read message Fw::SerializeStatus result = m_internal.peek(message, m_message_size, 0); if (result != Fw::FW_SERIALIZE_OK) { return result; @@ -62,5 +58,4 @@ FwSizeType Queue::getQueueSize() const { return m_internal.get_allocated_size() / m_message_size; } - } // namespace Types diff --git a/Utils/Types/test/ut/CircularBuffer/CircularBufferTester.cpp b/Utils/Types/test/ut/CircularBuffer/CircularBufferTester.cpp index 5c73f08313..c62a5c2160 100644 --- a/Utils/Types/test/ut/CircularBuffer/CircularBufferTester.cpp +++ b/Utils/Types/test/ut/CircularBuffer/CircularBufferTester.cpp @@ -6,7 +6,4 @@ #include "CircularBufferTester.hpp" - -namespace Types { - -} +namespace Types {} diff --git a/Utils/Types/test/ut/CircularBuffer/CircularBufferTester.hpp b/Utils/Types/test/ut/CircularBuffer/CircularBufferTester.hpp index 15b7a8c013..ad8147b4ae 100644 --- a/Utils/Types/test/ut/CircularBuffer/CircularBufferTester.hpp +++ b/Utils/Types/test/ut/CircularBuffer/CircularBufferTester.hpp @@ -11,20 +11,17 @@ namespace Types { - class CircularBufferTester{ +class CircularBufferTester { + public: + static void tester_m_allocated_size_decrement(Types::CircularBuffer& circular_buffer) { + circular_buffer.m_allocated_size--; + } - public: + static FwSizeType tester_get_m_head_idx(Types::CircularBuffer& circular_buffer) { + return circular_buffer.m_head_idx; + } +}; - static void tester_m_allocated_size_decrement(Types::CircularBuffer &circular_buffer){ - circular_buffer.m_allocated_size--; - } - - static FwSizeType tester_get_m_head_idx(Types::CircularBuffer &circular_buffer){ - return circular_buffer.m_head_idx; - } - - }; - -} +} // namespace Types #endif diff --git a/Utils/Types/test/ut/CircularBuffer/CircularRules.cpp b/Utils/Types/test/ut/CircularBuffer/CircularRules.cpp index bf4b56098d..4236e1681e 100644 --- a/Utils/Types/test/ut/CircularBuffer/CircularRules.cpp +++ b/Utils/Types/test/ut/CircularBuffer/CircularRules.cpp @@ -9,201 +9,161 @@ */ #include "CircularRules.hpp" -#include #include +#include namespace Types { +RandomizeRule::RandomizeRule(const char* const name) : STest::Rule(name) {} - RandomizeRule::RandomizeRule(const char *const name) - : STest::Rule(name) {} +bool RandomizeRule::precondition(const MockTypes::CircularState& state) { + return true; +} +void RandomizeRule::action(MockTypes::CircularState& truth) { + (void)truth.generateRandomBuffer(); +} - bool RandomizeRule::precondition(const MockTypes::CircularState& state) { - return true; +SerializeOkRule::SerializeOkRule(const char* const name) : STest::Rule(name) {} + +bool SerializeOkRule::precondition(const MockTypes::CircularState& state) { + return state.getRemainingSize() >= state.getRandomSize(); +} + +void SerializeOkRule::action(MockTypes::CircularState& state) { + state.checkSizes(); + Fw::SerializeStatus status = state.getTestBuffer().serialize(state.getBuffer(), state.getRandomSize()); + state.setRemainingSize(state.getRemainingSize() - state.getRandomSize()); + ASSERT_TRUE(state.addInfinite(state.getBuffer(), state.getRandomSize())); + ASSERT_EQ(status, Fw::FW_SERIALIZE_OK); + state.checkSizes(); +} + +SerializeOverflowRule::SerializeOverflowRule(const char* const name) : STest::Rule(name) {} + +bool SerializeOverflowRule::precondition(const MockTypes::CircularState& state) { + return state.getRemainingSize() < state.getRandomSize(); +} + +void SerializeOverflowRule::action(MockTypes::CircularState& state) { + Fw::SerializeStatus status = state.getTestBuffer().serialize(state.getBuffer(), state.getRandomSize()); + ASSERT_EQ(status, Fw::FW_SERIALIZE_NO_ROOM_LEFT); +} + +PeekOkRule::PeekOkRule(const char* const name) : STest::Rule(name) {} + +bool PeekOkRule::precondition(const MockTypes::CircularState& state) { + FwSizeType peek_available = (MAX_BUFFER_SIZE - state.getRemainingSize()); + if (state.getPeekType() == 0) { + return peek_available >= sizeof(I8) + state.getPeekOffset(); + } else if (state.getPeekType() == 1) { + return peek_available >= sizeof(U8) + state.getPeekOffset(); + } else if (state.getPeekType() == 2) { + return peek_available >= sizeof(U32) + state.getPeekOffset(); + } else if (state.getPeekType() == 3) { + return peek_available >= state.getRandomSize() + state.getPeekOffset(); } + return false; +} - - void RandomizeRule::action(MockTypes::CircularState& truth) { - (void) truth.generateRandomBuffer(); - } - - - - SerializeOkRule::SerializeOkRule(const char *const name) - : STest::Rule(name) {} - - - bool SerializeOkRule::precondition(const MockTypes::CircularState& state) { - return state.getRemainingSize() >= state.getRandomSize(); - } - - - void SerializeOkRule::action(MockTypes::CircularState& state) { - state.checkSizes(); - Fw::SerializeStatus status = state.getTestBuffer().serialize(state.getBuffer(), state.getRandomSize()); - state.setRemainingSize(state.getRemainingSize() - state.getRandomSize()); - ASSERT_TRUE(state.addInfinite(state.getBuffer(), state.getRandomSize())); - ASSERT_EQ(status, Fw::FW_SERIALIZE_OK); - state.checkSizes(); - } - - - - SerializeOverflowRule::SerializeOverflowRule(const char *const name) - : STest::Rule(name) {} - - - bool SerializeOverflowRule::precondition(const MockTypes::CircularState& state) { - return state.getRemainingSize() < state.getRandomSize(); - } - - - void SerializeOverflowRule::action(MockTypes::CircularState& state) { - Fw::SerializeStatus status = state.getTestBuffer().serialize(state.getBuffer(), state.getRandomSize()); - ASSERT_EQ(status, Fw::FW_SERIALIZE_NO_ROOM_LEFT); - } - - - PeekOkRule::PeekOkRule(const char *const name) - : STest::Rule(name) {} - - - bool PeekOkRule::precondition(const MockTypes::CircularState& state) { - FwSizeType peek_available = (MAX_BUFFER_SIZE - state.getRemainingSize()); - if (state.getPeekType() == 0 ) { - return peek_available >= sizeof(I8) + state.getPeekOffset(); +void PeekOkRule::action(MockTypes::CircularState& state) { + U8* buffer = nullptr; + char peek_char = 0; + U8 peek_u8 = 0; + U32 peek_u32 = 0; + U8 peek_buffer[MAX_BUFFER_SIZE]; + // Handle all cases for deserialization + if (state.getPeekType() == 0) { + ASSERT_TRUE(state.peek(buffer, sizeof(I8), state.getPeekOffset())); + peek_char = static_cast(buffer[0]); + ASSERT_EQ(state.getTestBuffer().peek(peek_char, state.getPeekOffset()), Fw::FW_SERIALIZE_OK); + ASSERT_EQ(static_cast(buffer[0]), peek_char); + } else if (state.getPeekType() == 1) { + ASSERT_TRUE(state.peek(buffer, sizeof(U8), state.getPeekOffset())); + peek_u8 = static_cast(buffer[0]); + ASSERT_EQ(state.getTestBuffer().peek(peek_u8, state.getPeekOffset()), Fw::FW_SERIALIZE_OK); + ASSERT_EQ(buffer[0], peek_u8); + } else if (state.getPeekType() == 2) { + ASSERT_TRUE(state.peek(buffer, sizeof(U32), state.getPeekOffset())); + ASSERT_EQ(state.getTestBuffer().peek(peek_u32, state.getPeekOffset()), Fw::FW_SERIALIZE_OK); + // Big-endian U32 + U32 value = 0; + value |= (buffer[0] << 24); + value |= (buffer[1] << 16); + value |= (buffer[2] << 8); + value |= (buffer[3] << 0); + ASSERT_EQ(value, peek_u32); + } else if (state.getPeekType() == 3) { + ASSERT_TRUE(state.peek(buffer, state.getRandomSize(), state.getPeekOffset())); + ASSERT_EQ(state.getTestBuffer().peek(peek_buffer, state.getRandomSize(), state.getPeekOffset()), + Fw::FW_SERIALIZE_OK); + for (FwSizeType i = 0; i < state.getRandomSize(); i++) { + ASSERT_EQ(buffer[i], peek_buffer[i]); } - else if (state.getPeekType() == 1) { - return peek_available >= sizeof(U8) + state.getPeekOffset(); - } - else if (state.getPeekType() == 2) { - return peek_available >= sizeof(U32) + state.getPeekOffset(); - } - else if (state.getPeekType() == 3) { - return peek_available >= state.getRandomSize() + state.getPeekOffset(); - } - return false; - } - - void PeekOkRule::action(MockTypes::CircularState& state) { - U8* buffer = nullptr; - char peek_char = 0; - U8 peek_u8 = 0; - U32 peek_u32 = 0; - U8 peek_buffer[MAX_BUFFER_SIZE]; - // Handle all cases for deserialization - if (state.getPeekType() == 0) { - ASSERT_TRUE(state.peek(buffer, sizeof(I8), state.getPeekOffset())); - peek_char = static_cast(buffer[0]); - ASSERT_EQ(state.getTestBuffer().peek(peek_char, state.getPeekOffset()), Fw::FW_SERIALIZE_OK); - ASSERT_EQ(static_cast(buffer[0]), peek_char); - } - else if (state.getPeekType() == 1) { - ASSERT_TRUE(state.peek(buffer, sizeof(U8), state.getPeekOffset())); - peek_u8 = static_cast(buffer[0]); - ASSERT_EQ(state.getTestBuffer().peek(peek_u8, state.getPeekOffset()), Fw::FW_SERIALIZE_OK); - ASSERT_EQ(buffer[0], peek_u8); - } - else if (state.getPeekType() == 2) { - ASSERT_TRUE(state.peek(buffer, sizeof(U32), state.getPeekOffset())); - ASSERT_EQ(state.getTestBuffer().peek(peek_u32, state.getPeekOffset()), Fw::FW_SERIALIZE_OK); - // Big-endian U32 - U32 value = 0; - value |= (buffer[0] << 24); - value |= (buffer[1] << 16); - value |= (buffer[2] << 8); - value |= (buffer[3] << 0); - ASSERT_EQ(value, peek_u32); - } - else if (state.getPeekType() == 3) { - ASSERT_TRUE(state.peek(buffer, state.getRandomSize(), state.getPeekOffset())); - ASSERT_EQ(state.getTestBuffer().peek(peek_buffer, state.getRandomSize(), state.getPeekOffset()), - Fw::FW_SERIALIZE_OK); - for (FwSizeType i = 0; i < state.getRandomSize(); i++) { - ASSERT_EQ(buffer[i], peek_buffer[i]); - } - } - else { - ASSERT_TRUE(false); // Fail the test, bad type - } - } - - - PeekBadRule::PeekBadRule(const char *const name) - : STest::Rule(name) {} - - - bool PeekBadRule::precondition(const MockTypes::CircularState& state) { - FwSizeType peek_available = (MAX_BUFFER_SIZE - state.getRemainingSize()); - if (state.getPeekType() == 0 ) { - return peek_available < sizeof(I8) + state.getPeekOffset(); - } - else if (state.getPeekType() == 1) { - return peek_available < sizeof(U8) + state.getPeekOffset(); - } - else if (state.getPeekType() == 2) { - return peek_available < sizeof(U32) + state.getPeekOffset(); - } - else if (state.getPeekType() == 3) { - return peek_available < state.getRandomSize() + state.getPeekOffset(); - } - return false; - } - - void PeekBadRule::action(MockTypes::CircularState& state) { - char peek_char = 0; - U8 peek_u8 = 0; - U32 peek_u32 = 0; - U8 peek_buffer[MAX_BUFFER_SIZE]; - // Handle all cases for deserialization - if (state.getPeekType() == 0) { - ASSERT_EQ(state.getTestBuffer().peek(peek_char, state.getPeekOffset()), Fw::FW_DESERIALIZE_BUFFER_EMPTY); - } - else if (state.getPeekType() == 1) { - ASSERT_EQ(state.getTestBuffer().peek(peek_u8, state.getPeekOffset()), Fw::FW_DESERIALIZE_BUFFER_EMPTY); - } - else if (state.getPeekType() == 2) { - ASSERT_EQ(state.getTestBuffer().peek(peek_u32, state.getPeekOffset()), Fw::FW_DESERIALIZE_BUFFER_EMPTY); - } - else if (state.getPeekType() == 3) { - ASSERT_EQ(state.getTestBuffer().peek(peek_buffer, state.getRandomSize(), state.getPeekOffset()), - Fw::FW_DESERIALIZE_BUFFER_EMPTY); - } - else { - ASSERT_TRUE(false); // Fail the test, bad type - } - } - - - RotateOkRule::RotateOkRule(const char *const name) - : STest::Rule(name) {} - - - bool RotateOkRule::precondition(const MockTypes::CircularState& state) { - FwSizeType rotate_available = (MAX_BUFFER_SIZE - state.getRemainingSize()); - return rotate_available >= state.getRandomSize(); - } - - void RotateOkRule::action(MockTypes::CircularState& state) { - state.checkSizes(); - ASSERT_EQ(state.getTestBuffer().rotate(state.getRandomSize()), Fw::FW_SERIALIZE_OK); - ASSERT_TRUE(state.rotate(state.getRandomSize())); - state.setRemainingSize(state.getRemainingSize() + state.getRandomSize()); - state.checkSizes(); - } - - - RotateBadRule::RotateBadRule(const char *const name) - : STest::Rule(name) {} - - - bool RotateBadRule::precondition(const MockTypes::CircularState& state) { - FwSizeType rotate_available = (MAX_BUFFER_SIZE - state.getRemainingSize()); - return rotate_available < state.getRandomSize(); - } - - void RotateBadRule::action(MockTypes::CircularState& state) { - ASSERT_EQ(state.getTestBuffer().rotate(state.getRandomSize()), Fw::FW_DESERIALIZE_BUFFER_EMPTY); + } else { + ASSERT_TRUE(false); // Fail the test, bad type } } + +PeekBadRule::PeekBadRule(const char* const name) : STest::Rule(name) {} + +bool PeekBadRule::precondition(const MockTypes::CircularState& state) { + FwSizeType peek_available = (MAX_BUFFER_SIZE - state.getRemainingSize()); + if (state.getPeekType() == 0) { + return peek_available < sizeof(I8) + state.getPeekOffset(); + } else if (state.getPeekType() == 1) { + return peek_available < sizeof(U8) + state.getPeekOffset(); + } else if (state.getPeekType() == 2) { + return peek_available < sizeof(U32) + state.getPeekOffset(); + } else if (state.getPeekType() == 3) { + return peek_available < state.getRandomSize() + state.getPeekOffset(); + } + return false; +} + +void PeekBadRule::action(MockTypes::CircularState& state) { + char peek_char = 0; + U8 peek_u8 = 0; + U32 peek_u32 = 0; + U8 peek_buffer[MAX_BUFFER_SIZE]; + // Handle all cases for deserialization + if (state.getPeekType() == 0) { + ASSERT_EQ(state.getTestBuffer().peek(peek_char, state.getPeekOffset()), Fw::FW_DESERIALIZE_BUFFER_EMPTY); + } else if (state.getPeekType() == 1) { + ASSERT_EQ(state.getTestBuffer().peek(peek_u8, state.getPeekOffset()), Fw::FW_DESERIALIZE_BUFFER_EMPTY); + } else if (state.getPeekType() == 2) { + ASSERT_EQ(state.getTestBuffer().peek(peek_u32, state.getPeekOffset()), Fw::FW_DESERIALIZE_BUFFER_EMPTY); + } else if (state.getPeekType() == 3) { + ASSERT_EQ(state.getTestBuffer().peek(peek_buffer, state.getRandomSize(), state.getPeekOffset()), + Fw::FW_DESERIALIZE_BUFFER_EMPTY); + } else { + ASSERT_TRUE(false); // Fail the test, bad type + } +} + +RotateOkRule::RotateOkRule(const char* const name) : STest::Rule(name) {} + +bool RotateOkRule::precondition(const MockTypes::CircularState& state) { + FwSizeType rotate_available = (MAX_BUFFER_SIZE - state.getRemainingSize()); + return rotate_available >= state.getRandomSize(); +} + +void RotateOkRule::action(MockTypes::CircularState& state) { + state.checkSizes(); + ASSERT_EQ(state.getTestBuffer().rotate(state.getRandomSize()), Fw::FW_SERIALIZE_OK); + ASSERT_TRUE(state.rotate(state.getRandomSize())); + state.setRemainingSize(state.getRemainingSize() + state.getRandomSize()); + state.checkSizes(); +} + +RotateBadRule::RotateBadRule(const char* const name) : STest::Rule(name) {} + +bool RotateBadRule::precondition(const MockTypes::CircularState& state) { + FwSizeType rotate_available = (MAX_BUFFER_SIZE - state.getRemainingSize()); + return rotate_available < state.getRandomSize(); +} + +void RotateBadRule::action(MockTypes::CircularState& state) { + ASSERT_EQ(state.getTestBuffer().rotate(state.getRandomSize()), Fw::FW_DESERIALIZE_BUFFER_EMPTY); +} +} // namespace Types diff --git a/Utils/Types/test/ut/CircularBuffer/CircularRules.hpp b/Utils/Types/test/ut/CircularBuffer/CircularRules.hpp index 430c6ff24a..b05b70fe9f 100644 --- a/Utils/Types/test/ut/CircularBuffer/CircularRules.hpp +++ b/Utils/Types/test/ut/CircularBuffer/CircularRules.hpp @@ -21,123 +21,122 @@ #include #include -#include -#include #include - +#include +#include namespace Types { - /** - * SetupRandomBufferRule: - * - * This rule sets up a random buffer, and other random state. - */ - struct RandomizeRule : public STest::Rule { - // Constructor - RandomizeRule(const char *const name); +/** + * SetupRandomBufferRule: + * + * This rule sets up a random buffer, and other random state. + */ +struct RandomizeRule : public STest::Rule { + // Constructor + RandomizeRule(const char* const name); - // Always valid - bool precondition(const MockTypes::CircularState& state); + // Always valid + bool precondition(const MockTypes::CircularState& state); - // Will randomize the test state - void action(MockTypes::CircularState& truth); - }; + // Will randomize the test state + void action(MockTypes::CircularState& truth); +}; - /** - * SerializeOkRule: - * - * This rule tests that the circular buffer can accept data when it is valid for the buffer to accept data. - */ - struct SerializeOkRule : public STest::Rule { - // Constructor - SerializeOkRule(const char *const name); +/** + * SerializeOkRule: + * + * This rule tests that the circular buffer can accept data when it is valid for the buffer to accept data. + */ +struct SerializeOkRule : public STest::Rule { + // Constructor + SerializeOkRule(const char* const name); - // Valid precondition for when the buffer should accept data - bool precondition(const MockTypes::CircularState& state); + // Valid precondition for when the buffer should accept data + bool precondition(const MockTypes::CircularState& state); - // Action that tests the buffer accepting data - void action(MockTypes::CircularState& state); - }; + // Action that tests the buffer accepting data + void action(MockTypes::CircularState& state); +}; - /** - * SerializeOverflowRule: - * - * This rule tests that the circular buffer cannot accept data when it is full. - */ - struct SerializeOverflowRule : public STest::Rule { - // Constructor - SerializeOverflowRule(const char *const name); +/** + * SerializeOverflowRule: + * + * This rule tests that the circular buffer cannot accept data when it is full. + */ +struct SerializeOverflowRule : public STest::Rule { + // Constructor + SerializeOverflowRule(const char* const name); - // Valid precondition for when the buffer should reject data - bool precondition(const MockTypes::CircularState& state); + // Valid precondition for when the buffer should reject data + bool precondition(const MockTypes::CircularState& state); - // Action that tests the buffer overflowing with an error - void action(MockTypes::CircularState& state); - }; + // Action that tests the buffer overflowing with an error + void action(MockTypes::CircularState& state); +}; - /** - * PeekOkRule: - * - * This rule tests that the circular buffer can peek correctly. - */ - struct PeekOkRule : public STest::Rule { - // Constructor - PeekOkRule(const char *const name); +/** + * PeekOkRule: + * + * This rule tests that the circular buffer can peek correctly. + */ +struct PeekOkRule : public STest::Rule { + // Constructor + PeekOkRule(const char* const name); - // Peek ok available for when buffer size - remaining size <= peek size - bool precondition(const MockTypes::CircularState& state); + // Peek ok available for when buffer size - remaining size <= peek size + bool precondition(const MockTypes::CircularState& state); - // Action that tests the buffer's ability to peek - void action(MockTypes::CircularState& state); - }; + // Action that tests the buffer's ability to peek + void action(MockTypes::CircularState& state); +}; - /** - * PeekOkRule: - * - * This rule tests that the circular buffer cannot peek when it should not peek. - */ - struct PeekBadRule : public STest::Rule { - // Constructor - PeekBadRule(const char *const name); +/** + * PeekOkRule: + * + * This rule tests that the circular buffer cannot peek when it should not peek. + */ +struct PeekBadRule : public STest::Rule { + // Constructor + PeekBadRule(const char* const name); - // Peek bad available for when buffer size - remaining size > peek size - bool precondition(const MockTypes::CircularState& state); + // Peek bad available for when buffer size - remaining size > peek size + bool precondition(const MockTypes::CircularState& state); - // Action that tests the buffer's ability to peek with a fail - void action(MockTypes::CircularState& state); - }; + // Action that tests the buffer's ability to peek with a fail + void action(MockTypes::CircularState& state); +}; - /** - * RotateOkRule: - * - * This rule tests that the circular buffer can rotate correctly. - */ - struct RotateOkRule : public STest::Rule { - // Constructor - RotateOkRule(const char *const name); +/** + * RotateOkRule: + * + * This rule tests that the circular buffer can rotate correctly. + */ +struct RotateOkRule : public STest::Rule { + // Constructor + RotateOkRule(const char* const name); - // Rotate is ok when there is more data then rotational size - bool precondition(const MockTypes::CircularState& state); + // Rotate is ok when there is more data then rotational size + bool precondition(const MockTypes::CircularState& state); - // Action that tests the buffer's ability to rotate - void action(MockTypes::CircularState& state); - }; + // Action that tests the buffer's ability to rotate + void action(MockTypes::CircularState& state); +}; - /** - * RotateOkRule: - * - * This rule tests that the circular buffer cannot rotate when it should not rotate. - */ - struct RotateBadRule : public STest::Rule { - // Constructor - RotateBadRule(const char *const name); +/** + * RotateOkRule: + * + * This rule tests that the circular buffer cannot rotate when it should not rotate. + */ +struct RotateBadRule : public STest::Rule { + // Constructor + RotateBadRule(const char* const name); - // Rotate is bad when there is less data then rotational size - bool precondition(const MockTypes::CircularState& state); + // Rotate is bad when there is less data then rotational size + bool precondition(const MockTypes::CircularState& state); - // Action that tests the buffer's ability to rotate - void action(MockTypes::CircularState& state); - }; -} -#endif //FPRIME_GROUNDINTERFACERULES_HPP + // Action that tests the buffer's ability to rotate + void action(MockTypes::CircularState& state); +}; +} // namespace Types +#endif // FPRIME_GROUNDINTERFACERULES_HPP diff --git a/Utils/Types/test/ut/CircularBuffer/CircularState.cpp b/Utils/Types/test/ut/CircularBuffer/CircularState.cpp index 39f22e482b..37bf199bf6 100644 --- a/Utils/Types/test/ut/CircularBuffer/CircularState.cpp +++ b/Utils/Types/test/ut/CircularBuffer/CircularState.cpp @@ -9,115 +9,114 @@ #include #include +#include #include #include -#include U8 CIRCULAR_BUFFER_MEMORY[MAX_BUFFER_SIZE]; namespace MockTypes { - CircularState::CircularState() : - m_remaining_size(static_cast(sizeof(CIRCULAR_BUFFER_MEMORY))), - m_random_size(MAX_BUFFER_SIZE), - m_peek_offset(0), - m_peek_type(0), - m_infinite_store(nullptr), - m_infinite_read(0), - m_infinite_write(0), - m_infinite_size(0), - m_test_buffer(CIRCULAR_BUFFER_MEMORY, static_cast(sizeof(CIRCULAR_BUFFER_MEMORY))) - { - memset(m_buffer, 0, sizeof m_buffer); - } +CircularState::CircularState() + : m_remaining_size(static_cast(sizeof(CIRCULAR_BUFFER_MEMORY))), + m_random_size(MAX_BUFFER_SIZE), + m_peek_offset(0), + m_peek_type(0), + m_infinite_store(nullptr), + m_infinite_read(0), + m_infinite_write(0), + m_infinite_size(0), + m_test_buffer(CIRCULAR_BUFFER_MEMORY, static_cast(sizeof(CIRCULAR_BUFFER_MEMORY))) { + memset(m_buffer, 0, sizeof m_buffer); +} - CircularState::~CircularState() { - if (m_infinite_size != 0) { - std::free(m_infinite_store); - } - } - - // Generates a random buffer - FwSizeType CircularState::generateRandomBuffer() { - m_peek_offset = static_cast(STest::Pick::lowerUpper(0, sizeof(m_buffer))); - m_peek_type = static_cast(STest::Pick::lowerUpper(0, 4)); - FwSizeType random_size = static_cast(STest::Pick::lowerUpper(0, sizeof(m_buffer))); - for (U32 i = 0; i < random_size; i++) { - m_buffer[i] = static_cast(STest::Pick::lowerUpper(0, 256)); - } - this->m_random_size = random_size; - return random_size; - } - - void CircularState::setRandom(FwSizeType random, FwSizeType peek_type, FwSizeType peek_offset) { - m_random_size = random; - m_peek_type = peek_type; - m_peek_offset = peek_offset; - } - - FwSizeType CircularState::getPeekOffset() const { - return m_peek_offset; - } - - FwSizeType CircularState::getPeekType() const { - return m_peek_type; - } - - bool CircularState::addInfinite(const U8* buffer, FwSizeType size) { - // If we are out of "infinite space" add another MB, and check allocation - if ((m_infinite_write + size) > m_infinite_size) { - void* new_pointer = std::realloc(m_infinite_store, m_infinite_size + 1048576); - if (new_pointer == nullptr) { - return false; - } - m_infinite_store = static_cast(new_pointer); - m_infinite_size += 1048576; - } - std::memcpy(m_infinite_store + m_infinite_write, buffer, size); - m_infinite_write += size; - return true; - } - - bool CircularState::peek(U8*& buffer, FwSizeType size, FwSizeType offset) { - FwSizeType final_offset = m_infinite_read + offset; - if ((final_offset + size) > m_infinite_write) { - return false; - } - buffer = m_infinite_store + final_offset; - return true; - } - - bool CircularState::rotate(FwSizeType size) { - // Fail if we try to rotate too far - if ((m_infinite_read + size) > m_infinite_write) { - return false; - } - m_infinite_read += size; - return true; - } - - FwSizeType CircularState::getRandomSize() const { - return m_random_size; - } - - const U8 *CircularState::getBuffer() const { - return m_buffer; - } - - FwSizeType CircularState::getRemainingSize() const { - return m_remaining_size; - } - - void CircularState::setRemainingSize(FwSizeType mRemainingSize) { - m_remaining_size = mRemainingSize; - } - - Types::CircularBuffer& CircularState::getTestBuffer() { - return m_test_buffer; - } - - void CircularState::checkSizes() const { - const FwSizeType allocated_size = (MAX_BUFFER_SIZE - m_remaining_size); - ASSERT_EQ(m_test_buffer.get_free_size(), m_remaining_size); - ASSERT_EQ(m_test_buffer.get_allocated_size(), allocated_size); +CircularState::~CircularState() { + if (m_infinite_size != 0) { + std::free(m_infinite_store); } } + +// Generates a random buffer +FwSizeType CircularState::generateRandomBuffer() { + m_peek_offset = static_cast(STest::Pick::lowerUpper(0, sizeof(m_buffer))); + m_peek_type = static_cast(STest::Pick::lowerUpper(0, 4)); + FwSizeType random_size = static_cast(STest::Pick::lowerUpper(0, sizeof(m_buffer))); + for (U32 i = 0; i < random_size; i++) { + m_buffer[i] = static_cast(STest::Pick::lowerUpper(0, 256)); + } + this->m_random_size = random_size; + return random_size; +} + +void CircularState::setRandom(FwSizeType random, FwSizeType peek_type, FwSizeType peek_offset) { + m_random_size = random; + m_peek_type = peek_type; + m_peek_offset = peek_offset; +} + +FwSizeType CircularState::getPeekOffset() const { + return m_peek_offset; +} + +FwSizeType CircularState::getPeekType() const { + return m_peek_type; +} + +bool CircularState::addInfinite(const U8* buffer, FwSizeType size) { + // If we are out of "infinite space" add another MB, and check allocation + if ((m_infinite_write + size) > m_infinite_size) { + void* new_pointer = std::realloc(m_infinite_store, m_infinite_size + 1048576); + if (new_pointer == nullptr) { + return false; + } + m_infinite_store = static_cast(new_pointer); + m_infinite_size += 1048576; + } + std::memcpy(m_infinite_store + m_infinite_write, buffer, size); + m_infinite_write += size; + return true; +} + +bool CircularState::peek(U8*& buffer, FwSizeType size, FwSizeType offset) { + FwSizeType final_offset = m_infinite_read + offset; + if ((final_offset + size) > m_infinite_write) { + return false; + } + buffer = m_infinite_store + final_offset; + return true; +} + +bool CircularState::rotate(FwSizeType size) { + // Fail if we try to rotate too far + if ((m_infinite_read + size) > m_infinite_write) { + return false; + } + m_infinite_read += size; + return true; +} + +FwSizeType CircularState::getRandomSize() const { + return m_random_size; +} + +const U8* CircularState::getBuffer() const { + return m_buffer; +} + +FwSizeType CircularState::getRemainingSize() const { + return m_remaining_size; +} + +void CircularState::setRemainingSize(FwSizeType mRemainingSize) { + m_remaining_size = mRemainingSize; +} + +Types::CircularBuffer& CircularState::getTestBuffer() { + return m_test_buffer; +} + +void CircularState::checkSizes() const { + const FwSizeType allocated_size = (MAX_BUFFER_SIZE - m_remaining_size); + ASSERT_EQ(m_test_buffer.get_free_size(), m_remaining_size); + ASSERT_EQ(m_test_buffer.get_allocated_size(), allocated_size); +} +} // namespace MockTypes diff --git a/Utils/Types/test/ut/CircularBuffer/CircularState.hpp b/Utils/Types/test/ut/CircularBuffer/CircularState.hpp index f9f36482c2..90072ac99d 100644 --- a/Utils/Types/test/ut/CircularBuffer/CircularState.hpp +++ b/Utils/Types/test/ut/CircularBuffer/CircularState.hpp @@ -17,96 +17,96 @@ namespace MockTypes { - class CircularState { - public: - // Constructor - CircularState(); - // Destructor - ~CircularState(); - /** - * Generates a random buffer for input to various calls to the CircularBuffer. - * @return size of this buffer - */ - FwSizeType generateRandomBuffer(); - /** - * Sets the random settings - * @param random: random size - * @param peek_type: peek type (0-3) - * @param peek_offset: offset size - */ - void setRandom(FwSizeType random, FwSizeType peek_type, FwSizeType peek_offset); - /** - * Add to the infinite pool of data. - * @return true if successful, false otherwise - */ - bool addInfinite(const U8* buffer, FwSizeType size); - /** - * Grab a peek buffer for given size and offset. - * @return true if successful, false if cannot. - */ - bool peek(U8*& buffer, FwSizeType size, FwSizeType offset = 0); - /** - * Rotate the circular buffer. - * @param size: size to rotate - * @return true if successful, false otherwise - */ - bool rotate(FwSizeType size); - /** - * Get the size of the random buffer data. - * @return size of the buffer - */ - FwSizeType getRandomSize() const; - /** - * Get the size of the random buffer data. - * @return size of the buffer - */ - FwSizeType getPeekOffset() const; - /** - * Get the size of the random buffer data. - * @return size of the buffer - */ - FwSizeType getPeekType() const; - /** - * Gets a pointer to the random buffer. - * @return random buffer storing data - */ - const U8 *getBuffer() const; - /** - * Get the remaining size of the circular buffer. This is a shadow field. - * @return shadow field for circular buffer. - */ - FwSizeType getRemainingSize() const; - /** - * Set the remaining size shadow field input. - * @param mRemainingSize: remaining size shadow field - */ - void setRemainingSize(FwSizeType mRemainingSize); - /** - * Get the in-test circular buffer. - * @return in-test circular buffer - */ - Types::CircularBuffer& getTestBuffer(); +class CircularState { + public: + // Constructor + CircularState(); + // Destructor + ~CircularState(); + /** + * Generates a random buffer for input to various calls to the CircularBuffer. + * @return size of this buffer + */ + FwSizeType generateRandomBuffer(); + /** + * Sets the random settings + * @param random: random size + * @param peek_type: peek type (0-3) + * @param peek_offset: offset size + */ + void setRandom(FwSizeType random, FwSizeType peek_type, FwSizeType peek_offset); + /** + * Add to the infinite pool of data. + * @return true if successful, false otherwise + */ + bool addInfinite(const U8* buffer, FwSizeType size); + /** + * Grab a peek buffer for given size and offset. + * @return true if successful, false if cannot. + */ + bool peek(U8*& buffer, FwSizeType size, FwSizeType offset = 0); + /** + * Rotate the circular buffer. + * @param size: size to rotate + * @return true if successful, false otherwise + */ + bool rotate(FwSizeType size); + /** + * Get the size of the random buffer data. + * @return size of the buffer + */ + FwSizeType getRandomSize() const; + /** + * Get the size of the random buffer data. + * @return size of the buffer + */ + FwSizeType getPeekOffset() const; + /** + * Get the size of the random buffer data. + * @return size of the buffer + */ + FwSizeType getPeekType() const; + /** + * Gets a pointer to the random buffer. + * @return random buffer storing data + */ + const U8* getBuffer() const; + /** + * Get the remaining size of the circular buffer. This is a shadow field. + * @return shadow field for circular buffer. + */ + FwSizeType getRemainingSize() const; + /** + * Set the remaining size shadow field input. + * @param mRemainingSize: remaining size shadow field + */ + void setRemainingSize(FwSizeType mRemainingSize); + /** + * Get the in-test circular buffer. + * @return in-test circular buffer + */ + Types::CircularBuffer& getTestBuffer(); - /** - * Check allocated and free sizes - */ - void checkSizes() const; + /** + * Check allocated and free sizes + */ + void checkSizes() const; - private: - FwSizeType m_remaining_size; - FwSizeType m_random_size; - FwSizeType m_peek_offset; - FwSizeType m_peek_type; + private: + FwSizeType m_remaining_size; + FwSizeType m_random_size; + FwSizeType m_peek_offset; + FwSizeType m_peek_type; - U8 m_buffer[MAX_BUFFER_SIZE]; - // May use just under 100MB of space - U8* m_infinite_store; - FwSizeType m_infinite_read; - FwSizeType m_infinite_write; - FwSizeType m_infinite_size; + U8 m_buffer[MAX_BUFFER_SIZE]; + // May use just under 100MB of space + U8* m_infinite_store; + FwSizeType m_infinite_read; + FwSizeType m_infinite_write; + FwSizeType m_infinite_size; - Types::CircularBuffer m_test_buffer; - }; + Types::CircularBuffer m_test_buffer; +}; -} -#endif //FPRIME_CIRCULARSTATE_HPP +} // namespace MockTypes +#endif // FPRIME_CIRCULARSTATE_HPP diff --git a/Utils/Types/test/ut/CircularBuffer/Main.cpp b/Utils/Types/test/ut/CircularBuffer/Main.cpp index 9d152b9beb..0ac88d468e 100644 --- a/Utils/Types/test/ut/CircularBuffer/Main.cpp +++ b/Utils/Types/test/ut/CircularBuffer/Main.cpp @@ -6,16 +6,16 @@ * Created on: May 23, 2019 * Author: mstarch */ -#include -#include #include +#include +#include +#include #include #include -#include -#include #include +#include #define STEP_COUNT 1000 @@ -41,22 +41,13 @@ TEST(CircularBufferTests, RandomCircularTests) { Types::PeekBadRule rotateBad("rotateBad"); // Setup a list of rules to choose from - STest::Rule* rules[] = { - &randomize, - &serializeOk, - &serializeOverflow, - &peekOk, - &peekBad, - &rotateOk, - &rotateBad - }; + STest::Rule* rules[] = {&randomize, &serializeOk, &serializeOverflow, &peekOk, + &peekBad, &rotateOk, &rotateBad}; // Construct the random scenario and run it with the defined bounds - STest::RandomScenario random("Random Rules", rules, - FW_NUM_ARRAY_ELEMENTS(rules)); + STest::RandomScenario random("Random Rules", rules, FW_NUM_ARRAY_ELEMENTS(rules)); // Setup a bounded scenario to run rules a set number of times - STest::BoundedScenario bounded("Bounded Random Rules Scenario", - random, STEP_COUNT); + STest::BoundedScenario bounded("Bounded Random Rules Scenario", random, STEP_COUNT); // Run! const U32 numSteps = bounded.run(state); printf("Ran %u steps.\n", numSteps); @@ -82,7 +73,7 @@ TEST(CircularBufferTests, BasicSerializeTest) { TEST(CircularBufferTests, BasicOverflowTest) { // Setup state and fill it with garbage MockTypes::CircularState state; - ASSERT_EQ(Fw::FW_SERIALIZE_OK , state.getTestBuffer().serialize(state.getBuffer(), state.getRandomSize())); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, state.getTestBuffer().serialize(state.getBuffer(), state.getRandomSize())); state.setRemainingSize(0); // Create rules, and assign them into the array @@ -100,7 +91,7 @@ TEST(CircularBufferTests, BasicPeekTest) { char peek_char = static_cast(0x85); U8 peek_u8 = 0x95; U32 peek_u32 = 0xdeadc0de; - U8 buffer[1024] = {}; // Clear out memory to appease valgrind + U8 buffer[1024] = {}; // Clear out memory to appease valgrind // Setup all circular state MockTypes::CircularState state; state.addInfinite(reinterpret_cast(&peek_char), sizeof(peek_char)); diff --git a/Utils/test/ut/RateLimiterTester.cpp b/Utils/test/ut/RateLimiterTester.cpp index 83f9c0e43a..ea55294d3e 100644 --- a/Utils/test/ut/RateLimiterTester.cpp +++ b/Utils/test/ut/RateLimiterTester.cpp @@ -13,140 +13,124 @@ #include "RateLimiterTester.hpp" - namespace Utils { - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- +// ---------------------------------------------------------------------- +// Construction and destruction +// ---------------------------------------------------------------------- - RateLimiterTester :: - RateLimiterTester() - { - } +RateLimiterTester ::RateLimiterTester() {} - RateLimiterTester :: - ~RateLimiterTester() - { +RateLimiterTester ::~RateLimiterTester() {} - } +// ---------------------------------------------------------------------- +// Tests +// ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- - - void RateLimiterTester :: - testCounterTriggering() - { +void RateLimiterTester ::testCounterTriggering() { U32 testCycles[] = {0, 5, 50, 832}; for (U32 i = 0; i < FW_NUM_ARRAY_ELEMENTS(testCycles); i++) { - const U32 cycles = testCycles[i]; + const U32 cycles = testCycles[i]; - // triggers at the beginning - RateLimiter limiter(cycles, 0); - ASSERT_TRUE(limiter.trigger()); - limiter.reset(); - - // does not trigger if skipped - if (cycles > 0) { - limiter.setCounter(1); - ASSERT_FALSE(limiter.trigger()); + // triggers at the beginning + RateLimiter limiter(cycles, 0); + ASSERT_TRUE(limiter.trigger()); limiter.reset(); - } - // test number of times triggered - const U32 numIter = 10000; - U32 triggerCount = 0; - for (U32 iter = 0; iter < numIter; iter++) { - bool shouldTrigger = (cycles == 0) || (iter % cycles == 0); - bool triggered = limiter.trigger(); - ASSERT_EQ(shouldTrigger, triggered) << " for cycles " << cycles << " at " << iter; - triggerCount += triggered; - } - if (cycles > 0) { - U32 expectedCount = (numIter / cycles) + (numIter % cycles > 0); - ASSERT_EQ(triggerCount, expectedCount); - } - } - } - - void RateLimiterTester :: - testTimeTriggering() - { - U32 testCycles[] = {0, 5, 50, 832}; - for (U32 i = 0; i < FW_NUM_ARRAY_ELEMENTS(testCycles); i++) { - const U32 cycles = testCycles[i]; - Fw::Time timeCyclesTime(cycles, 0); - - // triggers at the beginning - RateLimiter limiter(0, cycles); - ASSERT_TRUE(limiter.trigger(Fw::Time::zero())); - limiter.reset(); - - // does not trigger if skipped - if (cycles > 0) { - limiter.setTime(Fw::Time(1,0)); - ASSERT_FALSE(limiter.trigger(Fw::Time::zero())); - limiter.reset(); - } - - // test number of times triggered - const U32 numIter = 100000; - Fw::Time curTime(0, 0); - Fw::Time nextTriggerTime(0, 0); - for (U32 iter = 0; iter < numIter; iter++) { - curTime.add(0, STest::Pick::lowerUpper(1, 5) * 100000); - bool shouldTrigger = (cycles == 0) || (curTime >= nextTriggerTime); - bool triggered = limiter.trigger(curTime); - ASSERT_EQ(shouldTrigger, triggered) << " for cycles " << cycles << " at " << curTime.getSeconds() << "." << curTime.getUSeconds(); - if (triggered) { - nextTriggerTime = Fw::Time::add(curTime, timeCyclesTime); + // does not trigger if skipped + if (cycles > 0) { + limiter.setCounter(1); + ASSERT_FALSE(limiter.trigger()); + limiter.reset(); } - } - } - } - void RateLimiterTester :: - testCounterAndTimeTriggering() - { + // test number of times triggered + const U32 numIter = 10000; + U32 triggerCount = 0; + for (U32 iter = 0; iter < numIter; iter++) { + bool shouldTrigger = (cycles == 0) || (iter % cycles == 0); + bool triggered = limiter.trigger(); + ASSERT_EQ(shouldTrigger, triggered) << " for cycles " << cycles << " at " << iter; + triggerCount += triggered; + } + if (cycles > 0) { + U32 expectedCount = (numIter / cycles) + (numIter % cycles > 0); + ASSERT_EQ(triggerCount, expectedCount); + } + } +} + +void RateLimiterTester ::testTimeTriggering() { + U32 testCycles[] = {0, 5, 50, 832}; + for (U32 i = 0; i < FW_NUM_ARRAY_ELEMENTS(testCycles); i++) { + const U32 cycles = testCycles[i]; + Fw::Time timeCyclesTime(cycles, 0); + + // triggers at the beginning + RateLimiter limiter(0, cycles); + ASSERT_TRUE(limiter.trigger(Fw::Time::zero())); + limiter.reset(); + + // does not trigger if skipped + if (cycles > 0) { + limiter.setTime(Fw::Time(1, 0)); + ASSERT_FALSE(limiter.trigger(Fw::Time::zero())); + limiter.reset(); + } + + // test number of times triggered + const U32 numIter = 100000; + Fw::Time curTime(0, 0); + Fw::Time nextTriggerTime(0, 0); + for (U32 iter = 0; iter < numIter; iter++) { + curTime.add(0, STest::Pick::lowerUpper(1, 5) * 100000); + bool shouldTrigger = (cycles == 0) || (curTime >= nextTriggerTime); + bool triggered = limiter.trigger(curTime); + ASSERT_EQ(shouldTrigger, triggered) + << " for cycles " << cycles << " at " << curTime.getSeconds() << "." << curTime.getUSeconds(); + if (triggered) { + nextTriggerTime = Fw::Time::add(curTime, timeCyclesTime); + } + } + } +} + +void RateLimiterTester ::testCounterAndTimeTriggering() { U32 testCounterCycles[] = {37, 981, 4110}; U32 testTimeCycles[] = {12, 294, 1250}; for (U32 i = 0; i < (FW_NUM_ARRAY_ELEMENTS(testCounterCycles) * FW_NUM_ARRAY_ELEMENTS(testTimeCycles)); i++) { - const U32 counterCycles = testCounterCycles[i % FW_NUM_ARRAY_ELEMENTS(testCounterCycles)]; - const U32 timeCycles = testTimeCycles[i / FW_NUM_ARRAY_ELEMENTS(testCounterCycles)]; - Fw::Time timeCyclesTime(timeCycles, 0); + const U32 counterCycles = testCounterCycles[i % FW_NUM_ARRAY_ELEMENTS(testCounterCycles)]; + const U32 timeCycles = testTimeCycles[i / FW_NUM_ARRAY_ELEMENTS(testCounterCycles)]; + Fw::Time timeCyclesTime(timeCycles, 0); - // triggers at the beginning - RateLimiter limiter(counterCycles, timeCycles); - ASSERT_TRUE(limiter.trigger(Fw::Time::zero())); - limiter.reset(); + // triggers at the beginning + RateLimiter limiter(counterCycles, timeCycles); + ASSERT_TRUE(limiter.trigger(Fw::Time::zero())); + limiter.reset(); - // test trigger locations - const U32 numIter = 100000; // each iter is 0.1 seconds - Fw::Time curTime(0, 0); - U32 lastTriggerIter = 0; - Fw::Time nextTriggerTime(0, 0); - for (U32 iter = 0; iter < numIter; iter++) { - curTime.add(0, STest::Pick::lowerUpper(1, 5) * 100000); - bool shouldTrigger = ((iter-lastTriggerIter) % counterCycles == 0) || (curTime >= nextTriggerTime); - bool triggered = limiter.trigger(curTime); - ASSERT_EQ(shouldTrigger, triggered) << " for cycles " << counterCycles << "/" << timeCycles << " at " << iter << "/" << curTime.getSeconds() << "." << curTime.getUSeconds(); - if (triggered) { - nextTriggerTime = Fw::Time::add(curTime, timeCyclesTime); - lastTriggerIter = iter; + // test trigger locations + const U32 numIter = 100000; // each iter is 0.1 seconds + Fw::Time curTime(0, 0); + U32 lastTriggerIter = 0; + Fw::Time nextTriggerTime(0, 0); + for (U32 iter = 0; iter < numIter; iter++) { + curTime.add(0, STest::Pick::lowerUpper(1, 5) * 100000); + bool shouldTrigger = ((iter - lastTriggerIter) % counterCycles == 0) || (curTime >= nextTriggerTime); + bool triggered = limiter.trigger(curTime); + ASSERT_EQ(shouldTrigger, triggered) << " for cycles " << counterCycles << "/" << timeCycles << " at " + << iter << "/" << curTime.getSeconds() << "." << curTime.getUSeconds(); + if (triggered) { + nextTriggerTime = Fw::Time::add(curTime, timeCyclesTime); + lastTriggerIter = iter; + } } - } } - } +} +// ---------------------------------------------------------------------- +// Helper methods +// ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Helper methods - // ---------------------------------------------------------------------- +void RateLimiterTester ::initComponents() {} - void RateLimiterTester :: - initComponents() - { - } - -} // end namespace Utils +} // end namespace Utils diff --git a/Utils/test/ut/RateLimiterTester.hpp b/Utils/test/ut/RateLimiterTester.hpp index e47d4d3177..f3a18263fc 100644 --- a/Utils/test/ut/RateLimiterTester.hpp +++ b/Utils/test/ut/RateLimiterTester.hpp @@ -14,60 +14,51 @@ #ifndef RATELIMITERTESTER_HPP #define RATELIMITERTESTER_HPP -#include "Utils/RateLimiter.hpp" #include -#include "gtest/gtest.h" #include +#include "Utils/RateLimiter.hpp" +#include "gtest/gtest.h" namespace Utils { - class RateLimiterTester - { +class RateLimiterTester { + // ---------------------------------------------------------------------- + // Construction and destruction + // ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- + public: + //! Construct object RateLimiterTester + //! + RateLimiterTester(); - public: + //! Destroy object RateLimiterTester + //! + ~RateLimiterTester(); - //! Construct object RateLimiterTester - //! - RateLimiterTester(); + public: + // ---------------------------------------------------------------------- + // Tests + // ---------------------------------------------------------------------- - //! Destroy object RateLimiterTester - //! - ~RateLimiterTester(); + void testCounterTriggering(); + void testTimeTriggering(); + void testCounterAndTimeTriggering(); - public: + private: + // ---------------------------------------------------------------------- + // Helper methods + // ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- + //! Initialize components + //! + void initComponents(); - void testCounterTriggering(); - void testTimeTriggering(); - void testCounterAndTimeTriggering(); + private: + // ---------------------------------------------------------------------- + // Variables + // ---------------------------------------------------------------------- +}; - private: - - // ---------------------------------------------------------------------- - // Helper methods - // ---------------------------------------------------------------------- - - //! Initialize components - //! - void initComponents(); - - private: - - // ---------------------------------------------------------------------- - // Variables - // ---------------------------------------------------------------------- - - - - }; - -} // end namespace Utils +} // end namespace Utils #endif diff --git a/Utils/test/ut/TokenBucketTester.cpp b/Utils/test/ut/TokenBucketTester.cpp index d4eb13de4c..db1addf846 100644 --- a/Utils/test/ut/TokenBucketTester.cpp +++ b/Utils/test/ut/TokenBucketTester.cpp @@ -16,60 +16,49 @@ namespace Utils { - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- +// ---------------------------------------------------------------------- +// Construction and destruction +// ---------------------------------------------------------------------- - TokenBucketTester :: - TokenBucketTester() - { - } +TokenBucketTester ::TokenBucketTester() {} - TokenBucketTester :: - ~TokenBucketTester() - { +TokenBucketTester ::~TokenBucketTester() {} - } +// ---------------------------------------------------------------------- +// Tests +// ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- - - void TokenBucketTester :: - testTriggering() - { +void TokenBucketTester ::testTriggering() { const U32 interval = 1000000; U32 testMaxTokens[] = {1, 5, 50, 832}; for (U32 i = 0; i < FW_NUM_ARRAY_ELEMENTS(testMaxTokens); i++) { - const U32 maxTokens = testMaxTokens[i]; - TokenBucket bucket(interval, maxTokens); + const U32 maxTokens = testMaxTokens[i]; + TokenBucket bucket(interval, maxTokens); - // can activate maxTokens times in a row - for (U32 j = 0; j < maxTokens; j++) { - bool triggered = bucket.trigger(Fw::Time(0, 0)); - ASSERT_TRUE(triggered); - ASSERT_EQ(bucket.getTokens(), maxTokens - j - 1); - } + // can activate maxTokens times in a row + for (U32 j = 0; j < maxTokens; j++) { + bool triggered = bucket.trigger(Fw::Time(0, 0)); + ASSERT_TRUE(triggered); + ASSERT_EQ(bucket.getTokens(), maxTokens - j - 1); + } - // replenish - bucket.replenish(); + // replenish + bucket.replenish(); - Fw::Time time(0, 0); - const U32 attempts = maxTokens * 5; - Fw::Time attemptInterval(0, interval / 4); - U32 triggerCount = 0; - for (U32 attempt = 0; attempt < attempts; attempt++) { - triggerCount += bucket.trigger(time); - time = Fw::Time::add(time, attemptInterval); - } - U32 expected = maxTokens + (attempts - 1) / 4; - ASSERT_EQ(expected, triggerCount); + Fw::Time time(0, 0); + const U32 attempts = maxTokens * 5; + Fw::Time attemptInterval(0, interval / 4); + U32 triggerCount = 0; + for (U32 attempt = 0; attempt < attempts; attempt++) { + triggerCount += bucket.trigger(time); + time = Fw::Time::add(time, attemptInterval); + } + U32 expected = maxTokens + (attempts - 1) / 4; + ASSERT_EQ(expected, triggerCount); } - } +} - void TokenBucketTester :: - testReconfiguring() - { +void TokenBucketTester ::testReconfiguring() { U32 initialInterval = 1000000; U32 initialMaxTokens = 5; @@ -80,44 +69,43 @@ namespace Utils { // trigger bucket.trigger(Fw::Time(0, 0)); - ASSERT_EQ(bucket.getTokens(), initialMaxTokens-1); + ASSERT_EQ(bucket.getTokens(), initialMaxTokens - 1); // replenished, then triggered bucket.trigger(Fw::Time(1, 0)); - ASSERT_EQ(bucket.getTokens(), initialMaxTokens-1); + ASSERT_EQ(bucket.getTokens(), initialMaxTokens - 1); // set new interval, can't replenish using old interval U32 newInterval = 2000000; bucket.setReplenishInterval(newInterval); ASSERT_EQ(bucket.getReplenishInterval(), newInterval); ASSERT_TRUE(bucket.trigger(Fw::Time(2, 0))); - ASSERT_EQ(bucket.getTokens(), initialMaxTokens-2); + ASSERT_EQ(bucket.getTokens(), initialMaxTokens - 2); // set new max tokens, replenish up to new max U32 newMaxTokens = 10; bucket.setMaxTokens(newMaxTokens); ASSERT_EQ(bucket.getMaxTokens(), newMaxTokens); ASSERT_TRUE(bucket.trigger(Fw::Time(20, 0))); - ASSERT_EQ(bucket.getTokens(), newMaxTokens-1); + ASSERT_EQ(bucket.getTokens(), newMaxTokens - 1); // set new rate, replenish quickly - while (bucket.trigger(Fw::Time(0,0))); + while (bucket.trigger(Fw::Time(0, 0))) + ; bucket.setReplenishInterval(1000000); U32 newRate = 2; bucket.setReplenishRate(newRate); ASSERT_EQ(bucket.getReplenishRate(), newRate); ASSERT_TRUE(bucket.trigger(Fw::Time(21, 0))); ASSERT_EQ(bucket.getTokens(), 1); - } +} - void TokenBucketTester :: - testInitialSettings() - { +void TokenBucketTester ::testInitialSettings() { U32 interval = 1000000; U32 maxTokens = 5; U32 rate = 2; U32 startTokens = 2; - Fw::Time startTime(5,0); + Fw::Time startTime(5, 0); TokenBucket bucket(interval, maxTokens, rate, startTokens, startTime); ASSERT_NE(bucket.getTokens(), maxTokens); @@ -125,20 +113,16 @@ namespace Utils { ASSERT_EQ(bucket.getReplenishRate(), rate); for (U32 i = 0; i < startTokens; i++) { - bool triggered = bucket.trigger(Fw::Time(0,0)); - ASSERT_TRUE(triggered); + bool triggered = bucket.trigger(Fw::Time(0, 0)); + ASSERT_TRUE(triggered); } - ASSERT_FALSE(bucket.trigger(Fw::Time(0,0))); - } + ASSERT_FALSE(bucket.trigger(Fw::Time(0, 0))); +} +// ---------------------------------------------------------------------- +// Helper methods +// ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Helper methods - // ---------------------------------------------------------------------- +void TokenBucketTester ::initComponents() {} - void TokenBucketTester :: - initComponents() - { - } - -} // end namespace Utils +} // end namespace Utils diff --git a/Utils/test/ut/TokenBucketTester.hpp b/Utils/test/ut/TokenBucketTester.hpp index 598f7fe276..281aa6546d 100644 --- a/Utils/test/ut/TokenBucketTester.hpp +++ b/Utils/test/ut/TokenBucketTester.hpp @@ -14,57 +14,50 @@ #ifndef TOKENBUCKETTESTER_HPP #define TOKENBUCKETTESTER_HPP -#include "Utils/TokenBucket.hpp" #include +#include "Utils/TokenBucket.hpp" #include "gtest/gtest.h" namespace Utils { - class TokenBucketTester - { +class TokenBucketTester { + // ---------------------------------------------------------------------- + // Construction and destruction + // ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- + public: + //! Construct object TokenBucketTester + //! + TokenBucketTester(); - public: + //! Destroy object TokenBucketTester + //! + ~TokenBucketTester(); - //! Construct object TokenBucketTester - //! - TokenBucketTester(); + public: + // ---------------------------------------------------------------------- + // Tests + // ---------------------------------------------------------------------- - //! Destroy object TokenBucketTester - //! - ~TokenBucketTester(); + void testTriggering(); + void testReconfiguring(); + void testInitialSettings(); - public: + private: + // ---------------------------------------------------------------------- + // Helper methods + // ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- + //! Initialize components + //! + void initComponents(); - void testTriggering(); - void testReconfiguring(); - void testInitialSettings(); + private: + // ---------------------------------------------------------------------- + // Variables + // ---------------------------------------------------------------------- +}; - private: - - // ---------------------------------------------------------------------- - // Helper methods - // ---------------------------------------------------------------------- - - //! Initialize components - //! - void initComponents(); - - private: - - // ---------------------------------------------------------------------- - // Variables - // ---------------------------------------------------------------------- - - }; - -} // end namespace Utils +} // end namespace Utils #endif diff --git a/Utils/test/ut/main.cpp b/Utils/test/ut/main.cpp index 3b53643b8a..49bcbcefbb 100644 --- a/Utils/test/ut/main.cpp +++ b/Utils/test/ut/main.cpp @@ -35,7 +35,7 @@ TEST(TokenBucketTest, TestInitialSettings) { tester.testInitialSettings(); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/default/config/ActiveRateGroupCfg.hpp b/default/config/ActiveRateGroupCfg.hpp index 8181a2823b..dad99ba94d 100644 --- a/default/config/ActiveRateGroupCfg.hpp +++ b/default/config/ActiveRateGroupCfg.hpp @@ -1,29 +1,27 @@ /* -* \author: Tim Canham -* \file: -* \brief -* -* This file has configuration settings for the ActiveRateGroup component. -* -* -* Copyright 2014-2015, by the California Institute of Technology. -* ALL RIGHTS RESERVED. United States Government Sponsorship -* acknowledged. -* -*/ + * \author: Tim Canham + * \file: + * \brief + * + * This file has configuration settings for the ActiveRateGroup component. + * + * + * Copyright 2014-2015, by the California Institute of Technology. + * ALL RIGHTS RESERVED. United States Government Sponsorship + * acknowledged. + * + */ #ifndef ACTIVERATEGROUP_ACTIVERATEGROUPCFG_HPP_ #define ACTIVERATEGROUP_ACTIVERATEGROUPCFG_HPP_ namespace Svc { - enum { - //! Number of overruns allowed before overrun event is throttled - ACTIVE_RATE_GROUP_OVERRUN_THROTTLE = 5, - }; +enum { + //! Number of overruns allowed before overrun event is throttled + ACTIVE_RATE_GROUP_OVERRUN_THROTTLE = 5, +}; } - - #endif /* ACTIVERATEGROUP_ACTIVERATEGROUPCFG_HPP_ */ diff --git a/default/config/ActiveTextLoggerCfg.hpp b/default/config/ActiveTextLoggerCfg.hpp index 69228c881e..690f7e47cd 100644 --- a/default/config/ActiveTextLoggerCfg.hpp +++ b/default/config/ActiveTextLoggerCfg.hpp @@ -2,7 +2,7 @@ #define Config_ActiveTextLoggerCfg_HPP_ enum { - ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE = 25, //!< Size of event ID filter + ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE = 25, //!< Size of event ID filter }; #endif /* Config_ActiveTextLoggerCfg_HPP_ */ diff --git a/default/config/BufferManagerComponentImplCfg.hpp b/default/config/BufferManagerComponentImplCfg.hpp index 6ae12c580c..119e5589e9 100644 --- a/default/config/BufferManagerComponentImplCfg.hpp +++ b/default/config/BufferManagerComponentImplCfg.hpp @@ -4,8 +4,7 @@ #include namespace Svc { - static const U16 BUFFERMGR_MAX_NUM_BINS = 10; +static const U16 BUFFERMGR_MAX_NUM_BINS = 10; } - -#endif // __BUFFERMANAGERCOMPONENTIMPLCFG_HPP__ +#endif // __BUFFERMANAGERCOMPONENTIMPLCFG_HPP__ diff --git a/default/config/CRCCheckerConfig.hpp b/default/config/CRCCheckerConfig.hpp index fb843f580d..c728a5181f 100644 --- a/default/config/CRCCheckerConfig.hpp +++ b/default/config/CRCCheckerConfig.hpp @@ -6,10 +6,9 @@ #ifndef CONFIG_CRC_CHECKER_CONFIG_HPP #define CONFIG_CRC_CHECKER_CONFIG_HPP -#include - +#include // Default block size used when reading files for CRC calculation constexpr FwSignedSizeType CONFIG_CRC_FILE_READ_BLOCK = 2048; -#endif +#endif diff --git a/default/config/CommandDispatcherImplCfg.hpp b/default/config/CommandDispatcherImplCfg.hpp index 4daa043ad9..789069fd79 100644 --- a/default/config/CommandDispatcherImplCfg.hpp +++ b/default/config/CommandDispatcherImplCfg.hpp @@ -11,10 +11,8 @@ // Define configuration values for dispatcher enum { - CMD_DISPATCHER_DISPATCH_TABLE_SIZE = 100, // !< The size of the table holding opcodes to dispatch - CMD_DISPATCHER_SEQUENCER_TABLE_SIZE = 25, // !< The size of the table holding commands in progress + CMD_DISPATCHER_DISPATCH_TABLE_SIZE = 100, // !< The size of the table holding opcodes to dispatch + CMD_DISPATCHER_SEQUENCER_TABLE_SIZE = 25, // !< The size of the table holding commands in progress }; - - #endif /* CMDDISPATCHER_COMMANDDISPATCHERIMPLCFG_HPP_ */ diff --git a/default/config/DpCatalogCfg.hpp b/default/config/DpCatalogCfg.hpp index 893b6b9909..43b3d576da 100644 --- a/default/config/DpCatalogCfg.hpp +++ b/default/config/DpCatalogCfg.hpp @@ -9,12 +9,12 @@ #include namespace Svc { - // Sets the maximum number of directories where - // data products can be stored. The array passed - // to the initializer for DpCatalog cannot exceed - // this size. - static const FwIndexType DP_MAX_DIRECTORIES = 2; - static const FwIndexType DP_MAX_FILES = 127; -} +// Sets the maximum number of directories where +// data products can be stored. The array passed +// to the initializer for DpCatalog cannot exceed +// this size. +static const FwIndexType DP_MAX_DIRECTORIES = 2; +static const FwIndexType DP_MAX_FILES = 127; +} // namespace Svc #endif /* SVC_DPCATALOG_CONFIG_HPP_ */ diff --git a/default/config/DpCfg.hpp b/default/config/DpCfg.hpp index 796e2871ea..92d72fb052 100644 --- a/default/config/DpCfg.hpp +++ b/default/config/DpCfg.hpp @@ -18,6 +18,6 @@ // The format string for a file name // The format arguments are base directory, container ID, time seconds, and time microseconds #define DP_EXT ".fdp" -constexpr const char *DP_FILENAME_FORMAT = "%s/Dp_%08" PRI_FwDpIdType "_%08" PRIu32 "_%08" PRIu32 DP_EXT; +constexpr const char* DP_FILENAME_FORMAT = "%s/Dp_%08" PRI_FwDpIdType "_%08" PRIu32 "_%08" PRIu32 DP_EXT; #endif diff --git a/default/config/EventManagerCfg.hpp b/default/config/EventManagerCfg.hpp index 69bb77944d..d877a8bb32 100644 --- a/default/config/EventManagerCfg.hpp +++ b/default/config/EventManagerCfg.hpp @@ -11,17 +11,16 @@ // set default filters enum { - FILTER_WARNING_HI_DEFAULT = true, //!< WARNING HI events are filtered at input - FILTER_WARNING_LO_DEFAULT = true, //!< WARNING LO events are filtered at input - FILTER_COMMAND_DEFAULT = true, //!< COMMAND events are filtered at input - FILTER_ACTIVITY_HI_DEFAULT = true, //!< ACTIVITY HI events are filtered at input - FILTER_ACTIVITY_LO_DEFAULT = true, //!< ACTIVITY LO events are filtered at input - FILTER_DIAGNOSTIC_DEFAULT = false, //!< DIAGNOSTIC events are filtered at input + FILTER_WARNING_HI_DEFAULT = true, //!< WARNING HI events are filtered at input + FILTER_WARNING_LO_DEFAULT = true, //!< WARNING LO events are filtered at input + FILTER_COMMAND_DEFAULT = true, //!< COMMAND events are filtered at input + FILTER_ACTIVITY_HI_DEFAULT = true, //!< ACTIVITY HI events are filtered at input + FILTER_ACTIVITY_LO_DEFAULT = true, //!< ACTIVITY LO events are filtered at input + FILTER_DIAGNOSTIC_DEFAULT = false, //!< DIAGNOSTIC events are filtered at input }; - enum { - TELEM_ID_FILTER_SIZE = 25, //!< Size of telemetry ID filter + TELEM_ID_FILTER_SIZE = 25, //!< Size of telemetry ID filter }; #endif /* Config_EventManagerCfg_HPP_ */ diff --git a/default/config/FPrimeNumericalConfig.h b/default/config/FPrimeNumericalConfig.h index 955b713bec..b192302eef 100644 --- a/default/config/FPrimeNumericalConfig.h +++ b/default/config/FPrimeNumericalConfig.h @@ -22,7 +22,7 @@ #ifndef FPRIME_INTEGER_CONFIG_H #define FPRIME_INTEGER_CONFIG_H -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -31,8 +31,7 @@ extern "C" { #define FW_HAS_16_BIT 1 //!< Architecture supports 16 bit integers #define SKIP_FLOAT_IEEE_754_COMPLIANCE 0 //!< Check IEEE 754 compliance of floating point arithmetic -#ifdef __cplusplus +#ifdef __cplusplus } #endif #endif // FPRIME_INTEGER_CONFIG_H - diff --git a/default/config/FileDownlinkCfg.hpp b/default/config/FileDownlinkCfg.hpp index a6a5fe308d..4945ede8b1 100644 --- a/default/config/FileDownlinkCfg.hpp +++ b/default/config/FileDownlinkCfg.hpp @@ -9,18 +9,20 @@ #include namespace Svc { - // If this is set to true, the run handler will look to - // see if a packet is ready. If it is false, the next packet - // will be sent as soon as the previous is complete. - static const bool FILEDOWNLINK_PACKETS_BY_RUN = false; - // If this is set, errors that would cause FileDownlink to return an error response, such as a - // missing file or attempting to send a partial chunk past the end of the file will instead - // return success. This is recommended to avoid a non-serious FileDownlink error aborting a - // sequence early. These errors will still be logged as events. - static const bool FILEDOWNLINK_COMMAND_FAILURES_DISABLED = true; - // Size of the internal file downlink buffer. This must now be static as - // file down maintains its own internal buffer. - static const U32 FILEDOWNLINK_INTERNAL_BUFFER_SIZE = FW_FILE_BUFFER_MAX_SIZE; -} + +// If this is set to true, the run handler will look to +// see if a packet is ready. If it is false, the next packet +// will be sent as soon as the previous is complete. +static const bool FILEDOWNLINK_PACKETS_BY_RUN = false; +// If this is set, errors that would cause FileDownlink to return an error response, such as a +// missing file or attempting to send a partial chunk past the end of the file will instead +// return success. This is recommended to avoid a non-serious FileDownlink error aborting a +// sequence early. These errors will still be logged as events. +static const bool FILEDOWNLINK_COMMAND_FAILURES_DISABLED = true; +// Size of the internal file downlink buffer. This must now be static as +// file down maintains its own internal buffer. +static const U32 FILEDOWNLINK_INTERNAL_BUFFER_SIZE = FW_FILE_BUFFER_MAX_SIZE; + +} // namespace Svc #endif /* SVC_FILEDOWNLINK_FILEDOWNLINKCFG_HPP_ */ diff --git a/default/config/FileManagerConfig.hpp b/default/config/FileManagerConfig.hpp index 281467f4a3..2d3431a209 100644 --- a/default/config/FileManagerConfig.hpp +++ b/default/config/FileManagerConfig.hpp @@ -4,13 +4,13 @@ #include namespace Svc { - namespace FileManagerConfig { - //! Number of directory entries to process per rate group tick - //! Higher values = faster directory listing but more events per tick - //! Lower values = slower directory listing but bounded event rate - //! Default: 1 - static constexpr U32 FILES_PER_RATE_TICK = 1; - } -} +namespace FileManagerConfig { +//! Number of directory entries to process per rate group tick +//! Higher values = faster directory listing but more events per tick +//! Lower values = slower directory listing but bounded event rate +//! Default: 1 +static constexpr U32 FILES_PER_RATE_TICK = 1; +} // namespace FileManagerConfig +} // namespace Svc #endif diff --git a/default/config/FpConfig.h b/default/config/FpConfig.h index f46193863e..e9075412b5 100644 --- a/default/config/FpConfig.h +++ b/default/config/FpConfig.h @@ -11,12 +11,11 @@ #ifndef FPCONFIG_H_ #define FPCONFIG_H_ -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif -#include #include - +#include // ---------------------------------------------------------------------- // Type aliases @@ -90,8 +89,8 @@ extern "C" { // This generates code to connect to serialized ports #ifndef FW_PORT_SERIALIZATION #define FW_PORT_SERIALIZATION \ - 1 //!< Indicates whether there is code in ports to serialize the call (more code, but ability to serialize calls - //!< for multi-note systems) + 1 //!< Indicates whether there is code in ports to serialize the call (more code, but ability to serialize + //!< calls for multi-note systems) #endif // Component Facilities @@ -333,7 +332,7 @@ extern "C" { // *** NOTE configuration checks are in Fw/Cfg/ConfigCheck.cpp in order to have // the type definitions in Fw/Types/BasicTypes available. -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/default/config/IpCfg.hpp b/default/config/IpCfg.hpp index d7c7fcd827..f7f1515bfc 100644 --- a/default/config/IpCfg.hpp +++ b/default/config/IpCfg.hpp @@ -23,5 +23,4 @@ enum IpCfg { }; static const Fw::TimeInterval SOCKET_RETRY_INTERVAL = Fw::TimeInterval(1, 0); - -#endif //REF_IPCFG_HPP +#endif // REF_IPCFG_HPP diff --git a/default/config/PassiveTextLoggerCfg.hpp b/default/config/PassiveTextLoggerCfg.hpp index c0efd3ea42..7df609cbf1 100644 --- a/default/config/PassiveTextLoggerCfg.hpp +++ b/default/config/PassiveTextLoggerCfg.hpp @@ -2,7 +2,7 @@ #define Config_PassiveTextLoggerCfg_HPP_ enum { - PASSIVE_TEXT_LOGGER_ID_FILTER_SIZE = 25, //!< Size of event ID filter + PASSIVE_TEXT_LOGGER_ID_FILTER_SIZE = 25, //!< Size of event ID filter }; #endif /* Config_PassiveTextLoggerCfg_HPP_ */ diff --git a/default/config/PrmDbImplCfg.hpp b/default/config/PrmDbImplCfg.hpp index 3d149c11c2..b62f267a17 100644 --- a/default/config/PrmDbImplCfg.hpp +++ b/default/config/PrmDbImplCfg.hpp @@ -11,13 +11,12 @@ // Anonymous namespace for configuration parameters namespace { - enum { - PRMDB_NUM_DB_ENTRIES = 25, // !< Number of entries in the parameter database - PRMDB_ENTRY_DELIMITER = 0xA5 // !< Byte value that should precede each parameter in file; sanity check against file integrity. Should match ground system. - }; +enum { + PRMDB_NUM_DB_ENTRIES = 25, // !< Number of entries in the parameter database + PRMDB_ENTRY_DELIMITER = 0xA5 // !< Byte value that should precede each parameter in file; sanity check against + // file integrity. Should match ground system. +}; } - - #endif /* PRMDB_PRMDBLIMPLCFG_HPP_ */ diff --git a/default/config/PrmDbImplTesterCfg.hpp b/default/config/PrmDbImplTesterCfg.hpp index 26e1fd002f..7651726441 100644 --- a/default/config/PrmDbImplTesterCfg.hpp +++ b/default/config/PrmDbImplTesterCfg.hpp @@ -8,10 +8,6 @@ #ifndef PRMDB_TEST_UT_PRMDBIMPLTESTERCFG_HPP_ #define PRMDB_TEST_UT_PRMDBIMPLTESTERCFG_HPP_ -enum { - PRMDB_IMPL_TESTER_MAX_READ_BUFFER = 256 -}; - - +enum { PRMDB_IMPL_TESTER_MAX_READ_BUFFER = 256 }; #endif /* PRMDB_TEST_UT_PRMDBIMPLTESTERCFG_HPP_ */ diff --git a/default/config/StaticMemoryConfig.hpp b/default/config/StaticMemoryConfig.hpp index 23dc514148..11ba3bd097 100644 --- a/default/config/StaticMemoryConfig.hpp +++ b/default/config/StaticMemoryConfig.hpp @@ -8,10 +8,7 @@ #define SVC_STATIC_MEMORY_CFG_HPP_ namespace Svc { - enum StaticMemoryConfig { - STATIC_MEMORY_ALLOCATION_SIZE = 2048 - }; +enum StaticMemoryConfig { STATIC_MEMORY_ALLOCATION_SIZE = 2048 }; } #endif - diff --git a/default/config/TlmChanImplCfg.hpp b/default/config/TlmChanImplCfg.hpp index 986252e8bf..432d1a777b 100644 --- a/default/config/TlmChanImplCfg.hpp +++ b/default/config/TlmChanImplCfg.hpp @@ -15,7 +15,6 @@ // Anonymous namespace for configuration parameters - // The parameters below provide for tuning of the hash function used to // write and read entries in the database. The has function is very simple; // It first takes the telemetry ID and does a modulo computation with @@ -41,16 +40,15 @@ namespace { - enum { - TLMCHAN_NUM_TLM_HASH_SLOTS = 15, // !< Number of slots in the hash table. - // Works best when set to about twice the number of components producing telemetry - TLMCHAN_HASH_MOD_VALUE = 99, // !< The modulo value of the hashing function. - // Should be set to a little below the ID gaps to spread the entries around - - TLMCHAN_HASH_BUCKETS = 500 // !< Buckets assignable to a hash slot. - // Buckets must be >= number of telemetry channels in system - }; +enum { + TLMCHAN_NUM_TLM_HASH_SLOTS = 15, // !< Number of slots in the hash table. + // Works best when set to about twice the number of components producing telemetry + TLMCHAN_HASH_MOD_VALUE = 99, // !< The modulo value of the hashing function. + // Should be set to a little below the ID gaps to spread the entries around + TLMCHAN_HASH_BUCKETS = 500 // !< Buckets assignable to a hash slot. + // Buckets must be >= number of telemetry channels in system +}; } diff --git a/default/config/TlmPacketizerCfg.hpp b/default/config/TlmPacketizerCfg.hpp index 2aa7ddc621..8a515edcc8 100644 --- a/default/config/TlmPacketizerCfg.hpp +++ b/default/config/TlmPacketizerCfg.hpp @@ -17,18 +17,17 @@ namespace Svc { static const FwChanIdType MAX_PACKETIZER_PACKETS = 200; -static const FwChanIdType TLMPACKETIZER_NUM_TLM_HASH_SLOTS = - 15; // !< Number of slots in the hash table. - // Works best when set to about twice the number of components producing telemetry -static const FwChanIdType TLMPACKETIZER_HASH_MOD_VALUE = - 99; // !< The modulo value of the hashing function. - // Should be set to a little below the ID gaps to spread the entries around -static const FwChanIdType TLMPACKETIZER_HASH_BUCKETS = - 1000; // !< Buckets assignable to a hash slot. - // Buckets must be >= number of telemetry channels in system -static const FwChanIdType TLMPACKETIZER_MAX_MISSING_TLM_CHECK = - 25; // !< Maximum number of missing telemetry channel checks +// Works best when set to about twice the number of components producing telemetry +static const FwChanIdType TLMPACKETIZER_NUM_TLM_HASH_SLOTS = 15; // !< Number of slots in the hash table. + +// Should be set to a little below the ID gaps to spread the entries around +static const FwChanIdType TLMPACKETIZER_HASH_MOD_VALUE = 99; // !< The modulo value of the hashing function. + +// Buckets must be >= number of telemetry channels in system +static const FwChanIdType TLMPACKETIZER_HASH_BUCKETS = 1000; // !< Buckets assignable to a hash slot. + +static const FwChanIdType TLMPACKETIZER_MAX_MISSING_TLM_CHECK = 25; // !< Max number of missing channel checks // packet update mode enum PacketUpdateMode {