| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title TmFramer.cpp | ||
| 3 | // \author thomas-bc | ||
| 4 | // \brief cpp file for TmFramer component implementation class | ||
| 5 | // ====================================================================== | ||
| 6 | |||
| 7 | #include "Svc/Ccsds/TmFramer/TmFramer.hpp" | ||
| 8 | #include "Svc/Ccsds/Utils/CRC16.hpp" | ||
| 9 | #include "config/FppConstantsAc.hpp" | ||
| 10 | |||
| 11 | namespace Svc { | ||
| 12 | |||
| 13 | namespace Ccsds { | ||
| 14 | |||
| 15 | // ---------------------------------------------------------------------- | ||
| 16 | // Component construction and destruction | ||
| 17 | // ---------------------------------------------------------------------- | ||
| 18 | |||
| 19 | 8 | TmFramer ::TmFramer(const char* const compName) | |
| 20 | 8 | : TmFramerComponentBase(compName), m_masterFrameCount(0), m_virtualFrameCount(0) {} | |
| 21 | |||
| 22 | 16 | TmFramer ::~TmFramer() {} | |
| 23 | |||
| 24 | // ---------------------------------------------------------------------- | ||
| 25 | // Handler implementations for typed input ports | ||
| 26 | // ---------------------------------------------------------------------- | ||
| 27 | |||
| 28 | 15 | void TmFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) { | |
| 29 | // The data must fill the data field exactly: idle filling (Standard 4.2.2.5) is done upstream by Svc::ComAggregator | ||
| 30 | 15 | FW_ASSERT(data.getSize() == TmPayloadCapacity, static_cast<FwAssertArgType>(data.getSize())); | |
| 31 | 15 | FW_ASSERT(context.get_firstHeaderPointer() <= TMSubfields::fhpMask, | |
| 32 | static_cast<FwAssertArgType>(context.get_firstHeaderPointer())); | ||
| 33 | 15 | FW_ASSERT(this->m_bufferState == BufferOwnershipState::OWNED, static_cast<FwAssertArgType>(this->m_bufferState)); | |
| 34 | |||
| 35 | // ----------------------------------------------- | ||
| 36 | // Header | ||
| 37 | // ----------------------------------------------- | ||
| 38 |
1/1✓ Branch 2 taken 15 times.
|
15 | TMHeader header; |
| 39 | |||
| 40 | // GVCID (Global Virtual Channel ID) (Standard 4.1.2.2 and 4.1.2.3) | ||
| 41 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
|
15 | U16 globalVcId = static_cast<U16>(context.get_vcId() << TMSubfields::virtualChannelIdOffset); |
| 42 | 15 | globalVcId |= static_cast<U16>(ComCfg::SpacecraftId << TMSubfields::spacecraftIdOffset); | |
| 43 | 15 | globalVcId |= 0x0; // Operational Control Field: Flag set to 0 (Standard 4.1.2.4) | |
| 44 | |||
| 45 | // Data Field Status (Standard 4.1.2.7): | ||
| 46 | // - all flags to 0 except Segment Length Id 0b11 (Standard 4.1.2.7.5) | ||
| 47 | // - First Header Pointer from context (Standard 4.1.2.7.6): set by an upstream aggregator when packets | ||
| 48 | // span frames; the default of 0 indicates a packet header at offset 0 of the data field | ||
| 49 | const U16 dataFieldStatus = | ||
| 50 | 15 | static_cast<U16>((0x3 << TMSubfields::segLengthOffset) | context.get_firstHeaderPointer()); | |
| 51 | |||
| 52 |
1/1✓ Branch 2 taken 15 times.
|
15 | header.set_globalVcId(globalVcId); |
| 53 |
1/1✓ Branch 6 taken 15 times.
|
15 | header.set_masterFrameCount(this->m_masterFrameCount); |
| 54 |
1/1✓ Branch 6 taken 15 times.
|
15 | header.set_virtualFrameCount(this->m_virtualFrameCount); |
| 55 |
1/1✓ Branch 2 taken 15 times.
|
15 | header.set_dataFieldStatus(dataFieldStatus); |
| 56 | |||
| 57 | // We use only a single Virtual Channel for now, so master and virtual frame counts are the same | ||
| 58 | 15 | this->m_masterFrameCount++; // U8 intended to wrap around (modulo 256) | |
| 59 | 15 | this->m_virtualFrameCount++; // U8 intended to wrap around (modulo 256) | |
| 60 | |||
| 61 | // ------------------------------------------------- | ||
| 62 | // Data field | ||
| 63 | // ------------------------------------------------- | ||
| 64 | // Payload packet | ||
| 65 | Fw::SerializeStatus status; | ||
| 66 | // Create frame Fw::Buffer using member data field | ||
| 67 |
1/1✓ Branch 4 taken 15 times.
|
15 | Fw::Buffer frameBuffer = Fw::Buffer(this->m_frameBuffer, sizeof(this->m_frameBuffer)); |
| 68 |
1/1✓ Branch 2 taken 15 times.
|
15 | auto frameSerializer = frameBuffer.getSerializer(); |
| 69 |
1/1✓ Branch 2 taken 15 times.
|
15 | status = frameSerializer.serializeFrom(header); |
| 70 | 15 | FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); | |
| 71 |
3/3✓ Branch 5 taken 15 times.
✓ Branch 11 taken 15 times.
✓ Branch 14 taken 15 times.
|
15 | status = frameSerializer.serializeFrom(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH); |
| 72 | 15 | FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); | |
| 73 | |||
| 74 | // ------------------------------------------------- | ||
| 75 | // Trailer (CRC) | ||
| 76 | // ------------------------------------------------- | ||
| 77 |
1/1✓ Branch 2 taken 15 times.
|
15 | TMTrailer trailer; |
| 78 | // Compute CRC over the entire frame buffer minus the FECF trailer (Standard 4.1.6) | ||
| 79 | U16 crc = | ||
| 80 |
2/2✓ Branch 2 taken 15 times.
✓ Branch 5 taken 15 times.
|
15 | Ccsds::Utils::CRC16::compute(frameBuffer.getData(), sizeof(this->m_frameBuffer) - TMTrailer::SERIALIZED_SIZE); |
| 81 | // Set the Frame Error Control Field (FECF) | ||
| 82 |
1/1✓ Branch 2 taken 15 times.
|
15 | trailer.set_fecf(crc); |
| 83 | // Move the serializer pointer to the end of the location where the trailer will be serialized | ||
| 84 |
1/1✓ Branch 2 taken 15 times.
|
15 | status = frameSerializer.moveSerToOffset(ComCfg::TmFrameFixedSize - TMTrailer::SERIALIZED_SIZE); |
| 85 | 15 | FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); | |
| 86 |
1/1✓ Branch 2 taken 15 times.
|
15 | status = frameSerializer.serializeFrom(trailer); |
| 87 | 15 | FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status); | |
| 88 | |||
| 89 | 15 | this->m_bufferState = BufferOwnershipState::NOT_OWNED; | |
| 90 |
1/1✓ Branch 5 taken 15 times.
|
15 | this->dataOut_out(0, frameBuffer, context); |
| 91 |
1/1✓ Branch 5 taken 15 times.
|
15 | this->dataReturnOut_out(0, data, context); // return ownership of the original data buffer |
| 92 | 30 | } | |
| 93 | |||
| 94 | 2 | void TmFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) { | |
| 95 |
1/2✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
2 | if (this->isConnected_comStatusOut_OutputPort(portNum)) { |
| 96 | 2 | this->comStatusOut_out(portNum, condition); | |
| 97 | } | ||
| 98 | 2 | } | |
| 99 | |||
| 100 | 1 | void TmFramer ::dataReturnIn_handler(FwIndexType portNum, | |
| 101 | Fw::Buffer& frameBuffer, | ||
| 102 | const ComCfg::FrameContext& context) { | ||
| 103 | // Assert that the returned buffer is the member, and set ownership state | ||
| 104 | 1 | FW_ASSERT(frameBuffer.getData() >= &this->m_frameBuffer[0]); | |
| 105 | 1 | FW_ASSERT(frameBuffer.getData() < &this->m_frameBuffer[0] + sizeof(this->m_frameBuffer)); | |
| 106 | 1 | this->m_bufferState = BufferOwnershipState::OWNED; | |
| 107 | 1 | } | |
| 108 | } // namespace Ccsds | ||
| 109 | } // namespace Svc | ||
| 110 |