From 152a21f990b8957f2ce0ef0997850bc5e339ab91 Mon Sep 17 00:00:00 2001 From: "Robert L. Bocchino Jr" Date: Fri, 26 Jan 2024 14:47:21 -0800 Subject: [PATCH] Update DpContainer --- .../test/fprime/Fw/Dp/DpContainer.cpp | 91 +++++++++++++------ .../test/fprime/Fw/Dp/DpContainer.hpp | 56 ++++++------ 2 files changed, 89 insertions(+), 58 deletions(-) diff --git a/compiler/tools/fpp-to-cpp/test/fprime/Fw/Dp/DpContainer.cpp b/compiler/tools/fpp-to-cpp/test/fprime/Fw/Dp/DpContainer.cpp index 2b4baa53f..44ac252a7 100644 --- a/compiler/tools/fpp-to-cpp/test/fprime/Fw/Dp/DpContainer.cpp +++ b/compiler/tools/fpp-to-cpp/test/fprime/Fw/Dp/DpContainer.cpp @@ -17,7 +17,7 @@ namespace Fw { // ---------------------------------------------------------------------- DpContainer::DpContainer(FwDpIdType id, const Fw::Buffer& buffer) - : id(id), priority(0), procTypes(0), dpState(), dataSize(0), buffer(), dataBuffer() { + : m_id(id), m_priority(0), m_timeTag(), m_procTypes(0), m_dpState(), m_dataSize(0), m_buffer(), m_dataBuffer() { // Initialize the user data field this->initUserDataField(); // Set the packet buffer @@ -25,7 +25,8 @@ DpContainer::DpContainer(FwDpIdType id, const Fw::Buffer& buffer) this->setBuffer(buffer); } -DpContainer::DpContainer() : id(0), priority(0), procTypes(0), dataSize(0), buffer(), dataBuffer() { +DpContainer::DpContainer() + : m_id(0), m_priority(0), m_timeTag(), m_procTypes(0), m_dataSize(0), m_buffer(), m_dataBuffer() { // Initialize the user data field this->initUserDataField(); } @@ -34,49 +35,79 @@ DpContainer::DpContainer() : id(0), priority(0), procTypes(0), dataSize(0), buff // Public member functions // ---------------------------------------------------------------------- -Fw::SerializeStatus DpContainer::moveSerToOffset(FwSizeType offset //!< The offset -) { - Fw::SerializeBufferBase& serializeRepr = this->buffer.getSerializeRepr(); - return serializeRepr.moveSerToOffset(offset); +void DpContainer::deserializeHeader() { + FW_ASSERT(this->m_buffer.isValid()); + Fw::SerializeBufferBase& serializeRepr = this->m_buffer.getSerializeRepr(); + // Reset deserialization + serializeRepr.setBuffLen(this->m_buffer.getSize()); + Fw::SerializeStatus status = serializeRepr.moveDeserToOffset(Header::ID_OFFSET); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); + // Deserialize the container id + status = serializeRepr.deserialize(this->m_id); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); + // Deserialize the priority + status = serializeRepr.deserialize(this->m_priority); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); + // Deserialize the time tag + status = serializeRepr.deserialize(this->m_timeTag); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); + // Deserialize the processing types + status = serializeRepr.deserialize(this->m_procTypes); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); + // Deserialize the user data + const bool omitLength = true; + const FwSizeType requestedSize = sizeof this->m_userData; + FwSizeType receivedSize = requestedSize; + status = serializeRepr.deserialize(this->m_userData, receivedSize, omitLength); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); + FW_ASSERT(receivedSize == requestedSize, static_cast(requestedSize), + static_cast(receivedSize)); + // Deserialize the data product state + status = serializeRepr.deserialize(this->m_dpState); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); + // Deserialize the data size + status = serializeRepr.deserialize(this->m_dataSize); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); } void DpContainer::serializeHeader() { - Fw::SerializeBufferBase& serializeRepr = this->buffer.getSerializeRepr(); + FW_ASSERT(this->m_buffer.isValid()); + Fw::SerializeBufferBase& serializeRepr = this->m_buffer.getSerializeRepr(); // Reset serialization serializeRepr.resetSer(); // Serialize the packet type Fw::SerializeStatus status = serializeRepr.serialize(static_cast(Fw::ComPacket::FW_PACKET_DP)); - FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); // Serialize the container id - status = serializeRepr.serialize(this->id); - FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); + status = serializeRepr.serialize(this->m_id); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); // Serialize the priority - status = serializeRepr.serialize(this->priority); - FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); + status = serializeRepr.serialize(this->m_priority); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); // Serialize the time tag - status = serializeRepr.serialize(this->timeTag); - FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); + status = serializeRepr.serialize(this->m_timeTag); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); // Serialize the processing types - status = serializeRepr.serialize(this->procTypes); - FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); + status = serializeRepr.serialize(this->m_procTypes); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); // Serialize the user data const bool omitLength = true; - status = serializeRepr.serialize(this->userData, sizeof userData, omitLength); - FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); + status = serializeRepr.serialize(this->m_userData, sizeof this->m_userData, omitLength); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); // Serialize the data product state - status = serializeRepr.serialize(this->dpState); - FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); + status = serializeRepr.serialize(this->m_dpState); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); // Serialize the data size - status = serializeRepr.serialize(this->dataSize); - FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); + status = serializeRepr.serialize(this->m_dataSize); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); // Update the header hash this->updateHeaderHash(); } void DpContainer::setBuffer(const Buffer& buffer) { // Set the buffer - this->buffer = buffer; + this->m_buffer = buffer; // Check that the buffer is large enough to hold a data product packet FW_ASSERT(buffer.getSize() >= MIN_PACKET_SIZE, buffer.getSize(), MIN_PACKET_SIZE); // Initialize the data buffer @@ -85,24 +116,24 @@ void DpContainer::setBuffer(const Buffer& buffer) { // Check that data buffer is in bounds for packet buffer FW_ASSERT(DATA_OFFSET + dataCapacity <= buffer.getSize()); U8* const dataAddr = &buffAddr[DATA_OFFSET]; - this->dataBuffer.setExtBuffer(dataAddr, dataCapacity); + this->m_dataBuffer.setExtBuffer(dataAddr, dataCapacity); } void DpContainer::updateHeaderHash() { Utils::HashBuffer hashBuffer; - U8* const buffAddr = this->buffer.getData(); + U8* const buffAddr = this->m_buffer.getData(); Utils::Hash::hash(buffAddr, Header::SIZE, hashBuffer); ExternalSerializeBuffer serialBuffer(&buffAddr[HEADER_HASH_OFFSET], HASH_DIGEST_LENGTH); const Fw::SerializeStatus status = hashBuffer.copyRaw(serialBuffer, HASH_DIGEST_LENGTH); - FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); } void DpContainer::updateDataHash() { Utils::HashBuffer hashBuffer; - U8* const buffAddrBase = this->buffer.getData(); + U8* const buffAddrBase = this->m_buffer.getData(); const U8* const dataAddr = &buffAddrBase[DATA_OFFSET]; const FwSizeType dataSize = this->getDataSize(); - const FwSizeType bufferSize = buffer.getSize(); + const FwSizeType bufferSize = this->m_buffer.getSize(); FW_ASSERT(DATA_OFFSET + dataSize <= bufferSize, DATA_OFFSET + dataSize, bufferSize); Utils::Hash::hash(dataAddr, dataSize, hashBuffer); const FwSizeType dataHashOffset = this->getDataHashOffset(); @@ -110,7 +141,7 @@ void DpContainer::updateDataHash() { FW_ASSERT(dataHashOffset + HASH_DIGEST_LENGTH <= bufferSize, dataHashOffset + HASH_DIGEST_LENGTH, bufferSize); ExternalSerializeBuffer serialBuffer(dataHashAddr, HASH_DIGEST_LENGTH); const Fw::SerializeStatus status = hashBuffer.copyRaw(serialBuffer, HASH_DIGEST_LENGTH); - FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); + FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast(status)); } // ---------------------------------------------------------------------- @@ -118,7 +149,7 @@ void DpContainer::updateDataHash() { // ---------------------------------------------------------------------- void DpContainer::initUserDataField() { - (void)::memset(this->userData, 0, sizeof this->userData); + (void)::memset(this->m_userData, 0, sizeof this->m_userData); } } // namespace Fw diff --git a/compiler/tools/fpp-to-cpp/test/fprime/Fw/Dp/DpContainer.hpp b/compiler/tools/fpp-to-cpp/test/fprime/Fw/Dp/DpContainer.hpp index 7a5a8f4b8..2b5352be0 100644 --- a/compiler/tools/fpp-to-cpp/test/fprime/Fw/Dp/DpContainer.hpp +++ b/compiler/tools/fpp-to-cpp/test/fprime/Fw/Dp/DpContainer.hpp @@ -76,73 +76,73 @@ class DpContainer { //! Get the container id //! \return The id - FwDpIdType getId() const { return this->id; } + FwDpIdType getId() const { return this->m_id; } //! Get the data size //! \return The data size - FwSizeType getDataSize() const { return this->dataSize; } + FwSizeType getDataSize() const { return this->m_dataSize; } //! Get the packet buffer //! \return The buffer - Fw::Buffer getBuffer() const { return this->buffer; } + Fw::Buffer getBuffer() const { return this->m_buffer; } //! Get the packet size corresponding to the data size - FwSizeType getPacketSize() const { return getPacketSizeForDataSize(this->dataSize); } + FwSizeType getPacketSize() const { return getPacketSizeForDataSize(this->m_dataSize); } //! Get the priority //! \return The priority - FwDpPriorityType getPriority() const { return this->priority; } + FwDpPriorityType getPriority() const { return this->m_priority; } //! Get the time tag //! \return The time tag - Fw::Time getTimeTag() const { return this->timeTag; } + Fw::Time getTimeTag() const { return this->m_timeTag; } //! Get the processing types //! \return The processing types - DpCfg::ProcType::SerialType getProcTypes() const { return this->procTypes; } + DpCfg::ProcType::SerialType getProcTypes() const { return this->m_procTypes; } - //! Move the packet serialization to the specified offset - //! \return The serialize status - Fw::SerializeStatus moveSerToOffset(FwSizeType offset //!< The offset - ); + //! Deserialize the header from the packet buffer + //! Buffer must be valid and large enough to hold a DP container packet + void deserializeHeader(); //! Serialize the header into the packet buffer and update the header hash + //! Buffer must be valid and large enough to hold a DP container packet void serializeHeader(); //! Set the id void setId(FwDpIdType id //!< The id ) { - this->id = id; + this->m_id = id; } //! Set the priority void setPriority(FwDpPriorityType priority //!< The priority ) { - this->priority = priority; + this->m_priority = priority; } //! Set the time tag void setTimeTag(Fw::Time timeTag //!< The time tag ) { - this->timeTag = timeTag; + this->m_timeTag = timeTag; } //! Set the processing types bit mask void setProcTypes(DpCfg::ProcType::SerialType procTypes //!< The processing types ) { - this->procTypes = procTypes; + this->m_procTypes = procTypes; } //! Set the data product state void setDpState(DpState dpState //!< The data product state ) { - this->dpState = dpState; + this->m_dpState = dpState; } //! Set the data size - void setDataSize(FwSizeType dataSize //!< The data size + void setDataSize(FwSizeType dataSize //!< The data size ) { - this->dataSize = dataSize; + this->m_dataSize = dataSize; } //! Set the packet buffer @@ -155,7 +155,7 @@ class DpContainer { //! Get the data hash offset FwSizeType getDataHashOffset() const { // Data hash goes after the header, the header hash, and the data - return Header::SIZE + HASH_DIGEST_LENGTH + this->dataSize; + return Header::SIZE + HASH_DIGEST_LENGTH + this->m_dataSize; } //! Update the data hash @@ -186,7 +186,7 @@ class DpContainer { // ---------------------------------------------------------------------- //! The user data - Header::UserData userData; + Header::UserData m_userData; PROTECTED: // ---------------------------------------------------------------------- @@ -195,28 +195,28 @@ class DpContainer { //! The container id //! This is a system-global id (component-local id + component base id) - FwDpIdType id; + FwDpIdType m_id; //! The priority - FwDpPriorityType priority; + FwDpPriorityType m_priority; //! The time tag - Time timeTag; + Time m_timeTag; //! The processing types - DpCfg::ProcType::SerialType procTypes; + DpCfg::ProcType::SerialType m_procTypes; //! The data product state - DpState dpState; + DpState m_dpState; //! The data size - FwSizeType dataSize; + FwSizeType m_dataSize; //! The packet buffer - Buffer buffer; + Buffer m_buffer; //! The data buffer - Fw::ExternalSerializeBuffer dataBuffer; + Fw::ExternalSerializeBuffer m_dataBuffer; }; } // end namespace Fw