GCC Code Coverage Report


Directory: ./
File: Svc/Ccsds/CcsdsSdlsFramer/CcsdsSdlsFramer.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 55 55 100.0%
Functions: 8 8 100.0%
Branches: 41 43 95.3%

Line Branch Exec Source
1 // ======================================================================
2 // \title CcsdsSdlsFramer.cpp
3 // \author devin
4 // \brief cpp file for CcsdsSdlsFramer component implementation class
5 // ======================================================================
6
7 #include "Svc/Ccsds/CcsdsSdlsFramer/CcsdsSdlsFramer.hpp"
8
9 #include <Fw/Prm/ParamValid.hpp>
10
11 namespace Svc {
12
13 namespace Ccsds {
14
15 // ----------------------------------------------------------------------
16 // Component construction and destruction
17 // ----------------------------------------------------------------------
18
19 7 CcsdsSdlsFramer ::CcsdsSdlsFramer(const char* const compName) : CcsdsSdlsFramerComponentBase(compName) {}
20
21 14 CcsdsSdlsFramer ::~CcsdsSdlsFramer() {}
22
23 // ----------------------------------------------------------------------
24 // Handler implementations for typed input ports
25 // ----------------------------------------------------------------------
26
27 1229 void CcsdsSdlsFramer ::bufferReturnIn_handler(FwIndexType portNum,
28 Fw::Buffer& data,
29 const ComCfg::FrameContext& context) {
30 // The encryption helper has returned the original data buffer: send it back upstream
31 1229 this->dataReturnOut_out(0, data, context);
32 1229 }
33
34 1264 void CcsdsSdlsFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
35
1/2
✓ Branch 5 taken 1264 times.
✗ Branch 6 not taken.
1264 if (this->isConnected_comStatusOut_OutputPort(portNum)) {
36 1264 this->comStatusOut_out(portNum, condition);
37 }
38 1264 }
39
40 2504 void CcsdsSdlsFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
41 // Determine the security association index: use the context's value when set, otherwise the SA_INDEX parameter
42 2504 const U16 unsetSaIndex = static_cast<U16>(ComCfg::SaIndexUnset);
43 2504 U16 saIndex = context.get_saIndex();
44
2/2
✓ Branch 0 taken 1227 times.
✓ Branch 1 taken 1277 times.
2504 if (saIndex == unsetSaIndex) {
45
1/1
✓ Branch 2 taken 1227 times.
1227 Fw::ParamValid valid = Fw::ParamValid::INVALID;
46
1/1
✓ Branch 5 taken 1227 times.
1227 saIndex = this->paramGet_SA_INDEX(valid);
47 1227 FW_ASSERT(FW_PARAM_OK(valid), static_cast<FwAssertArgType>(valid.e));
48 1227 }
49
50 // Copy context and record the security association index used for encryption
51
1/1
✓ Branch 2 taken 2504 times.
2504 ComCfg::FrameContext newContext = context;
52
1/1
✓ Branch 2 taken 2504 times.
2504 newContext.set_saIndex(saIndex);
53
54
1/1
✓ Branch 5 taken 2504 times.
2504 this->encryptOut_out(0, saIndex, data, newContext);
55 5008 }
56
57 1259 void CcsdsSdlsFramer ::dataReturnIn_handler(FwIndexType portNum,
58 Fw::Buffer& data,
59 const ComCfg::FrameContext& context) {
60 // dataReturnIn is the allocated frame buffer coming back from the dataOut port
61 1259 this->bufferDeallocate_out(0, data);
62 1259 }
63
64 3752 void CcsdsSdlsFramer ::encryptIn_handler(FwIndexType portNum,
65 const Svc::Ccsds::SdlsStatus& status,
66 Fw::Buffer& data,
67 const ComCfg::FrameContext& context) {
68
2/2
✓ Branch 4 taken 1319 times.
✓ Branch 5 taken 2433 times.
3752 if (status != Svc::Ccsds::SdlsStatus::SUCCESS) {
69
1/1
✓ Branch 5 taken 1319 times.
1319 this->log_WARNING_HI_EncryptionFailed(status);
70 // Drop the frame: return ownership of the buffer to the encryption subsystem
71
1/1
✓ Branch 5 taken 1319 times.
1319 this->encryptReturnOut_out(0, data, context);
72
1/1
✓ Branch 4 taken 1319 times.
1319 this->sendComStatusOnDrop();
73 1319 return;
74 }
75
76 2433 FW_ASSERT(data.getSize() <= std::numeric_limits<Fw::Buffer::SizeType>::max() - sizeof(U16),
77 static_cast<FwAssertArgType>(data.getSize()));
78
1/1
✓ Branch 4 taken 2433 times.
2433 const Fw::Buffer::SizeType frameSize = static_cast<Fw::Buffer::SizeType>(data.getSize() + sizeof(U16));
79
80 // Allocate the frame buffer used to prepend the security association index to the encrypted data
81
1/1
✓ Branch 3 taken 2433 times.
2433 Fw::Buffer frameBuffer = this->bufferAllocate_out(0, frameSize);
82
8/8
✓ Branch 2 taken 2433 times.
✓ Branch 4 taken 1886 times.
✓ Branch 5 taken 547 times.
✓ Branch 8 taken 1886 times.
✓ Branch 10 taken 584 times.
✓ Branch 11 taken 1302 times.
✓ Branch 12 taken 1131 times.
✓ Branch 13 taken 1302 times.
2433 if ((!frameBuffer.isValid()) || (frameBuffer.getSize() < frameSize)) {
83
1/1
✓ Branch 5 taken 1131 times.
1131 this->log_WARNING_HI_BufferAllocationFailed(frameSize);
84 // Drop the frame: return the undersized allocation (when valid) and the encrypted data buffer
85
3/3
✓ Branch 2 taken 1131 times.
✓ Branch 4 taken 584 times.
✓ Branch 5 taken 547 times.
1131 if (frameBuffer.isValid()) {
86
1/1
✓ Branch 5 taken 584 times.
584 this->bufferDeallocate_out(0, frameBuffer);
87 }
88
1/1
✓ Branch 5 taken 1131 times.
1131 this->encryptReturnOut_out(0, data, context);
89
1/1
✓ Branch 4 taken 1131 times.
1131 this->sendComStatusOnDrop();
90 1131 return;
91 }
92
93
1/1
✓ Branch 2 taken 1302 times.
1302 auto frameSerializer = frameBuffer.getSerializer();
94
1/1
✓ Branch 6 taken 1302 times.
1302 Fw::SerializeStatus serializeStatus = frameSerializer.serializeFrom(context.get_saIndex());
95 1302 FW_ASSERT(serializeStatus == Fw::FW_SERIALIZE_OK, serializeStatus);
96
3/3
✓ Branch 5 taken 1302 times.
✓ Branch 11 taken 1302 times.
✓ Branch 14 taken 1302 times.
1302 serializeStatus = frameSerializer.serializeFrom(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH);
97 1302 FW_ASSERT(serializeStatus == Fw::FW_SERIALIZE_OK, serializeStatus);
98
99 // Trim to actual frame size in case the allocator returned a larger buffer
100
1/1
✓ Branch 2 taken 1302 times.
1302 frameBuffer.setSize(frameSize);
101
102 // Return ownership of the encrypted data buffer to the encryption helper, then send the frame
103
1/1
✓ Branch 5 taken 1302 times.
1302 this->encryptReturnOut_out(0, data, context);
104
1/1
✓ Branch 5 taken 1302 times.
1302 this->dataOut_out(0, frameBuffer, context);
105 2433 }
106
107 // ----------------------------------------------------------------------
108 // Private helper implementations
109 // ----------------------------------------------------------------------
110
111 2450 void CcsdsSdlsFramer ::sendComStatusOnDrop() {
112 // Report ready-for-more on a dropped frame so a ComQueue-driven downlink does not stall
113
1/2
✓ Branch 5 taken 2450 times.
✗ Branch 6 not taken.
2450 if (this->isConnected_comStatusOut_OutputPort(0)) {
114
1/1
✓ Branch 2 taken 2450 times.
2450 Fw::Success status = Fw::Success::SUCCESS;
115
1/1
✓ Branch 5 taken 2450 times.
2450 this->comStatusOut_out(0, status);
116 2450 }
117 2450 }
118
119 } // namespace Ccsds
120
121 } // namespace Svc
122