GCC Code Coverage Report


Directory: /home/runner/work/fprime/fprime/Svc/Ccsds/SpacePacketFramer/
File: SpacePacketFramer.cpp
Date: 2026-09-23 22:12:43
Exec Total Coverage
Lines: 39 48 81.2%
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 703 void SpacePacketFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
28
1/1
✓ Branch 1 taken 703 times.
703 SpacePacketHeader header;
29 Fw::SerializeStatus status;
30
1/1
✓ Branch 1 taken 703 times.
703 FwSizeType frameSize = SpacePacketHeader::SERIALIZED_SIZE + data.getSize();
31 703 FW_ASSERT(data.getSize() <= std::numeric_limits<Fw::Buffer::SizeType>::max() - SpacePacketHeader::SERIALIZED_SIZE,
32 static_cast<FwAssertArgType>(data.getSize()));
33 703 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 703 times.
703 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 703 times.
✓ Branch 3 taken 703 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 703 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 703 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 703 times.
703 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 703 times.
703 auto frameSerializer = frameBuffer.getSerializer();
54
55 // -----------------------------------------------
56 // Header
57 // -----------------------------------------------
58 703 ComCfg::Apid::T apid = context.get_apid();
59 703 FW_ASSERT((apid >> SpacePacketSubfields::ApidWidth) == 0,
60 static_cast<FwAssertArgType>(apid)); // apid must fit in 11 bits
61
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 703 times.
703 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 703 const U16 packetIdentification = static_cast<U16>((static_cast<U16>(apid) & SpacePacketSubfields::ApidMask) |
65 (secHdrFlag << SpacePacketSubfields::SecHdrOffset));
66
67
2/2
✓ Branch 1 taken 703 times.
✓ Branch 4 taken 703 times.
703 U16 sequenceCount = this->getApidSeqCount_out(0, apid, 0); // retrieve the sequence count for this APID
68 703 const U8 seqFlags = context.get_sequenceFlags();
69 // 2 bit sequence flags | 14 bit sequence count
70 703 U16 packetSequenceControl = static_cast<U16>(
71 703 ((static_cast<U16>(seqFlags) << SpacePacketSubfields::SeqFlagsOffset) & SpacePacketSubfields::SeqFlagsMask) |
72 703 (sequenceCount & SpacePacketSubfields::SeqCountMask));
73
74 703 FW_ASSERT(data.getSize() <= std::numeric_limits<U16>::max(), static_cast<FwAssertArgType>(data.getSize()));
75 U16 packetDataLength =
76
1/1
✓ Branch 1 taken 703 times.
703 static_cast<U16>(data.getSize() - 1); // Standard specifies length is number of bytes minus 1
77
78
1/1
✓ Branch 1 taken 703 times.
703 header.set_packetIdentification(packetIdentification);
79
1/1
✓ Branch 1 taken 703 times.
703 header.set_packetSequenceControl(packetSequenceControl);
80
1/1
✓ Branch 1 taken 703 times.
703 header.set_packetDataLength(packetDataLength);
81
82 // -----------------------------------------------
83 // Serialize the packet
84 // -----------------------------------------------
85
1/1
✓ Branch 1 taken 703 times.
703 status = frameSerializer.serializeFrom(header);
86 703 FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
87
3/3
✓ Branch 1 taken 703 times.
✓ Branch 4 taken 703 times.
✓ Branch 7 taken 703 times.
703 status = frameSerializer.serializeFrom(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH);
88 703 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 1 taken 703 times.
703 frameBuffer.setSize(static_cast<Fw::Buffer::SizeType>(frameSize));
92
93
1/1
✓ Branch 1 taken 703 times.
703 this->dataOut_out(0, frameBuffer, context);
94
1/1
✓ Branch 1 taken 703 times.
703 this->dataReturnOut_out(0, data, context); // return ownership of the original data buffer
95 703 }
96
97 704 void SpacePacketFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
98
1/2
✓ Branch 1 taken 704 times.
✗ Branch 2 not taken.
704 if (this->isConnected_comStatusOut_OutputPort(portNum)) {
99 704 this->comStatusOut_out(portNum, condition);
100 }
101 704 }
102
103 703 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 703 this->bufferDeallocate_out(0, frameBuffer);
108 703 }
109
110 } // namespace Ccsds
111 } // namespace Svc
112