GCC Code Coverage Report


Directory: ./
File: Svc/Ccsds/SpacePacketFramer/SpacePacketFramer.cpp
Date: 2026-10-14 22:11:56
Exec Total Coverage
Lines: 42 51 82.4%
Functions: 5 5 100.0%
Branches: 24 40 60.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title SpacePacketFramer.cpp
3 // \author thomas-bc
4 // \brief cpp file for SpacePacketFramer component implementation class
5 // ======================================================================
6
7 #include "Svc/Ccsds/SpacePacketFramer/SpacePacketFramer.hpp"
8 #include "Svc/Ccsds/Types/FppConstantsAc.hpp"
9 #include "Svc/Ccsds/Types/SpacePacketHeaderSerializableAc.hpp"
10
11 namespace Svc {
12
13 namespace Ccsds {
14
15 // ----------------------------------------------------------------------
16 // Component construction and destruction
17 // ----------------------------------------------------------------------
18
19 1 SpacePacketFramer ::SpacePacketFramer(const char* const compName) : SpacePacketFramerComponentBase(compName) {}
20
21 2 SpacePacketFramer ::~SpacePacketFramer() {}
22
23 // ----------------------------------------------------------------------
24 // Handler implementations for typed input ports
25 // ----------------------------------------------------------------------
26
27 705 void SpacePacketFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
28
1/1
✓ Branch 1 taken 705 times.
705 SpacePacketHeader header;
29 Fw::SerializeStatus status;
30
1/1
✓ Branch 1 taken 705 times.
705 FwSizeType frameSize = SpacePacketHeader::SERIALIZED_SIZE + data.getSize();
31 705 FW_ASSERT(data.getSize() <= std::numeric_limits<Fw::Buffer::SizeType>::max() - SpacePacketHeader::SERIALIZED_SIZE,
32 static_cast<FwAssertArgType>(data.getSize()));
33 705 FW_ASSERT(
34 data.getSize() > 0,
35 static_cast<FwAssertArgType>(data.getSize())); // Protocol specifies at least 1 byte of data for a valid packet
36
37 // Allocate frame buffer
38
1/1
✓ Branch 1 taken 705 times.
705 Fw::Buffer frameBuffer = this->bufferAllocate_out(0, static_cast<Fw::Buffer::SizeType>(frameSize));
39 // The allocator may return an invalid or smaller-than-requested buffer
40
5/8
✓ Branch 1 taken 705 times.
✓ Branch 3 taken 705 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 705 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 705 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 705 times.
705 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 // No frame produced: report SUCCESS so the upstream ComQueue keeps sending (Framer Status Protocol)
47 ✗ if (this->isConnected_comStatusOut_OutputPort(0)) {
48 ✗ Fw::Success comStatus = Fw::Success::SUCCESS;
49 ✗ this->comStatusOut_out(0, comStatus);
50 ✗ }
51 ✗ return;
52 }
53
1/1
✓ Branch 1 taken 705 times.
705 auto frameSerializer = frameBuffer.getSerializer();
54
55 // -----------------------------------------------
56 // Header
57 // -----------------------------------------------
58 705 ComCfg::Apid::T apid = context.get_apid();
59 705 FW_ASSERT((apid >> SpacePacketSubfields::ApidWidth) == 0,
60 static_cast<FwAssertArgType>(apid)); // apid must fit in 11 bits
61 // Packet Type is 0 for Telemetry (downlink) 1 for Control command
62 705 const U16 pktType = static_cast<U16>(context.get_pktType());
63
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 705 times.
705 const U16 secHdrFlag = context.get_hasSecHdr() ? 1 : 0;
64 // PVN is always 0 per Standard
65 // 11 bit APID, 1 bit SecHdr flag, 1 bit packet type
66 705 const U16 packetIdentification = static_cast<U16>(
67 705 (static_cast<U16>(apid) & SpacePacketSubfields::ApidMask) | (secHdrFlag << SpacePacketSubfields::SecHdrOffset) |
68 705 ((pktType << SpacePacketSubfields::PktTypeOffset) & SpacePacketSubfields::PktTypeMask));
69
70
2/2
✓ Branch 1 taken 705 times.
✓ Branch 4 taken 705 times.
705 U16 sequenceCount = this->getApidSeqCount_out(0, apid, 0); // retrieve the sequence count for this APID
71 705 const U8 seqFlags = context.get_sequenceFlags();
72 // 2 bit sequence flags | 14 bit sequence count
73 705 U16 packetSequenceControl = static_cast<U16>(
74 705 ((static_cast<U16>(seqFlags) << SpacePacketSubfields::SeqFlagsOffset) & SpacePacketSubfields::SeqFlagsMask) |
75 705 (sequenceCount & SpacePacketSubfields::SeqCountMask));
76
77 705 FW_ASSERT(data.getSize() <= std::numeric_limits<U16>::max(), static_cast<FwAssertArgType>(data.getSize()));
78 U16 packetDataLength =
79
1/1
✓ Branch 1 taken 705 times.
705 static_cast<U16>(data.getSize() - 1); // Standard specifies length is number of bytes minus 1
80
81
1/1
✓ Branch 1 taken 705 times.
705 header.set_packetIdentification(packetIdentification);
82
1/1
✓ Branch 1 taken 705 times.
705 header.set_packetSequenceControl(packetSequenceControl);
83
1/1
✓ Branch 1 taken 705 times.
705 header.set_packetDataLength(packetDataLength);
84
85 // -----------------------------------------------
86 // Serialize the packet
87 // -----------------------------------------------
88
1/1
✓ Branch 1 taken 705 times.
705 status = frameSerializer.serializeFrom(header);
89 705 FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
90
3/3
✓ Branch 1 taken 705 times.
✓ Branch 4 taken 705 times.
✓ Branch 7 taken 705 times.
705 status = frameSerializer.serializeFrom(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH);
91 705 FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
92
93 // Trim to actual frame size in case allocator returned a larger buffer
94
1/1
✓ Branch 1 taken 705 times.
705 frameBuffer.setSize(static_cast<Fw::Buffer::SizeType>(frameSize));
95
96
1/1
✓ Branch 1 taken 705 times.
705 this->dataOut_out(0, frameBuffer, context);
97
1/1
✓ Branch 1 taken 705 times.
705 this->dataReturnOut_out(0, data, context); // return ownership of the original data buffer
98 705 }
99
100 706 void SpacePacketFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
101
1/2
✓ Branch 1 taken 706 times.
✗ Branch 2 not taken.
706 if (this->isConnected_comStatusOut_OutputPort(portNum)) {
102 706 this->comStatusOut_out(portNum, condition);
103 }
104 706 }
105
106 705 void SpacePacketFramer ::dataReturnIn_handler(FwIndexType portNum,
107 Fw::Buffer& frameBuffer,
108 const ComCfg::FrameContext& context) {
109 // dataReturnIn is the allocated buffer coming back from the dataOut port
110 705 this->bufferDeallocate_out(0, frameBuffer);
111 705 }
112
113 } // namespace Ccsds
114 } // namespace Svc
115