GCC Code Coverage Report


Directory: ./
File: Svc/Ccsds/SpacePacketFramer/SpacePacketFramer.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 38 44 86.4%
Functions: 5 5 100.0%
Branches: 27 39 69.2%

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 4 SpacePacketFramer ::SpacePacketFramer(const char* const compName) : SpacePacketFramerComponentBase(compName) {}
20
21 8 SpacePacketFramer ::~SpacePacketFramer() {}
22
23 // ----------------------------------------------------------------------
24 // Handler implementations for typed input ports
25 // ----------------------------------------------------------------------
26
27 2 void SpacePacketFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
28
1/1
✓ Branch 2 taken 2 times.
2 SpacePacketHeader header;
29 Fw::SerializeStatus status;
30
1/1
✓ Branch 4 taken 2 times.
2 FwSizeType frameSize = SpacePacketHeader::SERIALIZED_SIZE + data.getSize();
31 2 FW_ASSERT(data.getSize() <= std::numeric_limits<Fw::Buffer::SizeType>::max() - SpacePacketHeader::SERIALIZED_SIZE,
32 static_cast<FwAssertArgType>(data.getSize()));
33 2 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 2 times.
2 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 2 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
2 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 2 taken 2 times.
2 auto frameSerializer = frameBuffer.getSerializer();
49
50 // -----------------------------------------------
51 // Header
52 // -----------------------------------------------
53 2 ComCfg::Apid::T apid = context.get_apid();
54 2 FW_ASSERT((apid >> SpacePacketSubfields::ApidWidth) == 0,
55 static_cast<FwAssertArgType>(apid)); // apid must fit in 11 bits
56
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 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 2 const U16 packetIdentification = static_cast<U16>((static_cast<U16>(apid) & SpacePacketSubfields::ApidMask) |
60
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 (secHdrFlag << SpacePacketSubfields::SecHdrOffset));
61
62
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
63 2 const U8 seqFlags = context.get_sequenceFlags();
64 // 2 bit sequence flags | 14 bit sequence count
65 U16 packetSequenceControl = static_cast<U16>(
66 ((static_cast<U16>(seqFlags) << SpacePacketSubfields::SeqFlagsOffset) & SpacePacketSubfields::SeqFlagsMask) |
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 (sequenceCount & SpacePacketSubfields::SeqCountMask));
68
69 2 FW_ASSERT(data.getSize() <= std::numeric_limits<U16>::max(), static_cast<FwAssertArgType>(data.getSize()));
70 U16 packetDataLength =
71
1/1
✓ Branch 4 taken 2 times.
2 static_cast<U16>(data.getSize() - 1); // Standard specifies length is number of bytes minus 1
72
73
1/1
✓ Branch 2 taken 2 times.
2 header.set_packetIdentification(packetIdentification);
74
1/1
✓ Branch 2 taken 2 times.
2 header.set_packetSequenceControl(packetSequenceControl);
75
1/1
✓ Branch 2 taken 2 times.
2 header.set_packetDataLength(packetDataLength);
76
77 // -----------------------------------------------
78 // Serialize the packet
79 // -----------------------------------------------
80
1/1
✓ Branch 2 taken 2 times.
2 status = frameSerializer.serializeFrom(header);
81 2 FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
82
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);
83 2 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 2 taken 2 times.
2 frameBuffer.setSize(static_cast<Fw::Buffer::SizeType>(frameSize));
87
88
1/1
✓ Branch 5 taken 2 times.
2 this->dataOut_out(0, frameBuffer, context);
89
1/1
✓ Branch 5 taken 2 times.
2 this->dataReturnOut_out(0, data, context); // return ownership of the original data buffer
90 2 }
91
92 2 void SpacePacketFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
93
1/2
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
2 if (this->isConnected_comStatusOut_OutputPort(portNum)) {
94 2 this->comStatusOut_out(portNum, condition);
95 }
96 2 }
97
98 1 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 1 this->bufferDeallocate_out(0, frameBuffer);
103 1 }
104
105 } // namespace Ccsds
106 } // namespace Svc
107