From ea3b4e756596c583fd7e41200d502c2e3f8c7229 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 4 Aug 2025 10:13:01 -0700 Subject: [PATCH 1/3] Format Fw and add to CI --- .github/workflows/format-check.yml | 4 +- Fw/Comp/ActiveComponentBase.cpp | 201 +++--- Fw/Comp/ActiveComponentBase.hpp | 37 +- Fw/Comp/PassiveComponentBase.cpp | 68 +- Fw/Comp/PassiveComponentBase.hpp | 48 +- Fw/Comp/QueuedComponentBase.cpp | 49 +- Fw/Comp/QueuedComponentBase.hpp | 50 +- Fw/Deprecate.hpp | 8 +- Fw/Dp/DpContainer.cpp | 2 +- Fw/Dp/DpContainer.hpp | 7 +- Fw/Dp/test/ut/DpContainerTester.hpp | 61 +- Fw/Dp/test/ut/TestMain.cpp | 11 +- Fw/Dp/test/util/DpContainerHeader.hpp | 10 +- Fw/FPrimeBasicTypes.h | 19 +- Fw/FPrimeBasicTypes.hpp | 59 +- Fw/FilePacket/CancelPacket.cpp | 37 +- Fw/FilePacket/DataPacket.cpp | 85 +-- Fw/FilePacket/EndPacket.cpp | 66 +- Fw/FilePacket/FilePacket.cpp | 185 +++--- Fw/FilePacket/FilePacket.hpp | 625 ++++++++---------- Fw/FilePacket/GTest/CancelPacket.cpp | 18 +- Fw/FilePacket/GTest/DataPacket.cpp | 25 +- Fw/FilePacket/GTest/EndPacket.cpp | 29 +- Fw/FilePacket/GTest/FilePackets.hpp | 86 +-- Fw/FilePacket/GTest/Header.cpp | 19 +- Fw/FilePacket/GTest/PathName.cpp | 29 +- Fw/FilePacket/GTest/StartPacket.cpp | 24 +- Fw/FilePacket/Header.cpp | 39 +- Fw/FilePacket/PathName.cpp | 77 +-- Fw/FilePacket/StartPacket.cpp | 121 ++-- Fw/FilePacket/test/ut/FilePacketMain.cpp | 208 +++--- Fw/Fpy/StatementArgBuffer.cpp | 93 ++- Fw/Fpy/StatementArgBuffer.hpp | 51 +- Fw/Log/AmpcsEvrLogPacket.cpp | 190 +++--- Fw/Log/AmpcsEvrLogPacket.hpp | 61 +- Fw/Log/LogBuffer.cpp | 53 +- Fw/Log/LogBuffer.hpp | 36 +- Fw/Log/LogPacket.cpp | 133 ++-- Fw/Log/LogPacket.hpp | 49 +- Fw/Log/test/ut/LogTest.cpp | 25 +- Fw/Logger/Logger.hpp | 2 +- Fw/Logger/test/ut/FakeLogger.cpp | 2 +- Fw/Logger/test/ut/FakeLogger.hpp | 4 +- Fw/Logger/test/ut/LoggerRules.hpp | 2 +- Fw/Obj/ObjBase.cpp | 72 +- Fw/Obj/ObjBase.hpp | 198 +++--- Fw/Obj/SimpleObjRegistry.cpp | 82 ++- Fw/Obj/SimpleObjRegistry.hpp | 30 +- Fw/Port/InputPortBase.cpp | 35 +- Fw/Port/InputPortBase.hpp | 44 +- Fw/Port/InputSerializePort.cpp | 53 +- Fw/Port/InputSerializePort.hpp | 40 +- Fw/Port/OutputPortBase.cpp | 51 +- Fw/Port/OutputPortBase.hpp | 41 +- Fw/Port/OutputSerializePort.cpp | 25 +- Fw/Port/OutputSerializePort.hpp | 29 +- Fw/Port/PortBase.cpp | 131 ++-- Fw/Port/PortBase.hpp | 55 +- Fw/Prm/PrmBuffer.cpp | 53 +- Fw/Prm/PrmBuffer.hpp | 44 +- Fw/Prm/PrmExternalTypes.hpp | 63 +- Fw/SerializableFile/SerializableFile.cpp | 60 +- Fw/SerializableFile/SerializableFile.hpp | 27 +- Fw/SerializableFile/test/ut/Test.cpp | 101 ++- Fw/Sm/SmSignalBuffer.cpp | 69 +- Fw/Sm/SmSignalBuffer.hpp | 41 +- Fw/Test/String.hpp | 2 +- Fw/Test/UnitTest.hpp | 15 +- Fw/Test/UnitTestAssert.cpp | 133 ++-- Fw/Test/UnitTestAssert.hpp | 99 ++- Fw/Time/Time.cpp | 368 +++++------ Fw/Time/Time.hpp | 141 ++-- Fw/Time/TimeInterval.cpp | 260 ++++---- Fw/Time/TimeInterval.hpp | 117 ++-- Fw/Time/test/ut/TimeIntervalTester.cpp | 244 ++++--- Fw/Time/test/ut/TimeIntervalTester.hpp | 38 +- Fw/Time/test/ut/TimeTestMain.cpp | 4 +- Fw/Time/test/ut/TimeTester.cpp | 300 ++++----- Fw/Time/test/ut/TimeTester.hpp | 36 +- Fw/Tlm/TlmBuffer.cpp | 53 +- Fw/Tlm/TlmBuffer.hpp | 36 +- Fw/Tlm/TlmPacket.cpp | 257 ++++--- Fw/Tlm/TlmPacket.hpp | 77 +-- Fw/Tlm/test/ut/TlmTest.cpp | 69 +- Fw/Trap/TrapHandler.hpp | 36 +- Fw/Types/Assert.cpp | 89 ++- Fw/Types/Assert.hpp | 53 +- Fw/Types/BasicTypes.h | 22 +- Fw/Types/CAssert.h | 11 +- Fw/Types/PolyType.cpp | 4 +- Fw/Types/PolyType.hpp | 32 +- Fw/Types/SerIds.hpp | 68 +- Fw/Types/SerialBuffer.cpp | 2 +- Fw/Types/SerialBuffer.hpp | 10 +- Fw/Types/Serializable.cpp | 144 ++-- Fw/Types/Serializable.hpp | 34 +- Fw/Types/StringBase.hpp | 4 +- Fw/Types/StringTemplate.hpp | 3 +- Fw/Types/StringToNumber.cpp | 81 ++- Fw/Types/StringUtils.cpp | 2 +- Fw/Types/StringUtils.hpp | 35 +- Fw/Types/format.hpp | 16 +- Fw/Types/snprintf_format.cpp | 9 +- Fw/Types/test/ut/AssertTypesTest.cpp | 81 ++- Fw/Types/test/ut/CAssertTest.cpp | 172 +++-- .../test/ut/ExternalSerializeBufferTest.cpp | 56 +- .../test/ut/SerializeBufferBaseTester.hpp | 7 +- Fw/Types/test/ut/SnPrintfFormatTest.cpp | 2 +- Fw/Types/test/ut/TypesTest.cpp | 48 +- 109 files changed, 3599 insertions(+), 4023 deletions(-) diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml index a0dbb1ed6e7..f75f7ea8a9a 100644 --- a/.github/workflows/format-check.yml +++ b/.github/workflows/format-check.yml @@ -31,9 +31,7 @@ jobs: env: CHECKED_DIRS: >- Drv - Fw/Buffer - Fw/Cmd - Fw/Com + Fw Os Svc/Ccsds Svc/EventManager diff --git a/Fw/Comp/ActiveComponentBase.cpp b/Fw/Comp/ActiveComponentBase.cpp index 0f37dcf9cd5..67759c713b5 100644 --- a/Fw/Comp/ActiveComponentBase.cpp +++ b/Fw/Comp/ActiveComponentBase.cpp @@ -1,138 +1,127 @@ -#include #include +#include #include #include namespace Fw { - class ActiveComponentExitSerializableBuffer : public Fw::SerializeBufferBase { - - public: - FwSizeType getBuffCapacity() const { - return sizeof(m_buff); - } - - U8* getBuffAddr() { - return m_buff; - } +class ActiveComponentExitSerializableBuffer : public Fw::SerializeBufferBase { + public: + FwSizeType getBuffCapacity() const { return sizeof(m_buff); } - const U8* getBuffAddr() const { - return m_buff; - } + U8* getBuffAddr() { return m_buff; } - private: + const U8* getBuffAddr() const { return m_buff; } - U8 m_buff[sizeof(ActiveComponentBase::ACTIVE_COMPONENT_EXIT)]; + private: + U8 m_buff[sizeof(ActiveComponentBase::ACTIVE_COMPONENT_EXIT)]; +}; - }; +ActiveComponentBase::ActiveComponentBase(const char* name) : QueuedComponentBase(name) {} - ActiveComponentBase::ActiveComponentBase(const char* name) : QueuedComponentBase(name) { +ActiveComponentBase::~ActiveComponentBase() {} - } - - ActiveComponentBase::~ActiveComponentBase() { - } - - void ActiveComponentBase::init(FwEnumStoreType instance) { - QueuedComponentBase::init(instance); - } +void ActiveComponentBase::init(FwEnumStoreType instance) { + QueuedComponentBase::init(instance); +} #if FW_OBJECT_TO_STRING == 1 - const char* ActiveComponentBase::getToStringFormatString() { - return "ActComp: %s"; - } +const char* ActiveComponentBase::getToStringFormatString() { + return "ActComp: %s"; +} #endif - void ActiveComponentBase::start(FwTaskPriorityType priority, FwSizeType stackSize, FwSizeType cpuAffinity, FwTaskIdType identifier) { - Os::TaskString taskName; +void ActiveComponentBase::start(FwTaskPriorityType priority, + FwSizeType stackSize, + FwSizeType cpuAffinity, + FwTaskIdType identifier) { + Os::TaskString taskName; #if FW_OBJECT_NAMES == 1 - taskName = this->getObjName(); + taskName = this->getObjName(); #else - (void) taskName.format("ActComp_%" PRI_FwSizeType, Os::Task::getNumTasks()); + (void)taskName.format("ActComp_%" PRI_FwSizeType, Os::Task::getNumTasks()); #endif - // Cooperative threads tasks externalize the task loop, and as such use the state machine as their task function - // Standard multithreading tasks use the task loop to respectively call the state machine - Os::Task::taskRoutine routine = (m_task.isCooperative()) ? this->s_taskStateMachine : this->s_taskLoop; - Os::Task::Arguments arguments(taskName, routine, this, priority, stackSize, cpuAffinity, identifier); - Os::Task::Status status = this->m_task.start(arguments); - FW_ASSERT(status == Os::Task::Status::OP_OK,static_cast(status)); - } + // Cooperative threads tasks externalize the task loop, and as such use the state machine as their task function + // Standard multithreading tasks use the task loop to respectively call the state machine + Os::Task::taskRoutine routine = (m_task.isCooperative()) ? this->s_taskStateMachine : this->s_taskLoop; + Os::Task::Arguments arguments(taskName, routine, this, priority, stackSize, cpuAffinity, identifier); + Os::Task::Status status = this->m_task.start(arguments); + FW_ASSERT(status == Os::Task::Status::OP_OK, static_cast(status)); +} - void ActiveComponentBase::exit() { - ActiveComponentExitSerializableBuffer exitBuff; - SerializeStatus stat = exitBuff.serialize(static_cast(ACTIVE_COMPONENT_EXIT)); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); - (void)this->m_queue.send(exitBuff,0,Os::Queue::BlockingType::NONBLOCKING); - } +void ActiveComponentBase::exit() { + ActiveComponentExitSerializableBuffer exitBuff; + SerializeStatus stat = exitBuff.serialize(static_cast(ACTIVE_COMPONENT_EXIT)); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); + (void)this->m_queue.send(exitBuff, 0, Os::Queue::BlockingType::NONBLOCKING); +} - Os::Task::Status ActiveComponentBase::join() { - return this->m_task.join(); - } +Os::Task::Status ActiveComponentBase::join() { + return this->m_task.join(); +} - Os::Task::Status ActiveComponentBase::join(void** pointer) { - return this->m_task.join(); - } +Os::Task::Status ActiveComponentBase::join(void** pointer) { + return this->m_task.join(); +} - void ActiveComponentBase::s_taskStateMachine(void* component_pointer) { - FW_ASSERT(component_pointer != nullptr); - // cast void* back to active component - ActiveComponentBase* component = static_cast(component_pointer); - - // Each invocation of this function runs a single stage of the thread lifecycle. This has moved the thread - // while loop to the top level such that it can be replaced by something else (e.g. cooperative thread - // dispatcher) and is not intrinsic to this code. - switch (component->m_stage) { - // The first stage the active component triggers the "preamble" call before moving into the dispatching - // stage of the component thread. - case Lifecycle::CREATED: - component->preamble(); - component->m_stage = Lifecycle::DISPATCHING; - break; - // The second stage of the active component triggers the dispatching loop dispatching messages until an - // exit message is received. - case Lifecycle::DISPATCHING: - if (component->dispatch() == MsgDispatchStatus::MSG_DISPATCH_EXIT) { - component->m_stage = Lifecycle::FINALIZING; - } - break; - // The second-to-last stage is where the finalizer is called. This will transition to the final stage - // automatically after the finalizer is called - case Lifecycle::FINALIZING: - component->finalizer(); - component->m_stage = Lifecycle::DONE; - break; - // The last stage does nothing, cooperative tasks live here forever, threaded tasks exit on this condition - case Lifecycle::DONE: - break; - default: - FW_ASSERT(0); - break; - } +void ActiveComponentBase::s_taskStateMachine(void* component_pointer) { + FW_ASSERT(component_pointer != nullptr); + // cast void* back to active component + ActiveComponentBase* component = static_cast(component_pointer); + + // Each invocation of this function runs a single stage of the thread lifecycle. This has moved the thread + // while loop to the top level such that it can be replaced by something else (e.g. cooperative thread + // dispatcher) and is not intrinsic to this code. + switch (component->m_stage) { + // The first stage the active component triggers the "preamble" call before moving into the dispatching + // stage of the component thread. + case Lifecycle::CREATED: + component->preamble(); + component->m_stage = Lifecycle::DISPATCHING; + break; + // The second stage of the active component triggers the dispatching loop dispatching messages until an + // exit message is received. + case Lifecycle::DISPATCHING: + if (component->dispatch() == MsgDispatchStatus::MSG_DISPATCH_EXIT) { + component->m_stage = Lifecycle::FINALIZING; + } + break; + // The second-to-last stage is where the finalizer is called. This will transition to the final stage + // automatically after the finalizer is called + case Lifecycle::FINALIZING: + component->finalizer(); + component->m_stage = Lifecycle::DONE; + break; + // The last stage does nothing, cooperative tasks live here forever, threaded tasks exit on this condition + case Lifecycle::DONE: + break; + default: + FW_ASSERT(0); + break; } +} - void ActiveComponentBase::s_taskLoop(void* component_pointer) { - FW_ASSERT(component_pointer != nullptr); - ActiveComponentBase* component = static_cast(component_pointer); - // A non-cooperative task switching implementation is just a while-loop around the active component - // state-machine. Here the while loop is at top-level. - while (component->m_stage != ActiveComponentBase::Lifecycle::DONE) { - ActiveComponentBase::s_taskStateMachine(component); - } +void ActiveComponentBase::s_taskLoop(void* component_pointer) { + FW_ASSERT(component_pointer != nullptr); + ActiveComponentBase* component = static_cast(component_pointer); + // A non-cooperative task switching implementation is just a while-loop around the active component + // state-machine. Here the while loop is at top-level. + while (component->m_stage != ActiveComponentBase::Lifecycle::DONE) { + ActiveComponentBase::s_taskStateMachine(component); } +} - ActiveComponentBase::MsgDispatchStatus ActiveComponentBase::dispatch() { - // Cooperative tasks should return rather than block when no messages are available - if (this->m_task.isCooperative() and m_queue.getMessagesAvailable() == 0) { - return MsgDispatchStatus::MSG_DISPATCH_EMPTY; - } - return this->doDispatch(); +ActiveComponentBase::MsgDispatchStatus ActiveComponentBase::dispatch() { + // Cooperative tasks should return rather than block when no messages are available + if (this->m_task.isCooperative() and m_queue.getMessagesAvailable() == 0) { + return MsgDispatchStatus::MSG_DISPATCH_EMPTY; } + return this->doDispatch(); +} - void ActiveComponentBase::preamble() { - } +void ActiveComponentBase::preamble() {} - void ActiveComponentBase::finalizer() { - } +void ActiveComponentBase::finalizer() {} -} +} // namespace Fw diff --git a/Fw/Comp/ActiveComponentBase.hpp b/Fw/Comp/ActiveComponentBase.hpp index 847dc24a339..08f8eddae2b 100644 --- a/Fw/Comp/ActiveComponentBase.hpp +++ b/Fw/Comp/ActiveComponentBase.hpp @@ -11,9 +11,9 @@ #ifndef FW_ACTIVE_COMPONENT_BASE_HPP #define FW_ACTIVE_COMPONENT_BASE_HPP -#include #include #include +#include #include namespace Fw { @@ -22,11 +22,12 @@ class ActiveComponentBase : public QueuedComponentBase { void start(FwTaskPriorityType priority = Os::Task::TASK_PRIORITY_DEFAULT, FwSizeType stackSize = Os::Task::TASK_DEFAULT, FwSizeType cpuAffinity = Os::Task::TASK_DEFAULT, - FwTaskIdType identifier = - static_cast(Os::Task::TASK_DEFAULT)); //!< called by instantiator when task is to be started - void exit(); //!< exit task in active component - Os::Task::Status join(); //!< Join the thread - DEPRECATED(Os::Task::Status join(void** value_ptr), "Switch to .join()"); //!< Join to thread with discarded value_ptr + FwTaskIdType identifier = static_cast( + Os::Task::TASK_DEFAULT)); //!< called by instantiator when task is to be started + void exit(); //!< exit task in active component + Os::Task::Status join(); //!< Join the thread + DEPRECATED(Os::Task::Status join(void** value_ptr), + "Switch to .join()"); //!< Join to thread with discarded value_ptr enum { ACTIVE_COMPONENT_EXIT //!< message to exit active component task @@ -35,27 +36,27 @@ class ActiveComponentBase : public QueuedComponentBase { protected: //! Tracks the lifecycle of the component enum Lifecycle { - CREATED, //!< Initial stage, call preamble - DISPATCHING, //!< Component is dispatching messages - FINALIZING, //!< Penultimate stage, call finalizer - DONE, //!< Done, doing nothing + CREATED, //!< Initial stage, call preamble + DISPATCHING, //!< Component is dispatching messages + FINALIZING, //!< Penultimate stage, call finalizer + DONE, //!< Done, doing nothing }; explicit ActiveComponentBase(const char* name); //!< Constructor virtual ~ActiveComponentBase(); //!< Destructor void init(FwEnumStoreType instance); //!< initialization code - virtual void preamble(); //!< A function that will be called before the event loop is entered - MsgDispatchStatus dispatch(); //!< The function that will dispatching messages - virtual void finalizer(); //!< A function that will be called after exiting the loop - Os::Task m_task; //!< task object for active component + virtual void preamble(); //!< A function that will be called before the event loop is entered + MsgDispatchStatus dispatch(); //!< The function that will dispatching messages + virtual void finalizer(); //!< A function that will be called after exiting the loop + Os::Task m_task; //!< task object for active component #if FW_OBJECT_TO_STRING == 1 - virtual const char* getToStringFormatString(); //!< Format string for toString function + virtual const char* getToStringFormatString(); //!< Format string for toString function #endif private: - Lifecycle m_stage; //!< Lifecycle stage of the component - static void s_taskStateMachine(void*); //!< Task lifecycle state machine - static void s_taskLoop(void*); //!< Standard multi-threading task loop + Lifecycle m_stage; //!< Lifecycle stage of the component + static void s_taskStateMachine(void*); //!< Task lifecycle state machine + static void s_taskLoop(void*); //!< Standard multi-threading task loop }; } // namespace Fw diff --git a/Fw/Comp/PassiveComponentBase.cpp b/Fw/Comp/PassiveComponentBase.cpp index 389bf2ce462..016b0b829e7 100644 --- a/Fw/Comp/PassiveComponentBase.cpp +++ b/Fw/Comp/PassiveComponentBase.cpp @@ -1,58 +1,52 @@ #include -#include #include +#include #include namespace Fw { - PassiveComponentBase::PassiveComponentBase(const char* name) : Fw::ObjBase(name), m_idBase(0), m_instance(0) { - } +PassiveComponentBase::PassiveComponentBase(const char* name) : Fw::ObjBase(name), m_idBase(0), m_instance(0) {} #if FW_OBJECT_TO_STRING == 1 - const char* PassiveComponentBase::getToStringFormatString() { - return "Comp: %s"; - } +const char* PassiveComponentBase::getToStringFormatString() { + return "Comp: %s"; +} - void PassiveComponentBase::toString(char* buffer, FwSizeType size) { - FW_ASSERT(size > 0); - FW_ASSERT(buffer != nullptr); - Fw::FormatStatus status = Fw::ExternalString(buffer, static_cast(size)).format( - this->getToStringFormatString(), +void PassiveComponentBase::toString(char* buffer, FwSizeType size) { + FW_ASSERT(size > 0); + FW_ASSERT(buffer != nullptr); + Fw::FormatStatus status = Fw::ExternalString(buffer, static_cast(size)) + .format(this->getToStringFormatString(), #if FW_OBJECT_NAMES == 1 - this->m_objName.toChar() + this->m_objName.toChar() #else - "UNKNOWN" + "UNKNOWN" #endif - ); - if (status != Fw::FormatStatus::SUCCESS) { - buffer[0] = 0; - } + ); + if (status != Fw::FormatStatus::SUCCESS) { + buffer[0] = 0; } +} #endif - PassiveComponentBase::~PassiveComponentBase() { - } - - void PassiveComponentBase::init(FwEnumStoreType instance) { - ObjBase::init(); - this->m_instance = instance; - } +PassiveComponentBase::~PassiveComponentBase() {} - FwEnumStoreType PassiveComponentBase::getInstance() const { - return this->m_instance; - } +void PassiveComponentBase::init(FwEnumStoreType instance) { + ObjBase::init(); + this->m_instance = instance; +} - void PassiveComponentBase :: - setIdBase(const FwIdType idBase) - { - this->m_idBase = idBase; - } +FwEnumStoreType PassiveComponentBase::getInstance() const { + return this->m_instance; +} - FwIdType PassiveComponentBase :: - getIdBase() const - { - return this->m_idBase; - } +void PassiveComponentBase ::setIdBase(const FwIdType idBase) { + this->m_idBase = idBase; +} +FwIdType PassiveComponentBase ::getIdBase() const { + return this->m_idBase; } + +} // namespace Fw diff --git a/Fw/Comp/PassiveComponentBase.hpp b/Fw/Comp/PassiveComponentBase.hpp index 7074c4aa570..2f387d8a430 100644 --- a/Fw/Comp/PassiveComponentBase.hpp +++ b/Fw/Comp/PassiveComponentBase.hpp @@ -1,40 +1,36 @@ #ifndef FW_COMP_BASE_HPP #define FW_COMP_BASE_HPP +#include #include #include -#include namespace Fw { - class PassiveComponentBase : public Fw::ObjBase { - public: - //! Set the ID base - void setIdBase( - const FwIdType //< The new ID base - ); - //! Get the ID base - //! \return The ID base - FwIdType getIdBase() const; - - protected: - PassiveComponentBase(const char* name); //!< Named constructor - virtual ~PassiveComponentBase(); //!< Destructor - void init(FwEnumStoreType instance); //!< Initialization function - FwEnumStoreType getInstance() const; - +class PassiveComponentBase : public Fw::ObjBase { + public: + //! Set the ID base + void setIdBase(const FwIdType //< The new ID base + ); + //! Get the ID base + //! \return The ID base + FwIdType getIdBase() const; + + protected: + PassiveComponentBase(const char* name); //!< Named constructor + virtual ~PassiveComponentBase(); //!< Destructor + void init(FwEnumStoreType instance); //!< Initialization function + FwEnumStoreType getInstance() const; #if FW_OBJECT_TO_STRING == 1 - virtual const char* getToStringFormatString(); //!< Return the format for a generic component toString - void toString(char* str, FwSizeType size) override; //!< returns string description of component + virtual const char* getToStringFormatString(); //!< Return the format for a generic component toString + void toString(char* str, FwSizeType size) override; //!< returns string description of component #endif - private: - FwIdType m_idBase; //!< ID base for opcodes etc. - FwEnumStoreType m_instance; //!< instance of component object - - - }; + private: + FwIdType m_idBase; //!< ID base for opcodes etc. + FwEnumStoreType m_instance; //!< instance of component object +}; -} +} // namespace Fw #endif diff --git a/Fw/Comp/QueuedComponentBase.cpp b/Fw/Comp/QueuedComponentBase.cpp index bf241e4df4c..70e7ccff129 100644 --- a/Fw/Comp/QueuedComponentBase.cpp +++ b/Fw/Comp/QueuedComponentBase.cpp @@ -1,47 +1,42 @@ #include -#include #include +#include #include #include namespace Fw { - QueuedComponentBase::QueuedComponentBase(const char* name) : PassiveComponentBase(name),m_msgsDropped(0) { - - } +QueuedComponentBase::QueuedComponentBase(const char* name) : PassiveComponentBase(name), m_msgsDropped(0) {} - QueuedComponentBase::~QueuedComponentBase() { +QueuedComponentBase::~QueuedComponentBase() {} - } - - void QueuedComponentBase::init(FwEnumStoreType instance) { - PassiveComponentBase::init(instance); - } +void QueuedComponentBase::init(FwEnumStoreType instance) { + PassiveComponentBase::init(instance); +} #if FW_OBJECT_TO_STRING == 1 - const char* QueuedComponentBase::getToStringFormatString() { - return "QueueComp: %s"; - } +const char* QueuedComponentBase::getToStringFormatString() { + return "QueueComp: %s"; +} #endif - Os::Queue::Queue::Status QueuedComponentBase::createQueue(FwSizeType depth, FwSizeType msgSize) { - - Os::QueueString queueName; +Os::Queue::Queue::Status QueuedComponentBase::createQueue(FwSizeType depth, FwSizeType msgSize) { + Os::QueueString queueName; #if FW_OBJECT_NAMES == 1 - queueName = this->m_objName; + queueName = this->m_objName; #else - queueName.format("CompQ_%" PRI_FwSizeType,Os::Queue::getNumQueues()); + queueName.format("CompQ_%" PRI_FwSizeType, Os::Queue::getNumQueues()); #endif - return this->m_queue.create(queueName, depth, msgSize); - } - - FwSizeType QueuedComponentBase::getNumMsgsDropped() { - return this->m_msgsDropped; - } + return this->m_queue.create(queueName, depth, msgSize); +} - void QueuedComponentBase::incNumMsgDropped() { - this->m_msgsDropped++; - } +FwSizeType QueuedComponentBase::getNumMsgsDropped() { + return this->m_msgsDropped; +} +void QueuedComponentBase::incNumMsgDropped() { + this->m_msgsDropped++; } + +} // namespace Fw diff --git a/Fw/Comp/QueuedComponentBase.hpp b/Fw/Comp/QueuedComponentBase.hpp index ea1d436fb5a..a83edab995e 100644 --- a/Fw/Comp/QueuedComponentBase.hpp +++ b/Fw/Comp/QueuedComponentBase.hpp @@ -12,38 +12,36 @@ #define FW_QUEUED_COMPONENT_BASE_HPP #include +#include #include #include -#include - namespace Fw { - class QueuedComponentBase : public PassiveComponentBase { - public: - - // Note: Had to make MsgDispatchStatus public for LLVM. - typedef enum { - MSG_DISPATCH_OK, //!< Dispatch was normal - MSG_DISPATCH_EMPTY, //!< No more messages in the queue - MSG_DISPATCH_ERROR, //!< Errors dispatching messages - MSG_DISPATCH_EXIT //!< A message was sent requesting an exit of the loop - } MsgDispatchStatus; +class QueuedComponentBase : public PassiveComponentBase { + public: + // Note: Had to make MsgDispatchStatus public for LLVM. + typedef enum { + MSG_DISPATCH_OK, //!< Dispatch was normal + MSG_DISPATCH_EMPTY, //!< No more messages in the queue + MSG_DISPATCH_ERROR, //!< Errors dispatching messages + MSG_DISPATCH_EXIT //!< A message was sent requesting an exit of the loop + } MsgDispatchStatus; - protected: - QueuedComponentBase(const char* name); //!< Constructor - virtual ~QueuedComponentBase(); //!< Destructor - void init(FwEnumStoreType instance); //!< initialization function - Os::Queue m_queue; //!< queue object for active component - Os::Queue::Status createQueue(FwSizeType depth, FwSizeType msgSize); - virtual MsgDispatchStatus doDispatch()=0; //!< method to dispatch a single message in the queue. + protected: + QueuedComponentBase(const char* name); //!< Constructor + virtual ~QueuedComponentBase(); //!< Destructor + void init(FwEnumStoreType instance); //!< initialization function + Os::Queue m_queue; //!< queue object for active component + Os::Queue::Status createQueue(FwSizeType depth, FwSizeType msgSize); + virtual MsgDispatchStatus doDispatch() = 0; //!< method to dispatch a single message in the queue. #if FW_OBJECT_TO_STRING == 1 - virtual const char* getToStringFormatString(); //!< Format string for toString function + virtual const char* getToStringFormatString(); //!< Format string for toString function #endif - FwSizeType getNumMsgsDropped(); //!< return number of messages dropped - void incNumMsgDropped(); //!< increment the number of messages dropped - private: - FwSizeType m_msgsDropped; //!< number of messages dropped from full queue - }; + FwSizeType getNumMsgsDropped(); //!< return number of messages dropped + void incNumMsgDropped(); //!< increment the number of messages dropped + private: + FwSizeType m_msgsDropped; //!< number of messages dropped from full queue +}; -} +} // namespace Fw #endif diff --git a/Fw/Deprecate.hpp b/Fw/Deprecate.hpp index 11249129655..823ed9f68df 100644 --- a/Fw/Deprecate.hpp +++ b/Fw/Deprecate.hpp @@ -8,12 +8,12 @@ #ifndef DEPRECATED #ifdef __GNUC__ - #define DEPRECATED(func, message) func __attribute__ ((deprecated(message))) +#define DEPRECATED(func, message) func __attribute__((deprecated(message))) #else - #warning "No implementation of DEPRECATED for given compiler. Please check for use of DEPRECATED() functions" - #define DEPRECATED(func) func +#warning "No implementation of DEPRECATED for given compiler. Please check for use of DEPRECATED() functions" +#define DEPRECATED(func) func #endif #endif -#endif // FW_DEPRECATE_HPP +#endif // FW_DEPRECATE_HPP diff --git a/Fw/Dp/DpContainer.cpp b/Fw/Dp/DpContainer.cpp index d84fe7a1d60..8da9f5eef54 100644 --- a/Fw/Dp/DpContainer.cpp +++ b/Fw/Dp/DpContainer.cpp @@ -107,7 +107,7 @@ void DpContainer::serializeHeader() { FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); // Serialize the user data status = serializer.serialize(this->m_userData, static_cast(sizeof this->m_userData), - Fw::Serialization::OMIT_LENGTH); + Fw::Serialization::OMIT_LENGTH); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); // Serialize the data product state status = serializer.serialize(this->m_dpState); diff --git a/Fw/Dp/DpContainer.hpp b/Fw/Dp/DpContainer.hpp index eeefdc93afb..8503f6ae020 100644 --- a/Fw/Dp/DpContainer.hpp +++ b/Fw/Dp/DpContainer.hpp @@ -16,14 +16,15 @@ #include "config/ProcTypeEnumAc.hpp" // Forward declare for UTs -namespace Fw { class DpContainerTester; } +namespace Fw { +class DpContainerTester; +} namespace Fw { //! A data product Container class DpContainer { - - friend class Fw::DpContainerTester; + friend class Fw::DpContainerTester; public: // ---------------------------------------------------------------------- diff --git a/Fw/Dp/test/ut/DpContainerTester.hpp b/Fw/Dp/test/ut/DpContainerTester.hpp index 0b97d511c78..29b611e3c1d 100644 --- a/Fw/Dp/test/ut/DpContainerTester.hpp +++ b/Fw/Dp/test/ut/DpContainerTester.hpp @@ -11,37 +11,34 @@ namespace Fw { - class DpContainerTester { - - public: - - static bool verifyBufferSize(const Fw::DpContainer& container, FwSizeType expectedSize) { - return container.m_buffer.getSize() == expectedSize; - } - - static U8* getBufferPointers(const Fw::DpContainer& container) { - U8* const buffPtr = container.m_buffer.getData(); - return buffPtr; - } - - static bool verifyDataBufferAddress(const Fw::DpContainer& container, const U8* expectedAddr) { - return container.m_dataBuffer.getBuffAddr() == expectedAddr; - } - - static bool verifyDataBufferCapacity(const Fw::DpContainer& container, FwSizeType expectedCapacity) { - return container.m_dataBuffer.getBuffCapacity() == expectedCapacity; - } - - static bool isDataBufferEmpty(const Fw::DpContainer& container) { - const Fw::SerializeBufferBase& buffer = container.m_dataBuffer; - const FwSizeType buffLength = buffer.getBuffLength(); - const FwSizeType buffLeft = buffer.getBuffLeft(); - - return buffLength == 0 && buffLeft == 0; - } - - }; - -} +class DpContainerTester { + public: + static bool verifyBufferSize(const Fw::DpContainer& container, FwSizeType expectedSize) { + return container.m_buffer.getSize() == expectedSize; + } + + static U8* getBufferPointers(const Fw::DpContainer& container) { + U8* const buffPtr = container.m_buffer.getData(); + return buffPtr; + } + + static bool verifyDataBufferAddress(const Fw::DpContainer& container, const U8* expectedAddr) { + return container.m_dataBuffer.getBuffAddr() == expectedAddr; + } + + static bool verifyDataBufferCapacity(const Fw::DpContainer& container, FwSizeType expectedCapacity) { + return container.m_dataBuffer.getBuffCapacity() == expectedCapacity; + } + + static bool isDataBufferEmpty(const Fw::DpContainer& container) { + const Fw::SerializeBufferBase& buffer = container.m_dataBuffer; + const FwSizeType buffLength = buffer.getBuffLength(); + const FwSizeType buffLeft = buffer.getBuffLeft(); + + return buffLength == 0 && buffLeft == 0; + } +}; + +} // namespace Fw #endif diff --git a/Fw/Dp/test/ut/TestMain.cpp b/Fw/Dp/test/ut/TestMain.cpp index b55dc0c1f18..71b8f198ed3 100644 --- a/Fw/Dp/test/ut/TestMain.cpp +++ b/Fw/Dp/test/ut/TestMain.cpp @@ -8,11 +8,11 @@ #include "gtest/gtest.h" #include "Fw/Dp/DpContainer.hpp" +#include "Fw/Dp/test/ut/DpContainerTester.hpp" #include "Fw/Dp/test/util/DpContainerHeader.hpp" #include "Fw/Test/UnitTest.hpp" #include "STest/Pick/Pick.hpp" #include "STest/Random/Random.hpp" -#include "Fw/Dp/test/ut/DpContainerTester.hpp" using namespace Fw; @@ -35,8 +35,7 @@ void checkHeader(FwDpIdType id, Fw::Buffer& buffer, DpContainer& container) { container.setTimeTag(timeTag); // Set the processing types const FwSizeType numProcTypeStates = 1 << DpCfg::ProcType::NUM_CONSTANTS; - const auto procTypes = - static_cast(STest::Pick::startLength(0, numProcTypeStates)); + const auto procTypes = static_cast(STest::Pick::startLength(0, numProcTypeStates)); container.setProcTypes(procTypes); // Set the user data for (U8& data : userData) { @@ -108,7 +107,8 @@ TEST(Header, BufferInConstructor) { // Fill with data fillWithData(buffer); // Use the buffer to create a container - const FwDpIdType id = static_cast(STest::Pick::lowerUpper(0, static_cast(std::numeric_limits::max()))); + const FwDpIdType id = + static_cast(STest::Pick::lowerUpper(0, static_cast(std::numeric_limits::max()))); DpContainer container(id, buffer); // Check the header checkHeader(id, buffer, container); @@ -145,7 +145,8 @@ TEST(Header, BufferSet) { // Fill with data fillWithData(buffer); // Use the buffer to create a container - const FwDpIdType id = static_cast(STest::Pick::lowerUpper(0, static_cast(std::numeric_limits::max()))); + const FwDpIdType id = + static_cast(STest::Pick::lowerUpper(0, static_cast(std::numeric_limits::max()))); DpContainer container; container.setId(id); container.setBuffer(buffer); diff --git a/Fw/Dp/test/util/DpContainerHeader.hpp b/Fw/Dp/test/util/DpContainerHeader.hpp index 81095c43781..5b482bb3d49 100644 --- a/Fw/Dp/test/util/DpContainerHeader.hpp +++ b/Fw/Dp/test/util/DpContainerHeader.hpp @@ -9,9 +9,9 @@ #include "gtest/gtest.h" -#include "Fw/FPrimeBasicTypes.hpp" #include "Fw/Com/ComPacket.hpp" #include "Fw/Dp/DpContainer.hpp" +#include "Fw/FPrimeBasicTypes.hpp" #define DP_CONTAINER_HEADER_ASSERT_MSG(actual, expected) \ << file << ":" << line << "\n" \ @@ -30,10 +30,10 @@ struct DpContainerHeader { DpContainerHeader() : m_id(0), m_priority(0), m_timeTag(), m_procTypes(0), m_dpState(), m_dataSize(0) {} //! Move the buffer deserialization to the specified offset - static void moveDeserToOffset(const char* const file, //!< The call site file name - const U32 line, //!< The call site line number - ExternalSerializeBufferWithMemberCopy &deserializer, //!< The buffer - FwSizeType offset //!< The offset + static void moveDeserToOffset(const char* const file, //!< The call site file name + const U32 line, //!< The call site line number + ExternalSerializeBufferWithMemberCopy& deserializer, //!< The buffer + FwSizeType offset //!< The offset ) { // Reset deserialization deserializer.resetDeser(); diff --git a/Fw/FPrimeBasicTypes.h b/Fw/FPrimeBasicTypes.h index 7f9e2a3309a..b5d4cdb3c86 100644 --- a/Fw/FPrimeBasicTypes.h +++ b/Fw/FPrimeBasicTypes.h @@ -18,32 +18,31 @@ #ifndef FPRIME_BASIC_TYPES_H #define FPRIME_BASIC_TYPES_H -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif -#include #include #include - +#include // ---------------------------------------------------------------------- // Type aliases defined by FPP // ---------------------------------------------------------------------- +#include #include -#include +#include #include -#include -#include +#include #include -#include +#include -#include #include #include #include #include #include +#include #include #include #include @@ -58,7 +57,7 @@ extern "C" { typedef FwSizeStoreType FwBuffSizeType; #define PRI_FwBuffSizeType PRI_FwSizeStoreType -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif // FPRIME_BASIC_TYPES_H +#endif // FPRIME_BASIC_TYPES_H diff --git a/Fw/FPrimeBasicTypes.hpp b/Fw/FPrimeBasicTypes.hpp index 50a4e13eb88..a9f68035317 100644 --- a/Fw/FPrimeBasicTypes.hpp +++ b/Fw/FPrimeBasicTypes.hpp @@ -18,7 +18,7 @@ #define FPRIME_BASIC_TYPES_HPP #include extern "C" { - #include +#include } #include // Needed for FwAssertTextSize @@ -36,71 +36,72 @@ extern "C" { // default value in FPP. static_assert(FW_FIXED_LENGTH_STRING_SIZE >= FW_CMD_STRING_MAX_SIZE, - "A generic string should be able to hold a command string"); + "A generic string should be able to hold a command string"); static_assert(FW_FIXED_LENGTH_STRING_SIZE >= FW_LOG_STRING_MAX_SIZE, - "A generic string should be able to hold an event string"); + "A generic string should be able to hold an event string"); static_assert(FW_FIXED_LENGTH_STRING_SIZE >= FW_TLM_STRING_MAX_SIZE, - "A generic string should be able to hold a telemetry string"); + "A generic string should be able to hold a telemetry string"); static_assert(FW_FIXED_LENGTH_STRING_SIZE >= FW_PARAM_STRING_MAX_SIZE, - "A generic string should be able to hold a parameter string"); + "A generic string should be able to hold a parameter string"); // Check that command/telemetry strings are not larger than an argument buffer static_assert(FW_CMD_STRING_MAX_SIZE + sizeof(FwSizeStoreType) <= FW_CMD_ARG_BUFFER_MAX_SIZE, - "FW_CMD_STRING_MAX_SIZE cannot be larger than FW_CMD_ARG_BUFFER_MAX_SIZE"); + "FW_CMD_STRING_MAX_SIZE cannot be larger than FW_CMD_ARG_BUFFER_MAX_SIZE"); static_assert(FW_LOG_STRING_MAX_SIZE + sizeof(FwSizeStoreType) <= FW_LOG_BUFFER_MAX_SIZE, - "FW_LOG_STRING_MAX_SIZE cannot be larger than FW_LOG_BUFFER_MAX_SIZE"); + "FW_LOG_STRING_MAX_SIZE cannot be larger than FW_LOG_BUFFER_MAX_SIZE"); static_assert(FW_TLM_STRING_MAX_SIZE + sizeof(FwSizeStoreType) <= FW_TLM_BUFFER_MAX_SIZE, - "FW_TLM_STRING_MAX_SIZE cannot be larger than FW_TLM_BUFFER_MAX_SIZE"); + "FW_TLM_STRING_MAX_SIZE cannot be larger than FW_TLM_BUFFER_MAX_SIZE"); static_assert(FW_PARAM_STRING_MAX_SIZE + sizeof(FwSizeStoreType) <= FW_PARAM_BUFFER_MAX_SIZE, - "FW_PARAM_STRING_MAX_SIZE cannot be larger than FW_PARAM_BUFFER_MAX_SIZE"); + "FW_PARAM_STRING_MAX_SIZE cannot be larger than FW_PARAM_BUFFER_MAX_SIZE"); // Text logging needs the code generator for serializables to generate a stringified version of the // value. static_assert((FW_ENABLE_TEXT_LOGGING == 0) || (FW_SERIALIZABLE_TO_STRING != 0), - "FW_SERIALIZABLE_TO_STRING must be enabled to enable FW_ENABLE_TEXT_LOGGING"); + "FW_SERIALIZABLE_TO_STRING must be enabled to enable FW_ENABLE_TEXT_LOGGING"); // Unit testing needs serializable strings #ifdef BUILD_UT -static_assert(FW_SERIALIZABLE_TO_STRING != 0, - "FW_SERIALIZABLE_TO_STRING must be enabled for unit testing"); +static_assert(FW_SERIALIZABLE_TO_STRING != 0, "FW_SERIALIZABLE_TO_STRING must be enabled for unit testing"); #endif static_assert(std::numeric_limits::max() == std::numeric_limits::max() && - std::numeric_limits::min() == std::numeric_limits::min(), - "FwBuffSizeType must be equivalent to FwExternalSizeType"); + std::numeric_limits::min() == std::numeric_limits::min(), + "FwBuffSizeType must be equivalent to FwExternalSizeType"); static_assert(std::numeric_limits::max() >= std::numeric_limits::max() && - std::numeric_limits::min() <= std::numeric_limits::min(), - "FwSizeType cannot entirely store values of type FwExternalSizeType"); + std::numeric_limits::min() <= std::numeric_limits::min(), + "FwSizeType cannot entirely store values of type FwExternalSizeType"); // Check platform defined types for required invariants -static_assert(sizeof(PlatformPointerCastType) == sizeof(void*), "PlatformPointerCastType must be the same size as pointers"); +static_assert(sizeof(PlatformPointerCastType) == sizeof(void*), + "PlatformPointerCastType must be the same size as pointers"); static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), - "PlatformSizeType must be at least as large as unsigned int"); + "PlatformSizeType must be at least as large as unsigned int"); static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), - "PlatformSignedSizeType must be at least as large as int"); + "PlatformSignedSizeType must be at least as large as int"); static_assert(std::numeric_limits::min() <= std::numeric_limits::min(), - "PlatformSignedSizeType must be at least as small as int"); + "PlatformSignedSizeType must be at least as small as int"); static_assert(std::numeric_limits::is_signed, "PlatformIndexType must be signed"); static_assert(not std::numeric_limits::is_signed, "PlatformSizeType must be unsigned"); static_assert(std::numeric_limits::is_signed, "PlatformSignedSizeType must be signed"); -static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), "PlatformSizeType must be at least as large as U32"); -static_assert(sizeof(PlatformSizeType) == sizeof(PlatformSignedSizeType), "PlatformSizeType must be the same size as PlatformSignedSizeType"); +static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), + "PlatformSizeType must be at least as large as U32"); +static_assert(sizeof(PlatformSizeType) == sizeof(PlatformSignedSizeType), + "PlatformSizeType must be the same size as PlatformSignedSizeType"); // Check framework configured types for required invariants static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), - "FwSizeType must be at least as large as unsigned int"); + "FwSizeType must be at least as large as unsigned int"); static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), - "FwSignedSizeType must be at least as large as int"); + "FwSignedSizeType must be at least as large as int"); static_assert(std::numeric_limits::min() <= std::numeric_limits::min(), - "FwSignedSizeType must be at least as large as int"); + "FwSignedSizeType must be at least as large as int"); static_assert(std::numeric_limits::is_signed, "FwIndexType must be signed"); static_assert(not std::numeric_limits::is_signed, "FwSizeType must be unsigned"); static_assert(std::numeric_limits::is_signed, "FwSignedSizeType must be signed"); -static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), "FwSizeType must be at least as large as U32"); +static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), + "FwSizeType must be at least as large as U32"); static_assert(sizeof(FwSizeType) == sizeof(FwSignedSizeType), "FwSizeType must be the same size as FwSignedSizeType"); - - -#endif // FW_TYPES_HPP +#endif // FW_TYPES_HPP diff --git a/Fw/FilePacket/CancelPacket.cpp b/Fw/FilePacket/CancelPacket.cpp index 02049f630bb..1785cb14c54 100644 --- a/Fw/FilePacket/CancelPacket.cpp +++ b/Fw/FilePacket/CancelPacket.cpp @@ -15,40 +15,27 @@ namespace Fw { - void FilePacket::CancelPacket :: - initialize(const U32 sequenceIndex) - { +void FilePacket::CancelPacket ::initialize(const U32 sequenceIndex) { this->m_header.initialize(FilePacket::T_CANCEL, sequenceIndex); - } +} - U32 FilePacket::CancelPacket :: - bufferSize() const - { +U32 FilePacket::CancelPacket ::bufferSize() const { return this->m_header.bufferSize(); - } - - SerializeStatus FilePacket::CancelPacket :: - toBuffer(Buffer& buffer) const - { - SerialBuffer serialBuffer( - buffer.getData(), - buffer.getSize() - ); - return this->m_header.toSerialBuffer(serialBuffer); - } +} - SerializeStatus FilePacket::CancelPacket :: - fromSerialBuffer(SerialBuffer& serialBuffer) - { +SerializeStatus FilePacket::CancelPacket ::toBuffer(Buffer& buffer) const { + SerialBuffer serialBuffer(buffer.getData(), buffer.getSize()); + return this->m_header.toSerialBuffer(serialBuffer); +} +SerializeStatus FilePacket::CancelPacket ::fromSerialBuffer(SerialBuffer& serialBuffer) { FW_ASSERT(this->m_header.m_type == T_CANCEL); if (serialBuffer.getBuffLeft() != 0) { - return FW_DESERIALIZE_SIZE_MISMATCH; + return FW_DESERIALIZE_SIZE_MISMATCH; } return FW_SERIALIZE_OK; - - } - } + +} // namespace Fw diff --git a/Fw/FilePacket/DataPacket.cpp b/Fw/FilePacket/DataPacket.cpp index f158a1fe02b..83e2c2e5e09 100644 --- a/Fw/FilePacket/DataPacket.cpp +++ b/Fw/FilePacket/DataPacket.cpp @@ -15,103 +15,76 @@ namespace Fw { - void FilePacket::DataPacket :: - initialize( - const U32 sequenceIndex, - const U32 byteOffset, - const U16 dataSize, - const U8 *const data - ) - { +void FilePacket::DataPacket ::initialize(const U32 sequenceIndex, + const U32 byteOffset, + const U16 dataSize, + const U8* const data) { this->m_header.initialize(FilePacket::T_DATA, sequenceIndex); this->m_byteOffset = byteOffset; this->m_dataSize = dataSize; this->m_data = data; - } - - U32 FilePacket::DataPacket :: - bufferSize() const - { - return static_cast( - this->m_header.bufferSize() + - sizeof(this->m_byteOffset) + - sizeof(this->m_dataSize) + - this->m_dataSize); - } - - SerializeStatus FilePacket::DataPacket :: - toBuffer(Buffer& buffer) const - { - SerialBuffer serialBuffer( - buffer.getData(), - buffer.getSize() - ); - return this->toSerialBuffer(serialBuffer); - } +} - SerializeStatus FilePacket::DataPacket :: - fromSerialBuffer(SerialBuffer& serialBuffer) - { +U32 FilePacket::DataPacket ::bufferSize() const { + return static_cast(this->m_header.bufferSize() + sizeof(this->m_byteOffset) + sizeof(this->m_dataSize) + + this->m_dataSize); +} +SerializeStatus FilePacket::DataPacket ::toBuffer(Buffer& buffer) const { + SerialBuffer serialBuffer(buffer.getData(), buffer.getSize()); + return this->toSerialBuffer(serialBuffer); +} + +SerializeStatus FilePacket::DataPacket ::fromSerialBuffer(SerialBuffer& serialBuffer) { FW_ASSERT(this->m_header.m_type == T_DATA); SerializeStatus status = serialBuffer.deserialize(this->m_byteOffset); if (status != FW_SERIALIZE_OK) { - return status; + return status; } status = serialBuffer.deserialize(this->m_dataSize); if (status != FW_SERIALIZE_OK) { - return status; + return status; } if (serialBuffer.getBuffLeft() != this->m_dataSize) { - return FW_DESERIALIZE_SIZE_MISMATCH; + return FW_DESERIALIZE_SIZE_MISMATCH; } - U8 *const addr = serialBuffer.getBuffAddr(); + U8* const addr = serialBuffer.getBuffAddr(); this->m_data = &addr[this->fixedLengthSize()]; return FW_SERIALIZE_OK; +} - } - - U32 FilePacket::DataPacket :: - fixedLengthSize() const - { - return static_cast( - this->m_header.bufferSize() + - sizeof(this->m_byteOffset) + - sizeof(this->m_dataSize)); - } - - SerializeStatus FilePacket::DataPacket :: - toSerialBuffer(SerialBuffer& serialBuffer) const - { +U32 FilePacket::DataPacket ::fixedLengthSize() const { + return static_cast(this->m_header.bufferSize() + sizeof(this->m_byteOffset) + sizeof(this->m_dataSize)); +} +SerializeStatus FilePacket::DataPacket ::toSerialBuffer(SerialBuffer& serialBuffer) const { FW_ASSERT(this->m_header.m_type == T_DATA); SerializeStatus status; status = this->m_header.toSerialBuffer(serialBuffer); if (status != FW_SERIALIZE_OK) { - return status; + return status; } status = serialBuffer.serialize(this->m_byteOffset); if (status != FW_SERIALIZE_OK) { - return status; + return status; } status = serialBuffer.serialize(this->m_dataSize); if (status != FW_SERIALIZE_OK) { - return status; + return status; } status = serialBuffer.pushBytes(this->m_data, this->m_dataSize); return status; - - } - } + +} // namespace Fw diff --git a/Fw/FilePacket/EndPacket.cpp b/Fw/FilePacket/EndPacket.cpp index 36b3ed8f74c..79404f89b04 100644 --- a/Fw/FilePacket/EndPacket.cpp +++ b/Fw/FilePacket/EndPacket.cpp @@ -17,79 +17,53 @@ namespace Fw { - void FilePacket::EndPacket :: - initialize( - const U32 sequenceIndex, - const CFDP::Checksum& checksum - ) - { +void FilePacket::EndPacket ::initialize(const U32 sequenceIndex, const CFDP::Checksum& checksum) { this->m_header.initialize(FilePacket::T_END, sequenceIndex); this->setChecksum(checksum); - } +} - U32 FilePacket::EndPacket :: - bufferSize() const - { +U32 FilePacket::EndPacket ::bufferSize() const { return static_cast(this->m_header.bufferSize() + sizeof(this->m_checksumValue)); - } - - SerializeStatus FilePacket::EndPacket :: - toBuffer(Buffer& buffer) const - { - SerialBuffer serialBuffer( - buffer.getData(), - buffer.getSize() - ); +} + +SerializeStatus FilePacket::EndPacket ::toBuffer(Buffer& buffer) const { + SerialBuffer serialBuffer(buffer.getData(), buffer.getSize()); return this->toSerialBuffer(serialBuffer); - } +} - void FilePacket::EndPacket :: - setChecksum(const CFDP::Checksum& checksum) - { +void FilePacket::EndPacket ::setChecksum(const CFDP::Checksum& checksum) { this->m_checksumValue = checksum.getValue(); - } - +} - void FilePacket::EndPacket :: - getChecksum(CFDP::Checksum& checksum) const - { +void FilePacket::EndPacket ::getChecksum(CFDP::Checksum& checksum) const { CFDP::Checksum c(this->m_checksumValue); checksum = c; - } - - SerializeStatus FilePacket::EndPacket :: - fromSerialBuffer(SerialBuffer& serialBuffer) - { +} +SerializeStatus FilePacket::EndPacket ::fromSerialBuffer(SerialBuffer& serialBuffer) { FW_ASSERT(this->m_header.m_type == T_END); - const SerializeStatus status = - serialBuffer.deserialize(this->m_checksumValue); + const SerializeStatus status = serialBuffer.deserialize(this->m_checksumValue); return status; +} - } - - SerializeStatus FilePacket::EndPacket :: - toSerialBuffer(SerialBuffer& serialBuffer) const - { - +SerializeStatus FilePacket::EndPacket ::toSerialBuffer(SerialBuffer& serialBuffer) const { FW_ASSERT(this->m_header.m_type == T_END); SerializeStatus status; status = this->m_header.toSerialBuffer(serialBuffer); if (status != FW_SERIALIZE_OK) { - return status; + return status; } status = serialBuffer.serialize(this->m_checksumValue); if (status != FW_SERIALIZE_OK) { - return status; + return status; } return FW_SERIALIZE_OK; - - } - } + +} // namespace Fw diff --git a/Fw/FilePacket/FilePacket.cpp b/Fw/FilePacket/FilePacket.cpp index e2d4a25ce14..324970d3633 100644 --- a/Fw/FilePacket/FilePacket.cpp +++ b/Fw/FilePacket/FilePacket.cpp @@ -15,156 +15,127 @@ namespace Fw { - // ---------------------------------------------------------------------- - // Public instance methods - // ---------------------------------------------------------------------- - - SerializeStatus FilePacket :: - fromBuffer(const Buffer& buffer) - { - SerialBuffer serialBuffer( - const_cast(buffer).getData(), - const_cast(buffer).getSize() - ); +// ---------------------------------------------------------------------- +// Public instance methods +// ---------------------------------------------------------------------- + +SerializeStatus FilePacket ::fromBuffer(const Buffer& buffer) { + SerialBuffer serialBuffer(const_cast(buffer).getData(), const_cast(buffer).getSize()); serialBuffer.fill(); const SerializeStatus status = this->fromSerialBuffer(serialBuffer); return status; - } +} - const FilePacket::Header& FilePacket :: - asHeader() const - { +const FilePacket::Header& FilePacket ::asHeader() const { return this->m_header; - } +} - const FilePacket::StartPacket& FilePacket :: - asStartPacket() const - { +const FilePacket::StartPacket& FilePacket ::asStartPacket() const { FW_ASSERT(this->m_header.m_type == T_START); return this->m_startPacket; - } +} - const FilePacket::DataPacket& FilePacket :: - asDataPacket() const - { +const FilePacket::DataPacket& FilePacket ::asDataPacket() const { FW_ASSERT(this->m_header.m_type == T_DATA); return this->m_dataPacket; - } +} - const FilePacket::EndPacket& FilePacket :: - asEndPacket() const - { +const FilePacket::EndPacket& FilePacket ::asEndPacket() const { FW_ASSERT(this->m_header.m_type == T_END); return this->m_endPacket; - } +} - const FilePacket::CancelPacket& FilePacket :: - asCancelPacket() const - { +const FilePacket::CancelPacket& FilePacket ::asCancelPacket() const { FW_ASSERT(this->m_header.m_type == T_CANCEL); return this->m_cancelPacket; - } +} - void FilePacket :: - fromStartPacket(const StartPacket& startPacket) - { +void FilePacket ::fromStartPacket(const StartPacket& startPacket) { this->m_startPacket = startPacket; this->m_header.m_type = T_START; - } +} - void FilePacket :: - fromDataPacket(const DataPacket& dataPacket) - { +void FilePacket ::fromDataPacket(const DataPacket& dataPacket) { this->m_dataPacket = dataPacket; this->m_header.m_type = T_DATA; - } +} - void FilePacket :: - fromEndPacket(const EndPacket& endPacket) - { +void FilePacket ::fromEndPacket(const EndPacket& endPacket) { this->m_endPacket = endPacket; this->m_header.m_type = T_END; - } +} - void FilePacket :: - fromCancelPacket(const CancelPacket& cancelPacket) - { +void FilePacket ::fromCancelPacket(const CancelPacket& cancelPacket) { this->m_cancelPacket = cancelPacket; this->m_header.m_type = T_CANCEL; - } +} - U32 FilePacket :: - bufferSize() const - { +U32 FilePacket ::bufferSize() const { switch (this->m_header.m_type) { - case T_START: - return this->m_startPacket.bufferSize(); - case T_DATA: - return this->m_dataPacket.bufferSize(); - case T_END: - return this->m_endPacket.bufferSize(); - case T_CANCEL: - return this->m_cancelPacket.bufferSize(); - case T_NONE: - return 0; - default: - FW_ASSERT(0); - return 0; + case T_START: + return this->m_startPacket.bufferSize(); + case T_DATA: + return this->m_dataPacket.bufferSize(); + case T_END: + return this->m_endPacket.bufferSize(); + case T_CANCEL: + return this->m_cancelPacket.bufferSize(); + case T_NONE: + return 0; + default: + FW_ASSERT(0); + return 0; } - } +} - SerializeStatus FilePacket :: - toBuffer(Buffer& buffer) const - { +SerializeStatus FilePacket ::toBuffer(Buffer& buffer) const { switch (this->m_header.m_type) { - case T_START: - return this->m_startPacket.toBuffer(buffer); - case T_DATA: - return this->m_dataPacket.toBuffer(buffer); - case T_END: - return this->m_endPacket.toBuffer(buffer); - case T_CANCEL: - return this->m_cancelPacket.toBuffer(buffer); - default: - FW_ASSERT(0); - return static_cast(0); + case T_START: + return this->m_startPacket.toBuffer(buffer); + case T_DATA: + return this->m_dataPacket.toBuffer(buffer); + case T_END: + return this->m_endPacket.toBuffer(buffer); + case T_CANCEL: + return this->m_cancelPacket.toBuffer(buffer); + default: + FW_ASSERT(0); + return static_cast(0); } - } +} - // ---------------------------------------------------------------------- - // Private instance methods - // ---------------------------------------------------------------------- +// ---------------------------------------------------------------------- +// Private instance methods +// ---------------------------------------------------------------------- - SerializeStatus FilePacket :: - fromSerialBuffer(SerialBuffer& serialBuffer) - { +SerializeStatus FilePacket ::fromSerialBuffer(SerialBuffer& serialBuffer) { SerializeStatus status; status = this->m_header.fromSerialBuffer(serialBuffer); if (status != FW_SERIALIZE_OK) { - return status; + return status; } switch (this->m_header.m_type) { - case T_START: - status = this->m_startPacket.fromSerialBuffer(serialBuffer); - break; - case T_DATA: - status = this->m_dataPacket.fromSerialBuffer(serialBuffer); - break; - case T_END: - status = this->m_endPacket.fromSerialBuffer(serialBuffer); - break; - case T_CANCEL: - status = this->m_cancelPacket.fromSerialBuffer(serialBuffer); - break; - case T_NONE: - status = FW_DESERIALIZE_TYPE_MISMATCH; - break; - default: - FW_ASSERT(0,status); - break; + case T_START: + status = this->m_startPacket.fromSerialBuffer(serialBuffer); + break; + case T_DATA: + status = this->m_dataPacket.fromSerialBuffer(serialBuffer); + break; + case T_END: + status = this->m_endPacket.fromSerialBuffer(serialBuffer); + break; + case T_CANCEL: + status = this->m_cancelPacket.fromSerialBuffer(serialBuffer); + break; + case T_NONE: + status = FW_DESERIALIZE_TYPE_MISMATCH; + break; + default: + FW_ASSERT(0, status); + break; } return status; - } - } + +} // namespace Fw diff --git a/Fw/FilePacket/FilePacket.hpp b/Fw/FilePacket/FilePacket.hpp index 19f48465cc5..f412ad61204 100644 --- a/Fw/FilePacket/FilePacket.hpp +++ b/Fw/FilePacket/FilePacket.hpp @@ -21,455 +21,378 @@ // Forward declaration for UTs namespace Svc { - class FileUplinkTester; - class FileDownlinkTester; -} +class FileUplinkTester; +class FileDownlinkTester; +} // namespace Svc namespace Fw { - //! \class FilePacket - //! \brief A file packet - //! - union FilePacket { +//! \class FilePacket +//! \brief A file packet +//! +union FilePacket { + public: + // ---------------------------------------------------------------------- + // Types + // ---------------------------------------------------------------------- - public: - - // ---------------------------------------------------------------------- - // Types - // ---------------------------------------------------------------------- - - //! Packet type - typedef enum { - T_START = 0, - T_DATA = 1, - T_END = 2, - T_CANCEL = 3, - T_NONE = 255 - } Type; - - //! The type of a path name - class PathName { + //! Packet type + typedef enum { T_START = 0, T_DATA = 1, T_END = 2, T_CANCEL = 3, T_NONE = 255 } Type; + //! The type of a path name + class PathName { friend union FilePacket; friend class Svc::FileDownlinkTester; friend class Svc::FileUplinkTester; - public: - - //! The maximum length of a path name - enum { MAX_LENGTH = 255 }; - - private: - - //! The length - U8 m_length; - - //! Pointer to the path value - const char *m_value; - - public: - - //! Initialize a PathName - void initialize( - const char *const value //! The path value - ); - - //! Compute the buffer size needed to hold this PathName - U32 bufferSize() const; - - //! Get the length of the path name value - U32 getLength(void) const { - return this->m_length; - }; - - //! Get the path name value - const char* getValue(void) const { - return this->m_value; - }; - - private: - - //! Initialize this PathName from a SerialBuffer - SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); - - //! Write this PathName to a SerialBuffer - SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const; - - }; - - //! The type of a packet header - class Header { - - friend union FilePacket; - friend class FilePacketTester; - friend class Svc::FileDownlinkTester; - friend class Svc::FileUplinkTester; - - private: - - //! The packet type - Type m_type; - - //! The sequence index - U32 m_sequenceIndex; - - public: - - //! Header size - enum { HEADERSIZE = sizeof(U8) + sizeof(U32) }; - - private: + public: + //! The maximum length of a path name + enum { MAX_LENGTH = 255 }; - //! Initialize a file packet header - void initialize( - const Type type, //!< The packet type - const U32 sequenceIndex //!< The sequence index - ); + private: + //! The length + U8 m_length; - //! Compute the buffer size needed to hold this Header - U32 bufferSize() const; + //! Pointer to the path value + const char* m_value; - //! Initialize this Header from a SerialBuffer - SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); + public: + //! Initialize a PathName + void initialize(const char* const value //! The path value + ); - //! Write this Header to a SerialBuffer - SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const; + //! Compute the buffer size needed to hold this PathName + U32 bufferSize() const; - public: - Type getType(void) const { - return this->m_type; - }; + //! Get the length of the path name value + U32 getLength(void) const { return this->m_length; }; - U32 getSequenceIndex(void) const { - return this->m_sequenceIndex; - }; + //! Get the path name value + const char* getValue(void) const { return this->m_value; }; - }; + private: + //! Initialize this PathName from a SerialBuffer + SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); - //! The type of a start packet - struct StartPacket { + //! Write this PathName to a SerialBuffer + SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const; + }; - friend union FilePacket; - - private: - - //! The packet header - Header m_header; - - //! The file size - U32 m_fileSize; - - //! The source path - PathName m_sourcePath; - - //! The destination path - PathName m_destinationPath; - - public: - - //! Initialize a StartPacket with sequence number 0 - void initialize( - const U32 fileSize, //!< The file size - const char *const sourcePath, //!< The source path - const char *const destinationPath //!< The destination path - ); - - //! Compute the buffer size needed to hold this StartPacket - U32 bufferSize() const; - - //! Convert this StartPacket to a Buffer - SerializeStatus toBuffer(Buffer& buffer) const; - - //! Get this as a Header - const FilePacket::Header& asHeader() const { - return this->m_header; - }; - - //! Get the destination path - const PathName& getDestinationPath() const { - return this->m_destinationPath; - }; + //! The type of a packet header + class Header { + friend union FilePacket; + friend class FilePacketTester; + friend class Svc::FileDownlinkTester; + friend class Svc::FileUplinkTester; - //! Get the source path - const PathName& getSourcePath() const { - return this->m_sourcePath; - }; + private: + //! The packet type + Type m_type; - //! Get the file size - U32 getFileSize() const { - return this->m_fileSize; - }; - private: + //! The sequence index + U32 m_sequenceIndex; - //! Initialize this StartPacket from a SerialBuffer - SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); + public: + //! Header size + enum { HEADERSIZE = sizeof(U8) + sizeof(U32) }; - //! Write this StartPacket to a SerialBuffer - SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const; + private: + //! Initialize a file packet header + void initialize(const Type type, //!< The packet type + const U32 sequenceIndex //!< The sequence index + ); - }; + //! Compute the buffer size needed to hold this Header + U32 bufferSize() const; - //! The type of a data packet - class DataPacket { + //! Initialize this Header from a SerialBuffer + SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); - friend union FilePacket; - friend class Svc::FileDownlinkTester; - friend class Svc::FileUplinkTester; + //! Write this Header to a SerialBuffer + SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const; - private: + public: + Type getType(void) const { return this->m_type; }; - //! The packet header - Header m_header; + U32 getSequenceIndex(void) const { return this->m_sequenceIndex; }; + }; - //! The byte offset of the packet data into the destination file - U32 m_byteOffset; + //! The type of a start packet + struct StartPacket { + friend union FilePacket; - //! The size of the file data in the packet - U16 m_dataSize; + private: + //! The packet header + Header m_header; - //! Pointer to the file data - const U8 *m_data; + //! The file size + U32 m_fileSize; - public: + //! The source path + PathName m_sourcePath; - //! header size - enum { HEADERSIZE = Header::HEADERSIZE + - sizeof(U32) + - sizeof(U16) }; + //! The destination path + PathName m_destinationPath; - //! Initialize a data packet - void initialize( - const U32 sequenceIndex, //!< The sequence index - const U32 byteOffset, //!< The byte offset - const U16 dataSize, //!< The data size - const U8 *const data //!< The file data - ); + public: + //! Initialize a StartPacket with sequence number 0 + void initialize(const U32 fileSize, //!< The file size + const char* const sourcePath, //!< The source path + const char* const destinationPath //!< The destination path + ); - //! Compute the buffer size needed to hold this DataPacket - U32 bufferSize() const; + //! Compute the buffer size needed to hold this StartPacket + U32 bufferSize() const; - //! Convert this DataPacket to a Buffer - SerializeStatus toBuffer(Buffer& buffer) const; + //! Convert this StartPacket to a Buffer + SerializeStatus toBuffer(Buffer& buffer) const; - //! Get this as a Header - const FilePacket::Header& asHeader() const { - return this->m_header; - }; + //! Get this as a Header + const FilePacket::Header& asHeader() const { return this->m_header; }; - //! Get the byte offset - U32 getByteOffset() const { - return this->m_byteOffset; - }; + //! Get the destination path + const PathName& getDestinationPath() const { return this->m_destinationPath; }; - //! Get the data size - U32 getDataSize() const { - return this->m_dataSize; - }; + //! Get the source path + const PathName& getSourcePath() const { return this->m_sourcePath; }; - //! Get the data - const U8* getData() const { - return this->m_data; - }; - private: + //! Get the file size + U32 getFileSize() const { return this->m_fileSize; }; - //! Initialize this DataPacket from a SerialBuffer - SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); + private: + //! Initialize this StartPacket from a SerialBuffer + SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); - //! Compute the fixed-length data size of a StartPacket - U32 fixedLengthSize() const; + //! Write this StartPacket to a SerialBuffer + SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const; + }; - //! Write this DataPacket to a SerialBuffer - SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const; + //! The type of a data packet + class DataPacket { + friend union FilePacket; + friend class Svc::FileDownlinkTester; + friend class Svc::FileUplinkTester; - }; + private: + //! The packet header + Header m_header; - //! The type of an end packet - class EndPacket { + //! The byte offset of the packet data into the destination file + U32 m_byteOffset; - friend union FilePacket; - friend class Svc::FileDownlinkTester; - friend class Svc::FileUplinkTester; + //! The size of the file data in the packet + U16 m_dataSize; - private: + //! Pointer to the file data + const U8* m_data; - //! The packet header - Header m_header; + public: + //! header size + enum { HEADERSIZE = Header::HEADERSIZE + sizeof(U32) + sizeof(U16) }; - public: + //! Initialize a data packet + void initialize(const U32 sequenceIndex, //!< The sequence index + const U32 byteOffset, //!< The byte offset + const U16 dataSize, //!< The data size + const U8* const data //!< The file data + ); - //! Set the checksum - void setChecksum(const CFDP::Checksum& checksum); + //! Compute the buffer size needed to hold this DataPacket + U32 bufferSize() const; - //! Get the checksum - void getChecksum(CFDP::Checksum& checksum) const; + //! Convert this DataPacket to a Buffer + SerializeStatus toBuffer(Buffer& buffer) const; - //! Compute the buffer size needed to hold this EndPacket - U32 bufferSize() const; + //! Get this as a Header + const FilePacket::Header& asHeader() const { return this->m_header; }; - //! Convert this EndPacket to a Buffer - SerializeStatus toBuffer(Buffer& buffer) const; + //! Get the byte offset + U32 getByteOffset() const { return this->m_byteOffset; }; - //! Get this as a Header - const FilePacket::Header& asHeader() const { - return this->m_header; - }; - public: + //! Get the data size + U32 getDataSize() const { return this->m_dataSize; }; - //! Initialize an end packet - void initialize( - const U32 sequenceIndex, //!< The sequence index - const CFDP::Checksum& checksum //!< The checksum - ); + //! Get the data + const U8* getData() const { return this->m_data; }; - private: + private: + //! Initialize this DataPacket from a SerialBuffer + SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); - //! The checksum - U32 m_checksumValue; + //! Compute the fixed-length data size of a StartPacket + U32 fixedLengthSize() const; - //! Initialize this EndPacket from a SerialBuffer - SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); + //! Write this DataPacket to a SerialBuffer + SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const; + }; - //! Write this EndPacket to a SerialBuffer - SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const; + //! The type of an end packet + class EndPacket { + friend union FilePacket; + friend class Svc::FileDownlinkTester; + friend class Svc::FileUplinkTester; - }; + private: + //! The packet header + Header m_header; - //! The type of a cancel packet - class CancelPacket { + public: + //! Set the checksum + void setChecksum(const CFDP::Checksum& checksum); - friend union FilePacket; - friend class Svc::FileDownlinkTester; - friend class Svc::FileUplinkTester; + //! Get the checksum + void getChecksum(CFDP::Checksum& checksum) const; - private: + //! Compute the buffer size needed to hold this EndPacket + U32 bufferSize() const; - //! The packet header - Header m_header; + //! Convert this EndPacket to a Buffer + SerializeStatus toBuffer(Buffer& buffer) const; - public: + //! Get this as a Header + const FilePacket::Header& asHeader() const { return this->m_header; }; - //! Initialize a cancel packet - void initialize( - const U32 sequenceIndex //!< The sequence index - ); + public: + //! Initialize an end packet + void initialize(const U32 sequenceIndex, //!< The sequence index + const CFDP::Checksum& checksum //!< The checksum + ); - //! Compute the buffer size needed to hold this CancelPacket - U32 bufferSize() const; + private: + //! The checksum + U32 m_checksumValue; - //! Convert this CancelPacket to a Buffer - SerializeStatus toBuffer(Buffer& buffer) const; + //! Initialize this EndPacket from a SerialBuffer + SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); - //! Get this as a Header - const FilePacket::Header& asHeader() const { - return this->m_header; - }; - private: + //! Write this EndPacket to a SerialBuffer + SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const; + }; - //! Initialize this CancelPacket from a SerialBuffer - SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); + //! The type of a cancel packet + class CancelPacket { + friend union FilePacket; + friend class Svc::FileDownlinkTester; + friend class Svc::FileUplinkTester; - }; + private: + //! The packet header + Header m_header; - public: + public: + //! Initialize a cancel packet + void initialize(const U32 sequenceIndex //!< The sequence index + ); - // ---------------------------------------------------------------------- - // Constructor - // ---------------------------------------------------------------------- + //! Compute the buffer size needed to hold this CancelPacket + U32 bufferSize() const; - FilePacket() { this->m_header.m_type = T_NONE; } + //! Convert this CancelPacket to a Buffer + SerializeStatus toBuffer(Buffer& buffer) const; - public: + //! Get this as a Header + const FilePacket::Header& asHeader() const { return this->m_header; }; - // ---------------------------------------------------------------------- - // Public instance methods - // ---------------------------------------------------------------------- + private: + //! Initialize this CancelPacket from a SerialBuffer + SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); + }; - //! Initialize this from a Buffer - //! - SerializeStatus fromBuffer(const Buffer& buffer); + public: + // ---------------------------------------------------------------------- + // Constructor + // ---------------------------------------------------------------------- - //! Get this as a Header - //! - const Header& asHeader() const; + FilePacket() { this->m_header.m_type = T_NONE; } - //! Get this as a StartPacket - //! - const StartPacket& asStartPacket() const; + public: + // ---------------------------------------------------------------------- + // Public instance methods + // ---------------------------------------------------------------------- - //! Get this as a DataPacket - //! - const DataPacket& asDataPacket() const; + //! Initialize this from a Buffer + //! + SerializeStatus fromBuffer(const Buffer& buffer); - //! Get this as an EndPacket - //! - const EndPacket& asEndPacket() const; + //! Get this as a Header + //! + const Header& asHeader() const; - //! Get this as a CancelPacket - //! - const CancelPacket& asCancelPacket() const; + //! Get this as a StartPacket + //! + const StartPacket& asStartPacket() const; - //! Initialize this with a StartPacket - //! - void fromStartPacket(const StartPacket& startPacket); + //! Get this as a DataPacket + //! + const DataPacket& asDataPacket() const; - //! Initialize this with a DataPacket - //! - void fromDataPacket(const DataPacket& dataPacket); + //! Get this as an EndPacket + //! + const EndPacket& asEndPacket() const; - //! Initialize this with an EndPacket - //! - void fromEndPacket(const EndPacket& endPacket); + //! Get this as a CancelPacket + //! + const CancelPacket& asCancelPacket() const; - //! Initialize this with a CancelPacket - //! - void fromCancelPacket(const CancelPacket& cancelPacket); + //! Initialize this with a StartPacket + //! + void fromStartPacket(const StartPacket& startPacket); - //! Get the buffer size needed to hold this FilePacket - //! - U32 bufferSize() const; + //! Initialize this with a DataPacket + //! + void fromDataPacket(const DataPacket& dataPacket); - //! Convert this FilePacket to a Buffer - //! - SerializeStatus toBuffer(Buffer& buffer) const; + //! Initialize this with an EndPacket + //! + void fromEndPacket(const EndPacket& endPacket); - private: + //! Initialize this with a CancelPacket + //! + void fromCancelPacket(const CancelPacket& cancelPacket); - // ---------------------------------------------------------------------- - // Private methods - // ---------------------------------------------------------------------- + //! Get the buffer size needed to hold this FilePacket + //! + U32 bufferSize() const; - //! Initialize this from a SerialBuffer - //! - SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); + //! Convert this FilePacket to a Buffer + //! + SerializeStatus toBuffer(Buffer& buffer) const; - private: + private: + // ---------------------------------------------------------------------- + // Private methods + // ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - // Private data - // ---------------------------------------------------------------------- + //! Initialize this from a SerialBuffer + //! + SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer); - //! this, seen as a header - //! - Header m_header; + private: + // ---------------------------------------------------------------------- + // Private data + // ---------------------------------------------------------------------- - //! this, seen as a Start packet - //! - StartPacket m_startPacket; + //! this, seen as a header + //! + Header m_header; - //! this, seen as a Data packet - //! - DataPacket m_dataPacket; + //! this, seen as a Start packet + //! + StartPacket m_startPacket; - //! this, seen as an End packet - //! - EndPacket m_endPacket; + //! this, seen as a Data packet + //! + DataPacket m_dataPacket; - //! this, seen as a Cancel packet - //! - CancelPacket m_cancelPacket; + //! this, seen as an End packet + //! + EndPacket m_endPacket; - }; + //! this, seen as a Cancel packet + //! + CancelPacket m_cancelPacket; +}; -} +} // namespace Fw #endif diff --git a/Fw/FilePacket/GTest/CancelPacket.cpp b/Fw/FilePacket/GTest/CancelPacket.cpp index ef9ecafbc52..47aadd9d9e4 100644 --- a/Fw/FilePacket/GTest/CancelPacket.cpp +++ b/Fw/FilePacket/GTest/CancelPacket.cpp @@ -14,17 +14,13 @@ namespace Fw { - namespace GTest { +namespace GTest { - void FilePackets::CancelPacket :: - compare( - const FilePacket::CancelPacket& expected, - const FilePacket::CancelPacket& actual - ) - { - FilePackets::Header::compare(expected.asHeader(), actual.asHeader()); - } +void FilePackets::CancelPacket ::compare(const FilePacket::CancelPacket& expected, + const FilePacket::CancelPacket& actual) { + FilePackets::Header::compare(expected.asHeader(), actual.asHeader()); +} - } +} // namespace GTest -} +} // namespace Fw diff --git a/Fw/FilePacket/GTest/DataPacket.cpp b/Fw/FilePacket/GTest/DataPacket.cpp index 0e4df79de18..87282e9fa10 100644 --- a/Fw/FilePacket/GTest/DataPacket.cpp +++ b/Fw/FilePacket/GTest/DataPacket.cpp @@ -15,21 +15,16 @@ namespace Fw { - namespace GTest { +namespace GTest { - void FilePackets::DataPacket :: - compare( - const FilePacket::DataPacket& expected, - const FilePacket::DataPacket& actual - ) - { - FilePackets::Header::compare(expected.asHeader(), actual.asHeader()); - ASSERT_EQ(expected.getByteOffset(), actual.getByteOffset()); - Bytes expectedData(expected.getData(), expected.getDataSize()); - Bytes actualData(actual.getData(), actual.getDataSize()); - Bytes::compare(expectedData, actualData); - } +void FilePackets::DataPacket ::compare(const FilePacket::DataPacket& expected, const FilePacket::DataPacket& actual) { + FilePackets::Header::compare(expected.asHeader(), actual.asHeader()); + ASSERT_EQ(expected.getByteOffset(), actual.getByteOffset()); + Bytes expectedData(expected.getData(), expected.getDataSize()); + Bytes actualData(actual.getData(), actual.getDataSize()); + Bytes::compare(expectedData, actualData); +} - } +} // namespace GTest -} +} // namespace Fw diff --git a/Fw/FilePacket/GTest/EndPacket.cpp b/Fw/FilePacket/GTest/EndPacket.cpp index 58975ea2c15..817c12affc2 100644 --- a/Fw/FilePacket/GTest/EndPacket.cpp +++ b/Fw/FilePacket/GTest/EndPacket.cpp @@ -10,28 +10,23 @@ // // ====================================================================== -#include #include +#include #include namespace Fw { - namespace GTest { +namespace GTest { - void FilePackets::EndPacket :: - compare( - const FilePacket::EndPacket& expected, - const FilePacket::EndPacket& actual - ) - { - FilePackets::Header::compare(expected.asHeader(), actual.asHeader()); - CFDP::Checksum expectedChecksum; - CFDP::Checksum actualChecksum; - expected.getChecksum(expectedChecksum); - actual.getChecksum(actualChecksum); - CFDP::GTest::Checksums::compare(expectedChecksum, actualChecksum); - } +void FilePackets::EndPacket ::compare(const FilePacket::EndPacket& expected, const FilePacket::EndPacket& actual) { + FilePackets::Header::compare(expected.asHeader(), actual.asHeader()); + CFDP::Checksum expectedChecksum; + CFDP::Checksum actualChecksum; + expected.getChecksum(expectedChecksum); + actual.getChecksum(actualChecksum); + CFDP::GTest::Checksums::compare(expectedChecksum, actualChecksum); +} - } +} // namespace GTest -} +} // namespace Fw diff --git a/Fw/FilePacket/GTest/FilePackets.hpp b/Fw/FilePacket/GTest/FilePackets.hpp index 034602ff8cc..564089e18b5 100644 --- a/Fw/FilePacket/GTest/FilePackets.hpp +++ b/Fw/FilePacket/GTest/FilePackets.hpp @@ -1,4 +1,4 @@ -// ====================================================================== +// ====================================================================== // \title Fw/FilePacket/GTest/FilePackets.hpp // \author bocchino // \brief hpp file for File Packet testing utilities @@ -7,8 +7,8 @@ // Copyright (C) 2016 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. -// -// ====================================================================== +// +// ====================================================================== #ifndef Fw_GTest_FilePackets_HPP #define Fw_GTest_FilePackets_HPP @@ -19,76 +19,58 @@ namespace Fw { - namespace GTest { +namespace GTest { - //! Utilities for testing File Packet operations - //! - namespace FilePackets { +//! Utilities for testing File Packet operations +//! +namespace FilePackets { - namespace PathName { +namespace PathName { - //! Compare two path names - void compare( - const FilePacket::PathName& expected, - const FilePacket::PathName& actual - ); +//! Compare two path names +void compare(const FilePacket::PathName& expected, const FilePacket::PathName& actual); - } +} // namespace PathName - namespace Header { +namespace Header { - //! Compare two file packet headers - void compare( - const FilePacket::Header& expected, - const FilePacket::Header& actual - ); +//! Compare two file packet headers +void compare(const FilePacket::Header& expected, const FilePacket::Header& actual); - } +} // namespace Header - namespace StartPacket { +namespace StartPacket { - //! Compare two start packets - void compare( - const FilePacket::StartPacket& expected, - const FilePacket::StartPacket& actual - ); +//! Compare two start packets +void compare(const FilePacket::StartPacket& expected, const FilePacket::StartPacket& actual); - } +} // namespace StartPacket - namespace DataPacket { +namespace DataPacket { - //! Compare two data packets - void compare( - const FilePacket::DataPacket& expected, - const FilePacket::DataPacket& actual - ); +//! Compare two data packets +void compare(const FilePacket::DataPacket& expected, const FilePacket::DataPacket& actual); - } +} // namespace DataPacket - namespace EndPacket { +namespace EndPacket { - //! Compare two end packets - void compare( - const FilePacket::EndPacket& expected, - const FilePacket::EndPacket& actual - ); +//! Compare two end packets +void compare(const FilePacket::EndPacket& expected, const FilePacket::EndPacket& actual); - } +} // namespace EndPacket - namespace CancelPacket { +namespace CancelPacket { - //! Compare two cancel packets - void compare( - const FilePacket::CancelPacket& expected, - const FilePacket::CancelPacket& actual - ); +//! Compare two cancel packets +void compare(const FilePacket::CancelPacket& expected, const FilePacket::CancelPacket& actual); - } +} // namespace CancelPacket - } +} // namespace FilePackets - } +} // namespace GTest -} +} // namespace Fw #endif diff --git a/Fw/FilePacket/GTest/Header.cpp b/Fw/FilePacket/GTest/Header.cpp index 7e80cf971ab..eb6028bf286 100644 --- a/Fw/FilePacket/GTest/Header.cpp +++ b/Fw/FilePacket/GTest/Header.cpp @@ -14,18 +14,13 @@ namespace Fw { - namespace GTest { +namespace GTest { - void FilePackets::Header :: - compare( - const FilePacket::Header& expected, - const FilePacket::Header& actual - ) - { - ASSERT_EQ(expected.getType(), actual.getType()); - ASSERT_EQ(expected.getSequenceIndex(), actual.getSequenceIndex()); - } +void FilePackets::Header ::compare(const FilePacket::Header& expected, const FilePacket::Header& actual) { + ASSERT_EQ(expected.getType(), actual.getType()); + ASSERT_EQ(expected.getSequenceIndex(), actual.getSequenceIndex()); +} - } +} // namespace GTest -} +} // namespace Fw diff --git a/Fw/FilePacket/GTest/PathName.cpp b/Fw/FilePacket/GTest/PathName.cpp index 5fb2ac9e7f0..175864471e6 100644 --- a/Fw/FilePacket/GTest/PathName.cpp +++ b/Fw/FilePacket/GTest/PathName.cpp @@ -15,26 +15,15 @@ namespace Fw { - namespace GTest { +namespace GTest { - void FilePackets::PathName :: - compare( - const FilePacket::PathName& expected, - const FilePacket::PathName& actual - ) - { - ASSERT_EQ(expected.getLength(), actual.getLength()); - Bytes expectedPath( - reinterpret_cast(expected.getValue()), - expected.getLength() - ); - Bytes actualPath( - reinterpret_cast(actual.getValue()), - actual.getLength() - ); - Bytes::compare(expectedPath, actualPath); - } +void FilePackets::PathName ::compare(const FilePacket::PathName& expected, const FilePacket::PathName& actual) { + ASSERT_EQ(expected.getLength(), actual.getLength()); + Bytes expectedPath(reinterpret_cast(expected.getValue()), expected.getLength()); + Bytes actualPath(reinterpret_cast(actual.getValue()), actual.getLength()); + Bytes::compare(expectedPath, actualPath); +} - } +} // namespace GTest -} +} // namespace Fw diff --git a/Fw/FilePacket/GTest/StartPacket.cpp b/Fw/FilePacket/GTest/StartPacket.cpp index 52a7ebbd370..a8c6f7a45e0 100644 --- a/Fw/FilePacket/GTest/StartPacket.cpp +++ b/Fw/FilePacket/GTest/StartPacket.cpp @@ -15,20 +15,16 @@ namespace Fw { - namespace GTest { +namespace GTest { - void FilePackets::StartPacket :: - compare( - const FilePacket::StartPacket& expected, - const FilePacket::StartPacket& actual - ) - { - FilePackets::Header::compare(expected.asHeader(), actual.asHeader()); - ASSERT_EQ(expected.getFileSize(), actual.getFileSize()); - PathName::compare(expected.getSourcePath(), actual.getSourcePath()); - PathName::compare(expected.getDestinationPath(), actual.getDestinationPath()); - } +void FilePackets::StartPacket ::compare(const FilePacket::StartPacket& expected, + const FilePacket::StartPacket& actual) { + FilePackets::Header::compare(expected.asHeader(), actual.asHeader()); + ASSERT_EQ(expected.getFileSize(), actual.getFileSize()); + PathName::compare(expected.getSourcePath(), actual.getSourcePath()); + PathName::compare(expected.getDestinationPath(), actual.getDestinationPath()); +} - } +} // namespace GTest -} +} // namespace Fw diff --git a/Fw/FilePacket/Header.cpp b/Fw/FilePacket/Header.cpp index a7a68db2529..0131fd76787 100644 --- a/Fw/FilePacket/Header.cpp +++ b/Fw/FilePacket/Header.cpp @@ -15,60 +15,45 @@ namespace Fw { - void FilePacket::Header :: - initialize( - const Type type, - const U32 sequenceIndex - ) - { +void FilePacket::Header ::initialize(const Type type, const U32 sequenceIndex) { this->m_type = type; this->m_sequenceIndex = sequenceIndex; - } +} - U32 FilePacket::Header :: - bufferSize() const - { +U32 FilePacket::Header ::bufferSize() const { return sizeof(U8) + sizeof(this->m_sequenceIndex); - } - - SerializeStatus FilePacket::Header :: - fromSerialBuffer(SerialBuffer& serialBuffer) - { +} +SerializeStatus FilePacket::Header ::fromSerialBuffer(SerialBuffer& serialBuffer) { U8 new_type; SerializeStatus status; status = serialBuffer.deserialize(new_type); if (status != FW_SERIALIZE_OK) { - return status; + return status; } this->m_type = static_cast(new_type); status = serialBuffer.deserialize(this->m_sequenceIndex); return status; +} - } - - SerializeStatus FilePacket::Header :: - toSerialBuffer(SerialBuffer& serialBuffer) const - { - +SerializeStatus FilePacket::Header ::toSerialBuffer(SerialBuffer& serialBuffer) const { const U8 type_casted = static_cast(this->m_type); SerializeStatus status; status = serialBuffer.serialize(type_casted); if (status != FW_SERIALIZE_OK) { - return status; + return status; } status = serialBuffer.serialize(this->m_sequenceIndex); if (status != FW_SERIALIZE_OK) { - return status; + return status; } return FW_SERIALIZE_OK; - - } - } + +} // namespace Fw diff --git a/Fw/FilePacket/PathName.cpp b/Fw/FilePacket/PathName.cpp index 91741c828a8..df7b0a684b4 100644 --- a/Fw/FilePacket/PathName.cpp +++ b/Fw/FilePacket/PathName.cpp @@ -18,76 +18,59 @@ namespace Fw { - void FilePacket::PathName :: - initialize(const char *const value) - { +void FilePacket::PathName ::initialize(const char* const value) { const U8 length = static_cast(StringUtils::string_length(value, static_cast(MAX_LENGTH))); this->m_length = length; this->m_value = value; - } +} - U32 FilePacket::PathName :: - bufferSize() const - { +U32 FilePacket::PathName ::bufferSize() const { return static_cast(sizeof(this->m_length) + this->m_length); - } - - SerializeStatus FilePacket::PathName :: - fromSerialBuffer(SerialBuffer& serialBuffer) - { +} +SerializeStatus FilePacket::PathName ::fromSerialBuffer(SerialBuffer& serialBuffer) { { - const SerializeStatus status = - serialBuffer.deserialize(this->m_length); + const SerializeStatus status = serialBuffer.deserialize(this->m_length); - if (status != FW_SERIALIZE_OK) { - return status; - } + if (status != FW_SERIALIZE_OK) { + return status; + } } { - const U8* addrLeft = serialBuffer.getBuffAddrLeft(); - U8 bytes[MAX_LENGTH]; - const SerializeStatus status = - serialBuffer.popBytes(bytes, this->m_length); + const U8* addrLeft = serialBuffer.getBuffAddrLeft(); + U8 bytes[MAX_LENGTH]; + const SerializeStatus status = serialBuffer.popBytes(bytes, this->m_length); - if (status != FW_SERIALIZE_OK) { - return status; - } + if (status != FW_SERIALIZE_OK) { + return status; + } - this->m_value = reinterpret_cast(addrLeft); + this->m_value = reinterpret_cast(addrLeft); } return FW_SERIALIZE_OK; +} - } - - SerializeStatus FilePacket::PathName :: - toSerialBuffer(SerialBuffer& serialBuffer) const - { - +SerializeStatus FilePacket::PathName ::toSerialBuffer(SerialBuffer& serialBuffer) const { { - const SerializeStatus status = - serialBuffer.serialize(this->m_length); + const SerializeStatus status = serialBuffer.serialize(this->m_length); - if (status != FW_SERIALIZE_OK) { - return status; - } + if (status != FW_SERIALIZE_OK) { + return status; + } } { - const SerializeStatus status = serialBuffer.pushBytes( - reinterpret_cast(this->m_value), - this->m_length - ); - - if (status != FW_SERIALIZE_OK) { - return status; - } + const SerializeStatus status = + serialBuffer.pushBytes(reinterpret_cast(this->m_value), this->m_length); + + if (status != FW_SERIALIZE_OK) { + return status; + } } return FW_SERIALIZE_OK; - - } - } + +} // namespace Fw diff --git a/Fw/FilePacket/StartPacket.cpp b/Fw/FilePacket/StartPacket.cpp index f916e680b81..bcca923bf9d 100644 --- a/Fw/FilePacket/StartPacket.cpp +++ b/Fw/FilePacket/StartPacket.cpp @@ -15,120 +15,91 @@ namespace Fw { - void FilePacket::StartPacket :: - initialize( - const U32 fileSize, - const char *const sourcePath, - const char *const destinationPath - ) - { +void FilePacket::StartPacket ::initialize(const U32 fileSize, + const char* const sourcePath, + const char* const destinationPath) { this->m_header.initialize(FilePacket::T_START, 0); this->m_fileSize = fileSize; this->m_sourcePath.initialize(sourcePath); this->m_destinationPath.initialize(destinationPath); - } - - U32 FilePacket::StartPacket :: - bufferSize() const - { - return static_cast( - this->m_header.bufferSize() + - sizeof(this->m_fileSize) + - this->m_sourcePath.bufferSize() + - this->m_destinationPath.bufferSize()); - } - - SerializeStatus FilePacket::StartPacket :: - toBuffer(Buffer& buffer) const - { - SerialBuffer serialBuffer( - buffer.getData(), - buffer.getSize() - ); - return this->toSerialBuffer(serialBuffer); - } +} + +U32 FilePacket::StartPacket ::bufferSize() const { + return static_cast(this->m_header.bufferSize() + sizeof(this->m_fileSize) + this->m_sourcePath.bufferSize() + + this->m_destinationPath.bufferSize()); +} - SerializeStatus FilePacket::StartPacket :: - fromSerialBuffer(SerialBuffer& serialBuffer) - { +SerializeStatus FilePacket::StartPacket ::toBuffer(Buffer& buffer) const { + SerialBuffer serialBuffer(buffer.getData(), buffer.getSize()); + return this->toSerialBuffer(serialBuffer); +} +SerializeStatus FilePacket::StartPacket ::fromSerialBuffer(SerialBuffer& serialBuffer) { FW_ASSERT(this->m_header.m_type == T_START); { - const SerializeStatus status = - serialBuffer.deserialize(this->m_fileSize); + const SerializeStatus status = serialBuffer.deserialize(this->m_fileSize); - if (status != FW_SERIALIZE_OK) { - return status; - } + if (status != FW_SERIALIZE_OK) { + return status; + } } { - const SerializeStatus status = - this->m_sourcePath.fromSerialBuffer(serialBuffer); + const SerializeStatus status = this->m_sourcePath.fromSerialBuffer(serialBuffer); - if (status != FW_SERIALIZE_OK) { - return status; - } + if (status != FW_SERIALIZE_OK) { + return status; + } } { - const SerializeStatus status = - this->m_destinationPath.fromSerialBuffer(serialBuffer); + const SerializeStatus status = this->m_destinationPath.fromSerialBuffer(serialBuffer); - if (status != FW_SERIALIZE_OK) { - return status; - } + if (status != FW_SERIALIZE_OK) { + return status; + } } return FW_SERIALIZE_OK; +} - } - - SerializeStatus FilePacket::StartPacket :: - toSerialBuffer(SerialBuffer& serialBuffer) const - { - +SerializeStatus FilePacket::StartPacket ::toSerialBuffer(SerialBuffer& serialBuffer) const { FW_ASSERT(this->m_header.m_type == T_START); { - const SerializeStatus status = - this->m_header.toSerialBuffer(serialBuffer); + const SerializeStatus status = this->m_header.toSerialBuffer(serialBuffer); - if (status != FW_SERIALIZE_OK) { - return status; - } + if (status != FW_SERIALIZE_OK) { + return status; + } } { - const SerializeStatus status = - serialBuffer.serialize(this->m_fileSize); + const SerializeStatus status = serialBuffer.serialize(this->m_fileSize); - if (status != FW_SERIALIZE_OK) { - return status; - } + if (status != FW_SERIALIZE_OK) { + return status; + } } { - const SerializeStatus status = - this->m_sourcePath.toSerialBuffer(serialBuffer); + const SerializeStatus status = this->m_sourcePath.toSerialBuffer(serialBuffer); - if (status != FW_SERIALIZE_OK) { - return status; - } + if (status != FW_SERIALIZE_OK) { + return status; + } } { - const SerializeStatus status = - this->m_destinationPath.toSerialBuffer(serialBuffer); + const SerializeStatus status = this->m_destinationPath.toSerialBuffer(serialBuffer); - if (status != FW_SERIALIZE_OK) { - return status; - } + if (status != FW_SERIALIZE_OK) { + return status; + } } return FW_SERIALIZE_OK; - - } - } + +} // namespace Fw diff --git a/Fw/FilePacket/test/ut/FilePacketMain.cpp b/Fw/FilePacket/test/ut/FilePacketMain.cpp index 02a8621cd64..c3aa5db211a 100644 --- a/Fw/FilePacket/test/ut/FilePacketMain.cpp +++ b/Fw/FilePacket/test/ut/FilePacketMain.cpp @@ -11,184 +11,148 @@ namespace Fw { - class FilePacketTester{ - public: - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- - FilePacketTester(){} +class FilePacketTester { + public: + // ---------------------------------------------------------------------- + // Construction and destruction + // ---------------------------------------------------------------------- + FilePacketTester() {} - ~FilePacketTester(){} + ~FilePacketTester() {} - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- - void test_Header() - { - // const FilePacket::Header expected = { - // FilePacket::T_DATA, // Packet type - // 10 // Sequence number - // }; - Fw::FilePacket::Header expected; - expected.initialize(FilePacket::T_DATA, 10); - const U32 size = expected.bufferSize(); - U8 bytes[size]; - SerialBuffer serialBuffer(bytes, size); - { - const SerializeStatus status = - expected.toSerialBuffer(serialBuffer); - FW_ASSERT(status == FW_SERIALIZE_OK); - } - FilePacket::Header actual; - { - const SerializeStatus status = - actual.fromSerialBuffer(serialBuffer); - FW_ASSERT(status == FW_SERIALIZE_OK); - } - GTest::FilePackets::Header::compare( - expected, - actual - ); - } - }; + // ---------------------------------------------------------------------- + // Tests + // ---------------------------------------------------------------------- + void test_Header() { + // const FilePacket::Header expected = { + // FilePacket::T_DATA, // Packet type + // 10 // Sequence number + // }; + Fw::FilePacket::Header expected; + expected.initialize(FilePacket::T_DATA, 10); + const U32 size = expected.bufferSize(); + U8 bytes[size]; + SerialBuffer serialBuffer(bytes, size); + { + const SerializeStatus status = expected.toSerialBuffer(serialBuffer); + FW_ASSERT(status == FW_SERIALIZE_OK); + } + FilePacket::Header actual; + { + const SerializeStatus status = actual.fromSerialBuffer(serialBuffer); + FW_ASSERT(status == FW_SERIALIZE_OK); + } + GTest::FilePackets::Header::compare(expected, actual); + } +}; - // Serialize and deserialize a file packet header - TEST(FilePacket, Header) { +// Serialize and deserialize a file packet header +TEST(FilePacket, Header) { FilePacketTester tester; tester.test_Header(); - } - +} - // Serialize and deserialize a start packet - TEST(FilePacket, StartPacket) { +// Serialize and deserialize a start packet +TEST(FilePacket, StartPacket) { FilePacket::StartPacket expected; - expected.initialize( - 10, // File size - "source", // Source path - "dest" // Destination path + expected.initialize(10, // File size + "source", // Source path + "dest" // Destination path ); const U32 size = expected.bufferSize(); U8 bytes[size]; Buffer buffer(bytes, size); SerialBuffer serialBuffer(bytes, size); { - const SerializeStatus status = - expected.toBuffer(buffer); - ASSERT_EQ(status, FW_SERIALIZE_OK); + const SerializeStatus status = expected.toBuffer(buffer); + ASSERT_EQ(status, FW_SERIALIZE_OK); } FilePacket actual; { - const SerializeStatus status = - actual.fromBuffer(buffer); - ASSERT_EQ(status, FW_SERIALIZE_OK); + const SerializeStatus status = actual.fromBuffer(buffer); + ASSERT_EQ(status, FW_SERIALIZE_OK); } - const FilePacket::StartPacket& actualStartPacket = - actual.asStartPacket(); - GTest::FilePackets::StartPacket::compare( - expected, - actualStartPacket - ); - } + const FilePacket::StartPacket& actualStartPacket = actual.asStartPacket(); + GTest::FilePackets::StartPacket::compare(expected, actualStartPacket); +} - // Serialize and deserialize a data packet - TEST(FilePacket, DataPacket) { +// Serialize and deserialize a data packet +TEST(FilePacket, DataPacket) { FilePacket::DataPacket expected; const U32 dataSize = 10; - U8 data[dataSize] = {}; // Initialize to appease valgrind - expected.initialize( - 3, // Sequence index - 42, // Byte offset - dataSize, // Data size - data // Data + U8 data[dataSize] = {}; // Initialize to appease valgrind + expected.initialize(3, // Sequence index + 42, // Byte offset + dataSize, // Data size + data // Data ); const U32 size = expected.bufferSize(); U8 bytes[size]; Buffer buffer(bytes, size); SerialBuffer serialBuffer(bytes, size); { - const SerializeStatus status = - expected.toBuffer(buffer); - FW_ASSERT(status == FW_SERIALIZE_OK); + const SerializeStatus status = expected.toBuffer(buffer); + FW_ASSERT(status == FW_SERIALIZE_OK); } FilePacket actual; { - const SerializeStatus status = - actual.fromBuffer(buffer); - FW_ASSERT(status == FW_SERIALIZE_OK); + const SerializeStatus status = actual.fromBuffer(buffer); + FW_ASSERT(status == FW_SERIALIZE_OK); } - const FilePacket::DataPacket& actualDataPacket = - actual.asDataPacket(); - GTest::FilePackets::DataPacket::compare( - expected, - actualDataPacket - ); - } + const FilePacket::DataPacket& actualDataPacket = actual.asDataPacket(); + GTest::FilePackets::DataPacket::compare(expected, actualDataPacket); +} - // Serialize and deserialize an end packet - TEST(FilePacket, EndPacket) { +// Serialize and deserialize an end packet +TEST(FilePacket, EndPacket) { FilePacket::EndPacket expected; const CFDP::Checksum checksum(42); - expected.initialize( - 15, // Sequence index - checksum // Checksum + expected.initialize(15, // Sequence index + checksum // Checksum ); const U32 size = expected.bufferSize(); U8 bytes[size]; Buffer buffer(bytes, size); SerialBuffer serialBuffer(bytes, size); { - const SerializeStatus status = - expected.toBuffer(buffer); - FW_ASSERT(status == FW_SERIALIZE_OK); + const SerializeStatus status = expected.toBuffer(buffer); + FW_ASSERT(status == FW_SERIALIZE_OK); } FilePacket actual; { - const SerializeStatus status = - actual.fromBuffer(buffer); - FW_ASSERT(status == FW_SERIALIZE_OK); + const SerializeStatus status = actual.fromBuffer(buffer); + FW_ASSERT(status == FW_SERIALIZE_OK); } - const FilePacket::EndPacket& actualEndPacket = - actual.asEndPacket(); - GTest::FilePackets::EndPacket::compare( - expected, - actualEndPacket - ); - } + const FilePacket::EndPacket& actualEndPacket = actual.asEndPacket(); + GTest::FilePackets::EndPacket::compare(expected, actualEndPacket); +} - // Serialize and deserialize an end packet - TEST(FilePacket, CancelPacket) { +// Serialize and deserialize an end packet +TEST(FilePacket, CancelPacket) { FilePacket::CancelPacket expected; const CFDP::Checksum checksum(42); - expected.initialize( - 10 // Sequence index + expected.initialize(10 // Sequence index ); const U32 size = expected.bufferSize(); U8 bytes[size]; Buffer buffer(bytes, size); SerialBuffer serialBuffer(bytes, size); { - const SerializeStatus status = - expected.toBuffer(buffer); - FW_ASSERT(status == FW_SERIALIZE_OK); + const SerializeStatus status = expected.toBuffer(buffer); + FW_ASSERT(status == FW_SERIALIZE_OK); } FilePacket actual; { - const SerializeStatus status = - actual.fromBuffer(buffer); - FW_ASSERT(status == FW_SERIALIZE_OK); + const SerializeStatus status = actual.fromBuffer(buffer); + FW_ASSERT(status == FW_SERIALIZE_OK); } - const FilePacket::CancelPacket& actualCancelPacket = - actual.asCancelPacket(); - GTest::FilePackets::CancelPacket::compare( - expected, - actualCancelPacket - ); - } - + const FilePacket::CancelPacket& actualCancelPacket = actual.asCancelPacket(); + GTest::FilePackets::CancelPacket::compare(expected, actualCancelPacket); } -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} +} // namespace Fw +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/Fw/Fpy/StatementArgBuffer.cpp b/Fw/Fpy/StatementArgBuffer.cpp index 3c87e930f64..79e1bd5f034 100644 --- a/Fw/Fpy/StatementArgBuffer.cpp +++ b/Fw/Fpy/StatementArgBuffer.cpp @@ -4,69 +4,66 @@ namespace Fw { - StatementArgBuffer::StatementArgBuffer(const U8 *args, FwSizeType size) { - SerializeStatus stat = SerializeBufferBase::setBuff(args,size); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); - } +StatementArgBuffer::StatementArgBuffer(const U8* args, FwSizeType size) { + SerializeStatus stat = SerializeBufferBase::setBuff(args, size); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +} - StatementArgBuffer::StatementArgBuffer() { - } +StatementArgBuffer::StatementArgBuffer() {} - StatementArgBuffer::~StatementArgBuffer() { - } +StatementArgBuffer::~StatementArgBuffer() {} - StatementArgBuffer::StatementArgBuffer(const StatementArgBuffer& other) : Fw::SerializeBufferBase() { - SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); - } - - StatementArgBuffer& StatementArgBuffer::operator=(const StatementArgBuffer& other) { - if(this == &other) { - return *this; - } +StatementArgBuffer::StatementArgBuffer(const StatementArgBuffer& other) : Fw::SerializeBufferBase() { + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +} - SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); +StatementArgBuffer& StatementArgBuffer::operator=(const StatementArgBuffer& other) { + if (this == &other) { return *this; } - Serializable::SizeType StatementArgBuffer::getBuffCapacity() const { - return sizeof(this->m_bufferData); - } + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); + return *this; +} - const U8* StatementArgBuffer::getBuffAddr() const { - return this->m_bufferData; - } +Serializable::SizeType StatementArgBuffer::getBuffCapacity() const { + return sizeof(this->m_bufferData); +} - U8* StatementArgBuffer::getBuffAddr() { - return this->m_bufferData; - } +const U8* StatementArgBuffer::getBuffAddr() const { + return this->m_bufferData; +} - bool StatementArgBuffer::operator==(const StatementArgBuffer& other) const { - if (this->getBuffLength() != other.getBuffLength()) { - return false; - } +U8* StatementArgBuffer::getBuffAddr() { + return this->m_bufferData; +} - const U8* us = this->getBuffAddr(); - const U8* them = other.getBuffAddr(); +bool StatementArgBuffer::operator==(const StatementArgBuffer& other) const { + if (this->getBuffLength() != other.getBuffLength()) { + return false; + } - FW_ASSERT(us); - FW_ASSERT(them); + const U8* us = this->getBuffAddr(); + const U8* them = other.getBuffAddr(); - for (Serializable::SizeType byte = 0; byte < this->getBuffLength(); byte++) { - if (us[byte] != them[byte]) { - return false; - } - } + FW_ASSERT(us); + FW_ASSERT(them); - return true; + for (Serializable::SizeType byte = 0; byte < this->getBuffLength(); byte++) { + if (us[byte] != them[byte]) { + return false; + } } -#if FW_SERIALIZABLE_TO_STRING - void StatementArgBuffer::toString(Fw::StringBase& text) const { - static const char * formatString = "(data = %p, size = %" PRI_FwSizeType ")"; - text.format(formatString, &this->m_bufferData, this->getBuffLength()); - } -#endif + return true; } +#if FW_SERIALIZABLE_TO_STRING +void StatementArgBuffer::toString(Fw::StringBase& text) const { + static const char* formatString = "(data = %p, size = %" PRI_FwSizeType ")"; + text.format(formatString, &this->m_bufferData, this->getBuffLength()); +} +#endif +} // namespace Fw diff --git a/Fw/Fpy/StatementArgBuffer.hpp b/Fw/Fpy/StatementArgBuffer.hpp index bfea6c8d7d7..0aaf0f0e0f7 100644 --- a/Fw/Fpy/StatementArgBuffer.hpp +++ b/Fw/Fpy/StatementArgBuffer.hpp @@ -2,37 +2,36 @@ #define FW_STATEMENT_BUFFER_HPP #include -#include #include +#include namespace Fw { - class StatementArgBuffer : public SerializeBufferBase { - public: - - enum { - SERIALIZED_TYPE_ID = FW_TYPEID_TLM_BUFF, - SERIALIZED_SIZE = FW_STATEMENT_ARG_BUFFER_MAX_SIZE + sizeof(FwBuffSizeType) - }; - - StatementArgBuffer(const U8 *args, FwSizeType size); - StatementArgBuffer(); - StatementArgBuffer(const StatementArgBuffer& other); - virtual ~StatementArgBuffer(); - StatementArgBuffer& operator=(const StatementArgBuffer& other); - - Serializable::SizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer - U8* getBuffAddr(); - const U8* getBuffAddr() const; - bool operator==(const StatementArgBuffer& other) const; - - #if FW_SERIALIZABLE_TO_STRING - void toString(Fw::StringBase& text) const; - #endif - private: - U8 m_bufferData[FW_STATEMENT_ARG_BUFFER_MAX_SIZE]; // command argument buffer +class StatementArgBuffer : public SerializeBufferBase { + public: + enum { + SERIALIZED_TYPE_ID = FW_TYPEID_TLM_BUFF, + SERIALIZED_SIZE = FW_STATEMENT_ARG_BUFFER_MAX_SIZE + sizeof(FwBuffSizeType) }; -} + StatementArgBuffer(const U8* args, FwSizeType size); + StatementArgBuffer(); + StatementArgBuffer(const StatementArgBuffer& other); + virtual ~StatementArgBuffer(); + StatementArgBuffer& operator=(const StatementArgBuffer& other); + + Serializable::SizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer + U8* getBuffAddr(); + const U8* getBuffAddr() const; + bool operator==(const StatementArgBuffer& other) const; + +#if FW_SERIALIZABLE_TO_STRING + void toString(Fw::StringBase& text) const; +#endif + private: + U8 m_bufferData[FW_STATEMENT_ARG_BUFFER_MAX_SIZE]; // command argument buffer +}; + +} // namespace Fw #endif diff --git a/Fw/Log/AmpcsEvrLogPacket.cpp b/Fw/Log/AmpcsEvrLogPacket.cpp index 629ed7bede7..25bfd6145ad 100644 --- a/Fw/Log/AmpcsEvrLogPacket.cpp +++ b/Fw/Log/AmpcsEvrLogPacket.cpp @@ -11,132 +11,126 @@ namespace Fw { - AmpcsEvrLogPacket::AmpcsEvrLogPacket() : - m_eventID(0), - m_overSeqNum(0), - m_catSeqNum(0) { - this->m_type = FW_PACKET_LOG; - } +AmpcsEvrLogPacket::AmpcsEvrLogPacket() : m_eventID(0), m_overSeqNum(0), m_catSeqNum(0) { + this->m_type = FW_PACKET_LOG; +} - AmpcsEvrLogPacket::~AmpcsEvrLogPacket() { - } +AmpcsEvrLogPacket::~AmpcsEvrLogPacket() {} - SerializeStatus AmpcsEvrLogPacket::serialize(SerializeBufferBase& buffer) const { - // Deprecated method - calls new interface for backward compatibility - return this->serializeTo(buffer); - } +SerializeStatus AmpcsEvrLogPacket::serialize(SerializeBufferBase& buffer) const { + // Deprecated method - calls new interface for backward compatibility + return this->serializeTo(buffer); +} - SerializeStatus AmpcsEvrLogPacket::deserialize(SerializeBufferBase& buffer) { - // Deprecated method - calls new interface for backward compatibility - return this->deserializeFrom(buffer); - } +SerializeStatus AmpcsEvrLogPacket::deserialize(SerializeBufferBase& buffer) { + // Deprecated method - calls new interface for backward compatibility + return this->deserializeFrom(buffer); +} - SerializeStatus AmpcsEvrLogPacket::serializeTo(SerializeBufferBase& buffer) const { +SerializeStatus AmpcsEvrLogPacket::serializeTo(SerializeBufferBase& buffer) const { + SerializeStatus stat; - SerializeStatus stat; + stat = buffer.serialize(this->m_taskName, AMPCS_EVR_TASK_NAME_LEN, Fw::Serialization::OMIT_LENGTH); + if (stat != FW_SERIALIZE_OK) { + return stat; + } - stat = buffer.serialize(this->m_taskName, AMPCS_EVR_TASK_NAME_LEN, Fw::Serialization::OMIT_LENGTH); - if (stat != FW_SERIALIZE_OK) { - return stat; - } + stat = buffer.serialize(this->m_eventID); + if (stat != FW_SERIALIZE_OK) { + return stat; + } - stat = buffer.serialize(this->m_eventID); - if (stat != FW_SERIALIZE_OK) { - return stat; - } + stat = buffer.serialize(this->m_overSeqNum); + if (stat != FW_SERIALIZE_OK) { + return stat; + } - stat = buffer.serialize(this->m_overSeqNum); - if (stat != FW_SERIALIZE_OK) { - return stat; - } + stat = buffer.serialize(this->m_catSeqNum); + if (stat != FW_SERIALIZE_OK) { + return stat; + } - stat = buffer.serialize(this->m_catSeqNum); - if (stat != FW_SERIALIZE_OK) { - return stat; - } + return buffer.serialize(this->m_logBuffer.getBuffAddr(), m_logBuffer.getBuffLength(), + Fw::Serialization::OMIT_LENGTH); +} - return buffer.serialize(this->m_logBuffer.getBuffAddr(),m_logBuffer.getBuffLength(),Fw::Serialization::OMIT_LENGTH); +SerializeStatus AmpcsEvrLogPacket::deserializeFrom(SerializeBufferBase& buffer) { + FwSizeType len; - } + SerializeStatus stat; - SerializeStatus AmpcsEvrLogPacket::deserializeFrom(SerializeBufferBase& buffer) { - FwSizeType len; - - SerializeStatus stat; - - len = AMPCS_EVR_TASK_NAME_LEN; - stat = buffer.deserialize(this->m_taskName, len, true); - if (stat != FW_SERIALIZE_OK) { - return stat; - } - - stat = buffer.deserialize(this->m_eventID); - if (stat != FW_SERIALIZE_OK) { - return stat; - } - - stat = buffer.deserialize(this->m_overSeqNum); - if (stat != FW_SERIALIZE_OK) { - return stat; - } - - stat = buffer.deserialize(this->m_catSeqNum); - if (stat != FW_SERIALIZE_OK) { - return stat; - } - - FwSizeType size = buffer.getBuffLeft(); - stat = buffer.deserialize(this->m_logBuffer.getBuffAddr(),size,true); - if (stat == FW_SERIALIZE_OK) { - // Shouldn't fail - stat = this->m_logBuffer.setBuffLen(size); - FW_ASSERT(stat == FW_SERIALIZE_OK,static_cast(stat)); - } + len = AMPCS_EVR_TASK_NAME_LEN; + stat = buffer.deserialize(this->m_taskName, len, true); + if (stat != FW_SERIALIZE_OK) { return stat; } - void AmpcsEvrLogPacket::setTaskName(U8 *taskName, U8 len) { - FW_ASSERT(taskName != nullptr); - FW_ASSERT(len == AMPCS_EVR_TASK_NAME_LEN); - - memcpy(this->m_taskName, (const void*)taskName, len); + stat = buffer.deserialize(this->m_eventID); + if (stat != FW_SERIALIZE_OK) { + return stat; } - void AmpcsEvrLogPacket::setId(U32 eventID) { - this->m_eventID = eventID; + stat = buffer.deserialize(this->m_overSeqNum); + if (stat != FW_SERIALIZE_OK) { + return stat; } - void AmpcsEvrLogPacket::setOverSeqNum(U32 overSeqNum) { - this->m_overSeqNum = overSeqNum; + stat = buffer.deserialize(this->m_catSeqNum); + if (stat != FW_SERIALIZE_OK) { + return stat; } - void AmpcsEvrLogPacket::setCatSeqNum(U32 catSeqNum) { - this->m_catSeqNum = catSeqNum; + FwSizeType size = buffer.getBuffLeft(); + stat = buffer.deserialize(this->m_logBuffer.getBuffAddr(), size, true); + if (stat == FW_SERIALIZE_OK) { + // Shouldn't fail + stat = this->m_logBuffer.setBuffLen(size); + FW_ASSERT(stat == FW_SERIALIZE_OK, static_cast(stat)); } + return stat; +} - void AmpcsEvrLogPacket::setLogBuffer(LogBuffer& buffer) { - this->m_logBuffer = buffer; - } +void AmpcsEvrLogPacket::setTaskName(U8* taskName, U8 len) { + FW_ASSERT(taskName != nullptr); + FW_ASSERT(len == AMPCS_EVR_TASK_NAME_LEN); - const U8* AmpcsEvrLogPacket::getTaskName() const { - return this->m_taskName; - } + memcpy(this->m_taskName, (const void*)taskName, len); +} - U32 AmpcsEvrLogPacket::getId() const { - return this->m_eventID; - } +void AmpcsEvrLogPacket::setId(U32 eventID) { + this->m_eventID = eventID; +} - U32 AmpcsEvrLogPacket::getOverSeqNum() const { - return this->m_overSeqNum; - } +void AmpcsEvrLogPacket::setOverSeqNum(U32 overSeqNum) { + this->m_overSeqNum = overSeqNum; +} - U32 AmpcsEvrLogPacket::getCatSeqNum() const { - return this->m_catSeqNum; - } +void AmpcsEvrLogPacket::setCatSeqNum(U32 catSeqNum) { + this->m_catSeqNum = catSeqNum; +} - LogBuffer& AmpcsEvrLogPacket::getLogBuffer() { - return this->m_logBuffer; - } +void AmpcsEvrLogPacket::setLogBuffer(LogBuffer& buffer) { + this->m_logBuffer = buffer; +} + +const U8* AmpcsEvrLogPacket::getTaskName() const { + return this->m_taskName; +} + +U32 AmpcsEvrLogPacket::getId() const { + return this->m_eventID; +} + +U32 AmpcsEvrLogPacket::getOverSeqNum() const { + return this->m_overSeqNum; +} + +U32 AmpcsEvrLogPacket::getCatSeqNum() const { + return this->m_catSeqNum; +} +LogBuffer& AmpcsEvrLogPacket::getLogBuffer() { + return this->m_logBuffer; +} } /* namespace Fw */ diff --git a/Fw/Log/AmpcsEvrLogPacket.hpp b/Fw/Log/AmpcsEvrLogPacket.hpp index ccb95353b16..651ca6eb487 100644 --- a/Fw/Log/AmpcsEvrLogPacket.hpp +++ b/Fw/Log/AmpcsEvrLogPacket.hpp @@ -18,37 +18,36 @@ namespace Fw { - class AmpcsEvrLogPacket : public ComPacket { - public: - - AmpcsEvrLogPacket(); - virtual ~AmpcsEvrLogPacket(); - - SerializeStatus serialize(SerializeBufferBase& buffer) const override; //!< serialize contents - SerializeStatus deserialize(SerializeBufferBase& buffer) override; - - SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; //!< serialize contents - SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; - - void setTaskName(U8 *taskName, U8 len); - void setId(U32 eventID); - void setOverSeqNum(U32 overSeqNum); - void setCatSeqNum(U32 catSeqNum); - void setLogBuffer(LogBuffer& buffer); - - const U8* getTaskName() const; - U32 getId() const; - U32 getOverSeqNum() const; - U32 getCatSeqNum() const; - LogBuffer& getLogBuffer(); - - protected: - U8 m_taskName[AMPCS_EVR_TASK_NAME_LEN]; - U32 m_eventID; - U32 m_overSeqNum; - U32 m_catSeqNum; - LogBuffer m_logBuffer; // !< serialized argument data - }; +class AmpcsEvrLogPacket : public ComPacket { + public: + AmpcsEvrLogPacket(); + virtual ~AmpcsEvrLogPacket(); + + SerializeStatus serialize(SerializeBufferBase& buffer) const override; //!< serialize contents + SerializeStatus deserialize(SerializeBufferBase& buffer) override; + + SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; //!< serialize contents + SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; + + void setTaskName(U8* taskName, U8 len); + void setId(U32 eventID); + void setOverSeqNum(U32 overSeqNum); + void setCatSeqNum(U32 catSeqNum); + void setLogBuffer(LogBuffer& buffer); + + const U8* getTaskName() const; + U32 getId() const; + U32 getOverSeqNum() const; + U32 getCatSeqNum() const; + LogBuffer& getLogBuffer(); + + protected: + U8 m_taskName[AMPCS_EVR_TASK_NAME_LEN]; + U32 m_eventID; + U32 m_overSeqNum; + U32 m_catSeqNum; + LogBuffer m_logBuffer; // !< serialized argument data +}; } /* namespace Fw */ diff --git a/Fw/Log/LogBuffer.cpp b/Fw/Log/LogBuffer.cpp index e85534c6da1..9a7be1511f9 100644 --- a/Fw/Log/LogBuffer.cpp +++ b/Fw/Log/LogBuffer.cpp @@ -3,43 +3,40 @@ namespace Fw { - LogBuffer::LogBuffer(const U8 *args, FwSizeType size) { - SerializeStatus stat = SerializeBufferBase::setBuff(args,size); - FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); - } +LogBuffer::LogBuffer(const U8* args, FwSizeType size) { + SerializeStatus stat = SerializeBufferBase::setBuff(args, size); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +} - LogBuffer::LogBuffer() { - } +LogBuffer::LogBuffer() {} - LogBuffer::~LogBuffer() { - } +LogBuffer::~LogBuffer() {} - LogBuffer::LogBuffer(const LogBuffer& other) : Fw::SerializeBufferBase() { - SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); - FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); - } - - LogBuffer& LogBuffer::operator=(const LogBuffer& other) { - if(this == &other) { - return *this; - } +LogBuffer::LogBuffer(const LogBuffer& other) : Fw::SerializeBufferBase() { + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +} - SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); - FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +LogBuffer& LogBuffer::operator=(const LogBuffer& other) { + if (this == &other) { return *this; } - FwSizeType LogBuffer::getBuffCapacity() const { - return sizeof(this->m_bufferData); - } + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); + return *this; +} - const U8* LogBuffer::getBuffAddr() const { - return this->m_bufferData; - } +FwSizeType LogBuffer::getBuffCapacity() const { + return sizeof(this->m_bufferData); +} - U8* LogBuffer::getBuffAddr() { - return this->m_bufferData; - } +const U8* LogBuffer::getBuffAddr() const { + return this->m_bufferData; +} +U8* LogBuffer::getBuffAddr() { + return this->m_bufferData; } +} // namespace Fw diff --git a/Fw/Log/LogBuffer.hpp b/Fw/Log/LogBuffer.hpp index c5d4125106e..e8845681030 100644 --- a/Fw/Log/LogBuffer.hpp +++ b/Fw/Log/LogBuffer.hpp @@ -13,33 +13,29 @@ #define FW_LOG_BUFFER_HPP #include -#include #include +#include namespace Fw { - class LogBuffer final : public SerializeBufferBase { - public: - - enum { - SERIALIZED_TYPE_ID = FW_TYPEID_LOG_BUFF, - SERIALIZED_SIZE = FW_LOG_BUFFER_MAX_SIZE + sizeof(FwBuffSizeType) - }; +class LogBuffer final : public SerializeBufferBase { + public: + enum { SERIALIZED_TYPE_ID = FW_TYPEID_LOG_BUFF, SERIALIZED_SIZE = FW_LOG_BUFFER_MAX_SIZE + sizeof(FwBuffSizeType) }; - LogBuffer(const U8 *args, FwSizeType size); - LogBuffer(); - LogBuffer(const LogBuffer& other); - virtual ~LogBuffer(); - LogBuffer& operator=(const LogBuffer& other); + LogBuffer(const U8* args, FwSizeType size); + LogBuffer(); + LogBuffer(const LogBuffer& other); + virtual ~LogBuffer(); + LogBuffer& operator=(const LogBuffer& other); - FwSizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer - U8* getBuffAddr(); - const U8* getBuffAddr() const; + FwSizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer + U8* getBuffAddr(); + const U8* getBuffAddr() const; - private: - U8 m_bufferData[FW_LOG_BUFFER_MAX_SIZE]; // command argument buffer - }; + private: + U8 m_bufferData[FW_LOG_BUFFER_MAX_SIZE]; // command argument buffer +}; -} +} // namespace Fw #endif diff --git a/Fw/Log/LogPacket.cpp b/Fw/Log/LogPacket.cpp index c1fcdf4787b..c584600defe 100644 --- a/Fw/Log/LogPacket.cpp +++ b/Fw/Log/LogPacket.cpp @@ -10,93 +10,92 @@ namespace Fw { - LogPacket::LogPacket() : m_id(0) { - this->m_type = ComPacketType::FW_PACKET_LOG; - } +LogPacket::LogPacket() : m_id(0) { + this->m_type = ComPacketType::FW_PACKET_LOG; +} - LogPacket::~LogPacket() { - } +LogPacket::~LogPacket() {} - SerializeStatus LogPacket::serialize(SerializeBufferBase& buffer) const { - // Deprecated method - calls new interface for backward compatibility - return this->serializeTo(buffer); - } +SerializeStatus LogPacket::serialize(SerializeBufferBase& buffer) const { + // Deprecated method - calls new interface for backward compatibility + return this->serializeTo(buffer); +} + +SerializeStatus LogPacket::deserialize(SerializeBufferBase& buffer) { + // Deprecated method - calls new interface for backward compatibility + return this->deserializeFrom(buffer); +} - SerializeStatus LogPacket::deserialize(SerializeBufferBase& buffer) { - // Deprecated method - calls new interface for backward compatibility - return this->deserializeFrom(buffer); +SerializeStatus LogPacket::serializeTo(SerializeBufferBase& buffer) const { + SerializeStatus stat = ComPacket::serializeBase(buffer); + if (stat != FW_SERIALIZE_OK) { + return stat; } - SerializeStatus LogPacket::serializeTo(SerializeBufferBase& buffer) const { - SerializeStatus stat = ComPacket::serializeBase(buffer); - if (stat != FW_SERIALIZE_OK) { - return stat; - } + stat = buffer.serialize(this->m_id); + if (stat != FW_SERIALIZE_OK) { + return stat; + } - stat = buffer.serialize(this->m_id); - if (stat != FW_SERIALIZE_OK) { - return stat; - } + stat = buffer.serialize(this->m_timeTag); + if (stat != FW_SERIALIZE_OK) { + return stat; + } - stat = buffer.serialize(this->m_timeTag); - if (stat != FW_SERIALIZE_OK) { - return stat; - } + // We want to add data but not size for the ground software + return buffer.serialize(this->m_logBuffer.getBuffAddr(), m_logBuffer.getBuffLength(), + Fw::Serialization::OMIT_LENGTH); +} - // We want to add data but not size for the ground software - return buffer.serialize(this->m_logBuffer.getBuffAddr(),m_logBuffer.getBuffLength(),Fw::Serialization::OMIT_LENGTH); +SerializeStatus LogPacket::deserializeFrom(SerializeBufferBase& buffer) { + SerializeStatus stat = deserializeBase(buffer); + if (stat != FW_SERIALIZE_OK) { + return stat; } - SerializeStatus LogPacket::deserializeFrom(SerializeBufferBase& buffer) { - SerializeStatus stat = deserializeBase(buffer); - if (stat != FW_SERIALIZE_OK) { - return stat; - } - - stat = buffer.deserialize(this->m_id); - if (stat != FW_SERIALIZE_OK) { - return stat; - } - - stat = buffer.deserialize(this->m_timeTag); - if (stat != FW_SERIALIZE_OK) { - return stat; - } - - // remainder of buffer must be telemetry value - FwSizeType size = buffer.getBuffLeft(); - stat = buffer.deserialize(this->m_logBuffer.getBuffAddr(),size,Fw::Serialization::OMIT_LENGTH); - if (stat == FW_SERIALIZE_OK) { - // Shouldn't fail - stat = this->m_logBuffer.setBuffLen(size); - FW_ASSERT(stat == FW_SERIALIZE_OK,static_cast(stat)); - } + stat = buffer.deserialize(this->m_id); + if (stat != FW_SERIALIZE_OK) { return stat; } - void LogPacket::setId(FwEventIdType id) { - this->m_id = id; + stat = buffer.deserialize(this->m_timeTag); + if (stat != FW_SERIALIZE_OK) { + return stat; } - void LogPacket::setLogBuffer(const LogBuffer& buffer) { - this->m_logBuffer = buffer; + // remainder of buffer must be telemetry value + FwSizeType size = buffer.getBuffLeft(); + stat = buffer.deserialize(this->m_logBuffer.getBuffAddr(), size, Fw::Serialization::OMIT_LENGTH); + if (stat == FW_SERIALIZE_OK) { + // Shouldn't fail + stat = this->m_logBuffer.setBuffLen(size); + FW_ASSERT(stat == FW_SERIALIZE_OK, static_cast(stat)); } + return stat; +} - void LogPacket::setTimeTag(const Fw::Time& timeTag) { - this->m_timeTag = timeTag; - } +void LogPacket::setId(FwEventIdType id) { + this->m_id = id; +} - FwEventIdType LogPacket::getId() { - return this->m_id; - } +void LogPacket::setLogBuffer(const LogBuffer& buffer) { + this->m_logBuffer = buffer; +} - Fw::Time& LogPacket::getTimeTag() { - return this->m_timeTag; - } +void LogPacket::setTimeTag(const Fw::Time& timeTag) { + this->m_timeTag = timeTag; +} - LogBuffer& LogPacket::getLogBuffer() { - return this->m_logBuffer; - } +FwEventIdType LogPacket::getId() { + return this->m_id; +} + +Fw::Time& LogPacket::getTimeTag() { + return this->m_timeTag; +} +LogBuffer& LogPacket::getLogBuffer() { + return this->m_logBuffer; +} } /* namespace Fw */ diff --git a/Fw/Log/LogPacket.hpp b/Fw/Log/LogPacket.hpp index a6c3fe68e24..a613cf37309 100644 --- a/Fw/Log/LogPacket.hpp +++ b/Fw/Log/LogPacket.hpp @@ -14,31 +14,30 @@ namespace Fw { - class LogPacket : public ComPacket { - public: - - LogPacket(); - virtual ~LogPacket(); - - SerializeStatus serialize(SerializeBufferBase& buffer) const override; //!< serialize contents - SerializeStatus deserialize(SerializeBufferBase& buffer) override; - - SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; //!< serialize contents - SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; - - void setId(FwEventIdType id); - void setLogBuffer(const LogBuffer& buffer); - void setTimeTag(const Fw::Time& timeTag); - - FwEventIdType getId(); - Fw::Time& getTimeTag(); - LogBuffer& getLogBuffer(); - - protected: - FwEventIdType m_id; // !< Channel id - Fw::Time m_timeTag; // !< time tag - LogBuffer m_logBuffer; // !< serialized argument data - }; +class LogPacket : public ComPacket { + public: + LogPacket(); + virtual ~LogPacket(); + + SerializeStatus serialize(SerializeBufferBase& buffer) const override; //!< serialize contents + SerializeStatus deserialize(SerializeBufferBase& buffer) override; + + SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; //!< serialize contents + SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; + + void setId(FwEventIdType id); + void setLogBuffer(const LogBuffer& buffer); + void setTimeTag(const Fw::Time& timeTag); + + FwEventIdType getId(); + Fw::Time& getTimeTag(); + LogBuffer& getLogBuffer(); + + protected: + FwEventIdType m_id; // !< Channel id + Fw::Time m_timeTag; // !< time tag + LogBuffer m_logBuffer; // !< serialized argument data +}; } /* namespace Fw */ diff --git a/Fw/Log/test/ut/LogTest.cpp b/Fw/Log/test/ut/LogTest.cpp index 8491cf6a59a..13e576cefaa 100644 --- a/Fw/Log/test/ut/LogTest.cpp +++ b/Fw/Log/test/ut/LogTest.cpp @@ -1,37 +1,36 @@ #include -#include #include +#include #include -TEST(FwLogTest,LogPacketSerialize) { - +TEST(FwLogTest, LogPacketSerialize) { // Serialize data Fw::LogPacket pktIn; Fw::LogBuffer buffIn; - ASSERT_EQ(Fw::FW_SERIALIZE_OK,buffIn.serialize(static_cast(12))); - Fw::Time timeIn(TimeBase::TB_WORKSTATION_TIME,10,11); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, buffIn.serialize(static_cast(12))); + Fw::Time timeIn(TimeBase::TB_WORKSTATION_TIME, 10, 11); pktIn.setId(10); pktIn.setTimeTag(timeIn); pktIn.setLogBuffer(buffIn); Fw::ComBuffer comBuff; - ASSERT_EQ(Fw::FW_SERIALIZE_OK,comBuff.serialize(pktIn)); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(pktIn)); // Deserialize data Fw::LogPacket pktOut; Fw::LogBuffer buffOut; - Fw::Time timeOut(TimeBase::TB_WORKSTATION_TIME,10,11); + Fw::Time timeOut(TimeBase::TB_WORKSTATION_TIME, 10, 11); - ASSERT_EQ(Fw::FW_SERIALIZE_OK,comBuff.deserialize(pktOut)); - ASSERT_EQ(pktOut.getId(),10u); - ASSERT_EQ(pktOut.getTimeTag(),timeOut); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.deserialize(pktOut)); + ASSERT_EQ(pktOut.getId(), 10u); + ASSERT_EQ(pktOut.getTimeTag(), timeOut); U32 valOut = 0; buffOut = pktOut.getLogBuffer(); buffOut.resetDeser(); - ASSERT_EQ(Fw::FW_SERIALIZE_OK,buffOut.deserialize(valOut)); - ASSERT_EQ(valOut,12u); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, buffOut.deserialize(valOut)); + ASSERT_EQ(valOut, 12u); // serialize string Fw::LogStringArg str1; @@ -41,7 +40,7 @@ TEST(FwLogTest,LogPacketSerialize) { buffOut.resetSer(); str1.serialize(buffOut); str2.deserialize(buffOut); - ASSERT_EQ(str1,str2); + ASSERT_EQ(str1, str2); } int main(int argc, char* argv[]) { diff --git a/Fw/Logger/Logger.hpp b/Fw/Logger/Logger.hpp index 14975e91867..98af188583a 100644 --- a/Fw/Logger/Logger.hpp +++ b/Fw/Logger/Logger.hpp @@ -8,8 +8,8 @@ */ #ifndef Fw_Logger_hpp_ #define Fw_Logger_hpp_ -#include #include +#include #include // Unit testing predeclaration hook diff --git a/Fw/Logger/test/ut/FakeLogger.cpp b/Fw/Logger/test/ut/FakeLogger.cpp index b8a48ceff02..1c66b68a95e 100644 --- a/Fw/Logger/test/ut/FakeLogger.cpp +++ b/Fw/Logger/test/ut/FakeLogger.cpp @@ -12,7 +12,7 @@ namespace MockLogging { Fw::Logger* FakeLogger::s_current = nullptr; -FakeLogger::FakeLogger(): m_last("") {} +FakeLogger::FakeLogger() : m_last("") {} void FakeLogger::writeMessage(const Fw::StringBase& message) { m_last = message.toChar(); diff --git a/Fw/Logger/test/ut/FakeLogger.hpp b/Fw/Logger/test/ut/FakeLogger.hpp index 87f16a96ca9..b32a65af295 100644 --- a/Fw/Logger/test/ut/FakeLogger.hpp +++ b/Fw/Logger/test/ut/FakeLogger.hpp @@ -8,8 +8,8 @@ */ #include -#include #include +#include #include #ifndef FPRIME_FAKELOGGER_HPP @@ -46,5 +46,5 @@ class FakeLogger : public Fw::Logger { //!< Logger to use within the system static Fw::Logger* s_current; }; -} // namespace MockLogging +} // namespace MockLogging #endif // FPRIME_FAKELOGGER_HPP diff --git a/Fw/Logger/test/ut/LoggerRules.hpp b/Fw/Logger/test/ut/LoggerRules.hpp index 150e5214dec..7b603166655 100644 --- a/Fw/Logger/test/ut/LoggerRules.hpp +++ b/Fw/Logger/test/ut/LoggerRules.hpp @@ -87,5 +87,5 @@ struct LogGoodStringObject : public STest::Rule { // Log valid messages void action(MockLogging::FakeLogger& truth); }; -} // namespace LoggerRules +} // namespace LoggerRules #endif // FPRIME_LOGGERRULES_HPP diff --git a/Fw/Obj/ObjBase.cpp b/Fw/Obj/ObjBase.cpp index e6a7ecbd4c2..81be200aa20 100644 --- a/Fw/Obj/ObjBase.cpp +++ b/Fw/Obj/ObjBase.cpp @@ -6,62 +6,58 @@ namespace Fw { #if FW_OBJECT_REGISTRATION == 1 - ObjRegistry* ObjBase::s_objRegistry = nullptr; +ObjRegistry* ObjBase::s_objRegistry = nullptr; #endif #if FW_OBJECT_NAMES == 1 - ObjBase::ObjBase(const char* objName) { - if (nullptr == objName) { - this->setObjName("NoName"); - } else { - this->setObjName(objName); - } +ObjBase::ObjBase(const char* objName) { + if (nullptr == objName) { + this->setObjName("NoName"); + } else { + this->setObjName(objName); } +} #else - ObjBase::ObjBase(const char* objName) { - - } +ObjBase::ObjBase(const char* objName) {} #endif - void ObjBase::init() { +void ObjBase::init() { #if FW_OBJECT_REGISTRATION - if (ObjBase::s_objRegistry) { - ObjBase::s_objRegistry->regObject(this); - } -#endif + if (ObjBase::s_objRegistry) { + ObjBase::s_objRegistry->regObject(this); } +#endif +} - ObjBase::~ObjBase() { - - } +ObjBase::~ObjBase() {} #if FW_OBJECT_NAMES == 1 - const char* ObjBase::getObjName() { - return this->m_objName.toChar(); - } +const char* ObjBase::getObjName() { + return this->m_objName.toChar(); +} - void ObjBase::setObjName(const char* name) { - this->m_objName = name; - } +void ObjBase::setObjName(const char* name) { + this->m_objName = name; +} #if FW_OBJECT_TO_STRING == 1 - void ObjBase::toString(char* str, FwSizeType size) { - FW_ASSERT(size > 0); - FW_ASSERT(str != nullptr); - Fw::FormatStatus formatStatus = Fw::ExternalString(str, static_cast(size)).format("Obj: %s", this->m_objName.toChar()); - if (formatStatus != Fw::FormatStatus::SUCCESS) { - str[0] = 0; - } - } +void ObjBase::toString(char* str, FwSizeType size) { + FW_ASSERT(size > 0); + FW_ASSERT(str != nullptr); + Fw::FormatStatus formatStatus = Fw::ExternalString(str, static_cast(size)) + .format("Obj: %s", this->m_objName.toChar()); + if (formatStatus != Fw::FormatStatus::SUCCESS) { + str[0] = 0; + } +} #endif #endif #if FW_OBJECT_REGISTRATION == 1 - void ObjBase::setObjRegistry(ObjRegistry* reg) { - ObjBase::s_objRegistry = reg; - } +void ObjBase::setObjRegistry(ObjRegistry* reg) { + ObjBase::s_objRegistry = reg; +} - ObjRegistry::~ObjRegistry() { - } +ObjRegistry::~ObjRegistry() {} #endif -} // Fw +} // namespace Fw diff --git a/Fw/Obj/ObjBase.hpp b/Fw/Obj/ObjBase.hpp index 59726b53e36..d4bea9033f3 100644 --- a/Fw/Obj/ObjBase.hpp +++ b/Fw/Obj/ObjBase.hpp @@ -21,122 +21,120 @@ namespace Fw { #if FW_OBJECT_REGISTRATION == 1 - class ObjRegistry; //!< forward declaration for object registry +class ObjRegistry; //!< forward declaration for object registry #endif - //! \class ObjBase - //! \brief Brief class description - //! - //! This class is the base class of the ISF object class hierarchy. - //! Depending on which features of the architecture are enabled, this class: - //! 1) Stores an object name - //! 2) Provides for object registration +//! \class ObjBase +//! \brief Brief class description +//! +//! This class is the base class of the ISF object class hierarchy. +//! Depending on which features of the architecture are enabled, this class: +//! 1) Stores an object name +//! 2) Provides for object registration - class ObjBase { - public: +class ObjBase { + public: #if FW_OBJECT_NAMES == 1 - //! \brief Returns the object's name - //! - //! This function returns a pointer to the name of the object - //! - //! \return object name - const char* getObjName(); //!< Returns object name - - //! \brief Sets the object name - //! - //! This function takes the provided string and copies it - //! to the private buffer containing the name of the object. - //! - //! \param name the name of the object - void setObjName(const char* name); //!< sets object name + //! \brief Returns the object's name + //! + //! This function returns a pointer to the name of the object + //! + //! \return object name + const char* getObjName(); //!< Returns object name + + //! \brief Sets the object name + //! + //! This function takes the provided string and copies it + //! to the private buffer containing the name of the object. + //! + //! \param name the name of the object + void setObjName(const char* name); //!< sets object name #if FW_OBJECT_TO_STRING == 1 - //! \brief Returns a string representation of the object - //! - //! A virtual function defined for all ObjBase types. It is - //! meant to be overridden by subclasses to return a description - //! of the object. The default implementation in this class - //! returns the name of the object. - //! - //! \param str destination buffer where string description is placed - //! \param size destination buffer size (including terminator). String should be terminated - virtual void toString(char* str, FwSizeType size); //!< virtual method to get description of object -#endif // FW_OBJECT_TO_STRING -#endif // FW_OBJECT_NAMES + //! \brief Returns a string representation of the object + //! + //! A virtual function defined for all ObjBase types. It is + //! meant to be overridden by subclasses to return a description + //! of the object. The default implementation in this class + //! returns the name of the object. + //! + //! \param str destination buffer where string description is placed + //! \param size destination buffer size (including terminator). String should be terminated + virtual void toString(char* str, FwSizeType size); //!< virtual method to get description of object +#endif // FW_OBJECT_TO_STRING +#endif // FW_OBJECT_NAMES #if FW_OBJECT_REGISTRATION == 1 - //! \brief static function to set object registry. - //! - //! This function registers an instance of an object registry class (see below). - //! After the registration call is made, any subsequent calls to ObjBase::init() - //! will call the regObject() method on the registry. - //! **NOTE** The call may not be reentrant or thread-safe. The provided - //! SimObjRegistry is not reentrant. - //! - //! \param reg Instance of registry to be stored. - static void setObjRegistry(ObjRegistry* reg); //!< sets the object registry, if desired + //! \brief static function to set object registry. + //! + //! This function registers an instance of an object registry class (see below). + //! After the registration call is made, any subsequent calls to ObjBase::init() + //! will call the regObject() method on the registry. + //! **NOTE** The call may not be reentrant or thread-safe. The provided + //! SimObjRegistry is not reentrant. + //! + //! \param reg Instance of registry to be stored. + static void setObjRegistry(ObjRegistry* reg); //!< sets the object registry, if desired #endif - protected: - + protected: #if FW_OBJECT_NAMES == 1 - Fw::ObjectName m_objName; //!< stores object name + Fw::ObjectName m_objName; //!< stores object name #endif - //! \brief ObjBase constructor - //! - //! The constructor for the base class. Protected so it will only be called - //! by derived classes. Stores the object name (calls setObjName()). - //! - //! \param name Object name - ObjBase(const char* name); - - //! \brief Destructor - //! - //! ObjBase destructor. Empty. - //! - virtual ~ObjBase(); //!< Destructor. Should only be called by derived classes - - //! \brief Object initializer - //! - //! Initializes the object. For the base class, it calls - //! the object registry if registered by setObjRegistry() - //! - void init(); //! #include #include -#include #include #include #include @@ -9,67 +9,61 @@ namespace Fw { - SimpleObjRegistry::SimpleObjRegistry() { - ObjBase::setObjRegistry(this); - this->m_numEntries = 0; - // Initialize pointer array - for (FwSizeType entry = 0; entry < FW_OBJ_SIMPLE_REG_ENTRIES; entry++) { - this->m_objPtrArray[entry] = nullptr; - } +SimpleObjRegistry::SimpleObjRegistry() { + ObjBase::setObjRegistry(this); + this->m_numEntries = 0; + // Initialize pointer array + for (FwSizeType entry = 0; entry < FW_OBJ_SIMPLE_REG_ENTRIES; entry++) { + this->m_objPtrArray[entry] = nullptr; } +} - SimpleObjRegistry::~SimpleObjRegistry() { - ObjBase::setObjRegistry(nullptr); - } +SimpleObjRegistry::~SimpleObjRegistry() { + ObjBase::setObjRegistry(nullptr); +} - void SimpleObjRegistry::dump() { - for (FwSizeType obj = 0; obj < this->m_numEntries; obj++) { +void SimpleObjRegistry::dump() { + for (FwSizeType obj = 0; obj < this->m_numEntries; obj++) { #if FW_OBJECT_NAMES == 1 #if FW_OBJECT_TO_STRING == 1 - char objDump[FW_OBJ_SIMPLE_REG_BUFF_SIZE]; - this->m_objPtrArray[obj]->toString(objDump,sizeof(objDump)); - Fw::Logger::log("Entry: %d Ptr: %p Str: %s\n", obj, - this->m_objPtrArray[obj], objDump); + char objDump[FW_OBJ_SIMPLE_REG_BUFF_SIZE]; + this->m_objPtrArray[obj]->toString(objDump, sizeof(objDump)); + Fw::Logger::log("Entry: %d Ptr: %p Str: %s\n", obj, this->m_objPtrArray[obj], objDump); #else - Fw::Logger::log("Entry: %d Ptr: %p Name: %s\n", obj, - this->m_objPtrArray[obj], - this->m_objPtrArray[obj]->getObjName()); -#endif // FW_OBJECT_TO_STRING + Fw::Logger::log("Entry: %d Ptr: %p Name: %s\n", obj, this->m_objPtrArray[obj], + this->m_objPtrArray[obj]->getObjName()); +#endif // FW_OBJECT_TO_STRING #else - Fw::Logger::log("Entry: %d Ptr: %p\n", obj, this->m_objPtrArray[obj]); + Fw::Logger::log("Entry: %d Ptr: %p\n", obj, this->m_objPtrArray[obj]); #endif - } } +} #if FW_OBJECT_NAMES == 1 - void SimpleObjRegistry::dump(const char* objName) { - for (FwSizeType obj = 0; obj < this->m_numEntries; obj++) { - char objDump[FW_OBJ_SIMPLE_REG_BUFF_SIZE]; - if (strncmp(objName,this->m_objPtrArray[obj]->getObjName(),sizeof(objDump)) == 0) { +void SimpleObjRegistry::dump(const char* objName) { + for (FwSizeType obj = 0; obj < this->m_numEntries; obj++) { + char objDump[FW_OBJ_SIMPLE_REG_BUFF_SIZE]; + if (strncmp(objName, this->m_objPtrArray[obj]->getObjName(), sizeof(objDump)) == 0) { #if FW_OBJECT_TO_STRING == 1 - this->m_objPtrArray[obj]->toString(objDump,sizeof(objDump)); - Fw::Logger::log("Entry: %d Ptr: %p Str: %s\n", obj, - this->m_objPtrArray[obj], objDump); + this->m_objPtrArray[obj]->toString(objDump, sizeof(objDump)); + Fw::Logger::log("Entry: %d Ptr: %p Str: %s\n", obj, this->m_objPtrArray[obj], objDump); #else - Fw::Logger::log("Entry: %d Ptr: %p Name: %s\n",obj, - this->m_objPtrArray[obj], - this->m_objPtrArray[obj]->getObjName()); + Fw::Logger::log("Entry: %d Ptr: %p Name: %s\n", obj, this->m_objPtrArray[obj], + this->m_objPtrArray[obj]->getObjName()); #endif - } } } +} #endif - void SimpleObjRegistry::regObject(ObjBase* obj) { - FW_ASSERT(this->m_numEntries < FW_OBJ_SIMPLE_REG_ENTRIES); - this->m_objPtrArray[this->m_numEntries++] = obj; - - } - - void SimpleObjRegistry::clear() { - this->m_numEntries = 0; - } +void SimpleObjRegistry::regObject(ObjBase* obj) { + FW_ASSERT(this->m_numEntries < FW_OBJ_SIMPLE_REG_ENTRIES); + this->m_objPtrArray[this->m_numEntries++] = obj; +} +void SimpleObjRegistry::clear() { + this->m_numEntries = 0; } -#endif +} // namespace Fw +#endif diff --git a/Fw/Obj/SimpleObjRegistry.hpp b/Fw/Obj/SimpleObjRegistry.hpp index 0203e035a09..5cb484ca1c0 100644 --- a/Fw/Obj/SimpleObjRegistry.hpp +++ b/Fw/Obj/SimpleObjRegistry.hpp @@ -26,23 +26,23 @@ namespace Fw { - class SimpleObjRegistry : public ObjRegistry { - public: - SimpleObjRegistry(); //!< constructor for registry - ~SimpleObjRegistry(); //!< destructor for registry - void dump(); //!< dump contents of registry - void clear(); //!< clear registry entries +class SimpleObjRegistry : public ObjRegistry { + public: + SimpleObjRegistry(); //!< constructor for registry + ~SimpleObjRegistry(); //!< destructor for registry + void dump(); //!< dump contents of registry + void clear(); //!< clear registry entries #if FW_OBJECT_NAMES == 1 - void dump(const char* objName); //!< dump a particular object + void dump(const char* objName); //!< dump a particular object #endif - private: - void regObject(ObjBase* obj); //!< register an object with the registry - ObjBase* m_objPtrArray[FW_OBJ_SIMPLE_REG_ENTRIES]; //!< array of objects - FwSizeType m_numEntries; //!< number of entries in the registry - }; + private: + void regObject(ObjBase* obj); //!< register an object with the registry + ObjBase* m_objPtrArray[FW_OBJ_SIMPLE_REG_ENTRIES]; //!< array of objects + FwSizeType m_numEntries; //!< number of entries in the registry +}; -} +} // namespace Fw -#endif // FW_OBJECT_REGISTRATION +#endif // FW_OBJECT_REGISTRATION -#endif // FW_OBJ_SIMPLE_OBJ_REGISTRY_HPP +#endif // FW_OBJ_SIMPLE_OBJ_REGISTRY_HPP diff --git a/Fw/Port/InputPortBase.cpp b/Fw/Port/InputPortBase.cpp index 5ec1c964ee4..f261312ac2b 100644 --- a/Fw/Port/InputPortBase.cpp +++ b/Fw/Port/InputPortBase.cpp @@ -5,32 +5,23 @@ namespace Fw { - InputPortBase::InputPortBase() : - PortBase(), - m_comp(nullptr), - m_portNum(-1) { - } +InputPortBase::InputPortBase() : PortBase(), m_comp(nullptr), m_portNum(-1) {} - InputPortBase::~InputPortBase() { +InputPortBase::~InputPortBase() {} - } - - void InputPortBase::init() { - PortBase::init(); - - } +void InputPortBase::init() { + PortBase::init(); +} - void InputPortBase::setPortNum(FwIndexType portNum) { - FW_ASSERT(portNum >= 0, static_cast(portNum)); - this->m_portNum = portNum; - } +void InputPortBase::setPortNum(FwIndexType portNum) { + FW_ASSERT(portNum >= 0, static_cast(portNum)); + this->m_portNum = portNum; +} #if FW_OBJECT_TO_STRING == 1 - const char* InputPortBase::getToStringFormatString() { - return "Input Port: %s %s->(%s)"; - } -#endif - - +const char* InputPortBase::getToStringFormatString() { + return "Input Port: %s %s->(%s)"; } +#endif +} // namespace Fw diff --git a/Fw/Port/InputPortBase.hpp b/Fw/Port/InputPortBase.hpp index fdc96b3a684..21db274e54a 100644 --- a/Fw/Port/InputPortBase.hpp +++ b/Fw/Port/InputPortBase.hpp @@ -1,43 +1,41 @@ #ifndef FW_INPUT_PORT_BASE_HPP #define FW_INPUT_PORT_BASE_HPP +#include #include #include -#include -#include #include +#include namespace Fw { - class InputPortBase : public PortBase { - public: - void setPortNum(FwIndexType portNum); // !< set the port number +class InputPortBase : public PortBase { + public: + void setPortNum(FwIndexType portNum); // !< set the port number #if FW_PORT_SERIALIZATION - virtual SerializeStatus invokeSerial(SerializeBufferBase &buffer) = 0; // !< invoke the port with a serialized version of the call + virtual SerializeStatus invokeSerial( + SerializeBufferBase& buffer) = 0; // !< invoke the port with a serialized version of the call #endif - protected: + protected: + InputPortBase(); // Constructor + virtual ~InputPortBase(); // Destructor + void init() override; - InputPortBase(); // Constructor - virtual ~InputPortBase(); // Destructor - void init() override; - - PassiveComponentBase* m_comp; // !< pointer to containing component - FwIndexType m_portNum; // !< port number in containing object + PassiveComponentBase* m_comp; // !< pointer to containing component + FwIndexType m_portNum; // !< port number in containing object #if FW_OBJECT_TO_STRING == 1 - const char* getToStringFormatString() override; //!< Get format string for toString call + const char* getToStringFormatString() override; //!< Get format string for toString call #endif - private: - - // Disable constructors since we don't want to instantiate directly - InputPortBase(InputPortBase*); - InputPortBase(InputPortBase&); - InputPortBase& operator=(InputPortBase&); - - }; + private: + // Disable constructors since we don't want to instantiate directly + InputPortBase(InputPortBase*); + InputPortBase(InputPortBase&); + InputPortBase& operator=(InputPortBase&); +}; -} +} // namespace Fw #endif diff --git a/Fw/Port/InputSerializePort.cpp b/Fw/Port/InputSerializePort.cpp index e518b977062..479515fe01f 100644 --- a/Fw/Port/InputSerializePort.cpp +++ b/Fw/Port/InputSerializePort.cpp @@ -6,41 +6,38 @@ namespace Fw { - // SerializePort has no call interface. It is to pass through serialized data - InputSerializePort::InputSerializePort() : InputPortBase(), m_func(nullptr) { - } - InputSerializePort::~InputSerializePort() { - } +// SerializePort has no call interface. It is to pass through serialized data +InputSerializePort::InputSerializePort() : InputPortBase(), m_func(nullptr) {} +InputSerializePort::~InputSerializePort() {} - void InputSerializePort::init() { - InputPortBase::init(); - - } +void InputSerializePort::init() { + InputPortBase::init(); +} - SerializeStatus InputSerializePort::invokeSerial(SerializeBufferBase &buffer) { - FW_ASSERT(this->m_comp); - FW_ASSERT(this->m_func); +SerializeStatus InputSerializePort::invokeSerial(SerializeBufferBase& buffer) { + FW_ASSERT(this->m_comp); + FW_ASSERT(this->m_func); - this->m_func(this->m_comp,this->m_portNum,buffer); + this->m_func(this->m_comp, this->m_portNum, buffer); - // The normal input ports perform deserialize() on the passed buffer, - // which is what this status is based on. This is not the case for the - // InputSerializePort, so just return an okay status - return FW_SERIALIZE_OK; - } + // The normal input ports perform deserialize() on the passed buffer, + // which is what this status is based on. This is not the case for the + // InputSerializePort, so just return an okay status + return FW_SERIALIZE_OK; +} - void InputSerializePort::addCallComp(Fw::PassiveComponentBase* callComp, CompFuncPtr funcPtr) { - FW_ASSERT(callComp); - FW_ASSERT(funcPtr); - this->m_comp = callComp; - this->m_func = funcPtr; - } +void InputSerializePort::addCallComp(Fw::PassiveComponentBase* callComp, CompFuncPtr funcPtr) { + FW_ASSERT(callComp); + FW_ASSERT(funcPtr); + this->m_comp = callComp; + this->m_func = funcPtr; +} #if FW_OBJECT_TO_STRING == 1 - const char* InputSerializePort::getToStringFormatString() { - return "Input Serial Port: %s %s->(%s)"; - } +const char* InputSerializePort::getToStringFormatString() { + return "Input Serial Port: %s %s->(%s)"; +} #endif -} +} // namespace Fw #endif diff --git a/Fw/Port/InputSerializePort.hpp b/Fw/Port/InputSerializePort.hpp index 7f49c7598f6..61c70608c9f 100644 --- a/Fw/Port/InputSerializePort.hpp +++ b/Fw/Port/InputSerializePort.hpp @@ -9,33 +9,35 @@ namespace Fw { - class InputSerializePort final : public InputPortBase { - public: - InputSerializePort(); - virtual ~InputSerializePort(); +class InputSerializePort final : public InputPortBase { + public: + InputSerializePort(); + virtual ~InputSerializePort(); - void init() override; + void init() override; - SerializeStatus invokeSerial(SerializeBufferBase &buffer) override; // !< invoke the port with a serialized version of the call + SerializeStatus invokeSerial( + SerializeBufferBase& buffer) override; // !< invoke the port with a serialized version of the call - typedef void (*CompFuncPtr)(Fw::PassiveComponentBase* callComp, FwIndexType portNum, SerializeBufferBase &arg); //!< port callback definition - void addCallComp(Fw::PassiveComponentBase* callComp, CompFuncPtr funcPtr); //!< call to register a component - - protected: + typedef void (*CompFuncPtr)(Fw::PassiveComponentBase* callComp, + FwIndexType portNum, + SerializeBufferBase& arg); //!< port callback definition + void addCallComp(Fw::PassiveComponentBase* callComp, CompFuncPtr funcPtr); //!< call to register a component + protected: #if FW_OBJECT_TO_STRING == 1 - const char* getToStringFormatString() override; //!< Get format string for toString call + const char* getToStringFormatString() override; //!< Get format string for toString call #endif - private: - CompFuncPtr m_func; //!< pointer to port callback function - InputSerializePort(InputSerializePort*); - InputSerializePort(InputSerializePort&); - InputSerializePort& operator=(InputSerializePort&); - }; + private: + CompFuncPtr m_func; //!< pointer to port callback function + InputSerializePort(InputSerializePort*); + InputSerializePort(InputSerializePort&); + InputSerializePort& operator=(InputSerializePort&); +}; -} +} // namespace Fw -#endif // FW_INPUT_SERIALIZE_PORT_HPP +#endif // FW_INPUT_SERIALIZE_PORT_HPP #endif diff --git a/Fw/Port/OutputPortBase.cpp b/Fw/Port/OutputPortBase.cpp index 1922b6326ca..ca73b574906 100644 --- a/Fw/Port/OutputPortBase.cpp +++ b/Fw/Port/OutputPortBase.cpp @@ -1,45 +1,42 @@ #include #include +#include #include #include -#include - namespace Fw { - OutputPortBase::OutputPortBase() : PortBase() +OutputPortBase::OutputPortBase() + : PortBase() #if FW_PORT_SERIALIZATION == 1 - ,m_serPort(nullptr) + , + m_serPort(nullptr) #endif - { - - } +{ +} - OutputPortBase::~OutputPortBase() { - } +OutputPortBase::~OutputPortBase() {} - void OutputPortBase::init() { - PortBase::init(); - } +void OutputPortBase::init() { + PortBase::init(); +} #if FW_PORT_SERIALIZATION == 1 - void OutputPortBase::registerSerialPort(InputPortBase* port) { - FW_ASSERT(port); - this->m_connObj = port; - this->m_serPort = port; - } +void OutputPortBase::registerSerialPort(InputPortBase* port) { + FW_ASSERT(port); + this->m_connObj = port; + this->m_serPort = port; +} - SerializeStatus OutputPortBase::invokeSerial(SerializeBufferBase &buffer) { - FW_ASSERT(this->m_serPort); - return this->m_serPort->invokeSerial(buffer); - } +SerializeStatus OutputPortBase::invokeSerial(SerializeBufferBase& buffer) { + FW_ASSERT(this->m_serPort); + return this->m_serPort->invokeSerial(buffer); +} #endif #if FW_OBJECT_TO_STRING == 1 - const char* OutputPortBase::getToStringFormatString() { - return "Output Port: %s %s->(%s)"; - } -#endif - - +const char* OutputPortBase::getToStringFormatString() { + return "Output Port: %s %s->(%s)"; } +#endif +} // namespace Fw diff --git a/Fw/Port/OutputPortBase.hpp b/Fw/Port/OutputPortBase.hpp index 706130ab129..630a7703fd2 100644 --- a/Fw/Port/OutputPortBase.hpp +++ b/Fw/Port/OutputPortBase.hpp @@ -3,39 +3,38 @@ #include #include -#include #include +#include namespace Fw { - class OutputPortBase : public PortBase { - public: +class OutputPortBase : public PortBase { + public: #if FW_PORT_SERIALIZATION == 1 - void registerSerialPort(InputPortBase* port); // !< register a port for serialized calls - SerializeStatus invokeSerial(SerializeBufferBase &buffer); // !< invoke the port with a serialized version of the call + void registerSerialPort(InputPortBase* port); // !< register a port for serialized calls + SerializeStatus invokeSerial( + SerializeBufferBase& buffer); // !< invoke the port with a serialized version of the call #endif - protected: - - OutputPortBase(); // constructor - virtual ~OutputPortBase(); // destructor - void init() override; + protected: + OutputPortBase(); // constructor + virtual ~OutputPortBase(); // destructor + void init() override; #if FW_OBJECT_TO_STRING == 1 - const char* getToStringFormatString() override; //!< Get format string for toString call + const char* getToStringFormatString() override; //!< Get format string for toString call #endif #if FW_PORT_SERIALIZATION == 1 - Fw::InputPortBase* m_serPort; // !< pointer to port for serialized calls + Fw::InputPortBase* m_serPort; // !< pointer to port for serialized calls #endif - private: - - // Disable constructors - OutputPortBase(OutputPortBase*); - OutputPortBase(OutputPortBase&); - OutputPortBase& operator=(OutputPortBase&); - }; - -} + private: + // Disable constructors + OutputPortBase(OutputPortBase*); + OutputPortBase(OutputPortBase&); + OutputPortBase& operator=(OutputPortBase&); +}; + +} // namespace Fw #endif diff --git a/Fw/Port/OutputSerializePort.cpp b/Fw/Port/OutputSerializePort.cpp index ab2d6801b72..7b2b20a5167 100644 --- a/Fw/Port/OutputSerializePort.cpp +++ b/Fw/Port/OutputSerializePort.cpp @@ -6,25 +6,22 @@ namespace Fw { - // SerializePort has no call interface. It is to pass through serialized data +// SerializePort has no call interface. It is to pass through serialized data - OutputSerializePort::OutputSerializePort() : OutputPortBase() { - } +OutputSerializePort::OutputSerializePort() : OutputPortBase() {} - OutputSerializePort::~OutputSerializePort() { - } +OutputSerializePort::~OutputSerializePort() {} - void OutputSerializePort::init() { - OutputPortBase::init(); - } +void OutputSerializePort::init() { + OutputPortBase::init(); +} #if FW_OBJECT_TO_STRING == 1 - const char* OutputSerializePort::getToStringFormatString() { - return "Output Serial Port: %s %s->(%s)"; - } +const char* OutputSerializePort::getToStringFormatString() { + return "Output Serial Port: %s %s->(%s)"; +} #endif +} // namespace Fw -} - -#endif // FW_PORT_SERIALIZATION +#endif // FW_PORT_SERIALIZATION diff --git a/Fw/Port/OutputSerializePort.hpp b/Fw/Port/OutputSerializePort.hpp index 3709c7d53a5..27d88788b43 100644 --- a/Fw/Port/OutputSerializePort.hpp +++ b/Fw/Port/OutputSerializePort.hpp @@ -9,26 +9,25 @@ namespace Fw { - class OutputSerializePort final : public OutputPortBase { - public: - OutputSerializePort(); - virtual ~OutputSerializePort(); - void init() override; +class OutputSerializePort final : public OutputPortBase { + public: + OutputSerializePort(); + virtual ~OutputSerializePort(); + void init() override; - protected: + protected: #if FW_OBJECT_TO_STRING == 1 - const char* getToStringFormatString() override; //!< Get format string for toString call + const char* getToStringFormatString() override; //!< Get format string for toString call #endif - private: + private: + OutputSerializePort(OutputSerializePort*); + OutputSerializePort(OutputSerializePort&); + OutputSerializePort& operator=(OutputSerializePort&); +}; - OutputSerializePort(OutputSerializePort*); - OutputSerializePort(OutputSerializePort&); - OutputSerializePort& operator=(OutputSerializePort&); - }; +} // namespace Fw -} - -#endif // FW_OUTPUT_SERIALIZE_PORT_HPP +#endif // FW_OUTPUT_SERIALIZE_PORT_HPP #endif diff --git a/Fw/Port/PortBase.cpp b/Fw/Port/PortBase.cpp index 2a04dea3e2e..a281a63ed48 100644 --- a/Fw/Port/PortBase.cpp +++ b/Fw/Port/PortBase.cpp @@ -1,6 +1,6 @@ -#include #include #include +#include #include #include "Fw/Types/Assert.hpp" #include "Fw/Types/ExternalString.hpp" @@ -11,109 +11,100 @@ void setConnTrace(bool trace) { } namespace Fw { - bool PortBase::s_trace = false; +bool PortBase::s_trace = false; } -#endif // FW_PORT_TRACING +#endif // FW_PORT_TRACING namespace Fw { - PortBase::PortBase() - : - Fw::ObjBase(nullptr), - m_connObj(nullptr) +PortBase::PortBase() + : Fw::ObjBase(nullptr), + m_connObj(nullptr) #if FW_PORT_TRACING == 1 - ,m_trace(false), - m_ovr_trace(false) + , + m_trace(false), + m_ovr_trace(false) #endif - { - - } - - PortBase::~PortBase() { - - } +{ +} - void PortBase::init() { - ObjBase::init(); +PortBase::~PortBase() {} - } +void PortBase::init() { + ObjBase::init(); +} - bool PortBase::isConnected() const { - return m_connObj == nullptr?false:true; - } +bool PortBase::isConnected() const { + return m_connObj == nullptr ? false : true; +} #if FW_PORT_TRACING == 1 - void PortBase::trace() const { - bool do_trace = false; +void PortBase::trace() const { + bool do_trace = false; - if (this->m_ovr_trace) { - if (this->m_trace) { - do_trace = true; - } - } else if (PortBase::s_trace) { + if (this->m_ovr_trace) { + if (this->m_trace) { do_trace = true; } + } else if (PortBase::s_trace) { + do_trace = true; + } - if (do_trace) { + if (do_trace) { #if FW_OBJECT_NAMES == 1 - Fw::Logger::log("Trace: %s\n", this->m_objName.toChar()); + Fw::Logger::log("Trace: %s\n", this->m_objName.toChar()); #else - Fw::Logger::log("Trace: %p\n", this); + Fw::Logger::log("Trace: %p\n", this); #endif - } } +} - void PortBase::setTrace(bool trace) { - PortBase::s_trace = trace; - } +void PortBase::setTrace(bool trace) { + PortBase::s_trace = trace; +} - void PortBase::ovrTrace(bool ovr, bool trace) { - this->m_ovr_trace = ovr; - this->m_trace = trace; - } +void PortBase::ovrTrace(bool ovr, bool trace) { + this->m_ovr_trace = ovr; + this->m_trace = trace; +} -#endif // FW_PORT_TRACING +#endif // FW_PORT_TRACING #if FW_OBJECT_TO_STRING == 1 - const char* PortBase::getToStringFormatString() { - return "Port: %s %s->(%s)"; - } +const char* PortBase::getToStringFormatString() { + return "Port: %s %s->(%s)"; +} - void PortBase::toString(char* buffer, FwSizeType size) { - FW_ASSERT(size > 0); - // Get the port-custom format string - const char* formatString = this->getToStringFormatString(); - // Determine this port object name (or use "UNKNOWN") - const char* object_name = +void PortBase::toString(char* buffer, FwSizeType size) { + FW_ASSERT(size > 0); + // Get the port-custom format string + const char* formatString = this->getToStringFormatString(); + // Determine this port object name (or use "UNKNOWN") + const char* object_name = #if FW_OBJECT_NAMES == 1 - this->m_objName.toChar(); + this->m_objName.toChar(); #else - "UNKNOWN"; + "UNKNOWN"; #endif - // Get the C/NC for connected or not - const char* this_is_connected = this->isConnected() ? "C" : "NC"; + // Get the C/NC for connected or not + const char* this_is_connected = this->isConnected() ? "C" : "NC"; - // Get the name of the connection object, "UNKNOWN" or "NONE" - const char* connected_to = this->isConnected() ? + // Get the name of the connection object, "UNKNOWN" or "NONE" + const char* connected_to = this->isConnected() ? #if FW_OBJECT_NAMES == 1 - this->m_connObj->getObjName() + this->m_connObj->getObjName() #else - "UNKNOWN" + "UNKNOWN" #endif - : "None"; - // Format the external string or use "" on error - if (Fw::ExternalString(buffer, static_cast(size)).format( - formatString, - object_name, - this_is_connected, - connected_to) != Fw::FormatStatus::SUCCESS) { - buffer[0] = 0; - } + : "None"; + // Format the external string or use "" on error + if (Fw::ExternalString(buffer, static_cast(size)) + .format(formatString, object_name, this_is_connected, connected_to) != Fw::FormatStatus::SUCCESS) { + buffer[0] = 0; } -#endif // FW_OBJECT_TO_STRING - - } +#endif // FW_OBJECT_TO_STRING +} // namespace Fw diff --git a/Fw/Port/PortBase.hpp b/Fw/Port/PortBase.hpp index f196a65a2c0..d65624c5729 100644 --- a/Fw/Port/PortBase.hpp +++ b/Fw/Port/PortBase.hpp @@ -1,57 +1,56 @@ #ifndef FW_PORT_BASE_HPP #define FW_PORT_BASE_HPP -#include #include +#include #include #if FW_PORT_TRACING == 1 extern "C" { - void setConnTrace(bool trace); +void setConnTrace(bool trace); } #endif namespace Fw { - class PortBase : public Fw::ObjBase { - public: +class PortBase : public Fw::ObjBase { + public: #if FW_PORT_TRACING == 1 - static void setTrace(bool trace); // !< turn tracing on or off - void ovrTrace(bool ovr, bool trace); // !< override tracing for a particular port + static void setTrace(bool trace); // !< turn tracing on or off + void ovrTrace(bool ovr, bool trace); // !< override tracing for a particular port #endif - bool isConnected() const; - protected: - // Should only be accessed by derived classes - PortBase(); // Constructor - virtual ~PortBase(); // Destructor - virtual void init(); // !< initialization function + bool isConnected() const; + + protected: + // Should only be accessed by derived classes + PortBase(); // Constructor + virtual ~PortBase(); // Destructor + virtual void init(); // !< initialization function #if FW_PORT_TRACING == 1 - void trace() const; // !< trace port calls if active + void trace() const; // !< trace port calls if active #endif - Fw::ObjBase* m_connObj; // !< object port is connected to + Fw::ObjBase* m_connObj; // !< object port is connected to #if FW_OBJECT_TO_STRING - virtual const char* getToStringFormatString(); //!< Get format string for toString call + virtual const char* getToStringFormatString(); //!< Get format string for toString call - void toString(char* str, FwSizeType size) override; //!< Unified port toString method + void toString(char* str, FwSizeType size) override; //!< Unified port toString method #endif - - private: + private: #if FW_PORT_TRACING == 1 - static bool s_trace; // !< global tracing is active - bool m_trace; // !< local trace flag - bool m_ovr_trace; // !< flag to override global trace + static bool s_trace; // !< global tracing is active + bool m_trace; // !< local trace flag + bool m_ovr_trace; // !< flag to override global trace #endif - // Disable constructors - PortBase(PortBase*); - PortBase(PortBase&); - PortBase& operator=(PortBase&); - - }; + // Disable constructors + PortBase(PortBase*); + PortBase(PortBase&); + PortBase& operator=(PortBase&); +}; -} +} // namespace Fw #endif diff --git a/Fw/Prm/PrmBuffer.cpp b/Fw/Prm/PrmBuffer.cpp index f4c68beead8..f6b2549752d 100644 --- a/Fw/Prm/PrmBuffer.cpp +++ b/Fw/Prm/PrmBuffer.cpp @@ -3,43 +3,40 @@ namespace Fw { - ParamBuffer::ParamBuffer(const U8 *args, FwSizeType size) { - SerializeStatus stat = SerializeBufferBase::setBuff(args,size); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); - } - - ParamBuffer::ParamBuffer() { - } +ParamBuffer::ParamBuffer(const U8* args, FwSizeType size) { + SerializeStatus stat = SerializeBufferBase::setBuff(args, size); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +} - ParamBuffer::~ParamBuffer() { - } +ParamBuffer::ParamBuffer() {} - ParamBuffer::ParamBuffer(const ParamBuffer& other) : Fw::SerializeBufferBase() { - SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); - } +ParamBuffer::~ParamBuffer() {} - ParamBuffer& ParamBuffer::operator=(const ParamBuffer& other) { - if(this == &other) { - return *this; - } +ParamBuffer::ParamBuffer(const ParamBuffer& other) : Fw::SerializeBufferBase() { + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +} - SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); +ParamBuffer& ParamBuffer::operator=(const ParamBuffer& other) { + if (this == &other) { return *this; } - FwSizeType ParamBuffer::getBuffCapacity() const { - return sizeof(this->m_bufferData); - } + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); + return *this; +} - const U8* ParamBuffer::getBuffAddr() const { - return this->m_bufferData; - } +FwSizeType ParamBuffer::getBuffCapacity() const { + return sizeof(this->m_bufferData); +} - U8* ParamBuffer::getBuffAddr() { - return this->m_bufferData; - } +const U8* ParamBuffer::getBuffAddr() const { + return this->m_bufferData; +} +U8* ParamBuffer::getBuffAddr() { + return this->m_bufferData; } +} // namespace Fw diff --git a/Fw/Prm/PrmBuffer.hpp b/Fw/Prm/PrmBuffer.hpp index 7a4ff72b178..682d50a8f4e 100644 --- a/Fw/Prm/PrmBuffer.hpp +++ b/Fw/Prm/PrmBuffer.hpp @@ -13,39 +13,37 @@ #define FW_PRM_BUFFER_HPP #include -#include #include +#include #include "Fw/Types/StringBase.hpp" - namespace Fw { - static_assert(FW_PARAM_BUFFER_MAX_SIZE >= StringBase::BUFFER_SIZE(FW_PARAM_STRING_MAX_SIZE), - "param string must fit into param buffer"); +static_assert(FW_PARAM_BUFFER_MAX_SIZE >= StringBase::BUFFER_SIZE(FW_PARAM_STRING_MAX_SIZE), + "param string must fit into param buffer"); - class ParamBuffer final : public SerializeBufferBase { - public: - - enum { - SERIALIZED_TYPE_ID = FW_TYPEID_PRM_BUFF, - SERIALIZED_SIZE = FW_PARAM_BUFFER_MAX_SIZE + sizeof(FwBuffSizeType) - }; +class ParamBuffer final : public SerializeBufferBase { + public: + enum { + SERIALIZED_TYPE_ID = FW_TYPEID_PRM_BUFF, + SERIALIZED_SIZE = FW_PARAM_BUFFER_MAX_SIZE + sizeof(FwBuffSizeType) + }; - ParamBuffer(const U8 *args, FwSizeType size); - ParamBuffer(); - ParamBuffer(const ParamBuffer& other); - virtual ~ParamBuffer(); - ParamBuffer& operator=(const ParamBuffer& other); + ParamBuffer(const U8* args, FwSizeType size); + ParamBuffer(); + ParamBuffer(const ParamBuffer& other); + virtual ~ParamBuffer(); + ParamBuffer& operator=(const ParamBuffer& other); - FwSizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer - U8* getBuffAddr(); - const U8* getBuffAddr() const; + FwSizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer + U8* getBuffAddr(); + const U8* getBuffAddr() const; - private: - U8 m_bufferData[FW_PARAM_BUFFER_MAX_SIZE]; // command argument buffer - }; + private: + U8 m_bufferData[FW_PARAM_BUFFER_MAX_SIZE]; // command argument buffer +}; -} +} // namespace Fw #endif diff --git a/Fw/Prm/PrmExternalTypes.hpp b/Fw/Prm/PrmExternalTypes.hpp index 65d6608b2a2..c8802f32920 100644 --- a/Fw/Prm/PrmExternalTypes.hpp +++ b/Fw/Prm/PrmExternalTypes.hpp @@ -7,46 +7,43 @@ #ifndef FW_EXTERNAL_PARAM_TYPES_HPP #define FW_EXTERNAL_PARAM_TYPES_HPP -#include #include +#include #include "PrmBuffer.hpp" namespace Fw { - //! Fw::ParamExternalDelegate is used for parameters that are stored and managed - //! externally to the owning F' component. +//! Fw::ParamExternalDelegate is used for parameters that are stored and managed +//! externally to the owning F' component. +//! +//! Fw::ParamExternalDelegate is an abstract base class that defines the interfaces +//! needed by the F' component to interact with the externally managed parameter(s) +class ParamExternalDelegate { + public: + //! Deserialize a parameter from a parameter buffer //! - //! Fw::ParamExternalDelegate is an abstract base class that defines the interfaces - //! needed by the F' component to interact with the externally managed parameter(s) - class ParamExternalDelegate { - public: - - //! Deserialize a parameter from a parameter buffer - //! - //! \param base_id: The component base ID of the parameter being deserialized - //! \param local_id: The local parameter ID of the parameter being deserialized - //! \param prmStat: The parameter status of the parameter being deserialized - //! \param buff: The buffer contained the serialized parameter - //! - //! \return: The status of the deserialize operation - virtual SerializeStatus deserializeParam( - const FwPrmIdType base_id, - const FwPrmIdType local_id, - const ParamValid prmStat, - SerializeBufferBase& buff) = 0; + //! \param base_id: The component base ID of the parameter being deserialized + //! \param local_id: The local parameter ID of the parameter being deserialized + //! \param prmStat: The parameter status of the parameter being deserialized + //! \param buff: The buffer contained the serialized parameter + //! + //! \return: The status of the deserialize operation + virtual SerializeStatus deserializeParam(const FwPrmIdType base_id, + const FwPrmIdType local_id, + const ParamValid prmStat, + SerializeBufferBase& buff) = 0; - //! Serialize a parameter into a parameter buffer - //! - //! \param base_id: The component base ID of the parameter being deserialized - //! \param local_id: The local Parameter ID of the parameter to serialized - //! \param buff: The buffer to serialize the parameter into - //! - //! \return: The status of the serialize operation - virtual SerializeStatus serializeParam( - const FwPrmIdType base_id, - const FwPrmIdType local_id, - SerializeBufferBase& buff) const = 0; - }; + //! Serialize a parameter into a parameter buffer + //! + //! \param base_id: The component base ID of the parameter being deserialized + //! \param local_id: The local Parameter ID of the parameter to serialized + //! \param buff: The buffer to serialize the parameter into + //! + //! \return: The status of the serialize operation + virtual SerializeStatus serializeParam(const FwPrmIdType base_id, + const FwPrmIdType local_id, + SerializeBufferBase& buff) const = 0; +}; } // namespace Fw diff --git a/Fw/SerializableFile/SerializableFile.cpp b/Fw/SerializableFile/SerializableFile.cpp index ab99b24c83e..93afff24926 100644 --- a/Fw/SerializableFile/SerializableFile.cpp +++ b/Fw/SerializableFile/SerializableFile.cpp @@ -16,34 +16,34 @@ namespace Fw { - SerializableFile::SerializableFile(MemAllocator* allocator, FwSizeType maxSerializedSize) : - m_allocator(allocator), - m_recoverable(false), // for compiler; not used - m_actualSize(maxSerializedSize), - m_buffer(static_cast(this->m_allocator->allocate(0, m_actualSize, m_recoverable)), m_actualSize) - { +SerializableFile::SerializableFile(MemAllocator* allocator, FwSizeType maxSerializedSize) + : m_allocator(allocator), + m_recoverable(false), // for compiler; not used + m_actualSize(maxSerializedSize), + m_buffer(static_cast(this->m_allocator->allocate(0, m_actualSize, m_recoverable)), m_actualSize) { // assert if allocator returns smaller size - FW_ASSERT(maxSerializedSize == m_actualSize, static_cast(maxSerializedSize), static_cast(m_actualSize)); + FW_ASSERT(maxSerializedSize == m_actualSize, static_cast(maxSerializedSize), + static_cast(m_actualSize)); FW_ASSERT(nullptr != m_buffer.getBuffAddr()); - } +} - SerializableFile::~SerializableFile() { +SerializableFile::~SerializableFile() { this->m_allocator->deallocate(0, this->m_buffer.getBuffAddr()); - } +} - SerializableFile::Status SerializableFile::load(const char* fileName, Serializable& serializable) { +SerializableFile::Status SerializableFile::load(const char* fileName, Serializable& serializable) { Os::File file; Os::File::Status status; status = file.open(fileName, Os::File::OPEN_READ); - if(Os::File::OP_OK != status) { - return FILE_OPEN_ERROR; + if (Os::File::OP_OK != status) { + return FILE_OPEN_ERROR; } FwSizeType length = this->m_buffer.getBuffCapacity(); status = file.read(this->m_buffer.getBuffAddr(), length, Os::File::WaitType::NO_WAIT); - if( Os::File::OP_OK != status) { - file.close(); - return FILE_READ_ERROR; + if (Os::File::OP_OK != status) { + file.close(); + return FILE_READ_ERROR; } file.close(); @@ -52,14 +52,14 @@ namespace Fw { serStatus = this->m_buffer.setBuffLen(length); FW_ASSERT(FW_SERIALIZE_OK == serStatus, serStatus); serStatus = serializable.deserialize(this->m_buffer); - if(FW_SERIALIZE_OK != serStatus) { - return DESERIALIZATION_ERROR; + if (FW_SERIALIZE_OK != serStatus) { + return DESERIALIZATION_ERROR; } return SerializableFile::OP_OK; - } +} - SerializableFile::Status SerializableFile::save(const char* fileName, Serializable& serializable) { +SerializableFile::Status SerializableFile::save(const char* fileName, Serializable& serializable) { this->reset(); SerializeStatus serStatus = serializable.serialize(this->m_buffer); FW_ASSERT(FW_SERIALIZE_OK == serStatus, serStatus); @@ -67,24 +67,24 @@ namespace Fw { Os::File file; Os::File::Status status; status = file.open(fileName, Os::File::OPEN_WRITE); - if( Os::File::OP_OK != status ) { - return FILE_OPEN_ERROR; + if (Os::File::OP_OK != status) { + return FILE_OPEN_ERROR; } FwSizeType length = this->m_buffer.getBuffLength(); status = file.write(this->m_buffer.getBuffAddr(), length); - if((Os::File::OP_OK != status) || (length != this->m_buffer.getBuffLength())) { - file.close(); - return FILE_WRITE_ERROR; + if ((Os::File::OP_OK != status) || (length != this->m_buffer.getBuffLength())) { + file.close(); + return FILE_WRITE_ERROR; } file.close(); return SerializableFile::OP_OK; - } +} - void SerializableFile::reset() { - this->m_buffer.resetSer(); //!< reset to beginning of buffer to reuse for serialization - this->m_buffer.resetDeser(); //!< reset deserialization to beginning - } +void SerializableFile::reset() { + this->m_buffer.resetSer(); //!< reset to beginning of buffer to reuse for serialization + this->m_buffer.resetDeser(); //!< reset deserialization to beginning } +} // namespace Fw diff --git a/Fw/SerializableFile/SerializableFile.hpp b/Fw/SerializableFile/SerializableFile.hpp index 4bb64648375..2564c06fdb7 100644 --- a/Fw/SerializableFile/SerializableFile.hpp +++ b/Fw/SerializableFile/SerializableFile.hpp @@ -13,23 +13,16 @@ #ifndef Fw_SerializableFile_HPP #define Fw_SerializableFile_HPP -#include #include #include +#include namespace Fw { - //! The type of a packet header - class SerializableFile { - - public: - enum Status { - OP_OK, - FILE_OPEN_ERROR, - FILE_WRITE_ERROR, - FILE_READ_ERROR, - DESERIALIZATION_ERROR - }; +//! The type of a packet header +class SerializableFile { + public: + enum Status { OP_OK, FILE_OPEN_ERROR, FILE_WRITE_ERROR, FILE_READ_ERROR, DESERIALIZATION_ERROR }; // NOTE!: This should not be used with an allocator that can return a smaller buffer than requested SerializableFile(MemAllocator* allocator, FwSizeType maxSerializedSize); @@ -38,13 +31,13 @@ namespace Fw { Status load(const char* fileName, Serializable& serializable); Status save(const char* fileName, Serializable& serializable); - private: + private: void reset(); MemAllocator* m_allocator; - bool m_recoverable; // don't care; for allocator - FwSizeType m_actualSize; // for checking + bool m_recoverable; // don't care; for allocator + FwSizeType m_actualSize; // for checking SerialBuffer m_buffer; - }; -} +}; +} // namespace Fw #endif diff --git a/Fw/SerializableFile/test/ut/Test.cpp b/Fw/SerializableFile/test/ut/Test.cpp index 1110589d50b..3dfbff2aa2d 100644 --- a/Fw/SerializableFile/test/ut/Test.cpp +++ b/Fw/SerializableFile/test/ut/Test.cpp @@ -1,61 +1,60 @@ // ---------------------------------------------------------------------- -// Main.cpp +// Main.cpp // ---------------------------------------------------------------------- -#include -#include #include -#include -#include #include #include +#include +#include +#include +#include using namespace Fw; -int main(int argc, char **argv) { - - // Create local serializable: - U32 element1 = 4294967284U; - I8 element2 = -18; - F64 element3 = 3.14159; - U32 size = Test::SERIALIZED_SIZE; - Test config(element1, element2, element3); - - // Create the serializable file: - MallocAllocator theMallocator; - SerializableFile configFile(&theMallocator, size); - SerializableFile::Status status; - - // Save the serializable to a file: - printf("Testing save... "); - status = configFile.save("test.ser", config); - FW_ASSERT(SerializableFile::OP_OK == status, status); - printf("Passed\n"); - - // Load the serializable from a file: - printf("Testing load... "); - Test config2; - status = configFile.load("test.ser", config2); - FW_ASSERT(SerializableFile::OP_OK == status, status); - printf("Passed\n"); - - // Compare the results: - printf("Testing compare... "); - FW_ASSERT(config == config2); - printf("Passed\n"); - - // Test saving to impossible file: - printf("Testing bad save... "); - status = configFile.save("this/file/does/not/exist", config); - FW_ASSERT(SerializableFile::FILE_OPEN_ERROR == status, status); - printf("Passed\n"); - - // Test reading from nonexistent file: - printf("Testing bad load... "); - Test config3; - status = configFile.load("thisfiledoesnotexist.ser", config3); - FW_ASSERT(SerializableFile::FILE_OPEN_ERROR == status, status); - printf("Passed\n"); - - return 0; +int main(int argc, char** argv) { + // Create local serializable: + U32 element1 = 4294967284U; + I8 element2 = -18; + F64 element3 = 3.14159; + U32 size = Test::SERIALIZED_SIZE; + Test config(element1, element2, element3); + + // Create the serializable file: + MallocAllocator theMallocator; + SerializableFile configFile(&theMallocator, size); + SerializableFile::Status status; + + // Save the serializable to a file: + printf("Testing save... "); + status = configFile.save("test.ser", config); + FW_ASSERT(SerializableFile::OP_OK == status, status); + printf("Passed\n"); + + // Load the serializable from a file: + printf("Testing load... "); + Test config2; + status = configFile.load("test.ser", config2); + FW_ASSERT(SerializableFile::OP_OK == status, status); + printf("Passed\n"); + + // Compare the results: + printf("Testing compare... "); + FW_ASSERT(config == config2); + printf("Passed\n"); + + // Test saving to impossible file: + printf("Testing bad save... "); + status = configFile.save("this/file/does/not/exist", config); + FW_ASSERT(SerializableFile::FILE_OPEN_ERROR == status, status); + printf("Passed\n"); + + // Test reading from nonexistent file: + printf("Testing bad load... "); + Test config3; + status = configFile.load("thisfiledoesnotexist.ser", config3); + FW_ASSERT(SerializableFile::FILE_OPEN_ERROR == status, status); + printf("Passed\n"); + + return 0; } diff --git a/Fw/Sm/SmSignalBuffer.cpp b/Fw/Sm/SmSignalBuffer.cpp index 2293a51eb7e..afa85d7ef21 100644 --- a/Fw/Sm/SmSignalBuffer.cpp +++ b/Fw/Sm/SmSignalBuffer.cpp @@ -3,53 +3,48 @@ namespace Fw { - SmSignalBuffer::SmSignalBuffer(const U8 *args, Serializable::SizeType size) : m_bufferData{} { - FW_ASSERT(args != nullptr); - FW_ASSERT(size <= sizeof(this->m_bufferData)); - SerializeStatus stat = SerializeBufferBase::setBuff(args,size); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); - } +SmSignalBuffer::SmSignalBuffer(const U8* args, Serializable::SizeType size) : m_bufferData{} { + FW_ASSERT(args != nullptr); + FW_ASSERT(size <= sizeof(this->m_bufferData)); + SerializeStatus stat = SerializeBufferBase::setBuff(args, size); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +} - SmSignalBuffer::SmSignalBuffer() : m_bufferData{} { - } +SmSignalBuffer::SmSignalBuffer() : m_bufferData{} {} - SmSignalBuffer::~SmSignalBuffer() { - } +SmSignalBuffer::~SmSignalBuffer() {} - SmSignalBuffer::SmSignalBuffer(const SmSignalBuffer& other) : Fw::SerializeBufferBase(), - m_bufferData{} - { - FW_ASSERT(other.getBuffAddr() != nullptr); - FW_ASSERT(other.getBuffLength() <= sizeof(this->m_bufferData)); +SmSignalBuffer::SmSignalBuffer(const SmSignalBuffer& other) : Fw::SerializeBufferBase(), m_bufferData{} { + FW_ASSERT(other.getBuffAddr() != nullptr); + FW_ASSERT(other.getBuffLength() <= sizeof(this->m_bufferData)); - SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); - } - - SmSignalBuffer& SmSignalBuffer::operator=(const SmSignalBuffer& other) { - if(this == &other) { - return *this; - } - - FW_ASSERT(other.getBuffAddr() != nullptr); - FW_ASSERT(other.getBuffLength() <= sizeof(this->m_bufferData)); + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +} - SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); +SmSignalBuffer& SmSignalBuffer::operator=(const SmSignalBuffer& other) { + if (this == &other) { return *this; } - Serializable::SizeType SmSignalBuffer::getBuffCapacity() const { - return sizeof(this->m_bufferData); - } + FW_ASSERT(other.getBuffAddr() != nullptr); + FW_ASSERT(other.getBuffLength() <= sizeof(this->m_bufferData)); - const U8* SmSignalBuffer::getBuffAddr() const { - return this->m_bufferData; - } + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); + return *this; +} - U8* SmSignalBuffer::getBuffAddr() { - return this->m_bufferData; - } +Serializable::SizeType SmSignalBuffer::getBuffCapacity() const { + return sizeof(this->m_bufferData); +} + +const U8* SmSignalBuffer::getBuffAddr() const { + return this->m_bufferData; +} +U8* SmSignalBuffer::getBuffAddr() { + return this->m_bufferData; } +} // namespace Fw diff --git a/Fw/Sm/SmSignalBuffer.hpp b/Fw/Sm/SmSignalBuffer.hpp index 39b7bfe277d..6c8d246e36f 100644 --- a/Fw/Sm/SmSignalBuffer.hpp +++ b/Fw/Sm/SmSignalBuffer.hpp @@ -15,28 +15,27 @@ namespace Fw { - class SmSignalBuffer final : public SerializeBufferBase { - public: - - enum { - SERIALIZED_TYPE_ID = 1010, - SERIALIZED_SIZE = FW_COM_BUFFER_MAX_SIZE + sizeof(FwSizeStoreType) // size of buffer + storage of size word - }; - - SmSignalBuffer(const U8 *args, Serializable::SizeType size); - SmSignalBuffer(); - SmSignalBuffer(const SmSignalBuffer& other); - virtual ~SmSignalBuffer(); - SmSignalBuffer& operator=(const SmSignalBuffer& other); - - Serializable::SizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer - U8* getBuffAddr(); - const U8* getBuffAddr() const; - - private: - U8 m_bufferData[FW_SM_SIGNAL_BUFFER_MAX_SIZE]; // packet data buffer +class SmSignalBuffer final : public SerializeBufferBase { + public: + enum { + SERIALIZED_TYPE_ID = 1010, + SERIALIZED_SIZE = FW_COM_BUFFER_MAX_SIZE + sizeof(FwSizeStoreType) // size of buffer + storage of size word }; -} + SmSignalBuffer(const U8* args, Serializable::SizeType size); + SmSignalBuffer(); + SmSignalBuffer(const SmSignalBuffer& other); + virtual ~SmSignalBuffer(); + SmSignalBuffer& operator=(const SmSignalBuffer& other); + + Serializable::SizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer + U8* getBuffAddr(); + const U8* getBuffAddr() const; + + private: + U8 m_bufferData[FW_SM_SIGNAL_BUFFER_MAX_SIZE]; // packet data buffer +}; + +} // namespace Fw #endif diff --git a/Fw/Test/String.hpp b/Fw/Test/String.hpp index 54a92a16bd4..237056f5d1e 100644 --- a/Fw/Test/String.hpp +++ b/Fw/Test/String.hpp @@ -51,6 +51,6 @@ class String : public Fw::StringBase { private: char m_buf[BUFFER_SIZE(STRING_SIZE)]; }; -} // namespace Fw +} // namespace Test #endif diff --git a/Fw/Test/UnitTest.hpp b/Fw/Test/UnitTest.hpp index 19b6aa59f7d..dce77b9771e 100644 --- a/Fw/Test/UnitTest.hpp +++ b/Fw/Test/UnitTest.hpp @@ -16,22 +16,19 @@ #ifndef TEST_UNITTEST_HPP_ #define TEST_UNITTEST_HPP_ -#define TEST_CASE(tc, desc) \ +#define TEST_CASE(tc, desc) \ printf("\n***************************************\n"); \ - printf("TESTCASE %s: " desc "\n", #tc); \ + printf("TESTCASE %s: " desc "\n", #tc); \ printf("***************************************\n") -#define REQUIREMENT(str) \ +#define REQUIREMENT(str) \ printf("\n***************************************\n"); \ - printf("(RQ) %s\n", str); \ + printf("(RQ) %s\n", str); \ printf("***************************************\n") -#define COMMENT(str) \ +#define COMMENT(str) \ printf("\n***************************************\n"); \ - printf("%s\n", str); \ + printf("%s\n", str); \ printf("***************************************\n") - - - #endif /* TEST_UNITTEST_HPP_ */ diff --git a/Fw/Test/UnitTestAssert.cpp b/Fw/Test/UnitTestAssert.cpp index 0a253480f1f..3e8bf4b6c85 100644 --- a/Fw/Test/UnitTestAssert.cpp +++ b/Fw/Test/UnitTestAssert.cpp @@ -14,13 +14,13 @@ namespace Test { #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT - const UnitTestAssert::File UnitTestAssert::fileInit = 0; +const UnitTestAssert::File UnitTestAssert::fileInit = 0; #else - const UnitTestAssert::File UnitTestAssert::fileInit = ""; +const UnitTestAssert::File UnitTestAssert::fileInit = ""; #endif - UnitTestAssert::UnitTestAssert() : - m_file(fileInit), +UnitTestAssert::UnitTestAssert() + : m_file(fileInit), m_lineNo(0), m_numArgs(0), m_arg1(0), @@ -29,84 +29,75 @@ namespace Test { m_arg4(0), m_arg5(0), m_arg6(0), - m_assertFailed(false) - { - // register this hook - Fw::AssertHook::registerHook(); - } + m_assertFailed(false) { + // register this hook + Fw::AssertHook::registerHook(); +} - UnitTestAssert::~UnitTestAssert() { - // deregister the hook - Fw::AssertHook::deregisterHook(); - } +UnitTestAssert::~UnitTestAssert() { + // deregister the hook + Fw::AssertHook::deregisterHook(); +} - void UnitTestAssert::doAssert() { - this->m_assertFailed = true; +void UnitTestAssert::doAssert() { + this->m_assertFailed = true; #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT - (void)fprintf(stderr,"Assert: 0x%" PRIx32 ":%" PRI_FwSizeType "\n", this->m_file, this->m_lineNo); + (void)fprintf(stderr, "Assert: 0x%" PRIx32 ":%" PRI_FwSizeType "\n", this->m_file, this->m_lineNo); #else - (void)fprintf(stderr,"Assert: %s:%" PRI_FwSizeType "\n", this->m_file.toChar(), this->m_lineNo); + (void)fprintf(stderr, "Assert: %s:%" PRI_FwSizeType "\n", this->m_file.toChar(), this->m_lineNo); #endif - } - - void UnitTestAssert::reportAssert( - FILE_NAME_ARG file, - FwSizeType lineNo, - FwSizeType numArgs, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwAssertArgType arg5, - FwAssertArgType arg6 - ) { +} +void UnitTestAssert::reportAssert(FILE_NAME_ARG file, + FwSizeType lineNo, + FwSizeType numArgs, + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwAssertArgType arg5, + FwAssertArgType arg6) { #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT - this->m_file = file; + this->m_file = file; #else - this->m_file = reinterpret_cast(file); + this->m_file = reinterpret_cast(file); #endif - this->m_lineNo = lineNo; - this->m_numArgs = numArgs; - this->m_arg1 = arg1; - this->m_arg2 = arg2; - this->m_arg3 = arg3; - this->m_arg4 = arg4; - this->m_arg5 = arg5; - this->m_arg6 = arg6; - - - } - - void UnitTestAssert::retrieveAssert( - File& file, - FwSizeType& lineNo, - FwSizeType& numArgs, - FwAssertArgType& arg1, - FwAssertArgType& arg2, - FwAssertArgType& arg3, - FwAssertArgType& arg4, - FwAssertArgType& arg5, - FwAssertArgType& arg6 - ) const { + this->m_lineNo = lineNo; + this->m_numArgs = numArgs; + this->m_arg1 = arg1; + this->m_arg2 = arg2; + this->m_arg3 = arg3; + this->m_arg4 = arg4; + this->m_arg5 = arg5; + this->m_arg6 = arg6; +} - file = this->m_file; - lineNo = this->m_lineNo; - numArgs = this->m_numArgs; - arg1 = this->m_arg1; - arg2 = this->m_arg2; - arg3 = this->m_arg3; - arg4 = this->m_arg4; - arg5 = this->m_arg5; - arg6 = this->m_arg6; - } +void UnitTestAssert::retrieveAssert(File& file, + FwSizeType& lineNo, + FwSizeType& numArgs, + FwAssertArgType& arg1, + FwAssertArgType& arg2, + FwAssertArgType& arg3, + FwAssertArgType& arg4, + FwAssertArgType& arg5, + FwAssertArgType& arg6) const { + file = this->m_file; + lineNo = this->m_lineNo; + numArgs = this->m_numArgs; + arg1 = this->m_arg1; + arg2 = this->m_arg2; + arg3 = this->m_arg3; + arg4 = this->m_arg4; + arg5 = this->m_arg5; + arg6 = this->m_arg6; +} - bool UnitTestAssert::assertFailed() const { - return this->m_assertFailed; - } +bool UnitTestAssert::assertFailed() const { + return this->m_assertFailed; +} - void UnitTestAssert::clearAssertFailure() { - this->m_assertFailed = false; - } +void UnitTestAssert::clearAssertFailure() { + this->m_assertFailed = false; +} } /* namespace Test */ diff --git a/Fw/Test/UnitTestAssert.hpp b/Fw/Test/UnitTestAssert.hpp index 66d92e09771..4e6f63465ee 100644 --- a/Fw/Test/UnitTestAssert.hpp +++ b/Fw/Test/UnitTestAssert.hpp @@ -15,66 +15,61 @@ namespace Test { - class UnitTestAssert: public Fw::AssertHook { - public: +class UnitTestAssert : public Fw::AssertHook { + public: #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT - typedef U32 File; + typedef U32 File; #else - typedef String File; + typedef String File; #endif - // initial value for File - static const File fileInit; + // initial value for File + static const File fileInit; - public: - UnitTestAssert(); - virtual ~UnitTestAssert(); - // function for hook - void doAssert(); - void reportAssert( - FILE_NAME_ARG file, - FwSizeType lineNo, - FwSizeType numArgs, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwAssertArgType arg5, - FwAssertArgType arg6 - ); - // retrieves assertion failure values - void retrieveAssert( - File& file, - FwSizeType& lineNo, - FwSizeType& numArgs, - FwAssertArgType& arg1, - FwAssertArgType& arg2, - FwAssertArgType& arg3, - FwAssertArgType& arg4, - FwAssertArgType& arg5, - FwAssertArgType& arg6 - ) const; + public: + UnitTestAssert(); + virtual ~UnitTestAssert(); + // function for hook + void doAssert(); + void reportAssert(FILE_NAME_ARG file, + FwSizeType lineNo, + FwSizeType numArgs, + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwAssertArgType arg5, + FwAssertArgType arg6); + // retrieves assertion failure values + void retrieveAssert(File& file, + FwSizeType& lineNo, + FwSizeType& numArgs, + FwAssertArgType& arg1, + FwAssertArgType& arg2, + FwAssertArgType& arg3, + FwAssertArgType& arg4, + FwAssertArgType& arg5, + FwAssertArgType& arg6) const; - // check whether assertion failure occurred - bool assertFailed() const; + // check whether assertion failure occurred + bool assertFailed() const; - // clear assertion failure - void clearAssertFailure(); + // clear assertion failure + void clearAssertFailure(); - private: - File m_file; - FwSizeType m_lineNo; - FwSizeType m_numArgs; - FwAssertArgType m_arg1; - FwAssertArgType m_arg2; - FwAssertArgType m_arg3; - FwAssertArgType m_arg4; - FwAssertArgType m_arg5; - FwAssertArgType m_arg6; + private: + File m_file; + FwSizeType m_lineNo; + FwSizeType m_numArgs; + FwAssertArgType m_arg1; + FwAssertArgType m_arg2; + FwAssertArgType m_arg3; + FwAssertArgType m_arg4; + FwAssertArgType m_arg5; + FwAssertArgType m_arg6; - // Whether an assertion failed - bool m_assertFailed; - - }; + // Whether an assertion failed + bool m_assertFailed; +}; } /* namespace Test */ diff --git a/Fw/Time/Time.cpp b/Fw/Time/Time.cpp index 2ea7ab71b02..312427ae471 100644 --- a/Fw/Time/Time.cpp +++ b/Fw/Time/Time.cpp @@ -1,248 +1,234 @@ -#include #include +#include namespace Fw { - const Time ZERO_TIME = Time(); +const Time ZERO_TIME = Time(); - Time::Time() : m_val() { - m_val.set_timeBase(TimeBase::TB_NONE); - m_val.set_timeContext(0); - m_val.set_seconds(0); - m_val.set_useconds(0); - } +Time::Time() : m_val() { + m_val.set_timeBase(TimeBase::TB_NONE); + m_val.set_timeContext(0); + m_val.set_seconds(0); + m_val.set_useconds(0); +} - Time::~Time() { - } +Time::~Time() {} - Time::Time(const Time& other) : Serializable() { - this->set(other.m_val.get_timeBase(),other.m_val.get_timeContext(),other.m_val.get_seconds(),other.m_val.get_useconds()); - } +Time::Time(const Time& other) : Serializable() { + this->set(other.m_val.get_timeBase(), other.m_val.get_timeContext(), other.m_val.get_seconds(), + other.m_val.get_useconds()); +} - Time::Time(U32 seconds, U32 useconds) { - this->set(TimeBase::TB_NONE,0,seconds,useconds); - } +Time::Time(U32 seconds, U32 useconds) { + this->set(TimeBase::TB_NONE, 0, seconds, useconds); +} - Time::Time(TimeBase timeBase, U32 seconds, U32 useconds) { - this->set(timeBase,0,seconds,useconds); - } +Time::Time(TimeBase timeBase, U32 seconds, U32 useconds) { + this->set(timeBase, 0, seconds, useconds); +} - void Time::set(U32 seconds, U32 useconds) { - this->set(this->m_val.get_timeBase(),this->m_val.get_timeContext(),seconds,useconds); - } +void Time::set(U32 seconds, U32 useconds) { + this->set(this->m_val.get_timeBase(), this->m_val.get_timeContext(), seconds, useconds); +} - void Time::set(TimeBase timeBase, U32 seconds, U32 useconds) { - this->set(timeBase,this->m_val.get_timeContext(),seconds,useconds); - } +void Time::set(TimeBase timeBase, U32 seconds, U32 useconds) { + this->set(timeBase, this->m_val.get_timeContext(), seconds, useconds); +} - Time::Time(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 useconds) { - this->set(timeBase,context,seconds,useconds); - } +Time::Time(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 useconds) { + this->set(timeBase, context, seconds, useconds); +} - void Time::set(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 useconds) { - this->m_val.set(timeBase,context,seconds,useconds); - } +void Time::set(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 useconds) { + this->m_val.set(timeBase, context, seconds, useconds); +} - Time& Time::operator=(const Time& other) { - if (this != &other) { - this->m_val = other.m_val; - } - return *this; +Time& Time::operator=(const Time& other) { + if (this != &other) { + this->m_val = other.m_val; } + return *this; +} - bool Time::operator==(const Time& other) const { - return (Time::compare(*this,other) == EQ); - } +bool Time::operator==(const Time& other) const { + return (Time::compare(*this, other) == EQ); +} - bool Time::operator!=(const Time& other) const { - return (Time::compare(*this,other) != EQ); - } +bool Time::operator!=(const Time& other) const { + return (Time::compare(*this, other) != EQ); +} - bool Time::operator>(const Time& other) const { - return (Time::compare(*this,other) == GT); - } +bool Time::operator>(const Time& other) const { + return (Time::compare(*this, other) == GT); +} - bool Time::operator<(const Time& other) const { - return (Time::compare(*this,other) == LT); - } +bool Time::operator<(const Time& other) const { + return (Time::compare(*this, other) == LT); +} - bool Time::operator>=(const Time& other) const { - Time::Comparison c = Time::compare(*this,other); - return ((GT == c) or (EQ == c)); - } +bool Time::operator>=(const Time& other) const { + Time::Comparison c = Time::compare(*this, other); + return ((GT == c) or (EQ == c)); +} - bool Time::operator<=(const Time& other) const { - Time::Comparison c = Time::compare(*this,other); - return ((LT == c) or (EQ == c)); - } +bool Time::operator<=(const Time& other) const { + Time::Comparison c = Time::compare(*this, other); + return ((LT == c) or (EQ == c)); +} - SerializeStatus Time::serializeTo(SerializeBufferBase& buffer) const { - // Fallback approach for backward compatibility: - // Try new interface first, but if it returns UNIMPLEMENTED (indicating default implementation), - // fall back to old interface. This bridges auto-generated enums/structs (old interface only) - // with new serialization infrastructure. - SerializeStatus status = this->m_val.serializeTo(buffer); - if (status == FW_SERIALIZE_UNIMPLEMENTED) { - // Fallback to old interface for backward compatibility - status = this->m_val.serialize(buffer); - } - return status; - } +SerializeStatus Time::serializeTo(SerializeBufferBase& buffer) const { + // Fallback approach for backward compatibility: + // Try new interface first, but if it returns UNIMPLEMENTED (indicating default implementation), + // fall back to old interface. This bridges auto-generated enums/structs (old interface only) + // with new serialization infrastructure. + SerializeStatus status = this->m_val.serializeTo(buffer); + if (status == FW_SERIALIZE_UNIMPLEMENTED) { + // Fallback to old interface for backward compatibility + status = this->m_val.serialize(buffer); + } + return status; +} - SerializeStatus Time::deserializeFrom(SerializeBufferBase& buffer) { - // Fallback approach for backward compatibility: - // Try new interface first, but if it returns UNIMPLEMENTED (indicating default implementation), - // fall back to old interface. - SerializeStatus status = this->m_val.deserializeFrom(buffer); - if (status == FW_DESERIALIZE_UNIMPLEMENTED) { - // Fallback to old interface for backward compatibility - status = this->m_val.deserialize(buffer); - } - return status; +SerializeStatus Time::deserializeFrom(SerializeBufferBase& buffer) { + // Fallback approach for backward compatibility: + // Try new interface first, but if it returns UNIMPLEMENTED (indicating default implementation), + // fall back to old interface. + SerializeStatus status = this->m_val.deserializeFrom(buffer); + if (status == FW_DESERIALIZE_UNIMPLEMENTED) { + // Fallback to old interface for backward compatibility + status = this->m_val.deserialize(buffer); } + return status; +} - // Deprecated methods for backward compatibility - these call the new interface - SerializeStatus Time::serialize(SerializeBufferBase& buffer) const { - return this->serializeTo(buffer); - } +// Deprecated methods for backward compatibility - these call the new interface +SerializeStatus Time::serialize(SerializeBufferBase& buffer) const { + return this->serializeTo(buffer); +} - SerializeStatus Time::deserialize(SerializeBufferBase& buffer) { - return this->deserializeFrom(buffer); - } +SerializeStatus Time::deserialize(SerializeBufferBase& buffer) { + return this->deserializeFrom(buffer); +} - U32 Time::getSeconds() const { - return this->m_val.get_seconds(); - } +U32 Time::getSeconds() const { + return this->m_val.get_seconds(); +} - U32 Time::getUSeconds() const { - return this->m_val.get_useconds(); - } +U32 Time::getUSeconds() const { + return this->m_val.get_useconds(); +} - TimeBase Time::getTimeBase() const { - return this->m_val.get_timeBase(); - } +TimeBase Time::getTimeBase() const { + return this->m_val.get_timeBase(); +} - FwTimeContextStoreType Time::getContext() const { - return this->m_val.get_timeContext(); - } +FwTimeContextStoreType Time::getContext() const { + return this->m_val.get_timeContext(); +} - Time Time :: - zero(TimeBase timeBase) - { - Time time(timeBase,0, 0, 0); - return time; - } +Time Time ::zero(TimeBase timeBase) { + Time time(timeBase, 0, 0, 0); + return time; +} - Time::Comparison Time :: - compare( - const Time &time1, - const Time &time2 - ) - { - if (time1.getTimeBase() != time2.getTimeBase()) { - return INCOMPARABLE; - } +Time::Comparison Time ::compare(const Time& time1, const Time& time2) { + if (time1.getTimeBase() != time2.getTimeBase()) { + return INCOMPARABLE; + } - // Do not compare time context + // Do not compare time context - const U32 s1 = time1.getSeconds(); - const U32 s2 = time2.getSeconds(); - const U32 us1 = time1.getUSeconds(); - const U32 us2 = time2.getUSeconds(); + const U32 s1 = time1.getSeconds(); + const U32 s2 = time2.getSeconds(); + const U32 us1 = time1.getUSeconds(); + const U32 us2 = time2.getUSeconds(); - if (s1 < s2) { + if (s1 < s2) { return LT; - } else if (s1 > s2) { + } else if (s1 > s2) { return GT; - } else if (us1 < us2) { + } else if (us1 < us2) { return LT; - } else if (us1 > us2) { + } else if (us1 > us2) { return GT; - } else { + } else { return EQ; - } } +} - Time Time :: - add( - const Time& a, - const Time& b - ) - { - FW_ASSERT(a.getTimeBase() == b.getTimeBase(), static_cast(a.getTimeBase()), static_cast(b.getTimeBase()) ); - // Do not assert on time context match - - U32 seconds = a.getSeconds() + b.getSeconds(); - U32 uSeconds = a.getUSeconds() + b.getUSeconds(); - FW_ASSERT(uSeconds < 1999999); - if (uSeconds >= 1000000) { +Time Time ::add(const Time& a, const Time& b) { + FW_ASSERT(a.getTimeBase() == b.getTimeBase(), static_cast(a.getTimeBase()), + static_cast(b.getTimeBase())); + // Do not assert on time context match + + U32 seconds = a.getSeconds() + b.getSeconds(); + U32 uSeconds = a.getUSeconds() + b.getUSeconds(); + FW_ASSERT(uSeconds < 1999999); + if (uSeconds >= 1000000) { ++seconds; uSeconds -= 1000000; - } + } - // Return a time context of 0 if they do not match - FwTimeContextStoreType context = a.getContext(); - if (a.getContext() != b.getContext()){ + // Return a time context of 0 if they do not match + FwTimeContextStoreType context = a.getContext(); + if (a.getContext() != b.getContext()) { context = 0; - } - - Time c(a.getTimeBase(), context, seconds, uSeconds); - return c; } - Time Time :: - sub( - const Time& minuend, //!< Time minuend - const Time& subtrahend //!< Time subtrahend - ) - { - FW_ASSERT(minuend.getTimeBase() == subtrahend.getTimeBase(), static_cast(minuend.getTimeBase()), static_cast(subtrahend.getTimeBase())); - // Do not assert on time context match - // Assert minuend is greater than subtrahend - FW_ASSERT(minuend >= subtrahend); - - U32 seconds = minuend.getSeconds() - subtrahend.getSeconds(); - U32 uSeconds; - if (subtrahend.getUSeconds() > minuend.getUSeconds()) { - seconds--; - uSeconds = minuend.getUSeconds() + 1000000 - subtrahend.getUSeconds(); - } else { - uSeconds = minuend.getUSeconds() - subtrahend.getUSeconds(); - } - - // Return a time context of 0 if they do not match - FwTimeContextStoreType context = minuend.getContext(); - if (minuend.getContext() != subtrahend.getContext()){ - context = 0; - } + Time c(a.getTimeBase(), context, seconds, uSeconds); + return c; +} - return Time(minuend.getTimeBase(), context, seconds, static_cast(uSeconds)); +Time Time ::sub(const Time& minuend, //!< Time minuend + const Time& subtrahend //!< Time subtrahend +) { + FW_ASSERT(minuend.getTimeBase() == subtrahend.getTimeBase(), static_cast(minuend.getTimeBase()), + static_cast(subtrahend.getTimeBase())); + // Do not assert on time context match + // Assert minuend is greater than subtrahend + FW_ASSERT(minuend >= subtrahend); + + U32 seconds = minuend.getSeconds() - subtrahend.getSeconds(); + U32 uSeconds; + if (subtrahend.getUSeconds() > minuend.getUSeconds()) { + seconds--; + uSeconds = minuend.getUSeconds() + 1000000 - subtrahend.getUSeconds(); + } else { + uSeconds = minuend.getUSeconds() - subtrahend.getUSeconds(); + } + + // Return a time context of 0 if they do not match + FwTimeContextStoreType context = minuend.getContext(); + if (minuend.getContext() != subtrahend.getContext()) { + context = 0; } - void Time::add(U32 seconds, U32 useconds) { - U32 newSeconds = this->m_val.get_seconds() + seconds; - U32 newUSeconds = this->m_val.get_useconds() + useconds; - FW_ASSERT(newUSeconds < 1999999, static_cast(newUSeconds)); - if (newUSeconds >= 1000000) { - newSeconds += 1; - newUSeconds -= 1000000; - } - this->set(newSeconds, newUSeconds); - } + return Time(minuend.getTimeBase(), context, seconds, static_cast(uSeconds)); +} - void Time::setTimeBase(TimeBase timeBase) { - this->m_val.set_timeBase(timeBase); +void Time::add(U32 seconds, U32 useconds) { + U32 newSeconds = this->m_val.get_seconds() + seconds; + U32 newUSeconds = this->m_val.get_useconds() + useconds; + FW_ASSERT(newUSeconds < 1999999, static_cast(newUSeconds)); + if (newUSeconds >= 1000000) { + newSeconds += 1; + newUSeconds -= 1000000; } + this->set(newSeconds, newUSeconds); +} - void Time::setTimeContext(FwTimeContextStoreType context) { - this->m_val.set_timeContext(context); - } +void Time::setTimeBase(TimeBase timeBase) { + this->m_val.set_timeBase(timeBase); +} -#ifdef BUILD_UT - std::ostream& operator<<(std::ostream& os, const Time& val) { +void Time::setTimeContext(FwTimeContextStoreType context) { + this->m_val.set_timeContext(context); +} - os << "(" << val.getTimeBase() << "," << val.getUSeconds() << "," << val.getSeconds() << ")"; - return os; - } +#ifdef BUILD_UT +std::ostream& operator<<(std::ostream& os, const Time& val) { + os << "(" << val.getTimeBase() << "," << val.getUSeconds() << "," << val.getSeconds() << ")"; + return os; +} #endif -} +} // namespace Fw diff --git a/Fw/Time/Time.hpp b/Fw/Time/Time.hpp index db13485e5d3..619d5d57f57 100644 --- a/Fw/Time/Time.hpp +++ b/Fw/Time/Time.hpp @@ -2,95 +2,88 @@ #define FW_TIME_HPP #include +#include #include #include #include -#include namespace Fw { - class Time: public Serializable { - - friend class TimeTester; - - public: +class Time : public Serializable { + friend class TimeTester; - enum { - SERIALIZED_SIZE = sizeof(FwTimeBaseStoreType) - + sizeof(FwTimeContextStoreType) - + sizeof(U32) + sizeof(U32) - }; + public: + enum { SERIALIZED_SIZE = sizeof(FwTimeBaseStoreType) + sizeof(FwTimeContextStoreType) + sizeof(U32) + sizeof(U32) }; - Time(); // !< Default constructor - Time(const Time& other); // !< Copy constructor - Time(U32 seconds, U32 useconds); // !< Constructor with member values as arguments - Time(TimeBase timeBase, U32 seconds, U32 useconds); // !< Constructor with member values as arguments - Time(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 useconds); // !< Constructor with member values as arguments - virtual ~Time(); // !< Destructor - void set(U32 seconds, U32 useconds); // !< Sets value of time stored - void set(TimeBase timeBase, U32 seconds, U32 useconds); // !< Sets value of time stored - void set(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 useconds); // !< Sets value of time stored - void setTimeBase(TimeBase timeBase); - void setTimeContext(FwTimeContextStoreType context); - U32 getSeconds() const; // !< Gets seconds part of time - U32 getUSeconds() const; // !< Gets microseconds part of time - TimeBase getTimeBase() const; // !< Time base of time. This is project specific and is meant for indicating different sources of time - FwTimeContextStoreType getContext() const; // !< get the context value - SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; // !< Serialize method - SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; // !< Deserialize method - SerializeStatus serialize(SerializeBufferBase& buffer) const override; // !< Serialize method (deprecated) - SerializeStatus deserialize(SerializeBufferBase& buffer) override; // !< Deserialize method (deprecated) - bool operator==(const Time& other) const; - bool operator!=(const Time& other) const; - bool operator>(const Time& other) const; - bool operator<(const Time& other) const; - bool operator>=(const Time& other) const; - bool operator<=(const Time& other) const; - Time& operator=(const Time& other); + Time(); // !< Default constructor + Time(const Time& other); // !< Copy constructor + Time(U32 seconds, U32 useconds); // !< Constructor with member values as arguments + Time(TimeBase timeBase, U32 seconds, U32 useconds); // !< Constructor with member values as arguments + Time(TimeBase timeBase, + FwTimeContextStoreType context, + U32 seconds, + U32 useconds); // !< Constructor with member values as arguments + virtual ~Time(); // !< Destructor + void set(U32 seconds, U32 useconds); // !< Sets value of time stored + void set(TimeBase timeBase, U32 seconds, U32 useconds); // !< Sets value of time stored + void set(TimeBase timeBase, + FwTimeContextStoreType context, + U32 seconds, + U32 useconds); // !< Sets value of time stored + void setTimeBase(TimeBase timeBase); + void setTimeContext(FwTimeContextStoreType context); + U32 getSeconds() const; // !< Gets seconds part of time + U32 getUSeconds() const; // !< Gets microseconds part of time + TimeBase getTimeBase() + const; // !< Time base of time. This is project specific and is meant for indicating different sources of time + FwTimeContextStoreType getContext() const; // !< get the context value + SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; // !< Serialize method + SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; // !< Deserialize method + SerializeStatus serialize(SerializeBufferBase& buffer) const override; // !< Serialize method (deprecated) + SerializeStatus deserialize(SerializeBufferBase& buffer) override; // !< Deserialize method (deprecated) + bool operator==(const Time& other) const; + bool operator!=(const Time& other) const; + bool operator>(const Time& other) const; + bool operator<(const Time& other) const; + bool operator>=(const Time& other) const; + bool operator<=(const Time& other) const; + Time& operator=(const Time& other); - // Static methods: - //! The type of a comparison result - typedef enum { - LT = -1, - EQ = 0, - GT = 1, - INCOMPARABLE = 2 - } Comparison; + // Static methods: + //! The type of a comparison result + typedef enum { LT = -1, EQ = 0, GT = 1, INCOMPARABLE = 2 } Comparison; - //! \return time zero - static Time zero(TimeBase timeBase=TimeBase::TB_NONE); + //! \return time zero + static Time zero(TimeBase timeBase = TimeBase::TB_NONE); - //! Compare two times - //! \return The result - static Comparison compare( - const Time &time1, //!< Time 1 - const Time &time2 //!< Time 2 - ); + //! Compare two times + //! \return The result + static Comparison compare(const Time& time1, //!< Time 1 + const Time& time2 //!< Time 2 + ); - //! Add two times - //! \return The result - static Time add( - const Time& a, //!< Time a - const Time& b //!< Time b - ); + //! Add two times + //! \return The result + static Time add(const Time& a, //!< Time a + const Time& b //!< Time b + ); - //! Subtract subtrahend from minuend - //! \return The result - static Time sub( - const Time& minuend, //!< Value being subtracted from - const Time& subtrahend //!< Value being subtracted - ); + //! Subtract subtrahend from minuend + //! \return The result + static Time sub(const Time& minuend, //!< Value being subtracted from + const Time& subtrahend //!< Value being subtracted + ); - // add seconds and microseconds to existing time - void add(U32 seconds, U32 mseconds); + // add seconds and microseconds to existing time + void add(U32 seconds, U32 mseconds); -#ifdef BUILD_UT // Stream operators to support Googletest - friend std::ostream& operator<<(std::ostream& os, const Time& val); +#ifdef BUILD_UT // Stream operators to support Googletest + friend std::ostream& operator<<(std::ostream& os, const Time& val); #endif - private: - TimeValue m_val; // !< Time value - }; - extern const Time ZERO_TIME; + private: + TimeValue m_val; // !< Time value +}; +extern const Time ZERO_TIME; -} +} // namespace Fw #endif diff --git a/Fw/Time/TimeInterval.cpp b/Fw/Time/TimeInterval.cpp index f5337e3f84c..aa5b7b22862 100644 --- a/Fw/Time/TimeInterval.cpp +++ b/Fw/Time/TimeInterval.cpp @@ -1,158 +1,144 @@ -#include #include +#include namespace Fw { - TimeInterval::TimeInterval(const TimeInterval& other) : Serializable() { - this->m_val = other.m_val; - } - - TimeInterval::TimeInterval(U32 seconds, U32 useconds) : Serializable() { - this->set(seconds,useconds); - } - - void TimeInterval::set(U32 seconds, U32 useconds) { - this->m_val.set(seconds, useconds); - } - - TimeInterval& TimeInterval::operator=(const TimeInterval& other) { - if (this != &other) { - this->m_val = other.m_val; - } - return *this; - } - - bool TimeInterval::operator==(const TimeInterval& other) const { - return (TimeInterval::compare(*this, other) == EQ); - } - - bool TimeInterval::operator!=(const TimeInterval& other) const { - return (TimeInterval::compare(*this, other) != EQ); - } - - bool TimeInterval::operator>(const TimeInterval& other) const { - return (TimeInterval::compare(*this, other) == GT); - } - - bool TimeInterval::operator<(const TimeInterval& other) const { - return (TimeInterval::compare(*this, other) == LT); - } - - bool TimeInterval::operator>=(const TimeInterval& other) const { - TimeInterval::Comparison c = TimeInterval::compare(*this, other); - return ((GT == c) or (EQ == c)); - } - - bool TimeInterval::operator<=(const TimeInterval& other) const { - TimeInterval::Comparison c = TimeInterval::compare(*this, other); - return ((LT == c) or (EQ == c)); - } - - SerializeStatus TimeInterval::serialize(SerializeBufferBase& buffer) const { - // Deprecated method - calls new interface for backward compatibility - return this->serializeTo(buffer); - } +TimeInterval::TimeInterval(const TimeInterval& other) : Serializable() { + this->m_val = other.m_val; +} - SerializeStatus TimeInterval::deserialize(SerializeBufferBase& buffer) { - // Deprecated method - calls new interface for backward compatibility - return this->deserializeFrom(buffer); - } +TimeInterval::TimeInterval(U32 seconds, U32 useconds) : Serializable() { + this->set(seconds, useconds); +} - SerializeStatus TimeInterval::serializeTo(SerializeBufferBase& buffer) const { - // Use TimeIntervalValue's built-in serialization - return this->m_val.serializeTo(buffer); - } +void TimeInterval::set(U32 seconds, U32 useconds) { + this->m_val.set(seconds, useconds); +} - SerializeStatus TimeInterval::deserializeFrom(SerializeBufferBase& buffer) { - // Use TimeIntervalValue's built-in deserialization - return this->m_val.deserializeFrom(buffer); - } - - U32 TimeInterval::getSeconds() const { - return this->m_val.get_seconds(); - } - - U32 TimeInterval::getUSeconds() const { - return this->m_val.get_useconds(); +TimeInterval& TimeInterval::operator=(const TimeInterval& other) { + if (this != &other) { + this->m_val = other.m_val; } - - TimeInterval::Comparison TimeInterval :: - compare( - const TimeInterval &time1, - const TimeInterval &time2 - ) - { - const U32 s1 = time1.getSeconds(); - const U32 s2 = time2.getSeconds(); - const U32 us1 = time1.getUSeconds(); - const U32 us2 = time2.getUSeconds(); - - if (s1 < s2) { + return *this; +} + +bool TimeInterval::operator==(const TimeInterval& other) const { + return (TimeInterval::compare(*this, other) == EQ); +} + +bool TimeInterval::operator!=(const TimeInterval& other) const { + return (TimeInterval::compare(*this, other) != EQ); +} + +bool TimeInterval::operator>(const TimeInterval& other) const { + return (TimeInterval::compare(*this, other) == GT); +} + +bool TimeInterval::operator<(const TimeInterval& other) const { + return (TimeInterval::compare(*this, other) == LT); +} + +bool TimeInterval::operator>=(const TimeInterval& other) const { + TimeInterval::Comparison c = TimeInterval::compare(*this, other); + return ((GT == c) or (EQ == c)); +} + +bool TimeInterval::operator<=(const TimeInterval& other) const { + TimeInterval::Comparison c = TimeInterval::compare(*this, other); + return ((LT == c) or (EQ == c)); +} + +SerializeStatus TimeInterval::serialize(SerializeBufferBase& buffer) const { + // Deprecated method - calls new interface for backward compatibility + return this->serializeTo(buffer); +} + +SerializeStatus TimeInterval::deserialize(SerializeBufferBase& buffer) { + // Deprecated method - calls new interface for backward compatibility + return this->deserializeFrom(buffer); +} + +SerializeStatus TimeInterval::serializeTo(SerializeBufferBase& buffer) const { + // Use TimeIntervalValue's built-in serialization + return this->m_val.serializeTo(buffer); +} + +SerializeStatus TimeInterval::deserializeFrom(SerializeBufferBase& buffer) { + // Use TimeIntervalValue's built-in deserialization + return this->m_val.deserializeFrom(buffer); +} + +U32 TimeInterval::getSeconds() const { + return this->m_val.get_seconds(); +} + +U32 TimeInterval::getUSeconds() const { + return this->m_val.get_useconds(); +} + +TimeInterval::Comparison TimeInterval ::compare(const TimeInterval& time1, const TimeInterval& time2) { + const U32 s1 = time1.getSeconds(); + const U32 s2 = time2.getSeconds(); + const U32 us1 = time1.getUSeconds(); + const U32 us2 = time2.getUSeconds(); + + if (s1 < s2) { return LT; - } else if (s1 > s2) { + } else if (s1 > s2) { return GT; - } else if (us1 < us2) { + } else if (us1 < us2) { return LT; - } else if (us1 > us2) { + } else if (us1 > us2) { return GT; - } else { + } else { return EQ; - } } +} - TimeInterval TimeInterval :: - add( - const TimeInterval& a, - const TimeInterval& b - ) - { - U32 seconds = a.getSeconds() + b.getSeconds(); - U32 uSeconds = a.getUSeconds() + b.getUSeconds(); - FW_ASSERT(uSeconds < 1999999); - if (uSeconds >= 1000000) { +TimeInterval TimeInterval ::add(const TimeInterval& a, const TimeInterval& b) { + U32 seconds = a.getSeconds() + b.getSeconds(); + U32 uSeconds = a.getUSeconds() + b.getUSeconds(); + FW_ASSERT(uSeconds < 1999999); + if (uSeconds >= 1000000) { ++seconds; uSeconds -= 1000000; - } - TimeInterval c(seconds,uSeconds); - return c; - } - - TimeInterval TimeInterval :: - sub( - const TimeInterval& t1, //!< TimeInterval t1 - const TimeInterval& t2 //!< TimeInterval t2 - ) - { - const TimeInterval& minuend = (t1 > t2) ? t1 : t2; - const TimeInterval& subtrahend = (t1 > t2) ? t2 : t1; - - U32 seconds = minuend.getSeconds() - subtrahend.getSeconds(); - U32 uSeconds; - if (subtrahend.getUSeconds() > minuend.getUSeconds()) { - seconds--; - uSeconds = minuend.getUSeconds() + 1000000 - subtrahend.getUSeconds(); - } else { - uSeconds = minuend.getUSeconds() - subtrahend.getUSeconds(); - } - return TimeInterval(seconds, static_cast(uSeconds)); - } - - void TimeInterval::add(U32 seconds, U32 useconds) { - U32 newSeconds = this->m_val.get_seconds() + seconds; - U32 newUSeconds = this->m_val.get_useconds() + useconds; - FW_ASSERT(newUSeconds < 1999999, static_cast(newUSeconds)); - if (newUSeconds >= 1000000) { - newSeconds += 1; - newUSeconds -= 1000000; - } - this->m_val.set(newSeconds, newUSeconds); } + TimeInterval c(seconds, uSeconds); + return c; +} + +TimeInterval TimeInterval ::sub(const TimeInterval& t1, //!< TimeInterval t1 + const TimeInterval& t2 //!< TimeInterval t2 +) { + const TimeInterval& minuend = (t1 > t2) ? t1 : t2; + const TimeInterval& subtrahend = (t1 > t2) ? t2 : t1; + + U32 seconds = minuend.getSeconds() - subtrahend.getSeconds(); + U32 uSeconds; + if (subtrahend.getUSeconds() > minuend.getUSeconds()) { + seconds--; + uSeconds = minuend.getUSeconds() + 1000000 - subtrahend.getUSeconds(); + } else { + uSeconds = minuend.getUSeconds() - subtrahend.getUSeconds(); + } + return TimeInterval(seconds, static_cast(uSeconds)); +} + +void TimeInterval::add(U32 seconds, U32 useconds) { + U32 newSeconds = this->m_val.get_seconds() + seconds; + U32 newUSeconds = this->m_val.get_useconds() + useconds; + FW_ASSERT(newUSeconds < 1999999, static_cast(newUSeconds)); + if (newUSeconds >= 1000000) { + newSeconds += 1; + newUSeconds -= 1000000; + } + this->m_val.set(newSeconds, newUSeconds); +} #ifdef BUILD_UT - std::ostream& operator<<(std::ostream& os, const TimeInterval& val) { - - os << "(" << val.getSeconds() << "s," << val.getUSeconds() << "us)"; - return os; - } +std::ostream& operator<<(std::ostream& os, const TimeInterval& val) { + os << "(" << val.getSeconds() << "s," << val.getUSeconds() << "us)"; + return os; +} #endif -} \ No newline at end of file +} // namespace Fw \ No newline at end of file diff --git a/Fw/Time/TimeInterval.hpp b/Fw/Time/TimeInterval.hpp index ad5d165afe3..1b74e35c652 100644 --- a/Fw/Time/TimeInterval.hpp +++ b/Fw/Time/TimeInterval.hpp @@ -2,9 +2,9 @@ #define FW_TIME_INTERVAL_HPP #include +#include #include #include -#include //! //! @class TimeInterval @@ -16,78 +16,65 @@ //! namespace Fw { - class TimeInterval: public Serializable { - public: - - enum { - SERIALIZED_SIZE = sizeof(U32) * 2 - }; - - TimeInterval() = default; // !< Default constructor - ~TimeInterval() = default; // !< Default destructor - TimeInterval(const TimeInterval& other); // !< Copy constructor - TimeInterval(U32 seconds, U32 useconds); // !< Constructor with member values as arguments - void set(U32 seconds, U32 useconds); // !< Sets value of time stored - U32 getSeconds() const; // !< Gets seconds part of time - U32 getUSeconds() const; // !< Gets microseconds part of time - SerializeStatus serialize(SerializeBufferBase& buffer) const override; // !< Serialize method - SerializeStatus deserialize(SerializeBufferBase& buffer) override; // !< Deserialize method - - SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; // !< Serialize method - SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; // !< Deserialize method - void add(U32 seconds, U32 mseconds); // !< Add seconds and microseconds to existing time interval - bool operator==(const TimeInterval& other) const; - bool operator!=(const TimeInterval& other) const; - bool operator>(const TimeInterval& other) const; - bool operator<(const TimeInterval& other) const; - bool operator>=(const TimeInterval& other) const; - bool operator<=(const TimeInterval& other) const; - TimeInterval& operator=(const TimeInterval& other); +class TimeInterval : public Serializable { + public: + enum { SERIALIZED_SIZE = sizeof(U32) * 2 }; - //! The type of a comparison result - typedef enum { - LT = -1, - EQ = 0, - GT = 1, - INCOMPARABLE = 2 - } Comparison; + TimeInterval() = default; // !< Default constructor + ~TimeInterval() = default; // !< Default destructor + TimeInterval(const TimeInterval& other); // !< Copy constructor + TimeInterval(U32 seconds, U32 useconds); // !< Constructor with member values as arguments + void set(U32 seconds, U32 useconds); // !< Sets value of time stored + U32 getSeconds() const; // !< Gets seconds part of time + U32 getUSeconds() const; // !< Gets microseconds part of time + SerializeStatus serialize(SerializeBufferBase& buffer) const override; // !< Serialize method + SerializeStatus deserialize(SerializeBufferBase& buffer) override; // !< Deserialize method - //! Compare two time intervals - //! A time interval is considered greater than another if it spans a longer duration - //! The comparison is done on the seconds first, then the microseconds if the seconds are equal - //! \return TimeInterval result - static Comparison compare( - const TimeInterval &time1, //!< TimeInterval 1 - const TimeInterval &time2 //!< TimeInterval 2 - ); + SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; // !< Serialize method + SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; // !< Deserialize method + void add(U32 seconds, U32 mseconds); // !< Add seconds and microseconds to existing time interval + bool operator==(const TimeInterval& other) const; + bool operator!=(const TimeInterval& other) const; + bool operator>(const TimeInterval& other) const; + bool operator<(const TimeInterval& other) const; + bool operator>=(const TimeInterval& other) const; + bool operator<=(const TimeInterval& other) const; + TimeInterval& operator=(const TimeInterval& other); - //! Add two time intervals - //! Adds the seconds and microseconds fields of two time intervals together - //! \return TimeInterval result - static TimeInterval add( - const TimeInterval& a, //!< TimeInterval a - const TimeInterval& b //!< TimeInterval b - ); + //! The type of a comparison result + typedef enum { LT = -1, EQ = 0, GT = 1, INCOMPARABLE = 2 } Comparison; - //! Subtract two time intervals - //! This computes the absolute value of the difference between two time intervals - //! For example if t1=(0s, 5us) and t2=(0s, 3us), the result is (0s, 2us). - //! This operation is commutative, i.e. the result is the same regardless of the order of the arguments. - //! \return TimeInterval result - static TimeInterval sub( - const TimeInterval& t1, //!< TimeInterval 1 - const TimeInterval& t2 //!< TimeInterval 2 - ); + //! Compare two time intervals + //! A time interval is considered greater than another if it spans a longer duration + //! The comparison is done on the seconds first, then the microseconds if the seconds are equal + //! \return TimeInterval result + static Comparison compare(const TimeInterval& time1, //!< TimeInterval 1 + const TimeInterval& time2 //!< TimeInterval 2 + ); + //! Add two time intervals + //! Adds the seconds and microseconds fields of two time intervals together + //! \return TimeInterval result + static TimeInterval add(const TimeInterval& a, //!< TimeInterval a + const TimeInterval& b //!< TimeInterval b + ); + //! Subtract two time intervals + //! This computes the absolute value of the difference between two time intervals + //! For example if t1=(0s, 5us) and t2=(0s, 3us), the result is (0s, 2us). + //! This operation is commutative, i.e. the result is the same regardless of the order of the arguments. + //! \return TimeInterval result + static TimeInterval sub(const TimeInterval& t1, //!< TimeInterval 1 + const TimeInterval& t2 //!< TimeInterval 2 + ); -#ifdef BUILD_UT // Stream operators to support Googletest - friend std::ostream& operator<<(std::ostream& os, const TimeInterval& val); +#ifdef BUILD_UT // Stream operators to support Googletest + friend std::ostream& operator<<(std::ostream& os, const TimeInterval& val); #endif - private: - TimeIntervalValue m_val; // !< TimeInterval value - }; + private: + TimeIntervalValue m_val; // !< TimeInterval value +}; -} +} // namespace Fw #endif \ No newline at end of file diff --git a/Fw/Time/test/ut/TimeIntervalTester.cpp b/Fw/Time/test/ut/TimeIntervalTester.cpp index bb8a58353d2..ce4ade97d32 100644 --- a/Fw/Time/test/ut/TimeIntervalTester.cpp +++ b/Fw/Time/test/ut/TimeIntervalTester.cpp @@ -3,126 +3,124 @@ namespace Fw { - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- - - TimeIntervalTester::TimeIntervalTester() { - } - - TimeIntervalTester::~TimeIntervalTester() { - } - - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- - - void TimeIntervalTester::test_TimeIntervalInstantiateTest() { - Fw::TimeInterval time(1,2); - ASSERT_EQ(time.getSeconds(), 1); - ASSERT_EQ(time.getUSeconds(), 2); - std::cout << time << std::endl; - - Fw::TimeInterval time2(time); - ASSERT_EQ(time.getSeconds(), 1); - ASSERT_EQ(time.getUSeconds(), 2); - std::cout << time2 << std::endl; - } - - void TimeIntervalTester::test_TimeIntervalComparisonTest() { - Fw::TimeInterval t1(1, 0); - Fw::TimeInterval t2(1, 0); - Fw::TimeInterval t3(2, 0); - Fw::TimeInterval t4(1, 500000); - - // Equality operators - ASSERT_TRUE(t1 == t2); - ASSERT_FALSE(t1 == t3); - ASSERT_FALSE(t1 == t4); - - // Inequality operators - ASSERT_FALSE(t1 != t2); - ASSERT_TRUE(t1 != t3); - ASSERT_TRUE(t1 != t4); - - // Greater than operators - ASSERT_TRUE(t3 > t1); - ASSERT_FALSE(t1 > t3); - ASSERT_TRUE(t4 > t1); - - // Less than operators - ASSERT_TRUE(t1 < t3); - ASSERT_FALSE(t3 < t1); - ASSERT_TRUE(t1 < t4); - - // Greater than or equal operators - ASSERT_TRUE(t1 >= t2); - ASSERT_TRUE(t3 >= t1); - ASSERT_FALSE(t1 >= t3); - - // Less than or equal operators - ASSERT_TRUE(t1 <= t2); - ASSERT_TRUE(t1 <= t3); - ASSERT_FALSE(t3 <= t1); - } - - void TimeIntervalTester::test_TimeIntervalAdditionTest() { - Fw::TimeInterval t1(1, 500000); - Fw::TimeInterval t2(2, 600000); - - // Test instance add method - t1.add(3, 700000); - // 1 + 3 = 4s, 500000us + 700000us = 1s + 200000us -> 5s, 200000us - ASSERT_EQ(t1.getSeconds(), 5); - ASSERT_EQ(t1.getUSeconds(), 200000); - - // Test static add method - Fw::TimeInterval result = Fw::TimeInterval::add(t1, t2); - // 5 + 2 = 7s, 200000us + 600000us = 800000us - ASSERT_EQ(result.getSeconds(), 7); - ASSERT_EQ(result.getUSeconds(), 800000); - } - - void TimeIntervalTester::test_TimeIntervalCompareStaticTest() { - Fw::TimeInterval t1(1, 0); - Fw::TimeInterval t2(1, 0); - Fw::TimeInterval t3(2, 0); - Fw::TimeInterval t4(1, 500000); - - // Test static compare method - ASSERT_EQ(Fw::TimeInterval::compare(t1, t2), Fw::TimeInterval::EQ); - ASSERT_EQ(Fw::TimeInterval::compare(t1, t3), Fw::TimeInterval::LT); - ASSERT_EQ(Fw::TimeInterval::compare(t3, t1), Fw::TimeInterval::GT); - ASSERT_EQ(Fw::TimeInterval::compare(t1, t4), Fw::TimeInterval::LT); - ASSERT_EQ(Fw::TimeInterval::compare(t4, t1), Fw::TimeInterval::GT); - } - - void TimeIntervalTester::test_TimeIntervalSubtractionTest() { - Fw::TimeInterval t1(5, 500000); - Fw::TimeInterval t2(2, 300000); - Fw::TimeInterval result1 = Fw::TimeInterval::sub(t1, t2); - // 5s - 2s = 3s, 500000us - 300000us = 200000us - ASSERT_EQ(result1.getSeconds(), 3); - ASSERT_EQ(result1.getUSeconds(), 200000); - - // should be the same due to absolute value - Fw::TimeInterval result2 = Fw::TimeInterval::sub(t2, t1); - ASSERT_EQ(result2.getSeconds(), 3); - ASSERT_EQ(result2.getUSeconds(), 200000); - - Fw::TimeInterval t3(5, 200000); - Fw::TimeInterval t4(2, 500000); - Fw::TimeInterval result3 = Fw::TimeInterval::sub(t3, t4); - // 5s - 2s = 3s, 200000us - 500000us requires borrow - // So it's 2s + 700000us - ASSERT_EQ(result3.getSeconds(), 2); - ASSERT_EQ(result3.getUSeconds(), 700000); - - Fw::TimeInterval t5(3, 400000); - Fw::TimeInterval t6(3, 400000); - Fw::TimeInterval result4 = Fw::TimeInterval::sub(t5, t6); - ASSERT_EQ(result4.getSeconds(), 0); - ASSERT_EQ(result4.getUSeconds(), 0); - } - -} // namespace Fw +// ---------------------------------------------------------------------- +// Construction and destruction +// ---------------------------------------------------------------------- + +TimeIntervalTester::TimeIntervalTester() {} + +TimeIntervalTester::~TimeIntervalTester() {} + +// ---------------------------------------------------------------------- +// Tests +// ---------------------------------------------------------------------- + +void TimeIntervalTester::test_TimeIntervalInstantiateTest() { + Fw::TimeInterval time(1, 2); + ASSERT_EQ(time.getSeconds(), 1); + ASSERT_EQ(time.getUSeconds(), 2); + std::cout << time << std::endl; + + Fw::TimeInterval time2(time); + ASSERT_EQ(time.getSeconds(), 1); + ASSERT_EQ(time.getUSeconds(), 2); + std::cout << time2 << std::endl; +} + +void TimeIntervalTester::test_TimeIntervalComparisonTest() { + Fw::TimeInterval t1(1, 0); + Fw::TimeInterval t2(1, 0); + Fw::TimeInterval t3(2, 0); + Fw::TimeInterval t4(1, 500000); + + // Equality operators + ASSERT_TRUE(t1 == t2); + ASSERT_FALSE(t1 == t3); + ASSERT_FALSE(t1 == t4); + + // Inequality operators + ASSERT_FALSE(t1 != t2); + ASSERT_TRUE(t1 != t3); + ASSERT_TRUE(t1 != t4); + + // Greater than operators + ASSERT_TRUE(t3 > t1); + ASSERT_FALSE(t1 > t3); + ASSERT_TRUE(t4 > t1); + + // Less than operators + ASSERT_TRUE(t1 < t3); + ASSERT_FALSE(t3 < t1); + ASSERT_TRUE(t1 < t4); + + // Greater than or equal operators + ASSERT_TRUE(t1 >= t2); + ASSERT_TRUE(t3 >= t1); + ASSERT_FALSE(t1 >= t3); + + // Less than or equal operators + ASSERT_TRUE(t1 <= t2); + ASSERT_TRUE(t1 <= t3); + ASSERT_FALSE(t3 <= t1); +} + +void TimeIntervalTester::test_TimeIntervalAdditionTest() { + Fw::TimeInterval t1(1, 500000); + Fw::TimeInterval t2(2, 600000); + + // Test instance add method + t1.add(3, 700000); + // 1 + 3 = 4s, 500000us + 700000us = 1s + 200000us -> 5s, 200000us + ASSERT_EQ(t1.getSeconds(), 5); + ASSERT_EQ(t1.getUSeconds(), 200000); + + // Test static add method + Fw::TimeInterval result = Fw::TimeInterval::add(t1, t2); + // 5 + 2 = 7s, 200000us + 600000us = 800000us + ASSERT_EQ(result.getSeconds(), 7); + ASSERT_EQ(result.getUSeconds(), 800000); +} + +void TimeIntervalTester::test_TimeIntervalCompareStaticTest() { + Fw::TimeInterval t1(1, 0); + Fw::TimeInterval t2(1, 0); + Fw::TimeInterval t3(2, 0); + Fw::TimeInterval t4(1, 500000); + + // Test static compare method + ASSERT_EQ(Fw::TimeInterval::compare(t1, t2), Fw::TimeInterval::EQ); + ASSERT_EQ(Fw::TimeInterval::compare(t1, t3), Fw::TimeInterval::LT); + ASSERT_EQ(Fw::TimeInterval::compare(t3, t1), Fw::TimeInterval::GT); + ASSERT_EQ(Fw::TimeInterval::compare(t1, t4), Fw::TimeInterval::LT); + ASSERT_EQ(Fw::TimeInterval::compare(t4, t1), Fw::TimeInterval::GT); +} + +void TimeIntervalTester::test_TimeIntervalSubtractionTest() { + Fw::TimeInterval t1(5, 500000); + Fw::TimeInterval t2(2, 300000); + Fw::TimeInterval result1 = Fw::TimeInterval::sub(t1, t2); + // 5s - 2s = 3s, 500000us - 300000us = 200000us + ASSERT_EQ(result1.getSeconds(), 3); + ASSERT_EQ(result1.getUSeconds(), 200000); + + // should be the same due to absolute value + Fw::TimeInterval result2 = Fw::TimeInterval::sub(t2, t1); + ASSERT_EQ(result2.getSeconds(), 3); + ASSERT_EQ(result2.getUSeconds(), 200000); + + Fw::TimeInterval t3(5, 200000); + Fw::TimeInterval t4(2, 500000); + Fw::TimeInterval result3 = Fw::TimeInterval::sub(t3, t4); + // 5s - 2s = 3s, 200000us - 500000us requires borrow + // So it's 2s + 700000us + ASSERT_EQ(result3.getSeconds(), 2); + ASSERT_EQ(result3.getUSeconds(), 700000); + + Fw::TimeInterval t5(3, 400000); + Fw::TimeInterval t6(3, 400000); + Fw::TimeInterval result4 = Fw::TimeInterval::sub(t5, t6); + ASSERT_EQ(result4.getSeconds(), 0); + ASSERT_EQ(result4.getUSeconds(), 0); +} + +} // namespace Fw diff --git a/Fw/Time/test/ut/TimeIntervalTester.hpp b/Fw/Time/test/ut/TimeIntervalTester.hpp index 5d337da3882..0f8207de762 100644 --- a/Fw/Time/test/ut/TimeIntervalTester.hpp +++ b/Fw/Time/test/ut/TimeIntervalTester.hpp @@ -1,27 +1,27 @@ #ifndef FW_TIME_INTERVAL_TESTER_HPP #define FW_TIME_INTERVAL_TESTER_HPP -#include #include +#include namespace Fw { - class TimeIntervalTester { - public: - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- - TimeIntervalTester(); - ~TimeIntervalTester(); +class TimeIntervalTester { + public: + // ---------------------------------------------------------------------- + // Construction and destruction + // ---------------------------------------------------------------------- + TimeIntervalTester(); + ~TimeIntervalTester(); - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- - void test_TimeIntervalInstantiateTest(); - void test_TimeIntervalComparisonTest(); - void test_TimeIntervalCompareStaticTest(); - void test_TimeIntervalAdditionTest(); - void test_TimeIntervalSubtractionTest(); - }; -} // namespace Fw + // ---------------------------------------------------------------------- + // Tests + // ---------------------------------------------------------------------- + void test_TimeIntervalInstantiateTest(); + void test_TimeIntervalComparisonTest(); + void test_TimeIntervalCompareStaticTest(); + void test_TimeIntervalAdditionTest(); + void test_TimeIntervalSubtractionTest(); +}; +} // namespace Fw -#endif // FW_TIME_INTERVAL_TESTER_HPP +#endif // FW_TIME_INTERVAL_TESTER_HPP diff --git a/Fw/Time/test/ut/TimeTestMain.cpp b/Fw/Time/test/ut/TimeTestMain.cpp index eb4ea93144c..b4e9962e9e0 100644 --- a/Fw/Time/test/ut/TimeTestMain.cpp +++ b/Fw/Time/test/ut/TimeTestMain.cpp @@ -5,9 +5,9 @@ * Author: tcanham */ -#include "TimeTester.hpp" -#include "TimeIntervalTester.hpp" #include +#include "TimeIntervalTester.hpp" +#include "TimeTester.hpp" // Time tests TEST(TimeTestNominal, InstantiateTest) { diff --git a/Fw/Time/test/ut/TimeTester.cpp b/Fw/Time/test/ut/TimeTester.cpp index bfc4debf1fd..8fd53aeef44 100644 --- a/Fw/Time/test/ut/TimeTester.cpp +++ b/Fw/Time/test/ut/TimeTester.cpp @@ -3,156 +3,150 @@ namespace Fw { - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- - - TimeTester::TimeTester() { - } - - TimeTester::~TimeTester() { - } - - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- - - void TimeTester::test_InstantiateTest() { - Fw::Time time(TimeBase::TB_NONE,1,2); - ASSERT_EQ(time.getTimeBase(),TimeBase::TB_NONE); - ASSERT_EQ(time.getContext(),0); - ASSERT_EQ(time.getSeconds(),1); - ASSERT_EQ(time.getUSeconds(),2); - std::cout << time << std::endl; - } - - void TimeTester::test_MathTest() { - Fw::Time time1; - Fw::Time time2; - - // Comparison - time1.set(1000,1000); - time2.set(1000,1000); - ASSERT_TRUE(time1 == time2); - ASSERT_TRUE(time1 >= time2); - ASSERT_TRUE(time1 <= time2); - - time1.set(1000,1000); - time2.set(2000,1000); - ASSERT_TRUE(time1 != time2); - ASSERT_TRUE(time1 < time2); - ASSERT_TRUE(time1 <= time2); - - time1.set(2000,1000); - time2.set(1000,1000); - ASSERT_TRUE(time1 > time2); - ASSERT_TRUE(time1 >= time2); - - // Addition - time1.set(1000,1000); - time2.set(4000,2000); - Fw::Time time_sum = Fw::Time::add(time1,time2); - ASSERT_EQ(time_sum.getSeconds(),5000); - ASSERT_EQ(time_sum.getUSeconds(),3000); - - // Normal subtraction - time1.set(1000,1000); - time2.set(4000,2000); - Fw::Time time3 = Fw::Time::sub(time2,time1); - ASSERT_EQ(time3.getTimeBase(),TimeBase::TB_NONE); - ASSERT_EQ(time3.getContext(),0); - ASSERT_EQ(time3.getSeconds(),3000); - ASSERT_EQ(time3.getUSeconds(),1000); - - // Rollover subtraction - time1.set(1,999999); - time2.set(2,000001); - time3 = Fw::Time::sub(time2,time1); - ASSERT_EQ(time3.getTimeBase(),TimeBase::TB_NONE); - ASSERT_EQ(time3.getContext(),0); - EXPECT_EQ(time3.getSeconds(),0); - EXPECT_EQ(time3.getUSeconds(),2); - - // Addition - context is the same - time1.set(1000,0); - time2.set(2000,500); - time1.setTimeContext(2); - time2.setTimeContext(2); - time_sum = Fw::Time::add(time1,time2); - EXPECT_EQ(time_sum.getContext(),2); - EXPECT_EQ(time_sum.getSeconds(),3000); - EXPECT_EQ(time_sum.getUSeconds(),500); - - // Addition - context differs - time1.set(1000,0); - time2.set(2000,500); - time1.setTimeContext(1); - time2.setTimeContext(2); - time_sum = Fw::Time::add(time1,time2); - EXPECT_EQ(time_sum.getContext(),0); - EXPECT_EQ(time_sum.getSeconds(),3000); - EXPECT_EQ(time_sum.getUSeconds(),500); - - // Sub - context is the same - time1.set(3000,0); - time2.set(1500,0); - time1.setTimeContext(3); - time2.setTimeContext(3); - time_sum = Fw::Time::sub(time1,time2); - EXPECT_EQ(time_sum.getContext(),3); - EXPECT_EQ(time_sum.getSeconds(),1500); - - // Sub - context differs - time1.set(3000,0); - time2.set(1500,0); - time1.setTimeContext(3); - time2.setTimeContext(2); - time_sum = Fw::Time::sub(time1,time2); - EXPECT_EQ(time_sum.getContext(),0); - EXPECT_EQ(time_sum.getSeconds(),1500); - - } - - void TimeTester::test_CopyTest() { - Fw::Time time0; - - // make time that's guaranteed to be different from default - Fw::Time time1( - (time0.getTimeBase() != TimeBase::TB_NONE ? TimeBase::TB_NONE : TimeBase::TB_PROC_TIME), - static_cast(time0.getContext()+1), - time0.getSeconds()+1, - time0.getUSeconds()+1 - ); - - // copy construction - Fw::Time time2 = time1; - ASSERT_EQ(time1.getSeconds(), time2.getSeconds()); - ASSERT_EQ(time1.getUSeconds(), time2.getUSeconds()); - ASSERT_EQ(time1.getTimeBase(), time2.getTimeBase()); - ASSERT_EQ(time1.getContext(), time2.getContext()); - - // assignment operator - Fw::Time time3; - time3 = time1; - ASSERT_EQ(time1.getSeconds(), time3.getSeconds()); - ASSERT_EQ(time1.getUSeconds(), time3.getUSeconds()); - ASSERT_EQ(time1.getTimeBase(), time3.getTimeBase()); - ASSERT_EQ(time1.getContext(), time3.getContext()); - - // set method - Fw::Time time4; - time4.set(time1.getTimeBase(), time1.getContext(), time1.getSeconds(), time1.getUSeconds()); - ASSERT_EQ(time1.getSeconds(), time3.getSeconds()); - ASSERT_EQ(time1.getUSeconds(), time3.getUSeconds()); - ASSERT_EQ(time1.getTimeBase(), time3.getTimeBase()); - ASSERT_EQ(time1.getContext(), time3.getContext()); - } - - void TimeTester::test_ZeroTimeEquality() { - Fw::Time time(TimeBase::TB_PROC_TIME,1,2); - ASSERT_NE(time, Fw::ZERO_TIME); - Fw::Time time2; - ASSERT_EQ(time2, Fw::ZERO_TIME); - } - -} // namespace Fw +// ---------------------------------------------------------------------- +// Construction and destruction +// ---------------------------------------------------------------------- + +TimeTester::TimeTester() {} + +TimeTester::~TimeTester() {} + +// ---------------------------------------------------------------------- +// Tests +// ---------------------------------------------------------------------- + +void TimeTester::test_InstantiateTest() { + Fw::Time time(TimeBase::TB_NONE, 1, 2); + ASSERT_EQ(time.getTimeBase(), TimeBase::TB_NONE); + ASSERT_EQ(time.getContext(), 0); + ASSERT_EQ(time.getSeconds(), 1); + ASSERT_EQ(time.getUSeconds(), 2); + std::cout << time << std::endl; +} + +void TimeTester::test_MathTest() { + Fw::Time time1; + Fw::Time time2; + + // Comparison + time1.set(1000, 1000); + time2.set(1000, 1000); + ASSERT_TRUE(time1 == time2); + ASSERT_TRUE(time1 >= time2); + ASSERT_TRUE(time1 <= time2); + + time1.set(1000, 1000); + time2.set(2000, 1000); + ASSERT_TRUE(time1 != time2); + ASSERT_TRUE(time1 < time2); + ASSERT_TRUE(time1 <= time2); + + time1.set(2000, 1000); + time2.set(1000, 1000); + ASSERT_TRUE(time1 > time2); + ASSERT_TRUE(time1 >= time2); + + // Addition + time1.set(1000, 1000); + time2.set(4000, 2000); + Fw::Time time_sum = Fw::Time::add(time1, time2); + ASSERT_EQ(time_sum.getSeconds(), 5000); + ASSERT_EQ(time_sum.getUSeconds(), 3000); + + // Normal subtraction + time1.set(1000, 1000); + time2.set(4000, 2000); + Fw::Time time3 = Fw::Time::sub(time2, time1); + ASSERT_EQ(time3.getTimeBase(), TimeBase::TB_NONE); + ASSERT_EQ(time3.getContext(), 0); + ASSERT_EQ(time3.getSeconds(), 3000); + ASSERT_EQ(time3.getUSeconds(), 1000); + + // Rollover subtraction + time1.set(1, 999999); + time2.set(2, 000001); + time3 = Fw::Time::sub(time2, time1); + ASSERT_EQ(time3.getTimeBase(), TimeBase::TB_NONE); + ASSERT_EQ(time3.getContext(), 0); + EXPECT_EQ(time3.getSeconds(), 0); + EXPECT_EQ(time3.getUSeconds(), 2); + + // Addition - context is the same + time1.set(1000, 0); + time2.set(2000, 500); + time1.setTimeContext(2); + time2.setTimeContext(2); + time_sum = Fw::Time::add(time1, time2); + EXPECT_EQ(time_sum.getContext(), 2); + EXPECT_EQ(time_sum.getSeconds(), 3000); + EXPECT_EQ(time_sum.getUSeconds(), 500); + + // Addition - context differs + time1.set(1000, 0); + time2.set(2000, 500); + time1.setTimeContext(1); + time2.setTimeContext(2); + time_sum = Fw::Time::add(time1, time2); + EXPECT_EQ(time_sum.getContext(), 0); + EXPECT_EQ(time_sum.getSeconds(), 3000); + EXPECT_EQ(time_sum.getUSeconds(), 500); + + // Sub - context is the same + time1.set(3000, 0); + time2.set(1500, 0); + time1.setTimeContext(3); + time2.setTimeContext(3); + time_sum = Fw::Time::sub(time1, time2); + EXPECT_EQ(time_sum.getContext(), 3); + EXPECT_EQ(time_sum.getSeconds(), 1500); + + // Sub - context differs + time1.set(3000, 0); + time2.set(1500, 0); + time1.setTimeContext(3); + time2.setTimeContext(2); + time_sum = Fw::Time::sub(time1, time2); + EXPECT_EQ(time_sum.getContext(), 0); + EXPECT_EQ(time_sum.getSeconds(), 1500); +} + +void TimeTester::test_CopyTest() { + Fw::Time time0; + + // make time that's guaranteed to be different from default + Fw::Time time1((time0.getTimeBase() != TimeBase::TB_NONE ? TimeBase::TB_NONE : TimeBase::TB_PROC_TIME), + static_cast(time0.getContext() + 1), time0.getSeconds() + 1, + time0.getUSeconds() + 1); + + // copy construction + Fw::Time time2 = time1; + ASSERT_EQ(time1.getSeconds(), time2.getSeconds()); + ASSERT_EQ(time1.getUSeconds(), time2.getUSeconds()); + ASSERT_EQ(time1.getTimeBase(), time2.getTimeBase()); + ASSERT_EQ(time1.getContext(), time2.getContext()); + + // assignment operator + Fw::Time time3; + time3 = time1; + ASSERT_EQ(time1.getSeconds(), time3.getSeconds()); + ASSERT_EQ(time1.getUSeconds(), time3.getUSeconds()); + ASSERT_EQ(time1.getTimeBase(), time3.getTimeBase()); + ASSERT_EQ(time1.getContext(), time3.getContext()); + + // set method + Fw::Time time4; + time4.set(time1.getTimeBase(), time1.getContext(), time1.getSeconds(), time1.getUSeconds()); + ASSERT_EQ(time1.getSeconds(), time3.getSeconds()); + ASSERT_EQ(time1.getUSeconds(), time3.getUSeconds()); + ASSERT_EQ(time1.getTimeBase(), time3.getTimeBase()); + ASSERT_EQ(time1.getContext(), time3.getContext()); +} + +void TimeTester::test_ZeroTimeEquality() { + Fw::Time time(TimeBase::TB_PROC_TIME, 1, 2); + ASSERT_NE(time, Fw::ZERO_TIME); + Fw::Time time2; + ASSERT_EQ(time2, Fw::ZERO_TIME); +} + +} // namespace Fw diff --git a/Fw/Time/test/ut/TimeTester.hpp b/Fw/Time/test/ut/TimeTester.hpp index e8016682a71..5c6b2378bdf 100644 --- a/Fw/Time/test/ut/TimeTester.hpp +++ b/Fw/Time/test/ut/TimeTester.hpp @@ -1,26 +1,26 @@ #ifndef FW_TIME_TESTER_HPP #define FW_TIME_TESTER_HPP -#include #include +#include namespace Fw { - class TimeTester { - public: - // ---------------------------------------------------------------------- - // Construction and destruction - // ---------------------------------------------------------------------- - TimeTester(); - ~TimeTester(); +class TimeTester { + public: + // ---------------------------------------------------------------------- + // Construction and destruction + // ---------------------------------------------------------------------- + TimeTester(); + ~TimeTester(); - // ---------------------------------------------------------------------- - // Tests - // ---------------------------------------------------------------------- - void test_InstantiateTest(); - void test_MathTest(); - void test_CopyTest(); - void test_ZeroTimeEquality(); - }; -} // namespace Fw + // ---------------------------------------------------------------------- + // Tests + // ---------------------------------------------------------------------- + void test_InstantiateTest(); + void test_MathTest(); + void test_CopyTest(); + void test_ZeroTimeEquality(); +}; +} // namespace Fw -#endif // FW_TIME_TESTER_HPP +#endif // FW_TIME_TESTER_HPP diff --git a/Fw/Tlm/TlmBuffer.cpp b/Fw/Tlm/TlmBuffer.cpp index fea76543c14..396f5f1b813 100644 --- a/Fw/Tlm/TlmBuffer.cpp +++ b/Fw/Tlm/TlmBuffer.cpp @@ -3,43 +3,40 @@ namespace Fw { - TlmBuffer::TlmBuffer(const U8 *args, FwSizeType size) { - SerializeStatus stat = SerializeBufferBase::setBuff(args,size); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); - } +TlmBuffer::TlmBuffer(const U8* args, FwSizeType size) { + SerializeStatus stat = SerializeBufferBase::setBuff(args, size); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +} - TlmBuffer::TlmBuffer() { - } +TlmBuffer::TlmBuffer() {} - TlmBuffer::~TlmBuffer() { - } +TlmBuffer::~TlmBuffer() {} - TlmBuffer::TlmBuffer(const TlmBuffer& other) : Fw::SerializeBufferBase() { - SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); - } - - TlmBuffer& TlmBuffer::operator=(const TlmBuffer& other) { - if(this == &other) { - return *this; - } +TlmBuffer::TlmBuffer(const TlmBuffer& other) : Fw::SerializeBufferBase() { + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); +} - SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); - FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); +TlmBuffer& TlmBuffer::operator=(const TlmBuffer& other) { + if (this == &other) { return *this; } - FwSizeType TlmBuffer::getBuffCapacity() const { - return sizeof(this->m_bufferData); - } + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast(stat)); + return *this; +} - const U8* TlmBuffer::getBuffAddr() const { - return this->m_bufferData; - } +FwSizeType TlmBuffer::getBuffCapacity() const { + return sizeof(this->m_bufferData); +} - U8* TlmBuffer::getBuffAddr() { - return this->m_bufferData; - } +const U8* TlmBuffer::getBuffAddr() const { + return this->m_bufferData; +} +U8* TlmBuffer::getBuffAddr() { + return this->m_bufferData; } +} // namespace Fw diff --git a/Fw/Tlm/TlmBuffer.hpp b/Fw/Tlm/TlmBuffer.hpp index fd144168270..0c3dc69565e 100644 --- a/Fw/Tlm/TlmBuffer.hpp +++ b/Fw/Tlm/TlmBuffer.hpp @@ -12,33 +12,29 @@ #define FW_TLM_BUFFER_HPP #include -#include #include +#include namespace Fw { - class TlmBuffer final : public SerializeBufferBase { - public: - - enum { - SERIALIZED_TYPE_ID = FW_TYPEID_TLM_BUFF, - SERIALIZED_SIZE = FW_TLM_BUFFER_MAX_SIZE + sizeof(FwBuffSizeType) - }; +class TlmBuffer final : public SerializeBufferBase { + public: + enum { SERIALIZED_TYPE_ID = FW_TYPEID_TLM_BUFF, SERIALIZED_SIZE = FW_TLM_BUFFER_MAX_SIZE + sizeof(FwBuffSizeType) }; - TlmBuffer(const U8 *args, FwSizeType size); - TlmBuffer(); - TlmBuffer(const TlmBuffer& other); - virtual ~TlmBuffer(); - TlmBuffer& operator=(const TlmBuffer& other); + TlmBuffer(const U8* args, FwSizeType size); + TlmBuffer(); + TlmBuffer(const TlmBuffer& other); + virtual ~TlmBuffer(); + TlmBuffer& operator=(const TlmBuffer& other); - FwSizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer - U8* getBuffAddr(); - const U8* getBuffAddr() const; + FwSizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer + U8* getBuffAddr(); + const U8* getBuffAddr() const; - private: - U8 m_bufferData[FW_TLM_BUFFER_MAX_SIZE]; // command argument buffer - }; + private: + U8 m_bufferData[FW_TLM_BUFFER_MAX_SIZE]; // command argument buffer +}; -} +} // namespace Fw #endif diff --git a/Fw/Tlm/TlmPacket.cpp b/Fw/Tlm/TlmPacket.cpp index 40bf6ff416f..974a092e367 100644 --- a/Fw/Tlm/TlmPacket.cpp +++ b/Fw/Tlm/TlmPacket.cpp @@ -4,167 +4,162 @@ * Created on: May 24, 2014 * Author: Timothy Canham */ -#include #include #include +#include namespace Fw { - TlmPacket::TlmPacket() : m_numEntries(0) { - this->m_type = ComPacketType::FW_PACKET_TELEM; - this->m_tlmBuffer.resetSer(); +TlmPacket::TlmPacket() : m_numEntries(0) { + this->m_type = ComPacketType::FW_PACKET_TELEM; + this->m_tlmBuffer.resetSer(); +} + +TlmPacket::~TlmPacket() {} + +SerializeStatus TlmPacket::resetPktSer() { + this->m_tlmBuffer.resetSer(); + // reset packet count + this->m_numEntries = 0; + // make sure packet type is correct before serializing. It should + // never be anything but FW_PACKET_TELEM, so assert. + FW_ASSERT(ComPacketType::FW_PACKET_TELEM == this->m_type, static_cast(this->m_type)); + // serialize descriptor + // The function serializeBase inherited from ComPacket converts this->m_type + // to type FwPacketDescriptorType and serializes the result into this->m_tlmBuffer. + return this->serializeBase(this->m_tlmBuffer); +} + +SerializeStatus TlmPacket::resetPktDeser() { + this->m_tlmBuffer.resetDeser(); + // deserialize descriptor + // The function deserializeBase inherited from ComPacket deserializes a + // value of type FwPacketDescriptorType from this->m_tlmBuffer and stores it + // into this->m_type. + Fw::SerializeStatus stat = this->deserializeBase(this->m_tlmBuffer); + if (stat != Fw::FW_SERIALIZE_OK) { + return stat; } - - TlmPacket::~TlmPacket() { + // make sure that this->m_tlmBuffer stores a telemetry packet + if (this->m_type != ComPacketType::FW_PACKET_TELEM) { + return Fw::FW_DESERIALIZE_TYPE_MISMATCH; } - SerializeStatus TlmPacket::resetPktSer() { - this->m_tlmBuffer.resetSer(); - // reset packet count - this->m_numEntries = 0; - // make sure packet type is correct before serializing. It should - // never be anything but FW_PACKET_TELEM, so assert. - FW_ASSERT(ComPacketType::FW_PACKET_TELEM == this->m_type, static_cast(this->m_type)); - // serialize descriptor - // The function serializeBase inherited from ComPacket converts this->m_type - // to type FwPacketDescriptorType and serializes the result into this->m_tlmBuffer. - return this->serializeBase(this->m_tlmBuffer); - } + return Fw::FW_SERIALIZE_OK; +} - SerializeStatus TlmPacket::resetPktDeser() { - this->m_tlmBuffer.resetDeser(); - // deserialize descriptor - // The function deserializeBase inherited from ComPacket deserializes a - // value of type FwPacketDescriptorType from this->m_tlmBuffer and stores it - // into this->m_type. - Fw::SerializeStatus stat = this->deserializeBase(this->m_tlmBuffer); - if (stat != Fw::FW_SERIALIZE_OK) { - return stat; - } - // make sure that this->m_tlmBuffer stores a telemetry packet - if (this->m_type != ComPacketType::FW_PACKET_TELEM) { - return Fw::FW_DESERIALIZE_TYPE_MISMATCH; - } - - return Fw::FW_SERIALIZE_OK; - } +FwSizeType TlmPacket::getNumEntries() { + return this->m_numEntries; +} - FwSizeType TlmPacket::getNumEntries() { - return this->m_numEntries; - } +Fw::ComBuffer& TlmPacket::getBuffer() { + return this->m_tlmBuffer; +} - Fw::ComBuffer& TlmPacket::getBuffer() { - return this->m_tlmBuffer; - } - - void TlmPacket::setBuffer(Fw::ComBuffer& buffer) { - this->m_tlmBuffer = buffer; - } +void TlmPacket::setBuffer(Fw::ComBuffer& buffer) { + this->m_tlmBuffer = buffer; +} - SerializeStatus TlmPacket::addValue(FwChanIdType id, Time& timeTag, TlmBuffer& buffer) { - // check to make sure there is room for all the fields - FwSizeType left = this->m_tlmBuffer.getBuffCapacity()-this->m_tlmBuffer.getBuffLength(); - if ( - (sizeof(FwChanIdType) + Time::SERIALIZED_SIZE + buffer.getBuffLength()) > left - ) { - return Fw::FW_SERIALIZE_NO_ROOM_LEFT; - } - - // serialize items into buffer - - // id - SerializeStatus stat = this->m_tlmBuffer.serialize(id); - if (stat != Fw::FW_SERIALIZE_OK) { - return stat; - } - - // time tag - stat = this->m_tlmBuffer.serialize(timeTag); - if (stat != Fw::FW_SERIALIZE_OK) { - return stat; - } - - // telemetry buffer - stat = this->m_tlmBuffer.serialize(buffer.getBuffAddr(),buffer.getBuffLength(),Fw::Serialization::OMIT_LENGTH); - if (stat != Fw::FW_SERIALIZE_OK) { - return stat; - } - - // increment number of packets - this->m_numEntries++; - - return Fw::FW_SERIALIZE_OK; +SerializeStatus TlmPacket::addValue(FwChanIdType id, Time& timeTag, TlmBuffer& buffer) { + // check to make sure there is room for all the fields + FwSizeType left = this->m_tlmBuffer.getBuffCapacity() - this->m_tlmBuffer.getBuffLength(); + if ((sizeof(FwChanIdType) + Time::SERIALIZED_SIZE + buffer.getBuffLength()) > left) { + return Fw::FW_SERIALIZE_NO_ROOM_LEFT; } - // extract telemetry value - SerializeStatus TlmPacket::extractValue(FwChanIdType &id, Time& timeTag, TlmBuffer& buffer, FwSizeType bufferSize) { + // serialize items into buffer - // deserialize items out of buffer + // id + SerializeStatus stat = this->m_tlmBuffer.serialize(id); + if (stat != Fw::FW_SERIALIZE_OK) { + return stat; + } - // id - SerializeStatus stat = this->m_tlmBuffer.deserialize(id); - if (stat != Fw::FW_SERIALIZE_OK) { - return stat; - } + // time tag + stat = this->m_tlmBuffer.serialize(timeTag); + if (stat != Fw::FW_SERIALIZE_OK) { + return stat; + } - // time tag - stat = this->m_tlmBuffer.deserialize(timeTag); - if (stat != Fw::FW_SERIALIZE_OK) { - return stat; - } + // telemetry buffer + stat = this->m_tlmBuffer.serialize(buffer.getBuffAddr(), buffer.getBuffLength(), Fw::Serialization::OMIT_LENGTH); + if (stat != Fw::FW_SERIALIZE_OK) { + return stat; + } - // telemetry buffer - stat = this->m_tlmBuffer.deserialize(buffer.getBuffAddr(),bufferSize,Fw::Serialization::OMIT_LENGTH); - if (stat != Fw::FW_SERIALIZE_OK) { - return stat; - } + // increment number of packets + this->m_numEntries++; - // set buffer size - stat = buffer.setBuffLen(bufferSize); - if (stat != Fw::FW_SERIALIZE_OK) { - return stat; - } + return Fw::FW_SERIALIZE_OK; +} - return Fw::FW_SERIALIZE_OK; +// extract telemetry value +SerializeStatus TlmPacket::extractValue(FwChanIdType& id, Time& timeTag, TlmBuffer& buffer, FwSizeType bufferSize) { + // deserialize items out of buffer + // id + SerializeStatus stat = this->m_tlmBuffer.deserialize(id); + if (stat != Fw::FW_SERIALIZE_OK) { + return stat; } - SerializeStatus TlmPacket::serialize(SerializeBufferBase& buffer) const { - // Deprecated method - calls new interface for backward compatibility - return this->serializeTo(buffer); + // time tag + stat = this->m_tlmBuffer.deserialize(timeTag); + if (stat != Fw::FW_SERIALIZE_OK) { + return stat; } - SerializeStatus TlmPacket::deserialize(SerializeBufferBase& buffer) { - // Deprecated method - calls new interface for backward compatibility - return this->deserializeFrom(buffer); + // telemetry buffer + stat = this->m_tlmBuffer.deserialize(buffer.getBuffAddr(), bufferSize, Fw::Serialization::OMIT_LENGTH); + if (stat != Fw::FW_SERIALIZE_OK) { + return stat; } - SerializeStatus TlmPacket::serializeTo(SerializeBufferBase& buffer) const { - // serialize the number of packets - SerializeStatus stat = buffer.serialize(this->m_numEntries); - if (stat != Fw::FW_SERIALIZE_OK) { - return stat; - } - // Serialize the ComBuffer - return buffer.serialize(this->m_tlmBuffer.getBuffAddr(),m_tlmBuffer.getBuffLength(),Fw::Serialization::OMIT_LENGTH); + // set buffer size + stat = buffer.setBuffLen(bufferSize); + if (stat != Fw::FW_SERIALIZE_OK) { + return stat; } - SerializeStatus TlmPacket::deserializeFrom(SerializeBufferBase& buffer) { - - // deserialize the number of packets - SerializeStatus stat = buffer.deserialize(this->m_numEntries); - if (stat != Fw::FW_SERIALIZE_OK) { - return stat; - } - // deserialize the channel value entry buffers - FwSizeType size = buffer.getBuffLeft(); - stat = buffer.deserialize(this->m_tlmBuffer.getBuffAddr(),size,Fw::Serialization::OMIT_LENGTH); - if (stat == FW_SERIALIZE_OK) { - // Shouldn't fail - stat = this->m_tlmBuffer.setBuffLen(size); - FW_ASSERT(stat == FW_SERIALIZE_OK,static_cast(stat)); - } + return Fw::FW_SERIALIZE_OK; +} + +SerializeStatus TlmPacket::serialize(SerializeBufferBase& buffer) const { + // Deprecated method - calls new interface for backward compatibility + return this->serializeTo(buffer); +} + +SerializeStatus TlmPacket::deserialize(SerializeBufferBase& buffer) { + // Deprecated method - calls new interface for backward compatibility + return this->deserializeFrom(buffer); +} + +SerializeStatus TlmPacket::serializeTo(SerializeBufferBase& buffer) const { + // serialize the number of packets + SerializeStatus stat = buffer.serialize(this->m_numEntries); + if (stat != Fw::FW_SERIALIZE_OK) { return stat; } + // Serialize the ComBuffer + return buffer.serialize(this->m_tlmBuffer.getBuffAddr(), m_tlmBuffer.getBuffLength(), + Fw::Serialization::OMIT_LENGTH); +} + +SerializeStatus TlmPacket::deserializeFrom(SerializeBufferBase& buffer) { + // deserialize the number of packets + SerializeStatus stat = buffer.deserialize(this->m_numEntries); + if (stat != Fw::FW_SERIALIZE_OK) { + return stat; + } + // deserialize the channel value entry buffers + FwSizeType size = buffer.getBuffLeft(); + stat = buffer.deserialize(this->m_tlmBuffer.getBuffAddr(), size, Fw::Serialization::OMIT_LENGTH); + if (stat == FW_SERIALIZE_OK) { + // Shouldn't fail + stat = this->m_tlmBuffer.setBuffLen(size); + FW_ASSERT(stat == FW_SERIALIZE_OK, static_cast(stat)); + } + return stat; +} } /* namespace Fw */ diff --git a/Fw/Tlm/TlmPacket.hpp b/Fw/Tlm/TlmPacket.hpp index 0762fb220c6..f1b36f25036 100644 --- a/Fw/Tlm/TlmPacket.hpp +++ b/Fw/Tlm/TlmPacket.hpp @@ -8,49 +8,50 @@ #ifndef TLMPACKET_HPP_ #define TLMPACKET_HPP_ -#include -#include #include +#include #include +#include namespace Fw { - class TlmPacket : public ComPacket { - public: - - //! Constructor - TlmPacket(); - //! Destructor - virtual ~TlmPacket(); - - //! Serialize the packet before sending. For use internally in software. To send to the ground, use getBuffer() below. - SerializeStatus serialize(SerializeBufferBase& buffer) const override; //!< serialize contents - //! Deserialize the packet. For use internally in software. To extract channels, use setBuffer() and extractValue() below. This is NOT typically used. - SerializeStatus deserialize(SerializeBufferBase& buffer) override; - - SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; //!< serialize contents - SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; - //! Add telemetry value to buffer. - SerializeStatus addValue(FwChanIdType id, Time& timeTag, TlmBuffer& buffer); - //! extract telemetry value - since there are potentially multiple channel values in the packet, - //! the size of the entry must be known - SerializeStatus extractValue(FwChanIdType &id, Time& timeTag, TlmBuffer& buffer, FwSizeType bufferSize); - - //! Reset serialization of values. This should be done when starting to accumulate a new set of values. - SerializeStatus resetPktSer(); - //! Reset deserialization. This should be done before extracting values. - SerializeStatus resetPktDeser(); - //! get buffer to send to the ground - Fw::ComBuffer& getBuffer(); - //! set the internal buffer for deserializing values - void setBuffer(Fw::ComBuffer& buffer); - //! get the number of packets added via addValue() - FwSizeType getNumEntries(); - - private: - ComBuffer m_tlmBuffer; //!< serialized data - FwSizeType m_numEntries; //!< number of entries stored during addValue() - }; +class TlmPacket : public ComPacket { + public: + //! Constructor + TlmPacket(); + //! Destructor + virtual ~TlmPacket(); + + //! Serialize the packet before sending. For use internally in software. To send to the ground, use getBuffer() + //! below. + SerializeStatus serialize(SerializeBufferBase& buffer) const override; //!< serialize contents + //! Deserialize the packet. For use internally in software. To extract channels, use setBuffer() and extractValue() + //! below. This is NOT typically used. + SerializeStatus deserialize(SerializeBufferBase& buffer) override; + + SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; //!< serialize contents + SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; + //! Add telemetry value to buffer. + SerializeStatus addValue(FwChanIdType id, Time& timeTag, TlmBuffer& buffer); + //! extract telemetry value - since there are potentially multiple channel values in the packet, + //! the size of the entry must be known + SerializeStatus extractValue(FwChanIdType& id, Time& timeTag, TlmBuffer& buffer, FwSizeType bufferSize); + + //! Reset serialization of values. This should be done when starting to accumulate a new set of values. + SerializeStatus resetPktSer(); + //! Reset deserialization. This should be done before extracting values. + SerializeStatus resetPktDeser(); + //! get buffer to send to the ground + Fw::ComBuffer& getBuffer(); + //! set the internal buffer for deserializing values + void setBuffer(Fw::ComBuffer& buffer); + //! get the number of packets added via addValue() + FwSizeType getNumEntries(); + + private: + ComBuffer m_tlmBuffer; //!< serialized data + FwSizeType m_numEntries; //!< number of entries stored during addValue() +}; } /* namespace Fw */ diff --git a/Fw/Tlm/test/ut/TlmTest.cpp b/Fw/Tlm/test/ut/TlmTest.cpp index 7ca3eaa892f..27b1e42e5b1 100644 --- a/Fw/Tlm/test/ut/TlmTest.cpp +++ b/Fw/Tlm/test/ut/TlmTest.cpp @@ -1,76 +1,72 @@ #include -#include #include +#include -TEST(FwTlmTest,TlmPacketSerializeSingle) { - +TEST(FwTlmTest, TlmPacketSerializeSingle) { // Serialize data Fw::TlmPacket pktIn; Fw::TlmBuffer buffIn; - ASSERT_EQ(Fw::FW_SERIALIZE_OK,buffIn.serialize(static_cast(12))); - Fw::Time timeIn(TimeBase::TB_WORKSTATION_TIME,10,11); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, buffIn.serialize(static_cast(12))); + Fw::Time timeIn(TimeBase::TB_WORKSTATION_TIME, 10, 11); FwChanIdType id = 10; - ASSERT_EQ(Fw::FW_SERIALIZE_OK,pktIn.resetPktSer()); - ASSERT_EQ(Fw::FW_SERIALIZE_OK,pktIn.addValue(id,timeIn,buffIn)); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, pktIn.resetPktSer()); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, pktIn.addValue(id, timeIn, buffIn)); Fw::ComBuffer comBuff = pktIn.getBuffer(); // Deserialize data Fw::TlmPacket pktOut; Fw::TlmBuffer buffOut; - Fw::Time timeOut(TimeBase::TB_WORKSTATION_TIME,10,11); + Fw::Time timeOut(TimeBase::TB_WORKSTATION_TIME, 10, 11); pktOut.setBuffer(comBuff); - ASSERT_EQ(Fw::FW_SERIALIZE_OK,pktOut.resetPktDeser()); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, pktOut.resetPktDeser()); // extract values id = 0; - ASSERT_EQ(Fw::FW_SERIALIZE_OK,pktOut.extractValue(id,timeOut,buffOut,sizeof(U32))); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, pktOut.extractValue(id, timeOut, buffOut, sizeof(U32))); - ASSERT_EQ(10u,id); + ASSERT_EQ(10u, id); U32 valOut = 0; buffOut.resetDeser(); - ASSERT_EQ(Fw::FW_SERIALIZE_OK,buffOut.deserialize(valOut)); - ASSERT_EQ(valOut,12u); - + ASSERT_EQ(Fw::FW_SERIALIZE_OK, buffOut.deserialize(valOut)); + ASSERT_EQ(valOut, 12u); } -TEST(FwTlmTest,TlmPacketSerializeFill) { - +TEST(FwTlmTest, TlmPacketSerializeFill) { // compute a single entry size assuming for the test that the value of the telemetry channel // is a U32 static const FwSizeType SIZE_OF_ENTRY = sizeof(FwChanIdType) + Fw::Time::SERIALIZED_SIZE + sizeof(U32); - // compute the number of entries that should fit - will equal rounded down value of + // compute the number of entries that should fit - will equal rounded down value of // ComBuffer size - size of telemetry packet id / size of an entry - static const FwSizeType NUM_ENTRIES = (FW_COM_BUFFER_MAX_SIZE - sizeof(FwPacketDescriptorType))/SIZE_OF_ENTRY; + static const FwSizeType NUM_ENTRIES = (FW_COM_BUFFER_MAX_SIZE - sizeof(FwPacketDescriptorType)) / SIZE_OF_ENTRY; Fw::TlmPacket pktIn; - ASSERT_EQ(Fw::FW_SERIALIZE_OK,pktIn.resetPktSer()); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, pktIn.resetPktSer()); // fill a telemetry packet for (U32 entry = 0; entry < NUM_ENTRIES; entry++) { - // Serialize data Fw::TlmBuffer buffIn; - ASSERT_EQ(Fw::FW_SERIALIZE_OK,buffIn.serialize(static_cast(entry))); - Fw::Time timeIn(TimeBase::TB_WORKSTATION_TIME,entry+1,entry+2); - FwChanIdType id = static_cast(NUM_ENTRIES-entry); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, buffIn.serialize(static_cast(entry))); + Fw::Time timeIn(TimeBase::TB_WORKSTATION_TIME, entry + 1, entry + 2); + FwChanIdType id = static_cast(NUM_ENTRIES - entry); - ASSERT_EQ(Fw::FW_SERIALIZE_OK,pktIn.addValue(id,timeIn,buffIn)); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, pktIn.addValue(id, timeIn, buffIn)); } // Next one should fail because it's full { Fw::TlmBuffer buffIn; - ASSERT_EQ(Fw::FW_SERIALIZE_OK,buffIn.serialize(static_cast(12))); - Fw::Time timeIn(TimeBase::TB_WORKSTATION_TIME,10,11); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, buffIn.serialize(static_cast(12))); + Fw::Time timeIn(TimeBase::TB_WORKSTATION_TIME, 10, 11); FwChanIdType id = 10; - ASSERT_EQ(Fw::FW_SERIALIZE_NO_ROOM_LEFT,pktIn.addValue(id,timeIn,buffIn)); + ASSERT_EQ(Fw::FW_SERIALIZE_NO_ROOM_LEFT, pktIn.addValue(id, timeIn, buffIn)); } // Create a new packet from the ComBuffer @@ -78,7 +74,7 @@ TEST(FwTlmTest,TlmPacketSerializeFill) { Fw::ComBuffer comBuff = pktIn.getBuffer(); Fw::TlmPacket pktOut; pktOut.setBuffer(comBuff); - ASSERT_EQ(Fw::FW_SERIALIZE_OK,pktOut.resetPktDeser()); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, pktOut.resetPktDeser()); // empty the packet of entries for (U32 entry = 0; entry < NUM_ENTRIES; entry++) { @@ -86,23 +82,22 @@ TEST(FwTlmTest,TlmPacketSerializeFill) { Fw::TlmBuffer buffOut; Fw::Time timeOut; FwChanIdType id = 0; - ASSERT_EQ(Fw::FW_SERIALIZE_OK,pktOut.extractValue(id,timeOut,buffOut,sizeof(U32))); - ASSERT_EQ(NUM_ENTRIES-entry,id); - Fw::Time expTime(TimeBase::TB_WORKSTATION_TIME,entry+1,entry+2); - ASSERT_EQ(expTime,timeOut); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, pktOut.extractValue(id, timeOut, buffOut, sizeof(U32))); + ASSERT_EQ(NUM_ENTRIES - entry, id); + Fw::Time expTime(TimeBase::TB_WORKSTATION_TIME, entry + 1, entry + 2); + ASSERT_EQ(expTime, timeOut); U32 val = 0; - ASSERT_EQ(Fw::FW_SERIALIZE_OK,buffOut.deserialize(val)); - ASSERT_EQ(entry,val); + ASSERT_EQ(Fw::FW_SERIALIZE_OK, buffOut.deserialize(val)); + ASSERT_EQ(entry, val); } - + // try to extract one more, should fail { Fw::TlmBuffer buffOut; Fw::Time timeOut; FwChanIdType id = 0; - ASSERT_EQ(Fw::FW_DESERIALIZE_BUFFER_EMPTY,pktOut.extractValue(id,timeOut,buffOut,sizeof(U32))); + ASSERT_EQ(Fw::FW_DESERIALIZE_BUFFER_EMPTY, pktOut.extractValue(id, timeOut, buffOut, sizeof(U32))); } - } int main(int argc, char* argv[]) { diff --git a/Fw/Trap/TrapHandler.hpp b/Fw/Trap/TrapHandler.hpp index 755e88aef70..faf6ca1455f 100644 --- a/Fw/Trap/TrapHandler.hpp +++ b/Fw/Trap/TrapHandler.hpp @@ -3,24 +3,24 @@ #include namespace Fw { +/** + * TrapHandler: + * A framework class used to handle traps that occur during the execution of the + * the F' framework. Must be registered with a trap register. The user should + * inherit from this class and ensure that the doTrap function is implemented. The + * default implementation will be do-nothing. + */ +class TrapHandler { + public: + TrapHandler() {}; //!< constructor + virtual ~TrapHandler() {}; //!< destructor /** - * TrapHandler: - * A framework class used to handle traps that occur during the execution of the - * the F' framework. Must be registered with a trap register. The user should - * inherit from this class and ensure that the doTrap function is implemented. The - * default implementation will be do-nothing. + * Handles the incoming trap. + * Note: if user does not supply an implementer of this + * function, a do-nothing version will be run. + * \param trap: trap number */ - class TrapHandler { - public: - TrapHandler() {}; //!< constructor - virtual ~TrapHandler() {}; //!< destructor - /** - * Handles the incoming trap. - * Note: if user does not supply an implementer of this - * function, a do-nothing version will be run. - * \param trap: trap number - */ - virtual void doTrap(U32 trap) = 0; - }; -} + virtual void doTrap(U32 trap) = 0; +}; +} // namespace Fw #endif diff --git a/Fw/Types/Assert.cpp b/Fw/Types/Assert.cpp index 98f6f960efa..81729483bb3 100644 --- a/Fw/Types/Assert.cpp +++ b/Fw/Types/Assert.cpp @@ -1,7 +1,7 @@ #include #include -#include #include +#include #include #include @@ -15,8 +15,8 @@ namespace Fw { void defaultPrintAssert(const CHAR* msg) { // Write to stderr w/o formatting - (void) fputs(msg, stderr); - (void) fputs("\n", stderr); + (void)fputs(msg, stderr); + (void)fputs("\n", stderr); } void defaultReportAssert(FILE_NAME_ARG file, @@ -35,23 +35,22 @@ void defaultReportAssert(FILE_NAME_ARG file, (void)stringFormat(destBuffer, buffSize, fileIdFs, file, lineNo); break; case 1: - (void)stringFormat(destBuffer, buffSize, - fileIdFs " %" PRI_FwAssertArgType, file, lineNo, arg1); + (void)stringFormat(destBuffer, buffSize, fileIdFs " %" PRI_FwAssertArgType, file, lineNo, arg1); break; case 2: - (void)stringFormat(destBuffer, buffSize, - fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, file, lineNo, arg1, arg2); + (void)stringFormat(destBuffer, buffSize, fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, file, + lineNo, arg1, arg2); break; case 3: (void)stringFormat(destBuffer, buffSize, - fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, file, - lineNo, arg1, arg2, arg3); + fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, + file, lineNo, arg1, arg2, arg3); break; case 4: (void)stringFormat(destBuffer, buffSize, fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, - file, lineNo, arg1, arg2, arg3, arg4); + file, lineNo, arg1, arg2, arg3, arg4); break; case 5: (void)stringFormat(destBuffer, buffSize, @@ -84,7 +83,8 @@ void AssertHook::reportAssert(FILE_NAME_ARG file, FwAssertArgType arg5, FwAssertArgType arg6) { CHAR destBuffer[FW_ASSERT_TEXT_SIZE]; - defaultReportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6, destBuffer, static_cast(sizeof(destBuffer))); + defaultReportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6, destBuffer, + static_cast(sizeof(destBuffer))); // print message this->printAssert(destBuffer); } @@ -106,17 +106,18 @@ void AssertHook::deregisterHook() { // Default handler of SwAssert functions I8 defaultSwAssert(FILE_NAME_ARG file, - FwSizeType lineNo, - FwSizeType numArgs, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwAssertArgType arg5, - FwAssertArgType arg6) { + FwSizeType lineNo, + FwSizeType numArgs, + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwAssertArgType arg5, + FwAssertArgType arg6) { if (nullptr == s_assertHook) { CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; - defaultReportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6, assertMsg, static_cast(sizeof(assertMsg))); + defaultReportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6, assertMsg, + static_cast(sizeof(assertMsg))); defaultPrintAssert(assertMsg); assert(0); } else { @@ -138,41 +139,37 @@ I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwSi return defaultSwAssert(file, lineNo, 2, arg1, arg2, 0, 0, 0, 0); } -I8 SwAssert(FILE_NAME_ARG file, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwSizeType lineNo) { +I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwSizeType lineNo) { return defaultSwAssert(file, lineNo, 3, arg1, arg2, arg3, 0, 0, 0); } I8 SwAssert(FILE_NAME_ARG file, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwSizeType lineNo) { + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwSizeType lineNo) { return defaultSwAssert(file, lineNo, 4, arg1, arg2, arg3, arg4, 0, 0); } I8 SwAssert(FILE_NAME_ARG file, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwAssertArgType arg5, - FwSizeType lineNo) { + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwAssertArgType arg5, + FwSizeType lineNo) { return defaultSwAssert(file, lineNo, 5, arg1, arg2, arg3, arg4, arg5, 0); } I8 SwAssert(FILE_NAME_ARG file, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwAssertArgType arg5, - FwAssertArgType arg6, - FwSizeType lineNo) { + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwAssertArgType arg5, + FwAssertArgType arg6, + FwSizeType lineNo) { return defaultSwAssert(file, lineNo, 6, arg1, arg2, arg3, arg4, arg5, arg6); } } // namespace Fw @@ -186,7 +183,8 @@ I8 CAssert1(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo); I8 CAssert0(FILE_NAME_ARG file, FwSizeType lineNo) { if (nullptr == Fw::s_assertHook) { CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; - Fw::defaultReportAssert(file, lineNo, 0, 0, 0, 0, 0, 0, 0, assertMsg, static_cast(sizeof(assertMsg))); + Fw::defaultReportAssert(file, lineNo, 0, 0, 0, 0, 0, 0, 0, assertMsg, + static_cast(sizeof(assertMsg))); } else { Fw::s_assertHook->reportAssert(file, lineNo, 0, 0, 0, 0, 0, 0, 0); Fw::s_assertHook->doAssert(); @@ -197,7 +195,8 @@ I8 CAssert0(FILE_NAME_ARG file, FwSizeType lineNo) { I8 CAssert1(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) { if (nullptr == Fw::s_assertHook) { CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; - Fw::defaultReportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0, assertMsg, static_cast(sizeof(assertMsg))); + Fw::defaultReportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0, assertMsg, + static_cast(sizeof(assertMsg))); } else { Fw::s_assertHook->reportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0); Fw::s_assertHook->doAssert(); diff --git a/Fw/Types/Assert.hpp b/Fw/Types/Assert.hpp index 6c9690e5e15..7e946ed1663 100644 --- a/Fw/Types/Assert.hpp +++ b/Fw/Types/Assert.hpp @@ -47,8 +47,7 @@ // Helper macro asserting that a value fits into a type without overflow. Helpful for checking before static casts #define FW_ASSERT_NO_OVERFLOW(value, T) \ - FW_ASSERT((value) <= std::numeric_limits::max(), \ - static_cast(value)) + FW_ASSERT((value) <= std::numeric_limits::max(), static_cast(value)) // F' Assertion functions can technically return even though the intention is for the assertion to terminate the // program. This breaks static analysis depending on assertions, since the analyzer has to assume the assertion will @@ -72,42 +71,38 @@ I8 SwAssert(FILE_NAME_ARG file, FwSizeType lineNo) CLANG_ANALYZER_NORETURN; I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) CLANG_ANALYZER_NORETURN; //! Assert with two arguments -I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwSizeType lineNo) - CLANG_ANALYZER_NORETURN; +I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwSizeType lineNo) CLANG_ANALYZER_NORETURN; //! Assert with three arguments -I8 SwAssert(FILE_NAME_ARG file, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwSizeType lineNo) CLANG_ANALYZER_NORETURN; +I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwSizeType lineNo) + CLANG_ANALYZER_NORETURN; //! Assert with four arguments I8 SwAssert(FILE_NAME_ARG file, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwSizeType lineNo) CLANG_ANALYZER_NORETURN; + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwSizeType lineNo) CLANG_ANALYZER_NORETURN; //! Assert with five arguments I8 SwAssert(FILE_NAME_ARG file, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwAssertArgType arg5, - FwSizeType lineNo) CLANG_ANALYZER_NORETURN; + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwAssertArgType arg5, + FwSizeType lineNo) CLANG_ANALYZER_NORETURN; //! Assert with six arguments I8 SwAssert(FILE_NAME_ARG file, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwAssertArgType arg5, - FwAssertArgType arg6, - FwSizeType lineNo) CLANG_ANALYZER_NORETURN; + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwAssertArgType arg5, + FwAssertArgType arg6, + FwSizeType lineNo) CLANG_ANALYZER_NORETURN; } // namespace Fw // Base class for declaring an assert hook @@ -118,8 +113,8 @@ namespace Fw { // Base class for declaring an assert hook class AssertHook { public: - AssertHook() : previousHook(nullptr){}; //!< constructor - virtual ~AssertHook(){}; //!< destructor + AssertHook() : previousHook(nullptr) {}; //!< constructor + virtual ~AssertHook() {}; //!< destructor // override this function to intercept asserts virtual void reportAssert(FILE_NAME_ARG file, FwSizeType lineNo, diff --git a/Fw/Types/BasicTypes.h b/Fw/Types/BasicTypes.h index 3f2d100ba30..551840559c7 100644 --- a/Fw/Types/BasicTypes.h +++ b/Fw/Types/BasicTypes.h @@ -31,50 +31,50 @@ #ifndef FW_BASIC_TYPES_H #define FW_BASIC_TYPES_H -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif -#include // Standard integer types and printf macros #include - +#include // Standard integer types and printf macros // Compiler checks #if defined(__GNUC__) || defined(__llvm__) || defined(PLATFORM_OVERRIDE_GCC_CLANG_CHECK) #else -#error "FPrime only supports GCC or Clang compilers. You may attempt to use other compilers by defining PLATFORM_OVERRIDE_GCC_CLANG_CHECK, but this is not recommended." +#error \ + "FPrime only supports GCC or Clang compilers. You may attempt to use other compilers by defining PLATFORM_OVERRIDE_GCC_CLANG_CHECK, but this is not recommended." #endif /*----------------------------------------------------------------------------*/ /* Type definitions: I8, U8, I16, U16, ..., I64, U64, F32, and F64 */ /*----------------------------------------------------------------------------*/ -typedef int8_t I8; //!< 8-bit signed integer +typedef int8_t I8; //!< 8-bit signed integer #define PRI_I8 PRIi8 typedef uint8_t U8; //!< 8-bit unsigned integer #define PRI_U8 PRIu8 -typedef U8 BYTE; //!< byte type +typedef U8 BYTE; //!< byte type #define PRI_BYTE PRIu8 typedef char CHAR; #define PRI_CHAR "c" #if FW_HAS_16_BIT -typedef int16_t I16; //!< 16-bit signed integer +typedef int16_t I16; //!< 16-bit signed integer #define PRI_I16 PRIi16 typedef uint16_t U16; //!< 16-bit unsigned integer #define PRI_U16 PRIu16 #endif #if FW_HAS_32_BIT -typedef int32_t I32; //!< 32-bit signed integer +typedef int32_t I32; //!< 32-bit signed integer #define PRI_I32 PRIi32 typedef uint32_t U32; //!< 32-bit unsigned integer #define PRI_U32 PRIu32 #endif #if FW_HAS_64_BIT -typedef int64_t I64; //!< 64-bit signed integer +typedef int64_t I64; //!< 64-bit signed integer #define PRI_I64 PRIi64 typedef uint64_t U64; //!< 64-bit unsigned integer #define PRI_U64 PRIu64 @@ -99,9 +99,7 @@ typedef double F64; //!< 64-bit floating point (double). Required for compiler- 4 //!< Uses a relative file path (within fprime/fprime library) for assert. - requires -DASSERT_RELATIVE_PATH=path //!< to be set on the compile command line - - -#ifdef __cplusplus +#ifdef __cplusplus } #endif #endif // FW_BASIC_TYPES_H diff --git a/Fw/Types/CAssert.h b/Fw/Types/CAssert.h index 8255bbc268a..273a0c4250c 100644 --- a/Fw/Types/CAssert.h +++ b/Fw/Types/CAssert.h @@ -10,7 +10,7 @@ #include -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -28,16 +28,17 @@ extern "C" { #else #define FILE_NAME_ARG const CHAR* #define FW_CASSERT(cond) ((void)((cond) ? (0) : (CAssert0((FILE_NAME_ARG)(__FILE__), __LINE__)))) -#define FW_CASSERT_1(cond, arg1) ((void)((cond) ? (0) : (CAssert1((FILE_NAME_ARG)(__FILE__), (FwAssertArgType)(arg1), __LINE__)))) +#define FW_CASSERT_1(cond, arg1) \ + ((void)((cond) ? (0) : (CAssert1((FILE_NAME_ARG)(__FILE__), (FwAssertArgType)(arg1), __LINE__)))) #endif -I8 CAssert0(FILE_NAME_ARG file, FwSizeType lineNo); //!< C assert function +I8 CAssert0(FILE_NAME_ARG file, FwSizeType lineNo); //!< C assert function I8 CAssert1(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo); //!< C assert function with one argument #endif // ASSERT is defined -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* FWCASSERT_HPP_ */ +#endif /* FWCASSERT_HPP_ */ diff --git a/Fw/Types/PolyType.cpp b/Fw/Types/PolyType.cpp index 3d29b65dbfd..de4009ee5ee 100644 --- a/Fw/Types/PolyType.cpp +++ b/Fw/Types/PolyType.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include namespace Fw { @@ -603,7 +603,7 @@ void PolyType::toString(StringBase& dest) const { } void PolyType::toString(StringBase& dest, bool append) const { - char format[21]; // U64 max fits into 20 decimal digits + 1 null terminator + char format[21]; // U64 max fits into 20 decimal digits + 1 null terminator Fw::ExternalString external(format, sizeof format); switch (this->m_dataType) { case TYPE_U8: diff --git a/Fw/Types/PolyType.hpp b/Fw/Types/PolyType.hpp index 57095ee45ed..29e001ecba3 100644 --- a/Fw/Types/PolyType.hpp +++ b/Fw/Types/PolyType.hpp @@ -95,21 +95,21 @@ class PolyType : public Serializable { void toString(StringBase& dest) const override; //!< get string representation #endif - PolyType& operator=(const PolyType& src); //!< PolyType operator= - bool operator<(const PolyType& other) const; //!< PolyType operator< - bool operator>(const PolyType& other) const; //!< PolyType operator> - bool operator>=(const PolyType& other) const; //!< PolyType operator>= - bool operator<=(const PolyType& other) const; //!< PolyType operator<= - bool operator==(const PolyType& other) const; //!< PolyType operator== - bool operator!=(const PolyType& other) const; //!< PolyType operator!= - + PolyType& operator=(const PolyType& src); //!< PolyType operator= + bool operator<(const PolyType& other) const; //!< PolyType operator< + bool operator>(const PolyType& other) const; //!< PolyType operator> + bool operator>=(const PolyType& other) const; //!< PolyType operator>= + bool operator<=(const PolyType& other) const; //!< PolyType operator<= + bool operator==(const PolyType& other) const; //!< PolyType operator== + bool operator!=(const PolyType& other) const; //!< PolyType operator!= + // New serialization interface - SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; //!< Serialize function - SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; //!< Deserialize function - + SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; //!< Serialize function + SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; //!< Deserialize function + // Deprecated methods for backward compatibility - these call the new interface - SerializeStatus serialize(SerializeBufferBase& buffer) const override; //!< Serialize function (deprecated) - SerializeStatus deserialize(SerializeBufferBase& buffer) override; //!< Deserialize function (deprecated) + SerializeStatus serialize(SerializeBufferBase& buffer) const override; //!< Serialize function (deprecated) + SerializeStatus deserialize(SerializeBufferBase& buffer) override; //!< Deserialize function (deprecated) private: typedef enum { @@ -128,8 +128,8 @@ class PolyType : public Serializable { TYPE_U64, // !< U64 type stored TYPE_I64, // !< I64 type stored #endif - TYPE_F32, // !< F32 type stored - TYPE_F64, // !< F64 type stored + TYPE_F32, // !< F32 type stored + TYPE_F64, // !< F64 type stored TYPE_BOOL, // !< bool type stored TYPE_PTR // !< pointer type stored } Type; @@ -151,7 +151,7 @@ class PolyType : public Serializable { U64 u64Val; //!< U64 data storage I64 i64Val; //!< I64 data storage #endif - F64 f64Val; //!< F64 data storage + F64 f64Val; //!< F64 data storage F32 f32Val; // !< F32 data storage void* ptrVal; // !< pointer data storage bool boolVal; // !< bool data storage diff --git a/Fw/Types/SerIds.hpp b/Fw/Types/SerIds.hpp index 421922dfa94..5fbeb35a8d6 100644 --- a/Fw/Types/SerIds.hpp +++ b/Fw/Types/SerIds.hpp @@ -18,48 +18,48 @@ // Should fit in 16 bits namespace Fw { - enum { +enum { - // Built-in types + // Built-in types - FW_TYPEID_U8 = 10, //!< U8 serialized type id - FW_TYPEID_18 = 11, //!< I8 serialized type id - FW_TYPEID_U16 = 12, //!< U16 serialized type id - FW_TYPEID_I16 = 13, //!< I16 serialized type id - FW_TYPEID_U32 = 14, //!< U32 serialized type id - FW_TYPEID_I32 = 15, //!< I32 serialized type id - FW_TYPEID_U64 = 16, //!< U64 serialized type id - FW_TYPEID_I64 = 17, //!< I64 serialized type id - FW_TYPEID_F32 = 18, //!< F32 serialized type id - FW_TYPEID_F64 = 19, //!< F64 serialized type id - FW_TYPEID_BOOL = 20, //!< boolean serialized type id - FW_TYPEID_PTR = 21, //!< pointer serialized type id - FW_TYPEID_BUFF = 22, //!< buffer serialized type id + FW_TYPEID_U8 = 10, //!< U8 serialized type id + FW_TYPEID_18 = 11, //!< I8 serialized type id + FW_TYPEID_U16 = 12, //!< U16 serialized type id + FW_TYPEID_I16 = 13, //!< I16 serialized type id + FW_TYPEID_U32 = 14, //!< U32 serialized type id + FW_TYPEID_I32 = 15, //!< I32 serialized type id + FW_TYPEID_U64 = 16, //!< U64 serialized type id + FW_TYPEID_I64 = 17, //!< I64 serialized type id + FW_TYPEID_F32 = 18, //!< F32 serialized type id + FW_TYPEID_F64 = 19, //!< F64 serialized type id + FW_TYPEID_BOOL = 20, //!< boolean serialized type id + FW_TYPEID_PTR = 21, //!< pointer serialized type id + FW_TYPEID_BUFF = 22, //!< buffer serialized type id - // PolyType + // PolyType - FW_TYPEID_POLY = 30, //!< PolyType serialized type id + FW_TYPEID_POLY = 30, //!< PolyType serialized type id - // Command/Telemetry types + // Command/Telemetry types - FW_TYPEID_CMD_BUFF = 40, //!< Command Buffer type id - FW_TYPEID_CMD_STR = 41, //!< Command string type id - FW_TYPEID_TLM_BUFF = 42, //!< Telemetry Buffer type id - FW_TYPEID_TLM_STR = 43, //!< Telemetry string type id - FW_TYPEID_LOG_BUFF = 44, //!< Log Buffer type id - FW_TYPEID_LOG_STR = 45, //!< Log string type id - FW_TYPEID_PRM_BUFF = 46, //!< Parameter Buffer type id - FW_TYPEID_PRM_STR = 47, //!< Parameter string type id - FW_TYPEID_FILE_BUFF = 48, //!< File piece Buffer type id + FW_TYPEID_CMD_BUFF = 40, //!< Command Buffer type id + FW_TYPEID_CMD_STR = 41, //!< Command string type id + FW_TYPEID_TLM_BUFF = 42, //!< Telemetry Buffer type id + FW_TYPEID_TLM_STR = 43, //!< Telemetry string type id + FW_TYPEID_LOG_BUFF = 44, //!< Log Buffer type id + FW_TYPEID_LOG_STR = 45, //!< Log string type id + FW_TYPEID_PRM_BUFF = 46, //!< Parameter Buffer type id + FW_TYPEID_PRM_STR = 47, //!< Parameter string type id + FW_TYPEID_FILE_BUFF = 48, //!< File piece Buffer type id - // Other types + // Other types - FW_TYPEID_EIGHTY_CHAR_STRING = 50, //!< 80 char string Buffer type id - FW_TYPEID_INTERNAL_INTERFACE_STRING = 51, //!< interface string Buffer type id - FW_TYPEID_FIXED_LENGTH_STRING = 52, //!< 256 char string Buffer type id - FW_TYPEID_OBJECT_NAME = 53, //!< ObjectName string Buffer type id - FW_TYPEID_FILE_NAME_STRING = 54, //!< FileName string Buffer type id - }; + FW_TYPEID_EIGHTY_CHAR_STRING = 50, //!< 80 char string Buffer type id + FW_TYPEID_INTERNAL_INTERFACE_STRING = 51, //!< interface string Buffer type id + FW_TYPEID_FIXED_LENGTH_STRING = 52, //!< 256 char string Buffer type id + FW_TYPEID_OBJECT_NAME = 53, //!< ObjectName string Buffer type id + FW_TYPEID_FILE_NAME_STRING = 54, //!< FileName string Buffer type id +}; } #endif diff --git a/Fw/Types/SerialBuffer.cpp b/Fw/Types/SerialBuffer.cpp index d85f1e478b1..a861bd820db 100644 --- a/Fw/Types/SerialBuffer.cpp +++ b/Fw/Types/SerialBuffer.cpp @@ -10,8 +10,8 @@ // // ====================================================================== -#include "Fw/Types/Assert.hpp" #include "Fw/Types/SerialBuffer.hpp" +#include "Fw/Types/Assert.hpp" namespace Fw { diff --git a/Fw/Types/SerialBuffer.hpp b/Fw/Types/SerialBuffer.hpp index 2a13531b949..d54176085e9 100644 --- a/Fw/Types/SerialBuffer.hpp +++ b/Fw/Types/SerialBuffer.hpp @@ -29,7 +29,7 @@ class SerialBuffer final : public SerializeBufferBase { //! Construct a SerialBuffer //! - SerialBuffer(U8* const data, //!< Pointer to the data + SerialBuffer(U8* const data, //!< Pointer to the data const FwSizeType capacity //!< The buffer capacity ); @@ -53,13 +53,13 @@ class SerialBuffer final : public SerializeBufferBase { void fill(); //! Push n bytes onto the buffer - SerializeStatus pushBytes(const U8* const addr, //!< Address of bytes to push - const FwSizeType n //!< Number of bytes + SerializeStatus pushBytes(const U8* const addr, //!< Address of bytes to push + const FwSizeType n //!< Number of bytes ); //! Pop n bytes off the buffer - SerializeStatus popBytes(U8* const addr, //!< Address of bytes to pop - FwSizeType n //!< Number of bytes to pop + SerializeStatus popBytes(U8* const addr, //!< Address of bytes to pop + FwSizeType n //!< Number of bytes to pop ); private: diff --git a/Fw/Types/Serializable.cpp b/Fw/Types/Serializable.cpp index cdb2c24f124..fba7c89e497 100644 --- a/Fw/Types/Serializable.cpp +++ b/Fw/Types/Serializable.cpp @@ -269,7 +269,7 @@ SerializeStatus SerializeBufferBase::serializeFrom(const U8* buff, FwSizeType le SerializeStatus SerializeBufferBase::serializeFrom(const Serializable& val) { // Smart fallback approach for backward compatibility: // Try new interface first, but if it returns UNIMPLEMENTED (indicating default implementation), - // fall back to old interface. This bridges auto-generated enums (old interface only) + // fall back to old interface. This bridges auto-generated enums (old interface only) // with new serialization infrastructure. SerializeStatus status = val.serializeTo(*this); if (status == FW_SERIALIZE_UNIMPLEMENTED) { @@ -530,9 +530,9 @@ SerializeStatus SerializeBufferBase::deserializeTo(U8* buff, Serializable::SizeT if (mode == Serialization::INCLUDE_LENGTH) { FwSizeStoreType storedLength; - + SerializeStatus stat = this->deserializeTo(storedLength); - + if (stat != FW_SERIALIZE_OK) { return stat; } @@ -561,7 +561,7 @@ SerializeStatus SerializeBufferBase::deserializeTo(U8* buff, Serializable::SizeT SerializeStatus SerializeBufferBase::deserializeTo(Serializable& val) { // Try new interface first, but if it returns UNIMPLEMENTED (indicating default implementation), - // fall back to old interface. This bridges auto-generated enums (old interface only) + // fall back to old interface. This bridges auto-generated enums (old interface only) // with new serialization infrastructure. SerializeStatus status = val.deserializeFrom(*this); if (status == FW_DESERIALIZE_UNIMPLEMENTED) { @@ -815,70 +815,130 @@ SerializeStatus Serializable::deserialize(SerializeBufferBase& buffer) { return this->deserializeFrom(buffer); } -SerializeStatus SerializeBufferBase::serialize(U8 val) { return this->serializeFrom(val); } -SerializeStatus SerializeBufferBase::serialize(I8 val) { return this->serializeFrom(val); } +SerializeStatus SerializeBufferBase::serialize(U8 val) { + return this->serializeFrom(val); +} +SerializeStatus SerializeBufferBase::serialize(I8 val) { + return this->serializeFrom(val); +} #if FW_HAS_16_BIT == 1 -SerializeStatus SerializeBufferBase::serialize(U16 val) { return this->serializeFrom(val); } -SerializeStatus SerializeBufferBase::serialize(I16 val) { return this->serializeFrom(val); } +SerializeStatus SerializeBufferBase::serialize(U16 val) { + return this->serializeFrom(val); +} +SerializeStatus SerializeBufferBase::serialize(I16 val) { + return this->serializeFrom(val); +} #endif #if FW_HAS_32_BIT == 1 -SerializeStatus SerializeBufferBase::serialize(U32 val) { return this->serializeFrom(val); } -SerializeStatus SerializeBufferBase::serialize(I32 val) { return this->serializeFrom(val); } +SerializeStatus SerializeBufferBase::serialize(U32 val) { + return this->serializeFrom(val); +} +SerializeStatus SerializeBufferBase::serialize(I32 val) { + return this->serializeFrom(val); +} #endif #if FW_HAS_64_BIT == 1 -SerializeStatus SerializeBufferBase::serialize(U64 val) { return this->serializeFrom(val); } -SerializeStatus SerializeBufferBase::serialize(I64 val) { return this->serializeFrom(val); } +SerializeStatus SerializeBufferBase::serialize(U64 val) { + return this->serializeFrom(val); +} +SerializeStatus SerializeBufferBase::serialize(I64 val) { + return this->serializeFrom(val); +} #endif -SerializeStatus SerializeBufferBase::serialize(F32 val) { return this->serializeFrom(val); } -SerializeStatus SerializeBufferBase::serialize(F64 val) { return this->serializeFrom(val); } -SerializeStatus SerializeBufferBase::serialize(bool val) { return this->serializeFrom(val); } -SerializeStatus SerializeBufferBase::serialize(const void* val) { return this->serializeFrom(val); } +SerializeStatus SerializeBufferBase::serialize(F32 val) { + return this->serializeFrom(val); +} +SerializeStatus SerializeBufferBase::serialize(F64 val) { + return this->serializeFrom(val); +} +SerializeStatus SerializeBufferBase::serialize(bool val) { + return this->serializeFrom(val); +} +SerializeStatus SerializeBufferBase::serialize(const void* val) { + return this->serializeFrom(val); +} // Deprecated method for backward compatibility -SerializeStatus SerializeBufferBase::serialize(const U8* buff, FwSizeType length, bool noLength) { +SerializeStatus SerializeBufferBase::serialize(const U8* buff, FwSizeType length, bool noLength) { const Serialization::t mode = noLength ? Serialization::OMIT_LENGTH : Serialization::INCLUDE_LENGTH; - return this->serializeFrom(buff, length, mode); + return this->serializeFrom(buff, length, mode); } -SerializeStatus SerializeBufferBase::serialize(const U8* buff, FwSizeType length) { return this->serializeFrom(buff, length); } -SerializeStatus SerializeBufferBase::serialize(const U8* buff, FwSizeType length, Serialization::t mode) { return this->serializeFrom(buff, length, mode); } -SerializeStatus SerializeBufferBase::serialize(const Serializable& val) { return this->serializeFrom(val); } -SerializeStatus SerializeBufferBase::serialize(const SerializeBufferBase& val) { return this->serializeFrom(val); } +SerializeStatus SerializeBufferBase::serialize(const U8* buff, FwSizeType length) { + return this->serializeFrom(buff, length); +} +SerializeStatus SerializeBufferBase::serialize(const U8* buff, FwSizeType length, Serialization::t mode) { + return this->serializeFrom(buff, length, mode); +} +SerializeStatus SerializeBufferBase::serialize(const Serializable& val) { + return this->serializeFrom(val); +} +SerializeStatus SerializeBufferBase::serialize(const SerializeBufferBase& val) { + return this->serializeFrom(val); +} -SerializeStatus SerializeBufferBase::deserialize(U8& val) { return this->deserializeTo(val); } -SerializeStatus SerializeBufferBase::deserialize(I8& val) { return this->deserializeTo(val); } +SerializeStatus SerializeBufferBase::deserialize(U8& val) { + return this->deserializeTo(val); +} +SerializeStatus SerializeBufferBase::deserialize(I8& val) { + return this->deserializeTo(val); +} #if FW_HAS_16_BIT == 1 -SerializeStatus SerializeBufferBase::deserialize(U16& val) { return this->deserializeTo(val); } -SerializeStatus SerializeBufferBase::deserialize(I16& val) { return this->deserializeTo(val); } +SerializeStatus SerializeBufferBase::deserialize(U16& val) { + return this->deserializeTo(val); +} +SerializeStatus SerializeBufferBase::deserialize(I16& val) { + return this->deserializeTo(val); +} #endif #if FW_HAS_32_BIT == 1 -SerializeStatus SerializeBufferBase::deserialize(U32& val) { return this->deserializeTo(val); } -SerializeStatus SerializeBufferBase::deserialize(I32& val) { return this->deserializeTo(val); } +SerializeStatus SerializeBufferBase::deserialize(U32& val) { + return this->deserializeTo(val); +} +SerializeStatus SerializeBufferBase::deserialize(I32& val) { + return this->deserializeTo(val); +} #endif #if FW_HAS_64_BIT == 1 -SerializeStatus SerializeBufferBase::deserialize(U64& val) { return this->deserializeTo(val); } -SerializeStatus SerializeBufferBase::deserialize(I64& val) { return this->deserializeTo(val); } +SerializeStatus SerializeBufferBase::deserialize(U64& val) { + return this->deserializeTo(val); +} +SerializeStatus SerializeBufferBase::deserialize(I64& val) { + return this->deserializeTo(val); +} #endif -SerializeStatus SerializeBufferBase::deserialize(F32& val) { return this->deserializeTo(val); } -SerializeStatus SerializeBufferBase::deserialize(F64& val) { return this->deserializeTo(val); } -SerializeStatus SerializeBufferBase::deserialize(bool& val) { return this->deserializeTo(val); } -SerializeStatus SerializeBufferBase::deserialize(void*& val) { return this->deserializeTo(val); } +SerializeStatus SerializeBufferBase::deserialize(F32& val) { + return this->deserializeTo(val); +} +SerializeStatus SerializeBufferBase::deserialize(F64& val) { + return this->deserializeTo(val); +} +SerializeStatus SerializeBufferBase::deserialize(bool& val) { + return this->deserializeTo(val); +} +SerializeStatus SerializeBufferBase::deserialize(void*& val) { + return this->deserializeTo(val); +} // Deprecated method for backward compatibility -SerializeStatus SerializeBufferBase::deserialize(U8* buff, FwSizeType& length, bool noLength) { +SerializeStatus SerializeBufferBase::deserialize(U8* buff, FwSizeType& length, bool noLength) { const Serialization::t mode = noLength ? Serialization::OMIT_LENGTH : Serialization::INCLUDE_LENGTH; - return this->deserializeTo(buff, length, mode); + return this->deserializeTo(buff, length, mode); } -SerializeStatus SerializeBufferBase::deserialize(U8* buff, FwSizeType& length) { - return this->deserializeTo(buff, length, Serialization::INCLUDE_LENGTH); +SerializeStatus SerializeBufferBase::deserialize(U8* buff, FwSizeType& length) { + return this->deserializeTo(buff, length, Serialization::INCLUDE_LENGTH); } -SerializeStatus SerializeBufferBase::deserialize(U8* buff, FwSizeType& length, Serialization::t mode) { - return this->deserializeTo(buff, length, mode); +SerializeStatus SerializeBufferBase::deserialize(U8* buff, FwSizeType& length, Serialization::t mode) { + return this->deserializeTo(buff, length, mode); } -SerializeStatus SerializeBufferBase::deserialize(Serializable& val) { return this->deserializeTo(val); } -SerializeStatus SerializeBufferBase::deserialize(SerializeBufferBase& val) { return this->deserializeTo(val); } +SerializeStatus SerializeBufferBase::deserialize(Serializable& val) { + return this->deserializeTo(val); +} +SerializeStatus SerializeBufferBase::deserialize(SerializeBufferBase& val) { + return this->deserializeTo(val); +} } // namespace Fw diff --git a/Fw/Types/Serializable.hpp b/Fw/Types/Serializable.hpp index 5be15eae4d0..0c6f18ea2c6 100644 --- a/Fw/Types/Serializable.hpp +++ b/Fw/Types/Serializable.hpp @@ -30,9 +30,9 @@ class Serializable { using SizeType = FwSizeType; public: - virtual SerializeStatus serializeTo(SerializeBufferBase& buffer) const; //!< serialize contents to buffer - - virtual SerializeStatus deserializeFrom(SerializeBufferBase& buffer); //!< deserialize contents from buffer + virtual SerializeStatus serializeTo(SerializeBufferBase& buffer) const; //!< serialize contents to buffer + + virtual SerializeStatus deserializeFrom(SerializeBufferBase& buffer); //!< deserialize contents from buffer // ---------------------------------------------------------------------- // Methods @@ -63,8 +63,7 @@ class Serialization { }; class SerializeBufferBase { - - friend class SerializeBufferBaseTester; + friend class SerializeBufferBaseTester; protected: SerializeBufferBase& operator=(const SerializeBufferBase& src); //!< copy assignment operator @@ -89,8 +88,8 @@ class SerializeBufferBase { SerializeStatus serializeFrom(U64 val); //!< serialize 64-bit unsigned int SerializeStatus serializeFrom(I64 val); //!< serialize 64-bit signed int #endif - SerializeStatus serializeFrom(F32 val); //!< serialize 32-bit floating point - SerializeStatus serializeFrom(F64 val); //!< serialize 64-bit floating point + SerializeStatus serializeFrom(F32 val); //!< serialize 32-bit floating point + SerializeStatus serializeFrom(F64 val); //!< serialize 64-bit floating point SerializeStatus serializeFrom(bool val); //!< serialize boolean SerializeStatus serializeFrom( @@ -112,7 +111,8 @@ class SerializeBufferBase { SerializeStatus serializeFrom(const SerializeBufferBase& val); //!< serialize a serialized buffer - SerializeStatus serializeFrom(const Serializable& val); //!< serialize an object derived from serializable base class + SerializeStatus serializeFrom( + const Serializable& val); //!< serialize an object derived from serializable base class SerializeStatus serializeSize(const FwSizeType size); //!< serialize a size value @@ -134,8 +134,8 @@ class SerializeBufferBase { SerializeStatus deserializeTo(U64& val); //!< deserialize 64-bit unsigned int SerializeStatus deserializeTo(I64& val); //!< deserialize 64-bit signed int #endif - SerializeStatus deserializeTo(F32& val); //!< deserialize 32-bit floating point - SerializeStatus deserializeTo(F64& val); //!< deserialize 64-bit floating point + SerializeStatus deserializeTo(F32& val); //!< deserialize 32-bit floating point + SerializeStatus deserializeTo(F64& val); //!< deserialize 64-bit floating point SerializeStatus deserializeTo(bool& val); //!< deserialize boolean SerializeStatus deserializeTo(void*& val); //!< deserialize point value (careful, pointer value only, not contents) @@ -143,7 +143,7 @@ class SerializeBufferBase { SerializeStatus deserializeTo(U8* buff, FwSizeType& length); //!< deserialize data buffer //! \brief deserialize a byte buffer of a given length - //! + //! //! The `mode` parameter specifies whether the serialized length should be read from the buffer. //! \param buff: buffer to deserialize into //! \param length: length of the buffer, updated with the actual deserialized length @@ -179,7 +179,8 @@ class SerializeBufferBase { SerializeStatus serialize(F64 val); SerializeStatus serialize(bool val); SerializeStatus serialize(const void* val); - DEPRECATED(SerializeStatus serialize(const U8* buff, FwSizeType length, bool noLength), "Use serialize(const U8* buff, FwSizeType length, Serialization::t mode) instead"); + DEPRECATED(SerializeStatus serialize(const U8* buff, FwSizeType length, bool noLength), + "Use serialize(const U8* buff, FwSizeType length, Serialization::t mode) instead"); SerializeStatus serialize(const U8* buff, FwSizeType length); SerializeStatus serialize(const U8* buff, FwSizeType length, Serialization::t mode); SerializeStatus serialize(const Serializable& val); @@ -203,7 +204,8 @@ class SerializeBufferBase { SerializeStatus deserialize(F64& val); SerializeStatus deserialize(bool& val); SerializeStatus deserialize(void*& val); - DEPRECATED(SerializeStatus deserialize(U8* buff, FwSizeType& length, bool noLength), "Use deserialize(U8* buff, FwSizeType& length, Serialization::t mode) instead"); + DEPRECATED(SerializeStatus deserialize(U8* buff, FwSizeType& length, bool noLength), + "Use deserialize(U8* buff, FwSizeType& length, Serialization::t mode) instead"); SerializeStatus deserialize(U8* buff, FwSizeType& length); SerializeStatus deserialize(U8* buff, FwSizeType& length, Serialization::t mode); SerializeStatus deserialize(Serializable& val); @@ -244,9 +246,9 @@ class SerializeBufferBase { #endif protected: - SerializeBufferBase(); //!< default constructor - Serializable::SizeType m_serLoc; //!< current offset in buffer of serialized data - Serializable::SizeType m_deserLoc; //!< current offset for deserialization + SerializeBufferBase(); //!< default constructor + Serializable::SizeType m_serLoc; //!< current offset in buffer of serialized data + Serializable::SizeType m_deserLoc; //!< current offset for deserialization private: // Copy constructor can be used only by the implementation diff --git a/Fw/Types/StringBase.hpp b/Fw/Types/StringBase.hpp index c7d27c83f44..2b9d4c9f241 100644 --- a/Fw/Types/StringBase.hpp +++ b/Fw/Types/StringBase.hpp @@ -12,9 +12,9 @@ #ifndef FW_STRING_BASE_HPP #define FW_STRING_BASE_HPP -#include #include #include +#include #include #ifdef BUILD_UT #include @@ -63,7 +63,7 @@ class StringBase : public Serializable { StringBase& operator=(const CHAR* src); //!< Assign CHAR* StringBase& operator=(const StringBase& src); //!< Assign another StringBase - FormatStatus format(const CHAR* formatString, ...); //!< write formatted string to buffer + FormatStatus format(const CHAR* formatString, ...); //!< write formatted string to buffer FormatStatus vformat(const CHAR* formatString, va_list args); //!< write formatted string to buffer using va_list SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; diff --git a/Fw/Types/StringTemplate.hpp b/Fw/Types/StringTemplate.hpp index c52b82128ca..da08cbcec0e 100644 --- a/Fw/Types/StringTemplate.hpp +++ b/Fw/Types/StringTemplate.hpp @@ -13,7 +13,8 @@ namespace Fw { -template class StringTemplate final : public StringBase { +template +class StringTemplate final : public StringBase { public: enum { STRING_SIZE = size, diff --git a/Fw/Types/StringToNumber.cpp b/Fw/Types/StringToNumber.cpp index aa93b077317..439dec168e5 100644 --- a/Fw/Types/StringToNumber.cpp +++ b/Fw/Types/StringToNumber.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include Fw::StringUtils::StringToNumberStatus string_to_helper_input_check(const CHAR* input, FwSizeType buffer_size, U8 base) { Fw::StringUtils::StringToNumberStatus status = Fw::StringUtils::StringToNumberStatus::SUCCESSFUL_CONVERSION; @@ -22,7 +22,10 @@ Fw::StringUtils::StringToNumberStatus string_to_helper_input_check(const CHAR* i return status; } -Fw::StringUtils::StringToNumberStatus string_to_helper_output_check(Fw::StringUtils::StringToNumberStatus status, const char* original_input, char*& internal_next, char** external_next) { +Fw::StringUtils::StringToNumberStatus string_to_helper_output_check(Fw::StringUtils::StringToNumberStatus status, + const char* original_input, + char*& internal_next, + char** external_next) { // Check range, if error then if (errno == ERANGE) { status = Fw::StringUtils::INVALID_RANGE; @@ -45,12 +48,19 @@ Fw::StringUtils::StringToNumberStatus string_to_helper_output_check(Fw::StringUt // \tparam Tinternal: function api type // \tparam F: conversion function to use template -Fw::StringUtils::StringToNumberStatus string_to_number_as_template(const CHAR* input, FwSizeType buffer_size, T& output, char** next, U8 base) { +Fw::StringUtils::StringToNumberStatus string_to_number_as_template(const CHAR* input, + FwSizeType buffer_size, + T& output, + char** next, + U8 base) { static_assert(std::numeric_limits::is_integer, "Type must be integer"); static_assert(std::numeric_limits::is_integer, "Type must be integer"); - static_assert(std::numeric_limits::is_signed == std::numeric_limits::is_signed, "Signedness must match"); - static_assert(std::numeric_limits::max() <= std::numeric_limits::max(), "Invalid internal type chosen"); - static_assert(std::numeric_limits::min() >= std::numeric_limits::min(), "Invalid internal type chosen"); + static_assert(std::numeric_limits::is_signed == std::numeric_limits::is_signed, + "Signedness must match"); + static_assert(std::numeric_limits::max() <= std::numeric_limits::max(), + "Invalid internal type chosen"); + static_assert(std::numeric_limits::min() >= std::numeric_limits::min(), + "Invalid internal type chosen"); char* output_next = nullptr; Fw::StringUtils::StringToNumberStatus status = string_to_helper_input_check(input, buffer_size, base); @@ -71,40 +81,74 @@ Fw::StringUtils::StringToNumberStatus string_to_number_as_template(const CHAR* i } #if FW_HAS_64_BIT -Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, FwSizeType buffer_size, U64& output, char** next, U8 base) { +Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, + FwSizeType buffer_size, + U64& output, + char** next, + U8 base) { return string_to_number_as_template(input, buffer_size, output, next, base); } -Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, FwSizeType buffer_size, I64& output, char** next, U8 base) { +Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, + FwSizeType buffer_size, + I64& output, + char** next, + U8 base) { return string_to_number_as_template(input, buffer_size, output, next, base); } #endif #if FW_HAS_32_BIT -Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, FwSizeType buffer_size, U32& output, char** next, U8 base) { +Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, + FwSizeType buffer_size, + U32& output, + char** next, + U8 base) { return string_to_number_as_template(input, buffer_size, output, next, base); } - -Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, FwSizeType buffer_size, I32& output, char** next, U8 base) { +Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, + FwSizeType buffer_size, + I32& output, + char** next, + U8 base) { return string_to_number_as_template(input, buffer_size, output, next, base); } #endif #if FW_HAS_16_BIT -Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, FwSizeType buffer_size, U16& output, char** next, U8 base) { +Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, + FwSizeType buffer_size, + U16& output, + char** next, + U8 base) { return string_to_number_as_template(input, buffer_size, output, next, base); } -Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, FwSizeType buffer_size, I16& output, char** next, U8 base) { +Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, + FwSizeType buffer_size, + I16& output, + char** next, + U8 base) { return string_to_number_as_template(input, buffer_size, output, next, base); } #endif -Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, FwSizeType buffer_size, U8& output, char** next, U8 base) { +Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, + FwSizeType buffer_size, + U8& output, + char** next, + U8 base) { return string_to_number_as_template(input, buffer_size, output, next, base); } -Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, FwSizeType buffer_size, I8& output, char** next, U8 base) { +Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, + FwSizeType buffer_size, + I8& output, + char** next, + U8 base) { return string_to_number_as_template(input, buffer_size, output, next, base); } #if FW_HAS_F64 -Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, FwSizeType buffer_size, F64& output, char** next) { +Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, + FwSizeType buffer_size, + F64& output, + char** next) { char* output_next = nullptr; Fw::StringUtils::StringToNumberStatus status = string_to_helper_input_check(input, buffer_size, 0); if (status == SUCCESSFUL_CONVERSION) { @@ -115,7 +159,10 @@ Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CH } #endif -Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, FwSizeType buffer_size, F32& output, char** next) { +Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number(const CHAR* input, + FwSizeType buffer_size, + F32& output, + char** next) { char* output_next = nullptr; Fw::StringUtils::StringToNumberStatus status = string_to_helper_input_check(input, buffer_size, 0); if (status == SUCCESSFUL_CONVERSION) { diff --git a/Fw/Types/StringUtils.cpp b/Fw/Types/StringUtils.cpp index d97109a4691..cd2f9163e7a 100644 --- a/Fw/Types/StringUtils.cpp +++ b/Fw/Types/StringUtils.cpp @@ -1,8 +1,8 @@ #include "StringUtils.hpp" #include +#include #include #include -#include char* Fw::StringUtils::string_copy(char* destination, const char* source, FwSizeType num) { // Handle self-copy and 0 bytes copy diff --git a/Fw/Types/StringUtils.hpp b/Fw/Types/StringUtils.hpp index 346c95c9029..5c75aef1985 100644 --- a/Fw/Types/StringUtils.hpp +++ b/Fw/Types/StringUtils.hpp @@ -47,15 +47,18 @@ FwSizeType string_length(const CHAR* source, FwSizeType buffer_size); * \param sub_size: the size of the string to search for * \return index of substring, -1 if not found */ -FwSignedSizeType substring_find(const CHAR* source_string, FwSizeType source_size, const CHAR* sub_string, FwSizeType sub_size); +FwSignedSizeType substring_find(const CHAR* source_string, + FwSizeType source_size, + const CHAR* sub_string, + FwSizeType sub_size); enum StringToNumberStatus { - SUCCESSFUL_CONVERSION, //!< Output should be valid - NULL_INPUT, //!< A null string was supplied - INVALID_STRING, //!< No \0 detected within the supplied length - INVALID_BASE, //!< Base was not supplied as 0, or 2-36 - INVALID_NUMBER, //!< String did not contain a valid number matching supplied base - INVALID_RANGE, //!< + SUCCESSFUL_CONVERSION, //!< Output should be valid + NULL_INPUT, //!< A null string was supplied + INVALID_STRING, //!< No \0 detected within the supplied length + INVALID_BASE, //!< Base was not supplied as 0, or 2-36 + INVALID_NUMBER, //!< String did not contain a valid number matching supplied base + INVALID_RANGE, //!< }; #if FW_HAS_64_BIT @@ -84,7 +87,7 @@ enum StringToNumberStatus { * \param next: (output) will contain a pointer to the next character after the number and null pointer on error * \return SUCCESSFUL_CONVERSION when output is valid, something else on error. */ -StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, U64& output, char** next, U8 base=0); +StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, U64& output, char** next, U8 base = 0); /** * \brief converts a string to a I64 @@ -98,7 +101,7 @@ StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, * \param next: (output) will contain a pointer to the next character after the number and null pointer on error * \return SUCCESSFUL_CONVERSION when output is valid, something else on error. */ -StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, I64& output, char** next, U8 base=0); +StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, I64& output, char** next, U8 base = 0); #endif #if FW_HAS_32_BIT /** @@ -113,7 +116,7 @@ StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, * \param next: (output) will contain a pointer to the next character after the number and null pointer on error * \return SUCCESSFUL_CONVERSION when output is valid, something else on error. */ -StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, U32& output, char** next, U8 base=0); +StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, U32& output, char** next, U8 base = 0); /** * \brief converts a string to a I32 @@ -127,7 +130,7 @@ StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, * \param next: (output) will contain a pointer to the next character after the number and null pointer on error * \return SUCCESSFUL_CONVERSION when output is valid, something else on error. */ -StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, I32& output, char** next, U8 base=0); +StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, I32& output, char** next, U8 base = 0); #endif #if FW_HAS_16_BIT /** @@ -142,7 +145,7 @@ StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, * \param next: (output) will contain a pointer to the next character after the number and null pointer on error * \return SUCCESSFUL_CONVERSION when output is valid, something else on error. */ -StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, U16& output, char** next, U8 base=0); +StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, U16& output, char** next, U8 base = 0); /** * \brief converts a string to a I16 @@ -156,7 +159,7 @@ StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, * \param next: (output) will contain a pointer to the next character after the number and null pointer on error * \return SUCCESSFUL_CONVERSION when output is valid, something else on error. */ -StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, I16& output, char** next, U8 base=0); +StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, I16& output, char** next, U8 base = 0); #endif /** @@ -171,7 +174,7 @@ StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, * \param next: (output) will contain a pointer to the next character after the number and null pointer on error * \return SUCCESSFUL_CONVERSION when output is valid, something else on error. */ -StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, U8& output, char** next, U8 base=0); +StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, U8& output, char** next, U8 base = 0); /** * \brief converts a string to a I8 @@ -185,7 +188,7 @@ StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, * \param next: (output) will contain a pointer to the next character after the number and null pointer on error * \return SUCCESSFUL_CONVERSION when output is valid, something else on error. */ -StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, I8& output, char** next, U8 base=0); +StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, I8& output, char** next, U8 base = 0); /** * \brief converts a string to a F32 @@ -216,8 +219,6 @@ StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, StringToNumberStatus string_to_number(const CHAR* input, FwSizeType buffer_size, F64& output, char** next); #endif - - } // namespace StringUtils } // namespace Fw #endif // FW_STRINGUTILS_HPP diff --git a/Fw/Types/format.hpp b/Fw/Types/format.hpp index 4ce86128cc3..bf3e96ed05e 100644 --- a/Fw/Types/format.hpp +++ b/Fw/Types/format.hpp @@ -16,11 +16,11 @@ namespace Fw { //! \brief status of string format calls enum class FormatStatus { - SUCCESS, //!< Format worked - OVERFLOWED, //!< Format overflowed - INVALID_FORMAT_STRING, //!< Format provided invalid format string - SIZE_OVERFLOW, //!< FwSizeType overflowed the range of size_t - OTHER_ERROR //!< An error was returned from an underlying call + SUCCESS, //!< Format worked + OVERFLOWED, //!< Format overflowed + INVALID_FORMAT_STRING, //!< Format provided invalid format string + SIZE_OVERFLOW, //!< FwSizeType overflowed the range of size_t + OTHER_ERROR //!< An error was returned from an underlying call }; //! \brief format a c-string @@ -60,7 +60,5 @@ FormatStatus stringFormat(char* destination, const FwSizeType maximumSize, const //! \param args: variable arguments list //! \return: SUCCESS on successful formatting, OVERFLOWED on overflow, and something else on any error FormatStatus stringFormat(char* destination, const FwSizeType maximumSize, const char* formatString, va_list args); -} -#endif // FW_TYPES_FORMAT_HPP_ - - +} // namespace Fw +#endif // FW_TYPES_FORMAT_HPP_ diff --git a/Fw/Types/snprintf_format.cpp b/Fw/Types/snprintf_format.cpp index 4d6441414c8..c9111d9f123 100644 --- a/Fw/Types/snprintf_format.cpp +++ b/Fw/Types/snprintf_format.cpp @@ -4,8 +4,8 @@ // \brief cpp file for c-string format function as a implementation using snprintf // ====================================================================== #include -#include #include +#include Fw::FormatStatus Fw::stringFormat(char* destination, const FwSizeType maximumSize, const char* formatString, ...) { va_list args; @@ -15,7 +15,10 @@ Fw::FormatStatus Fw::stringFormat(char* destination, const FwSizeType maximumSiz return status; } -Fw::FormatStatus Fw::stringFormat(char* destination, const FwSizeType maximumSize, const char* formatString, va_list args) { +Fw::FormatStatus Fw::stringFormat(char* destination, + const FwSizeType maximumSize, + const char* formatString, + va_list args) { Fw::FormatStatus formatStatus = Fw::FormatStatus::SUCCESS; // Force null termination in error cases destination[0] = 0; @@ -28,7 +31,7 @@ Fw::FormatStatus Fw::stringFormat(char* destination, const FwSizeType maximumSiz formatStatus = Fw::FormatStatus::SIZE_OVERFLOW; } else { int needed_size = vsnprintf(destination, static_cast(maximumSize), formatString, args); - destination[maximumSize - 1] = 0; // Force null-termination + destination[maximumSize - 1] = 0; // Force null-termination if (needed_size < 0) { formatStatus = Fw::FormatStatus::OTHER_ERROR; } else if (static_cast(needed_size) >= maximumSize) { diff --git a/Fw/Types/test/ut/AssertTypesTest.cpp b/Fw/Types/test/ut/AssertTypesTest.cpp index 9ca5f7bea6a..84fe29fba46 100644 --- a/Fw/Types/test/ut/AssertTypesTest.cpp +++ b/Fw/Types/test/ut/AssertTypesTest.cpp @@ -1,11 +1,11 @@ -#include #include +#include /** * \file AssertTypesTest.h * \author Vince Woo - * \brief Tests for FW_ASSERT_LEVEL fall back when ASSERT_FILE_ID or - * ASSERT_RELATIVE_PATH are missing. + * \brief Tests for FW_ASSERT_LEVEL fall back when ASSERT_FILE_ID or + * ASSERT_RELATIVE_PATH are missing. */ #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT @@ -18,54 +18,53 @@ // Define an Assert handler class TestAssertHook : public Fw::AssertHook { - public: - TestAssertHook() {} - virtual ~TestAssertHook() {} - void reportAssert(FILE_NAME_ARG file, - FwSizeType lineNo, - FwSizeType numArgs, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwAssertArgType arg5, - FwAssertArgType arg6) { - this->m_file = file; - this->m_lineNo = lineNo; - this->m_numArgs = numArgs; - this->m_arg1 = arg1; - }; + public: + TestAssertHook() {} + virtual ~TestAssertHook() {} + void reportAssert(FILE_NAME_ARG file, + FwSizeType lineNo, + FwSizeType numArgs, + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwAssertArgType arg5, + FwAssertArgType arg6) { + this->m_file = file; + this->m_lineNo = lineNo; + this->m_numArgs = numArgs; + this->m_arg1 = arg1; + }; - void doAssert() { this->m_asserted = true; } + void doAssert() { this->m_asserted = true; } - FILE_NAME_ARG getFile() { return this->m_file; } + FILE_NAME_ARG getFile() { return this->m_file; } - FwSizeType getLineNo() { return this->m_lineNo; } + FwSizeType getLineNo() { return this->m_lineNo; } - FwSizeType getNumArgs() { return this->m_numArgs; } + FwSizeType getNumArgs() { return this->m_numArgs; } - FwAssertArgType getArg1() { return this->m_arg1; } + FwAssertArgType getArg1() { return this->m_arg1; } - bool asserted() { - bool didAssert = this->m_asserted; - this->m_asserted = false; - return didAssert; - } + bool asserted() { + bool didAssert = this->m_asserted; + this->m_asserted = false; + return didAssert; + } - private: + private: #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT - // Setting this to a non-zero initially as the test - // should set it to 0. - FILE_NAME_ARG m_file = 1; + // Setting this to a non-zero initially as the test + // should set it to 0. + FILE_NAME_ARG m_file = 1; #else - FILE_NAME_ARG m_file = nullptr; + FILE_NAME_ARG m_file = nullptr; #endif - FwSizeType m_lineNo = 0; - FwSizeType m_numArgs = 0; - FwAssertArgType m_arg1 = 0; - bool m_asserted = false; - }; - + FwSizeType m_lineNo = 0; + FwSizeType m_numArgs = 0; + FwAssertArgType m_arg1 = 0; + bool m_asserted = false; +}; // TEST(AssertTypesTest, FileDefaultTest) { diff --git a/Fw/Types/test/ut/CAssertTest.cpp b/Fw/Types/test/ut/CAssertTest.cpp index 1b5566c360b..85658326630 100644 --- a/Fw/Types/test/ut/CAssertTest.cpp +++ b/Fw/Types/test/ut/CAssertTest.cpp @@ -1,12 +1,12 @@ +#include #include #include -#include #include /** * \file CAssertTest.cpp * \brief Tests for FW_CASSERT_1 macro functionality - * + * * Note: F' C assertions use an assert hook system rather than directly * terminating the program. This allows for configurable assert handling * in embedded systems. @@ -14,92 +14,91 @@ // Define an Assert handler class TestAssertHook : public Fw::AssertHook { - public: - TestAssertHook() {} - virtual ~TestAssertHook() {} - void reportAssert(FILE_NAME_ARG file, - FwSizeType lineNo, - FwSizeType numArgs, - FwAssertArgType arg1, - FwAssertArgType arg2, - FwAssertArgType arg3, - FwAssertArgType arg4, - FwAssertArgType arg5, - FwAssertArgType arg6) { - this->m_file = file; - this->m_lineNo = lineNo; - this->m_numArgs = numArgs; - this->m_arg1 = arg1; - }; - - void doAssert() { this->m_asserted = true; } - - FILE_NAME_ARG getFile() { return this->m_file; } - - FwSizeType getLineNo() { return this->m_lineNo; } - - FwSizeType getNumArgs() { return this->m_numArgs; } - - FwAssertArgType getArg1() { return this->m_arg1; } - - bool asserted() { - bool didAssert = this->m_asserted; - this->m_asserted = false; - return didAssert; - } - - private: + public: + TestAssertHook() {} + virtual ~TestAssertHook() {} + void reportAssert(FILE_NAME_ARG file, + FwSizeType lineNo, + FwSizeType numArgs, + FwAssertArgType arg1, + FwAssertArgType arg2, + FwAssertArgType arg3, + FwAssertArgType arg4, + FwAssertArgType arg5, + FwAssertArgType arg6) { + this->m_file = file; + this->m_lineNo = lineNo; + this->m_numArgs = numArgs; + this->m_arg1 = arg1; + }; + + void doAssert() { this->m_asserted = true; } + + FILE_NAME_ARG getFile() { return this->m_file; } + + FwSizeType getLineNo() { return this->m_lineNo; } + + FwSizeType getNumArgs() { return this->m_numArgs; } + + FwAssertArgType getArg1() { return this->m_arg1; } + + bool asserted() { + bool didAssert = this->m_asserted; + this->m_asserted = false; + return didAssert; + } + + private: #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT - // Setting this to a non-zero initially as the test - // should set it to 0. - FILE_NAME_ARG m_file = 1; + // Setting this to a non-zero initially as the test + // should set it to 0. + FILE_NAME_ARG m_file = 1; #else - FILE_NAME_ARG m_file = nullptr; + FILE_NAME_ARG m_file = nullptr; #endif - FwSizeType m_lineNo = 0; - FwSizeType m_numArgs = 0; - FwAssertArgType m_arg1 = 0; - bool m_asserted = false; - }; + FwSizeType m_lineNo = 0; + FwSizeType m_numArgs = 0; + FwAssertArgType m_arg1 = 0; + bool m_asserted = false; +}; - // Test that FW_CASSERT_1 macro compiles and works correctly when true TEST(CAssertTest, CAssert1Macro) { - // Disable old-style cast warnings for this test since we're testing C macros - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wold-style-cast" - +// Disable old-style cast warnings for this test since we're testing C macros +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" + // Test that the macro compiles without errors int testValue = 42; - + // This should not trigger an assertion since condition is true FW_CASSERT_1(testValue == 42, testValue); - + // Test with different argument types U32 uintValue = 100; FW_CASSERT_1(uintValue > 0, uintValue); - + I32 intValue = -1; FW_CASSERT_1(intValue < 0, intValue); - - #pragma GCC diagnostic pop - + +#pragma GCC diagnostic pop + // Verify that the macro expands correctly - EXPECT_TRUE(true); // If we get here, the macro compiled successfully + EXPECT_TRUE(true); // If we get here, the macro compiled successfully } // Test basic FW_CASSERT macro (no arguments) TEST(CAssertTest, CAssertMacro) { - // Disable old-style cast warnings for this test since we're testing C macros - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wold-style-cast" - +// Disable old-style cast warnings for this test since we're testing C macros +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" + // Test basic assertion with true condition FW_CASSERT(1 == 1); FW_CASSERT(true); - - #pragma GCC diagnostic pop - + +#pragma GCC diagnostic pop + // If we reach here, compilation and execution were successful EXPECT_TRUE(true); } @@ -107,27 +106,27 @@ TEST(CAssertTest, CAssertMacro) { // Test that FW_CASSERT_1 properly triggers assert hook when condition is false TEST(CAssertTest, CAssert1MacroFailure) { #if FW_ASSERT_LEVEL != FW_NO_ASSERT - // Disable old-style cast warnings for this test since we're testing C macros - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wold-style-cast" - +// Disable old-style cast warnings for this test since we're testing C macros +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" + // Create and register test assert hook TestAssertHook hook; hook.registerHook(); - + // Test FW_CASSERT_1 with failing condition int testValue = 42; - FW_CASSERT_1(testValue == 999, testValue); // This should trigger the assert hook - + FW_CASSERT_1(testValue == 999, testValue); // This should trigger the assert hook + // Verify that assertion was triggered EXPECT_TRUE(hook.asserted()); EXPECT_EQ(hook.getNumArgs(), 1U); EXPECT_EQ(hook.getArg1(), static_cast(testValue)); - + // Deregister hook hook.deregisterHook(); - - #pragma GCC diagnostic pop + +#pragma GCC diagnostic pop #else GTEST_SKIP() << "Assertions are disabled (FW_ASSERT_LEVEL == FW_NO_ASSERT), skipping assert failure test"; #endif @@ -136,27 +135,26 @@ TEST(CAssertTest, CAssert1MacroFailure) { // Test that FW_CASSERT properly triggers assert hook when condition is false TEST(CAssertTest, CAssertMacroFailure) { #if FW_ASSERT_LEVEL != FW_NO_ASSERT - // Disable old-style cast warnings for this test since we're testing C macros - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wold-style-cast" - +// Disable old-style cast warnings for this test since we're testing C macros +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" + // Create and register test assert hook TestAssertHook hook; hook.registerHook(); - + // Test FW_CASSERT with failing condition - FW_CASSERT(1 == 2); // This should trigger the assert hook - + FW_CASSERT(1 == 2); // This should trigger the assert hook + // Verify that assertion was triggered EXPECT_TRUE(hook.asserted()); - EXPECT_EQ(hook.getNumArgs(), 0U); // FW_CASSERT has no arguments - + EXPECT_EQ(hook.getNumArgs(), 0U); // FW_CASSERT has no arguments + // Deregister hook hook.deregisterHook(); - - #pragma GCC diagnostic pop + +#pragma GCC diagnostic pop #else GTEST_SKIP() << "Assertions are disabled (FW_ASSERT_LEVEL == FW_NO_ASSERT), skipping assert failure test"; #endif } - diff --git a/Fw/Types/test/ut/ExternalSerializeBufferTest.cpp b/Fw/Types/test/ut/ExternalSerializeBufferTest.cpp index aa97a286edd..710c8893867 100644 --- a/Fw/Types/test/ut/ExternalSerializeBufferTest.cpp +++ b/Fw/Types/test/ut/ExternalSerializeBufferTest.cpp @@ -1,53 +1,53 @@ -#include #include +#include #include "Fw/Types/Serializable.hpp" namespace ExternalSerializeBufferTest { - using SizeType = Fw::Serializable::SizeType; +using SizeType = Fw::Serializable::SizeType; - constexpr SizeType BUFFER_SIZE = 10; +constexpr SizeType BUFFER_SIZE = 10; - U8 buffer[BUFFER_SIZE]; +U8 buffer[BUFFER_SIZE]; - void serializeOK(Fw::ExternalSerializeBuffer& esb) { +void serializeOK(Fw::ExternalSerializeBuffer& esb) { const SizeType buffCapacity = esb.getBuffCapacity(); ASSERT_EQ(esb.getBuffLength(), 0); for (SizeType i = 0; i < buffCapacity; i++) { - const U8 value = static_cast(i); - const Fw::SerializeStatus status = esb.serialize(value); - ASSERT_EQ(status, Fw::FW_SERIALIZE_OK); + const U8 value = static_cast(i); + const Fw::SerializeStatus status = esb.serialize(value); + ASSERT_EQ(status, Fw::FW_SERIALIZE_OK); } ASSERT_EQ(esb.getBuffLength(), buffCapacity); - } +} - void serializeFail(Fw::ExternalSerializeBuffer& esb) { +void serializeFail(Fw::ExternalSerializeBuffer& esb) { ASSERT_EQ(esb.getBuffLength(), esb.getBuffCapacity()); const Fw::SerializeStatus status = esb.serialize(static_cast(0)); ASSERT_EQ(status, Fw::FW_SERIALIZE_NO_ROOM_LEFT); - } +} - void deserializeOK(Fw::ExternalSerializeBuffer& esb) { +void deserializeOK(Fw::ExternalSerializeBuffer& esb) { const SizeType buffCapacity = esb.getBuffCapacity(); ASSERT_EQ(esb.getBuffLeft(), buffCapacity); for (SizeType i = 0; i < buffCapacity; i++) { - U8 value = 0; - const Fw::SerializeStatus status = esb.deserialize(value); - ASSERT_EQ(status, Fw::FW_SERIALIZE_OK); - ASSERT_EQ(value, static_cast(i)); + U8 value = 0; + const Fw::SerializeStatus status = esb.deserialize(value); + ASSERT_EQ(status, Fw::FW_SERIALIZE_OK); + ASSERT_EQ(value, static_cast(i)); } ASSERT_EQ(esb.getBuffLeft(), 0); - } +} - void deserializeFail(Fw::ExternalSerializeBuffer& esb) { +void deserializeFail(Fw::ExternalSerializeBuffer& esb) { U8 value = 0; ASSERT_EQ(esb.getBuffLeft(), 0); const Fw::SerializeStatus status = esb.deserialize(value); ASSERT_EQ(status, Fw::FW_DESERIALIZE_BUFFER_EMPTY); - } +} - TEST(ExternalSerializeBuffer, Basic) { +TEST(ExternalSerializeBuffer, Basic) { Fw::ExternalSerializeBuffer esb(buffer, BUFFER_SIZE); // Serialization should succeed serializeOK(esb); @@ -57,9 +57,9 @@ namespace ExternalSerializeBufferTest { deserializeOK(esb); // Deserialization should fail deserializeFail(esb); - } +} - TEST(ExternalSerializeBuffer, Clear) { +TEST(ExternalSerializeBuffer, Clear) { Fw::ExternalSerializeBuffer esb(buffer, BUFFER_SIZE); // Serialization should succeed serializeOK(esb); @@ -69,9 +69,9 @@ namespace ExternalSerializeBufferTest { serializeFail(esb); // Deserialization should fail deserializeFail(esb); - } +} - TEST(ExternalSerializeBuffer, SetExtBuffer) { +TEST(ExternalSerializeBuffer, SetExtBuffer) { Fw::ExternalSerializeBuffer esb(buffer, BUFFER_SIZE); // Serialization should succeed serializeOK(esb); @@ -82,9 +82,9 @@ namespace ExternalSerializeBufferTest { serializeOK(esb); // Deserialization should succeed deserializeOK(esb); - } +} - TEST(ExternalSerializeBufferWithMemberCopy, Assign) { +TEST(ExternalSerializeBufferWithMemberCopy, Assign) { Fw::ExternalSerializeBufferWithMemberCopy esb1(buffer, BUFFER_SIZE); Fw::ExternalSerializeBufferWithMemberCopy esb2(buffer, BUFFER_SIZE); // Serialization should succeed @@ -95,6 +95,6 @@ namespace ExternalSerializeBufferTest { deserializeFail(esb1); // Serialization should succeed serializeOK(esb1); - } - } + +} // namespace ExternalSerializeBufferTest diff --git a/Fw/Types/test/ut/SerializeBufferBaseTester.hpp b/Fw/Types/test/ut/SerializeBufferBaseTester.hpp index 0a4518ed5b2..9036a3b0622 100644 --- a/Fw/Types/test/ut/SerializeBufferBaseTester.hpp +++ b/Fw/Types/test/ut/SerializeBufferBaseTester.hpp @@ -7,9 +7,8 @@ #ifndef FW_SerializeBufferBaseTester_HPP #define FW_SerializeBufferBaseTester_HPP -#include #include - +#include namespace Fw { @@ -90,6 +89,6 @@ class SerializeBufferBaseTester { } }; -} +} // namespace Fw -#endif // FW_SerializeBufferBaseTester_HPP +#endif // FW_SerializeBufferBaseTester_HPP diff --git a/Fw/Types/test/ut/SnPrintfFormatTest.cpp b/Fw/Types/test/ut/SnPrintfFormatTest.cpp index dfde248a5c1..a8b5ef318e3 100644 --- a/Fw/Types/test/ut/SnPrintfFormatTest.cpp +++ b/Fw/Types/test/ut/SnPrintfFormatTest.cpp @@ -1,6 +1,6 @@ #include -#include "Fw/Types/format.hpp" #include +#include "Fw/Types/format.hpp" TEST(Nominal, snprintf_format) { char buffer_test[100]; diff --git a/Fw/Types/test/ut/TypesTest.cpp b/Fw/Types/test/ut/TypesTest.cpp index d7aa9f991e8..b8642c8e1d7 100644 --- a/Fw/Types/test/ut/TypesTest.cpp +++ b/Fw/Types/test/ut/TypesTest.cpp @@ -66,7 +66,7 @@ TEST(SerializationTest, Serialization1) { Fw::SerializeBufferBaseTester::assertResetState(buff); Fw::SerializeBufferBaseTester::verifyU8Serialization(buff, u8t1); - ASSERT_EQ(0xAB, ptr[0]); // Verify the actual byte value in the buffer + ASSERT_EQ(0xAB, ptr[0]); // Verify the actual byte value in the buffer Fw::SerializeBufferBaseTester::verifyU8Deserialization(buff, u8t2, u8t1); @@ -85,7 +85,7 @@ TEST(SerializationTest, Serialization1) { // Use the tester to verify I8 serialization Fw::SerializeBufferBaseTester::verifyI8Serialization(buff, i8t1); - ASSERT_EQ(0xFF, ptr[0]); // Verify the actual byte value in the buffer + ASSERT_EQ(0xFF, ptr[0]); // Verify the actual byte value in the buffer // Use the tester to verify I8 deserialization Fw::SerializeBufferBaseTester::verifyI8Deserialization(buff, i8t2, i8t1); @@ -1151,7 +1151,6 @@ TEST(TypesTest, StringTest) { ASSERT_EQ(es, es2); ASSERT_EQ(es2, "ExternalString"); - } TEST(TypesTest, ObjectNameTest) { @@ -1201,7 +1200,7 @@ TEST(TypesTest, FormatSpecifierTest) { str.format("I8: %" PRI_I8, numI8); ASSERT_STREQ(str.toChar(), "I8: -10"); - #if FW_HAS_16_BIT +#if FW_HAS_16_BIT U16 numU16 = 10; str.format("U16: %" PRI_U16, numU16); ASSERT_STREQ(str.toChar(), "U16: 10"); @@ -1209,9 +1208,9 @@ TEST(TypesTest, FormatSpecifierTest) { I16 numI16 = -10; str.format("I16: %" PRI_I16, numI16); ASSERT_STREQ(str.toChar(), "I16: -10"); - #endif +#endif - #if FW_HAS_32_BIT +#if FW_HAS_32_BIT U32 numU32 = 10; str.format("U32: %" PRI_U32, numU32); ASSERT_STREQ(str.toChar(), "U32: 10"); @@ -1219,9 +1218,9 @@ TEST(TypesTest, FormatSpecifierTest) { I32 numI32 = -10; str.format("I32: %" PRI_I32, numI32); ASSERT_STREQ(str.toChar(), "I32: -10"); - #endif +#endif - #if FW_HAS_64_BIT +#if FW_HAS_64_BIT U64 numU64 = 10; str.format("U64: %" PRI_U64, numU64); ASSERT_STREQ(str.toChar(), "U64: 10"); @@ -1229,17 +1228,17 @@ TEST(TypesTest, FormatSpecifierTest) { I64 numI64 = -10; str.format("I64: %" PRI_I64, numI64); ASSERT_STREQ(str.toChar(), "I64: -10"); - #endif +#endif F32 numF32 = 12.3456789; str.format("F32: %" PRI_F64, static_cast(numF32)); ASSERT_STREQ(str.toChar(), "F32: 12.345679"); - #if FW_HAS_F64 +#if FW_HAS_F64 F64 numF64 = 12.3456789; str.format("F64: %" PRI_F64, numF64); ASSERT_STREQ(str.toChar(), "F64: 12.345679"); - #endif +#endif char c = 'A'; str.format("CHAR: %" PRI_CHAR, c); @@ -1293,7 +1292,8 @@ TEST(Nominal, string_copy) { char buffer_out_truth[10]; char* out_truth = ::strncpy(buffer_out_truth, copy_string, static_cast(sizeof(buffer_out_truth))); - char* out_test = Fw::StringUtils::string_copy(buffer_out_test, copy_string, static_cast(sizeof(buffer_out_test))); + char* out_test = + Fw::StringUtils::string_copy(buffer_out_test, copy_string, static_cast(sizeof(buffer_out_test))); ASSERT_EQ(sizeof(buffer_out_truth), sizeof(buffer_out_test)) << "Buffer size mismatch"; @@ -1319,7 +1319,8 @@ TEST(OffNominal, string_copy) { char buffer_out_truth[sizeof(copy_string) - 1]; char* out_truth = ::strncpy(buffer_out_truth, copy_string, static_cast(sizeof(buffer_out_truth))); - char* out_test = Fw::StringUtils::string_copy(buffer_out_test, copy_string, static_cast(sizeof(buffer_out_test))); + char* out_test = + Fw::StringUtils::string_copy(buffer_out_test, copy_string, static_cast(sizeof(buffer_out_test))); ASSERT_EQ(sizeof(buffer_out_truth), sizeof(buffer_out_test)) << "Buffer size mismatch"; @@ -1351,64 +1352,63 @@ TEST(OffNominal, string_len_zero) { TEST(OffNominal, sub_string_no_match) { const char* source_string = "abc123"; const char* sub_string = "456"; - ASSERT_EQ(Fw::StringUtils::substring_find(source_string,6,sub_string,3),-1); + ASSERT_EQ(Fw::StringUtils::substring_find(source_string, 6, sub_string, 3), -1); } TEST(Nominal, sub_string_match_begin) { const char* source_string = "abc123"; const char* sub_string = "abc"; - ASSERT_EQ(Fw::StringUtils::substring_find(source_string,6,sub_string,3),0); + ASSERT_EQ(Fw::StringUtils::substring_find(source_string, 6, sub_string, 3), 0); } TEST(Nominal, sub_string_match_end) { const char* source_string = "abc123"; const char* sub_string = "123"; - ASSERT_EQ(Fw::StringUtils::substring_find(source_string,6,sub_string,3),3); + ASSERT_EQ(Fw::StringUtils::substring_find(source_string, 6, sub_string, 3), 3); } TEST(Nominal, sub_string_match_partway_1) { const char* source_string = "abc123"; const char* sub_string = "c12"; - ASSERT_EQ(Fw::StringUtils::substring_find(source_string,6,sub_string,3),2); + ASSERT_EQ(Fw::StringUtils::substring_find(source_string, 6, sub_string, 3), 2); } TEST(OffNominal, sub_string_partial_match_begin) { const char* source_string = "abc123"; const char* sub_string = "ab1"; - ASSERT_EQ(Fw::StringUtils::substring_find(source_string,6,sub_string,3),-1); + ASSERT_EQ(Fw::StringUtils::substring_find(source_string, 6, sub_string, 3), -1); } TEST(OffNominal, sub_string_partial_match_middle) { const char* source_string = "abc123"; const char* sub_string = "c13"; - ASSERT_EQ(Fw::StringUtils::substring_find(source_string,6,sub_string,3),-1); + ASSERT_EQ(Fw::StringUtils::substring_find(source_string, 6, sub_string, 3), -1); } TEST(OffNominal, sub_string_partial_match_end) { const char* source_string = "abc123"; const char* sub_string = "234"; - ASSERT_EQ(Fw::StringUtils::substring_find(source_string,6,sub_string,3),-1); + ASSERT_EQ(Fw::StringUtils::substring_find(source_string, 6, sub_string, 3), -1); } TEST(Nominal, sub_string_exact_match) { const char* source_string = "abc123"; const char* sub_string = "abc123"; - ASSERT_EQ(Fw::StringUtils::substring_find(source_string,6,sub_string,3),0); + ASSERT_EQ(Fw::StringUtils::substring_find(source_string, 6, sub_string, 3), 0); } TEST(OffNominal, sub_string_source_zero_size) { const char* source_string = ""; const char* sub_string = "234"; - ASSERT_EQ(Fw::StringUtils::substring_find(source_string,0,sub_string,3),-1); + ASSERT_EQ(Fw::StringUtils::substring_find(source_string, 0, sub_string, 3), -1); } TEST(OffNominal, sub_string_substring_zero_size) { const char* source_string = "abc123"; const char* sub_string = ""; - ASSERT_EQ(Fw::StringUtils::substring_find(source_string,6,sub_string,0),0); + ASSERT_EQ(Fw::StringUtils::substring_find(source_string, 6, sub_string, 0), 0); } - int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); From f48cf22aeb6aef280acfde28033bf0286b8f388d Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 4 Aug 2025 10:54:53 -0700 Subject: [PATCH 2/3] Fix include of HPP file instead of H in extern C --- Fw/FPrimeBasicTypes.h | 2 +- Fw/Types/BasicTypes.hpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Fw/FPrimeBasicTypes.h b/Fw/FPrimeBasicTypes.h index b5d4cdb3c86..dc01a825ec4 100644 --- a/Fw/FPrimeBasicTypes.h +++ b/Fw/FPrimeBasicTypes.h @@ -21,9 +21,9 @@ #ifdef __cplusplus extern "C" { #endif +#include #include #include -#include // ---------------------------------------------------------------------- // Type aliases defined by FPP diff --git a/Fw/Types/BasicTypes.hpp b/Fw/Types/BasicTypes.hpp index c85f1bc8ddb..111c3423517 100644 --- a/Fw/Types/BasicTypes.hpp +++ b/Fw/Types/BasicTypes.hpp @@ -8,15 +8,16 @@ * ALL RIGHTS RESERVED. United States Government Sponsorship * acknowledged. */ + +#ifndef FW_BASIC_TYPES_HPP +#define FW_BASIC_TYPES_HPP + #include // Use C linkage for the basic items extern "C" { #include "Fw/Types/BasicTypes.h" } -#ifndef FW_BASIC_TYPES_HPP -#define FW_BASIC_TYPES_HPP - // IEEE compliance checks must occur in C++ code #if !defined(SKIP_FLOAT_IEEE_754_COMPLIANCE) || !SKIP_FLOAT_IEEE_754_COMPLIANCE static_assert((std::numeric_limits::is_iec559 == true) && (std::numeric_limits::radix == 2) && From f99ab0bbbdb576dd625c32286a118c416dc3865f Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 4 Aug 2025 12:23:18 -0700 Subject: [PATCH 3/3] Fix format strings --- Fw/Obj/SimpleObjRegistry.cpp | 10 +++++----- Fw/Types/Assert.cpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Fw/Obj/SimpleObjRegistry.cpp b/Fw/Obj/SimpleObjRegistry.cpp index 4d1f5b986f7..970d72f9129 100644 --- a/Fw/Obj/SimpleObjRegistry.cpp +++ b/Fw/Obj/SimpleObjRegistry.cpp @@ -28,13 +28,13 @@ void SimpleObjRegistry::dump() { #if FW_OBJECT_TO_STRING == 1 char objDump[FW_OBJ_SIMPLE_REG_BUFF_SIZE]; this->m_objPtrArray[obj]->toString(objDump, sizeof(objDump)); - Fw::Logger::log("Entry: %d Ptr: %p Str: %s\n", obj, this->m_objPtrArray[obj], objDump); + Fw::Logger::log("Entry: %" PRI_FwSizeType " Ptr: %p Str: %s\n", obj, this->m_objPtrArray[obj], objDump); #else - Fw::Logger::log("Entry: %d Ptr: %p Name: %s\n", obj, this->m_objPtrArray[obj], + Fw::Logger::log("Entry: %" PRI_FwSizeType " Ptr: %p Name: %s\n", obj, this->m_objPtrArray[obj], this->m_objPtrArray[obj]->getObjName()); #endif // FW_OBJECT_TO_STRING #else - Fw::Logger::log("Entry: %d Ptr: %p\n", obj, this->m_objPtrArray[obj]); + Fw::Logger::log("Entry: %" PRI_FwSizeType " Ptr: %p\n", obj, this->m_objPtrArray[obj]); #endif } } @@ -46,9 +46,9 @@ void SimpleObjRegistry::dump(const char* objName) { if (strncmp(objName, this->m_objPtrArray[obj]->getObjName(), sizeof(objDump)) == 0) { #if FW_OBJECT_TO_STRING == 1 this->m_objPtrArray[obj]->toString(objDump, sizeof(objDump)); - Fw::Logger::log("Entry: %d Ptr: %p Str: %s\n", obj, this->m_objPtrArray[obj], objDump); + Fw::Logger::log("Entry: %" PRI_FwSizeType " Ptr: %p Str: %s\n", obj, this->m_objPtrArray[obj], objDump); #else - Fw::Logger::log("Entry: %d Ptr: %p Name: %s\n", obj, this->m_objPtrArray[obj], + Fw::Logger::log("Entry: %" PRI_FwSizeType " Ptr: %p Name: %s\n", obj, this->m_objPtrArray[obj], this->m_objPtrArray[obj]->getObjName()); #endif } diff --git a/Fw/Types/Assert.cpp b/Fw/Types/Assert.cpp index 81729483bb3..284809561b0 100644 --- a/Fw/Types/Assert.cpp +++ b/Fw/Types/Assert.cpp @@ -6,9 +6,9 @@ #include #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT -#define fileIdFs "Assert: 0x%08" PRIx32 ":%u" +#define fileIdFs "Assert: 0x%08" PRIx32 ":%" PRI_FwSizeType "" #else -#define fileIdFs "Assert: \"%s:%u\"" +#define fileIdFs "Assert: \"%s:%" PRI_FwSizeType "\"" #endif namespace Fw {