| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title FprimeFramer.cpp | ||
| 3 | // \author thomas-bc | ||
| 4 | // \brief cpp file for FprimeFramer component implementation class | ||
| 5 | // ====================================================================== | ||
| 6 | |||
| 7 | #include "Svc/FprimeFramer/FprimeFramer.hpp" | ||
| 8 | #include "Svc/FprimeProtocol/FrameHeaderSerializableAc.hpp" | ||
| 9 | #include "Svc/FprimeProtocol/FrameTrailerSerializableAc.hpp" | ||
| 10 | #include "Utils/Hash/Hash.hpp" | ||
| 11 | |||
| 12 | namespace Svc { | ||
| 13 | |||
| 14 | // ---------------------------------------------------------------------- | ||
| 15 | // Component construction and destruction | ||
| 16 | // ---------------------------------------------------------------------- | ||
| 17 | |||
| 18 | 4 | FprimeFramer ::FprimeFramer(const char* const compName) : FprimeFramerComponentBase(compName) {} | |
| 19 | |||
| 20 | 8 | FprimeFramer ::~FprimeFramer() {} | |
| 21 | |||
| 22 | // ---------------------------------------------------------------------- | ||
| 23 | // Handler implementations for typed input ports | ||
| 24 | // ---------------------------------------------------------------------- | ||
| 25 | |||
| 26 | 2 | void FprimeFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) { | |
| 27 |
1/1✓ Branch 2 taken 2 times.
|
2 | FprimeProtocol::FrameHeader header; |
| 28 |
1/1✓ Branch 2 taken 2 times.
|
2 | FprimeProtocol::FrameTrailer trailer; |
| 29 | |||
| 30 | // Full size of the frame will be size of header + data + trailer | ||
| 31 | FwSizeType frameSize = | ||
| 32 |
1/1✓ Branch 4 taken 2 times.
|
2 | FprimeProtocol::FrameHeader::SERIALIZED_SIZE + data.getSize() + FprimeProtocol::FrameTrailer::SERIALIZED_SIZE; |
| 33 | 2 | FW_ASSERT(data.getSize() <= std::numeric_limits<FprimeProtocol::TokenType>::max(), | |
| 34 | static_cast<FwAssertArgType>(frameSize)); | ||
| 35 | 2 | FW_ASSERT(frameSize <= std::numeric_limits<Fw::Buffer::SizeType>::max(), static_cast<FwAssertArgType>(frameSize)); | |
| 36 | |||
| 37 | // Allocate frame buffer | ||
| 38 |
1/1✓ Branch 3 taken 2 times.
|
2 | Fw::Buffer frameBuffer = this->bufferAllocate_out(0, frameSize); |
| 39 | // The allocator may return an invalid or smaller-than-requested buffer | ||
| 40 |
5/8✓ Branch 2 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
|
2 | if ((not frameBuffer.isValid()) || (frameBuffer.getSize() < frameSize)) { |
| 41 | ✗ | this->log_WARNING_HI_NoBufferAvailable(); | |
| 42 | ✗ | if (frameBuffer.isValid()) { | |
| 43 | ✗ | this->bufferDeallocate_out(0, frameBuffer); | |
| 44 | } | ||
| 45 | ✗ | this->dataReturnOut_out(0, data, context); | |
| 46 | ✗ | return; | |
| 47 | } | ||
| 48 |
1/1✓ Branch 2 taken 2 times.
|
2 | auto frameSerializer = frameBuffer.getSerializer(); |
| 49 | Fw::SerializeStatus status; | ||
| 50 | |||
| 51 | // Serialize the header | ||
| 52 | // 0xDEADBEEF is already set as the default value for the header startWord field in the FPP type definition | ||
| 53 |
2/2✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
|
2 | header.set_lengthField(static_cast<FprimeProtocol::TokenType>(data.getSize())); |
| 54 |
1/1✓ Branch 2 taken 2 times.
|
2 | status = frameSerializer.serializeFrom(header); |
| 55 | 2 | FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); | |
| 56 | |||
| 57 | // Serialize the data | ||
| 58 |
3/3✓ Branch 5 taken 2 times.
✓ Branch 11 taken 2 times.
✓ Branch 14 taken 2 times.
|
2 | status = frameSerializer.serializeFrom(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH); |
| 59 | 2 | FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); | |
| 60 | |||
| 61 | // Serialize the trailer (with CRC computation) | ||
| 62 |
1/1✓ Branch 2 taken 2 times.
|
2 | Utils::HashBuffer hashBuffer; |
| 63 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | Utils::Hash::hash(frameBuffer.getData(), frameSize - HASH_DIGEST_LENGTH, hashBuffer); |
| 64 |
2/2✓ Branch 3 taken 2 times.
✓ Branch 6 taken 2 times.
|
2 | trailer.set_crcField(hashBuffer.asBigEndianU32()); |
| 65 |
1/1✓ Branch 2 taken 2 times.
|
2 | status = frameSerializer.serializeFrom(trailer); |
| 66 | 2 | FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); | |
| 67 | // Trim to actual frame size in case allocator returned a larger buffer | ||
| 68 |
1/1✓ Branch 2 taken 2 times.
|
2 | frameBuffer.setSize(static_cast<Fw::Buffer::SizeType>(frameSize)); |
| 69 | |||
| 70 | // Send the full frame out - this port shall always be connected | ||
| 71 |
1/1✓ Branch 5 taken 2 times.
|
2 | this->dataOut_out(0, frameBuffer, context); |
| 72 | // Return original (unframed) data buffer ownership back to its sender - always connected | ||
| 73 |
1/1✓ Branch 5 taken 2 times.
|
2 | this->dataReturnOut_out(0, data, context); |
| 74 | 2 | } | |
| 75 | |||
| 76 | 2 | void FprimeFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) { | |
| 77 |
1/2✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
2 | if (this->isConnected_comStatusOut_OutputPort(portNum)) { |
| 78 | 2 | this->comStatusOut_out(portNum, condition); | |
| 79 | } | ||
| 80 | 2 | } | |
| 81 | |||
| 82 | 1 | void FprimeFramer ::dataReturnIn_handler(FwIndexType portNum, | |
| 83 | Fw::Buffer& frameBuffer, | ||
| 84 | const ComCfg::FrameContext& context) { | ||
| 85 | // dataReturnIn is the allocated buffer coming back from the ComManager (e.g. ComStub) component | ||
| 86 | 1 | this->bufferDeallocate_out(0, frameBuffer); | |
| 87 | 1 | } | |
| 88 | |||
| 89 | } // namespace Svc | ||
| 90 |