GCC Code Coverage Report


Directory: Svc/Ccsds/SpacePacketFramer/
File: SpacePacketFramer.cpp
Date: 2026-09-23 21:13:23
Exec Total Coverage
Lines: 47 48 97.9%
Functions: 5 5 100.0%
Branches: 40 44 90.9%

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 6 SpacePacketFramer ::SpacePacketFramer(const char* const compName) : SpacePacketFramerComponentBase(compName) {}
20
21 12 SpacePacketFramer ::~SpacePacketFramer() {}
22
23 // ----------------------------------------------------------------------
24 // Handler implementations for typed input ports
25 // ----------------------------------------------------------------------
26
27 4 void SpacePacketFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
28
1/1
✓ Branch 2 taken 4 times.
4 SpacePacketHeader header;
29 Fw::SerializeStatus status;
30
1/1
✓ Branch 4 taken 4 times.
4 FwSizeType frameSize = SpacePacketHeader::SERIALIZED_SIZE + data.getSize();
31 4 FW_ASSERT(data.getSize() <= std::numeric_limits<Fw::Buffer::SizeType>::max() - SpacePacketHeader::SERIALIZED_SIZE,
32 static_cast<FwAssertArgType>(data.getSize()));
33 4 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 3 taken 4 times.
4 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
8/8
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 times.
✓ Branch 8 taken 3 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 2 times.
4 if ((not frameBuffer.isValid()) || (frameBuffer.getSize() < frameSize)) {
41
1/1
✓ Branch 5 taken 2 times.
2 this->log_WARNING_HI_NoBufferAvailable();
42
3/3
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 if (frameBuffer.isValid()) {
43
1/1
✓ Branch 5 taken 1 times.
1 this->bufferDeallocate_out(0, frameBuffer);
44 }
45
1/1
✓ Branch 5 taken 2 times.
2 this->dataReturnOut_out(0, data, context);
46 // No frame produced: report SUCCESS so the upstream ComQueue keeps sending (Framer Status Protocol)
47
2/3
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
2 if (this->isConnected_comStatusOut_OutputPort(0)) {
48
1/1
✓ Branch 2 taken 2 times.
2 Fw::Success comStatus = Fw::Success::SUCCESS;
49
1/1
✓ Branch 5 taken 2 times.
2 this->comStatusOut_out(0, comStatus);
50 2 }
51 2 return;
52 }
53
1/1
✓ Branch 2 taken 2 times.
2 auto frameSerializer = frameBuffer.getSerializer();
54
55 // -----------------------------------------------
56 // Header
57 // -----------------------------------------------
58 2 ComCfg::Apid::T apid = context.get_apid();
59 2 FW_ASSERT((apid >> SpacePacketSubfields::ApidWidth) == 0,
60 static_cast<FwAssertArgType>(apid)); // apid must fit in 11 bits
61
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 const U16 secHdrFlag = context.get_hasSecHdr() ? 1 : 0;
62 // PVN is always 0 per Standard - Packet Type is 0 for Telemetry (downlink)
63 // 11 bit APID, 1 bit SecHdr flag
64 2 const U16 packetIdentification = static_cast<U16>((static_cast<U16>(apid) & SpacePacketSubfields::ApidMask) |
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 (secHdrFlag << SpacePacketSubfields::SecHdrOffset));
66
67
2/2
✓ Branch 6 taken 2 times.
✓ Branch 10 taken 2 times.
2 U16 sequenceCount = this->getApidSeqCount_out(0, apid, 0); // retrieve the sequence count for this APID
68 2 const U8 seqFlags = context.get_sequenceFlags();
69 // 2 bit sequence flags | 14 bit sequence count
70 U16 packetSequenceControl = static_cast<U16>(
71 ✗ ((static_cast<U16>(seqFlags) << SpacePacketSubfields::SeqFlagsOffset) & SpacePacketSubfields::SeqFlagsMask) |
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 (sequenceCount & SpacePacketSubfields::SeqCountMask));
73
74 2 FW_ASSERT(data.getSize() <= std::numeric_limits<U16>::max(), static_cast<FwAssertArgType>(data.getSize()));
75 U16 packetDataLength =
76
1/1
✓ Branch 4 taken 2 times.
2 static_cast<U16>(data.getSize() - 1); // Standard specifies length is number of bytes minus 1
77
78
1/1
✓ Branch 2 taken 2 times.
2 header.set_packetIdentification(packetIdentification);
79
1/1
✓ Branch 2 taken 2 times.
2 header.set_packetSequenceControl(packetSequenceControl);
80
1/1
✓ Branch 2 taken 2 times.
2 header.set_packetDataLength(packetDataLength);
81
82 // -----------------------------------------------
83 // Serialize the packet
84 // -----------------------------------------------
85
1/1
✓ Branch 2 taken 2 times.
2 status = frameSerializer.serializeFrom(header);
86 2 FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
87
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);
88 2 FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
89
90 // Trim to actual frame size in case allocator returned a larger buffer
91
1/1
✓ Branch 2 taken 2 times.
2 frameBuffer.setSize(static_cast<Fw::Buffer::SizeType>(frameSize));
92
93
1/1
✓ Branch 5 taken 2 times.
2 this->dataOut_out(0, frameBuffer, context);
94
1/1
✓ Branch 5 taken 2 times.
2 this->dataReturnOut_out(0, data, context); // return ownership of the original data buffer
95 6 }
96
97 2 void SpacePacketFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
98
1/2
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
2 if (this->isConnected_comStatusOut_OutputPort(portNum)) {
99 2 this->comStatusOut_out(portNum, condition);
100 }
101 2 }
102
103 1 void SpacePacketFramer ::dataReturnIn_handler(FwIndexType portNum,
104 Fw::Buffer& frameBuffer,
105 const ComCfg::FrameContext& context) {
106 // dataReturnIn is the allocated buffer coming back from the dataOut port
107 1 this->bufferDeallocate_out(0, frameBuffer);
108 1 }
109
110 } // namespace Ccsds
111 } // namespace Svc
112