Skip to content

Commit

Permalink
Merge pull request #372 from fprime-community/dp-code-gen
Browse files Browse the repository at this point in the history
Revise code generation for data products
  • Loading branch information
bocchino authored Jan 11, 2024
2 parents 4554cdc + 3ab3e57 commit 4174ca5
Show file tree
Hide file tree
Showing 100 changed files with 921 additions and 808 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ case class ComponentDataProducts (
|//! Get a buffer and use it to initialize container $name
|//! \\return The status of the buffer request
|Fw::Success::T dpGet_$name(
| FwSizeType size, //!< The buffer size (input)
| FwSizeType dataSize, //!< The data size (input)
| DpContainer& container //!< The container (output)
|) {
| return this->dpGet(ContainerId::$name, size, container);
| return this->dpGet(ContainerId::$name, dataSize, container);
|}"""
)
)
Expand Down Expand Up @@ -88,8 +88,9 @@ case class ComponentDataProducts (
|}
|container.setTimeTag(timeTag);
|// Serialize the header into the packet
|Fw::SerializeStatus status = container.serializeHeader();
|FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
|container.serializeHeader();
|// Update the data hash
|container.updateDataHash();
|// Update the size of the buffer according to the data size
|const FwSizeType packetSize = container.getPacketSize();
|Fw::Buffer buffer = container.getBuffer();
Expand Down Expand Up @@ -126,8 +127,8 @@ case class ComponentDataProducts (
),
CppDoc.Function.Param(
CppDoc.Type("FwSizeType"),
"size",
Some("The buffer size (input)")
"dataSize",
Some("The data size (input)")
),
CppDoc.Function.Param(
CppDoc.Type("DpContainer&"),
Expand All @@ -140,6 +141,7 @@ case class ComponentDataProducts (
val invokeProductGet = outputPortInvokerName(productGetPort.get)
lines(s"""|const FwDpIdType baseId = this->getIdBase();
|const FwDpIdType globalId = baseId + containerId;
|const FwSizeType size = DpContainer::getPacketSizeForDataSize(dataSize);
|Fw::Buffer buffer;
|const Fw::Success::T status = this->$invokeProductGet(0, globalId, size, buffer);
|if (status == Fw::Success::SUCCESS) {
Expand All @@ -161,15 +163,16 @@ case class ComponentDataProducts (
),
CppDoc.Function.Param(
CppDoc.Type("FwSizeType"),
"size",
Some("The buffer size")
"dataSize",
Some("The data size")
)
),
CppDoc.Type("void"),
{
val invokeProductRequest = outputPortInvokerName(productRequestPort.get)
lines(
s"""|const FwDpIdType globalId = this->getIdBase() + containerId;
|const FwSizeType size = DpContainer::getPacketSizeForDataSize(dataSize);
|this->$invokeProductRequest(0, globalId, size);"""
)
}
Expand Down Expand Up @@ -375,16 +378,15 @@ case class ComponentDataProducts (
),
CppDoc.Type("Fw::SerializeStatus"),
lines(
s"""|Fw::SerializeBufferBase& serializeRepr = this->buffer.getSerializeRepr();
|const FwSizeType sizeDelta =
s"""|const FwSizeType sizeDelta =
| sizeof(FwDpIdType) +
| $typeSize;
|Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
|if (serializeRepr.getBuffLength() + sizeDelta <= serializeRepr.getBuffCapacity()) {
|if (this->dataBuffer.getBuffLength() + sizeDelta <= this->dataBuffer.getBuffCapacity()) {
| const FwDpIdType id = this->baseId + RecordId::$name;
| status = serializeRepr.serialize(id);
| status = this->dataBuffer.serialize(id);
| FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
| status = serializeRepr.serialize(elt);
| status = this->dataBuffer.serialize(elt);
| FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
| this->dataSize += sizeDelta;
|}
Expand Down Expand Up @@ -423,27 +425,26 @@ case class ComponentDataProducts (
// Optimize the U8 case
case Type.U8 =>
"""| const bool omitSerializedLength = true;
| status = serializeRepr.serialize(array, size, omitSerializedLength);
| status = this->dataBuffer.serialize(array, size, omitSerializedLength);
| FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);"""
case _ =>
"""| for (FwSizeType i = 0; i < size; i++) {
| status = serializeRepr.serialize(array[i]);
| status = this->dataBuffer.serialize(array[i]);
| FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
| }"""
}).stripMargin
lines(
s"""|FW_ASSERT(array != nullptr);
|Fw::SerializeBufferBase& serializeRepr = this->buffer.getSerializeRepr();
|const FwSizeType sizeDelta =
| sizeof(FwDpIdType) +
| sizeof(FwSizeType) +
| size * $eltSize;
|Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
|if (serializeRepr.getBuffLength() + sizeDelta <= serializeRepr.getBuffCapacity()) {
|if (this->dataBuffer.getBuffLength() + sizeDelta <= this->dataBuffer.getBuffCapacity()) {
| const FwDpIdType id = this->baseId + RecordId::$name;
| status = serializeRepr.serialize(id);
| status = this->dataBuffer.serialize(id);
| FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
| status = serializeRepr.serialize(size);
| status = this->dataBuffer.serialize(size);
| FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
|$serializeElts
| this->dataSize += sizeDelta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ case class ComponentGTestBaseWriter(
"""#define ASSERT_PRODUCT_SEND_SIZE(size) \
| this->assertProductSend_size(__FILE__, __LINE__, size)
|
|#define ASSERT_PRODUCT_SEND(index, id, priority, timeTag, procType, userData, dataSize, buffer) \
| assertProductSend(__FILE__, __LINE__, index, id, priority, timeTag, procType, userData, dataSize, buffer)
|#define ASSERT_PRODUCT_SEND(index, id, priority, timeTag, procTypes, userData, dpState, dataSize, buffer) \
| assertProductSend(__FILE__, __LINE__, index, id, priority, timeTag, procTypes, userData, dpState, dataSize, buffer)
|"""
)
)
Expand Down Expand Up @@ -829,15 +829,20 @@ case class ComponentGTestBaseWriter(
Some("The expected time tag (input)")
),
CppDoc.Function.Param(
CppDoc.Type("Fw::DpCfg::ProcType"),
"procType",
Some("The expected processing type (input)")
CppDoc.Type("Fw::DpCfg::ProcType::SerialType"),
"procTypes",
Some("The expected processing types (input)")
),
CppDoc.Function.Param(
CppDoc.Type("const Fw::DpContainer::Header::UserData&"),
"userData",
Some("The expected user data (input)")
),
CppDoc.Function.Param(
CppDoc.Type("Fw::DpState"),
"dpState",
Some("The expected data product state (input)")
),
CppDoc.Function.Param(
CppDoc.Type("FwSizeType"),
"dataSize",
Expand Down Expand Up @@ -878,8 +883,9 @@ case class ComponentGTestBaseWriter(
| id,
| priority,
| timeTag,
| procType,
| procTypes,
| userData,
| dpState,
| dataSize
|);
|"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ case class ComponentTesterBaseWriter(
getPortFunctionParams(productGetPort.get).take(2),
CppDoc.Type("void"),
lines(
"""|DpGet e = { id, size };
"""|DpGet e = { id, dataSize };
|this->productGetHistory->push_back(e);"""
)
)
Expand All @@ -496,7 +496,7 @@ case class ComponentTesterBaseWriter(
CppDoc.Type("Fw::Success::T"),
lines(
"""|(void) buffer;
|this->pushProductGetEntry(id, size);
|this->pushProductGetEntry(id, dataSize);
|return Fw::Success::FAILURE;
|"""
),
Expand All @@ -508,7 +508,7 @@ case class ComponentTesterBaseWriter(
getPortFunctionParams(productRequestPort.get),
CppDoc.Type("void"),
lines(
"""|DpRequest e = { id, size };
"""|DpRequest e = { id, dataSize };
|this->productRequestHistory->push_back(e);"""
)
)
Expand All @@ -522,7 +522,7 @@ case class ComponentTesterBaseWriter(
"productRequest_handler",
getPortFunctionParams(productRequestPort.get),
CppDoc.Type("void"),
lines("this->pushProductRequestEntry(id, size);"),
lines("this->pushProductRequestEntry(id, dataSize);"),
CppDoc.Function.Virtual
)
lazy val sendProductResponse = functionClassMember(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void ActiveAsyncProductPortsOnlyComponentBase ::
productRequestOut_out(
NATIVE_INT_TYPE portNum,
FwDpIdType id,
FwSizeType size
FwSizeType dataSize
)
{
FW_ASSERT(
Expand All @@ -415,7 +415,7 @@ void ActiveAsyncProductPortsOnlyComponentBase ::
);
this->m_productRequestOut_OutputPort[portNum].invoke(
id,
size
dataSize
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class ActiveAsyncProductPortsOnlyComponentBase :
void productRequestOut_out(
NATIVE_INT_TYPE portNum, //!< The port number
FwDpIdType id, //!< The container ID
FwSizeType size //!< The size of the requested buffer
FwSizeType dataSize //!< The data size of the requested buffer
);

//! Invoke output port productSendOut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,19 @@ Fw::SerializeStatus ActiveAsyncProductsComponentBase::DpContainer ::
)
{
FW_ASSERT(array != nullptr);
Fw::SerializeBufferBase& serializeRepr = this->buffer.getSerializeRepr();
const FwSizeType sizeDelta =
sizeof(FwDpIdType) +
sizeof(FwSizeType) +
size * ActiveAsyncProducts_Data::SERIALIZED_SIZE;
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
if (serializeRepr.getBuffLength() + sizeDelta <= serializeRepr.getBuffCapacity()) {
if (this->dataBuffer.getBuffLength() + sizeDelta <= this->dataBuffer.getBuffCapacity()) {
const FwDpIdType id = this->baseId + RecordId::DataArrayRecord;
status = serializeRepr.serialize(id);
status = this->dataBuffer.serialize(id);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
status = serializeRepr.serialize(size);
status = this->dataBuffer.serialize(size);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
for (FwSizeType i = 0; i < size; i++) {
status = serializeRepr.serialize(array[i]);
status = this->dataBuffer.serialize(array[i]);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
}
this->dataSize += sizeDelta;
Expand All @@ -128,16 +127,15 @@ Fw::SerializeStatus ActiveAsyncProductsComponentBase::DpContainer ::
Fw::SerializeStatus ActiveAsyncProductsComponentBase::DpContainer ::
serializeRecord_DataRecord(const ActiveAsyncProducts_Data& elt)
{
Fw::SerializeBufferBase& serializeRepr = this->buffer.getSerializeRepr();
const FwSizeType sizeDelta =
sizeof(FwDpIdType) +
ActiveAsyncProducts_Data::SERIALIZED_SIZE;
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
if (serializeRepr.getBuffLength() + sizeDelta <= serializeRepr.getBuffCapacity()) {
if (this->dataBuffer.getBuffLength() + sizeDelta <= this->dataBuffer.getBuffCapacity()) {
const FwDpIdType id = this->baseId + RecordId::DataRecord;
status = serializeRepr.serialize(id);
status = this->dataBuffer.serialize(id);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
status = serializeRepr.serialize(elt);
status = this->dataBuffer.serialize(elt);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
this->dataSize += sizeDelta;
}
Expand All @@ -154,20 +152,19 @@ Fw::SerializeStatus ActiveAsyncProductsComponentBase::DpContainer ::
)
{
FW_ASSERT(array != nullptr);
Fw::SerializeBufferBase& serializeRepr = this->buffer.getSerializeRepr();
const FwSizeType sizeDelta =
sizeof(FwDpIdType) +
sizeof(FwSizeType) +
size * sizeof(U32);
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
if (serializeRepr.getBuffLength() + sizeDelta <= serializeRepr.getBuffCapacity()) {
if (this->dataBuffer.getBuffLength() + sizeDelta <= this->dataBuffer.getBuffCapacity()) {
const FwDpIdType id = this->baseId + RecordId::U32ArrayRecord;
status = serializeRepr.serialize(id);
status = this->dataBuffer.serialize(id);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
status = serializeRepr.serialize(size);
status = this->dataBuffer.serialize(size);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
for (FwSizeType i = 0; i < size; i++) {
status = serializeRepr.serialize(array[i]);
status = this->dataBuffer.serialize(array[i]);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
}
this->dataSize += sizeDelta;
Expand All @@ -181,16 +178,15 @@ Fw::SerializeStatus ActiveAsyncProductsComponentBase::DpContainer ::
Fw::SerializeStatus ActiveAsyncProductsComponentBase::DpContainer ::
serializeRecord_U32Record(U32 elt)
{
Fw::SerializeBufferBase& serializeRepr = this->buffer.getSerializeRepr();
const FwSizeType sizeDelta =
sizeof(FwDpIdType) +
sizeof(U32);
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
if (serializeRepr.getBuffLength() + sizeDelta <= serializeRepr.getBuffCapacity()) {
if (this->dataBuffer.getBuffLength() + sizeDelta <= this->dataBuffer.getBuffCapacity()) {
const FwDpIdType id = this->baseId + RecordId::U32Record;
status = serializeRepr.serialize(id);
status = this->dataBuffer.serialize(id);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
status = serializeRepr.serialize(elt);
status = this->dataBuffer.serialize(elt);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
this->dataSize += sizeDelta;
}
Expand All @@ -207,20 +203,19 @@ Fw::SerializeStatus ActiveAsyncProductsComponentBase::DpContainer ::
)
{
FW_ASSERT(array != nullptr);
Fw::SerializeBufferBase& serializeRepr = this->buffer.getSerializeRepr();
const FwSizeType sizeDelta =
sizeof(FwDpIdType) +
sizeof(FwSizeType) +
size * sizeof(U8);
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
if (serializeRepr.getBuffLength() + sizeDelta <= serializeRepr.getBuffCapacity()) {
if (this->dataBuffer.getBuffLength() + sizeDelta <= this->dataBuffer.getBuffCapacity()) {
const FwDpIdType id = this->baseId + RecordId::U8ArrayRecord;
status = serializeRepr.serialize(id);
status = this->dataBuffer.serialize(id);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
status = serializeRepr.serialize(size);
status = this->dataBuffer.serialize(size);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
const bool omitSerializedLength = true;
status = serializeRepr.serialize(array, size, omitSerializedLength);
status = this->dataBuffer.serialize(array, size, omitSerializedLength);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
this->dataSize += sizeDelta;
}
Expand Down Expand Up @@ -2744,7 +2739,7 @@ void ActiveAsyncProductsComponentBase ::
productRequestOut_out(
NATIVE_INT_TYPE portNum,
FwDpIdType id,
FwSizeType size
FwSizeType dataSize
)
{
FW_ASSERT(
Expand All @@ -2753,7 +2748,7 @@ void ActiveAsyncProductsComponentBase ::
);
this->m_productRequestOut_OutputPort[portNum].invoke(
id,
size
dataSize
);
}

Expand Down Expand Up @@ -2869,8 +2864,9 @@ void ActiveAsyncProductsComponentBase ::
}
container.setTimeTag(timeTag);
// Serialize the header into the packet
Fw::SerializeStatus status = container.serializeHeader();
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
container.serializeHeader();
// Update the data hash
container.updateDataHash();
// Update the size of the buffer according to the data size
const FwSizeType packetSize = container.getPacketSize();
Fw::Buffer buffer = container.getBuffer();
Expand Down Expand Up @@ -3619,10 +3615,11 @@ void ActiveAsyncProductsComponentBase ::
void ActiveAsyncProductsComponentBase ::
dpRequest(
ContainerId::T containerId,
FwSizeType size
FwSizeType dataSize
)
{
const FwDpIdType globalId = this->getIdBase() + containerId;
const FwSizeType size = DpContainer::getPacketSizeForDataSize(dataSize);
this->productRequestOut_out(0, globalId, size);
}

Expand Down
Loading

0 comments on commit 4174ca5

Please sign in to comment.