GCC Code Coverage Report


Directory: ./
File: Svc/Ccsds/CcsdsSdlsFramer/CcsdsSdlsFramer.cpp
Date: 2026-09-23 21:11:01
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 1238 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 1238 this->dataReturnOut_out(0, data, context);
32 1238 }
33
34 1233 void CcsdsSdlsFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
35
1/2
✓ Branch 5 taken 1233 times.
✗ Branch 6 not taken.
1233 if (this->isConnected_comStatusOut_OutputPort(portNum)) {
36 1233 this->comStatusOut_out(portNum, condition);
37 }
38 1233 }
39
40 2532 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 2532 const U16 unsetSaIndex = static_cast<U16>(ComCfg::SaIndexUnset);
43 2532 U16 saIndex = context.get_saIndex();
44
2/2
✓ Branch 0 taken 1241 times.
✓ Branch 1 taken 1291 times.
2532 if (saIndex == unsetSaIndex) {
45
1/1
✓ Branch 2 taken 1241 times.
1241 Fw::ParamValid valid = Fw::ParamValid::INVALID;
46
1/1
✓ Branch 5 taken 1241 times.
1241 saIndex = this->paramGet_SA_INDEX(valid);
47 1241 FW_ASSERT(FW_PARAM_OK(valid), static_cast<FwAssertArgType>(valid.e));
48 1241 }
49
50 // Copy context and record the security association index used for encryption
51
1/1
✓ Branch 2 taken 2532 times.
2532 ComCfg::FrameContext newContext = context;
52
1/1
✓ Branch 2 taken 2532 times.
2532 newContext.set_saIndex(saIndex);
53
54
1/1
✓ Branch 5 taken 2532 times.
2532 this->encryptOut_out(0, saIndex, data, newContext);
55 5064 }
56
57 1199 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 1199 this->bufferDeallocate_out(0, data);
62 1199 }
63
64 3806 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 1288 times.
✓ Branch 5 taken 2518 times.
3806 if (status != Svc::Ccsds::SdlsStatus::SUCCESS) {
69
1/1
✓ Branch 5 taken 1288 times.
1288 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 1288 times.
1288 this->encryptReturnOut_out(0, data, context);
72
1/1
✓ Branch 4 taken 1288 times.
1288 this->sendComStatusOnDrop();
73 1288 return;
74 }
75
76 2518 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 2518 times.
2518 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 2518 times.
2518 Fw::Buffer frameBuffer = this->bufferAllocate_out(0, frameSize);
82
8/8
✓ Branch 2 taken 2518 times.
✓ Branch 4 taken 1897 times.
✓ Branch 5 taken 621 times.
✓ Branch 8 taken 1897 times.
✓ Branch 10 taken 651 times.
✓ Branch 11 taken 1246 times.
✓ Branch 12 taken 1272 times.
✓ Branch 13 taken 1246 times.
2518 if ((!frameBuffer.isValid()) || (frameBuffer.getSize() < frameSize)) {
83
1/1
✓ Branch 5 taken 1272 times.
1272 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 1272 times.
✓ Branch 4 taken 651 times.
✓ Branch 5 taken 621 times.
1272 if (frameBuffer.isValid()) {
86
1/1
✓ Branch 5 taken 651 times.
651 this->bufferDeallocate_out(0, frameBuffer);
87 }
88
1/1
✓ Branch 5 taken 1272 times.
1272 this->encryptReturnOut_out(0, data, context);
89
1/1
✓ Branch 4 taken 1272 times.
1272 this->sendComStatusOnDrop();
90 1272 return;
91 }
92
93
1/1
✓ Branch 2 taken 1246 times.
1246 auto frameSerializer = frameBuffer.getSerializer();
94
1/1
✓ Branch 6 taken 1246 times.
1246 Fw::SerializeStatus serializeStatus = frameSerializer.serializeFrom(context.get_saIndex());
95 1246 FW_ASSERT(serializeStatus == Fw::FW_SERIALIZE_OK, serializeStatus);
96
3/3
✓ Branch 5 taken 1246 times.
✓ Branch 11 taken 1246 times.
✓ Branch 14 taken 1246 times.
1246 serializeStatus = frameSerializer.serializeFrom(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH);
97 1246 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 1246 times.
1246 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 1246 times.
1246 this->encryptReturnOut_out(0, data, context);
104
1/1
✓ Branch 5 taken 1246 times.
1246 this->dataOut_out(0, frameBuffer, context);
105 2518 }
106
107 // ----------------------------------------------------------------------
108 // Private helper implementations
109 // ----------------------------------------------------------------------
110
111 2560 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 2560 times.
✗ Branch 6 not taken.
2560 if (this->isConnected_comStatusOut_OutputPort(0)) {
114
1/1
✓ Branch 2 taken 2560 times.
2560 Fw::Success status = Fw::Success::SUCCESS;
115
1/1
✓ Branch 5 taken 2560 times.
2560 this->comStatusOut_out(0, status);
116 2560 }
117 2560 }
118
119 } // namespace Ccsds
120
121 } // namespace Svc
122