Skip to content

Commit 4d1ebbd

Browse files
authored
Refactor file and unknown data handling in FprimeRouter
1 parent 06fa9ff commit 4d1ebbd

1 file changed

Lines changed: 16 additions & 34 deletions

File tree

Svc/FprimeRouter/FprimeRouter.cpp

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,50 +48,31 @@ void FprimeRouter ::dataIn_handler(FwIndexType portNum, Fw::Buffer& packetBuffer
4848
case Fw::ComPacketType::FW_PACKET_FILE: {
4949
// If the file uplink output port is connected, send the file packet. Otherwise take no action.
5050
if (this->isConnected_fileOut_OutputPort(0)) {
51-
// Copy buffer into a new allocated buffer. This lets us return the original buffer with dataReturnOut,
52-
// and FprimeRouter can handle the deallocation of the file buffer when it returns on fileBufferReturnIn
53-
Fw::Buffer packetBufferCopy = this->bufferAllocate_out(0, packetBuffer.getSize());
54-
// Confirm we got a valid buffer before using it
55-
if (packetBufferCopy.isValid()) {
56-
auto copySerializer = packetBufferCopy.getSerializer();
57-
status = copySerializer.serializeFrom(packetBuffer.getData(), packetBuffer.getSize(),
58-
Fw::Serialization::OMIT_LENGTH);
59-
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
60-
// Send the copied buffer out. It will come back on fileBufferReturnIn once the receiver is done
61-
// with it
62-
this->fileOut_out(0, packetBufferCopy);
63-
} else {
64-
this->log_WARNING_HI_AllocationError(FprimeRouter_AllocationReason::FILE_UPLINK);
65-
}
51+
auto copySerializer = packetBufferCopy.getSerializer();
52+
status = copySerializer.serializeFrom(packetBuffer.getData(), packetBuffer.getSize(),
53+
Fw::Serialization::OMIT_LENGTH);
54+
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
55+
// Send the copied buffer out. It will come back on fileBufferReturnIn once the receiver is done
56+
// with it
57+
this->fileOut_out(0, packetBufferCopy);
6658
}
6759
break;
6860
}
6961
default: {
7062
// Packet type is not known to the F Prime protocol. If the unknownDataOut port is
7163
// connected, forward packet and context for further processing
7264
if (this->isConnected_unknownDataOut_OutputPort(0)) {
73-
// Copy buffer into a new allocated buffer. This lets us return the original buffer with dataReturnOut,
74-
// and FprimeRouter can handle the deallocation of the unknown buffer when it returns on bufferReturnIn
75-
Fw::Buffer packetBufferCopy = this->bufferAllocate_out(0, packetBuffer.getSize());
76-
// Confirm we got a valid buffer before using it
77-
if (packetBufferCopy.isValid()) {
78-
auto copySerializer = packetBufferCopy.getSerializer();
79-
status = copySerializer.serializeFrom(packetBuffer.getData(), packetBuffer.getSize(),
80-
Fw::Serialization::OMIT_LENGTH);
81-
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
82-
// Send the copied buffer out. It will come back on fileBufferReturnIn once the receiver is done
83-
// with it
84-
this->unknownDataOut_out(0, packetBufferCopy, context);
85-
} else {
86-
this->log_WARNING_HI_AllocationError(FprimeRouter_AllocationReason::USER_BUFFER);
87-
}
65+
auto copySerializer = packetBufferCopy.getSerializer();
66+
status = copySerializer.serializeFrom(packetBuffer.getData(), packetBuffer.getSize(),
67+
Fw::Serialization::OMIT_LENGTH);
68+
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
69+
// Send the copied buffer out. It will come back on fileBufferReturnIn once the receiver is done
70+
// with it
71+
this->unknownDataOut_out(0, packetBufferCopy, context);
8872
}
8973
break;
9074
}
9175
}
92-
93-
// Return ownership of the incoming packetBuffer
94-
this->dataReturnOut_out(0, packetBuffer, context);
9576
}
9677

9778
void FprimeRouter ::cmdResponseIn_handler(FwIndexType portNum,
@@ -102,7 +83,8 @@ void FprimeRouter ::cmdResponseIn_handler(FwIndexType portNum,
10283
}
10384

10485
void FprimeRouter ::fileBufferReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) {
105-
this->bufferDeallocate_out(0, fwBuffer);
86+
const ComCfg::FrameContext context;
87+
this->dataReturnOut_out(0, fwBuffer, context);
10688
}
10789

10890
} // namespace Svc

0 commit comments

Comments
 (0)