Skip to content

Commit

Permalink
Update DpContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
bocchino committed Jan 26, 2024
1 parent a87e232 commit 152a21f
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 58 deletions.
91 changes: 61 additions & 30 deletions compiler/tools/fpp-to-cpp/test/fprime/Fw/Dp/DpContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ 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
// This action also updates the data 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();
}
Expand All @@ -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<FwAssertArgType>(status));
// Deserialize the container id
status = serializeRepr.deserialize(this->m_id);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));
// Deserialize the priority
status = serializeRepr.deserialize(this->m_priority);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));
// Deserialize the time tag
status = serializeRepr.deserialize(this->m_timeTag);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));
// Deserialize the processing types
status = serializeRepr.deserialize(this->m_procTypes);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(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<FwAssertArgType>(status));
FW_ASSERT(receivedSize == requestedSize, static_cast<FwAssertArgType>(requestedSize),
static_cast<FwAssertArgType>(receivedSize));
// Deserialize the data product state
status = serializeRepr.deserialize(this->m_dpState);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));
// Deserialize the data size
status = serializeRepr.deserialize(this->m_dataSize);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(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<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_DP));
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(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<FwAssertArgType>(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<FwAssertArgType>(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<FwAssertArgType>(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<FwAssertArgType>(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<FwAssertArgType>(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<FwAssertArgType>(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<FwAssertArgType>(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
Expand All @@ -85,40 +116,40 @@ 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<FwAssertArgType>(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();
U8* const dataHashAddr = &buffAddrBase[dataHashOffset];
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<FwAssertArgType>(status));
}

// ----------------------------------------------------------------------
// Private member functions
// ----------------------------------------------------------------------

void DpContainer::initUserDataField() {
(void)::memset(this->userData, 0, sizeof this->userData);
(void)::memset(this->m_userData, 0, sizeof this->m_userData);
}

} // namespace Fw
56 changes: 28 additions & 28 deletions compiler/tools/fpp-to-cpp/test/fprime/Fw/Dp/DpContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -186,7 +186,7 @@ class DpContainer {
// ----------------------------------------------------------------------

//! The user data
Header::UserData userData;
Header::UserData m_userData;

PROTECTED:
// ----------------------------------------------------------------------
Expand All @@ -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
Expand Down

0 comments on commit 152a21f

Please sign in to comment.