GCC Code Coverage Report


Directory: /home/runner/work/fprime/fprime/Svc/Ccsds/SpacePacketFramer/
File: SpacePacketFramer.cpp
Date: 2026-09-03 22:13:27
Exec Total Coverage
Lines: 39 44 88.6%
Functions: 5 5 100.0%
Branches: 24 35 68.6%

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