GCC Code Coverage Report


Directory: /home/runner/work/fprime/fprime/Drv/Udp/
File: UdpComponentImpl.cpp
Date: 2026-09-03 22:12:46
Exec Total Coverage
Lines: 0 48 0.0%
Functions: 0 11 0.0%
Branches: 0 21 0.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title UdpComponentImpl.cpp
3 // \author mstarch
4 // \brief cpp file for UdpComponentImpl component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2020, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12
13 #include <Drv/Udp/UdpComponentImpl.hpp>
14 #include <Fw/FPrimeBasicTypes.hpp>
15 #include <config/IpCfg.hpp>
16 #include <limits>
17 #include "Fw/Types/Assert.hpp"
18
19 namespace Drv {
20
21 // ----------------------------------------------------------------------
22 // Construction, initialization, and destruction
23 // ----------------------------------------------------------------------
24
25 UdpComponentImpl::UdpComponentImpl(const char* const compName) : UdpComponentBase(compName) {}
26
27 SocketIpStatus UdpComponentImpl::configureSend(const char* const ipv4_address,
28 const U16 port,
29 const U32 send_timeout_seconds,
30 const U32 send_timeout_microseconds) {
31 return m_socket.configureSend(ipv4_address, port, send_timeout_seconds, send_timeout_microseconds);
32 }
33
34 SocketIpStatus UdpComponentImpl::configureRecv(const char* const ipv4_address, const U16 port, FwSizeType buffer_size) {
35 m_allocation_size = buffer_size; // Store the buffer size
36 return m_socket.configureRecv(ipv4_address, port);
37 }
38
39 UdpComponentImpl::~UdpComponentImpl() {}
40
41 U16 UdpComponentImpl::getRecvPort() {
42 return this->m_socket.getRecvPort();
43 }
44
45 // ----------------------------------------------------------------------
46 // Implementations for socket read task virtual methods
47 // ----------------------------------------------------------------------
48
49 IpSocket& UdpComponentImpl::getSocketHandler() {
50 return m_socket;
51 }
52
53 Fw::Buffer UdpComponentImpl::getBuffer() {
54 return allocate_out(0, m_allocation_size);
55 }
56
57 void UdpComponentImpl::sendBuffer(Fw::Buffer buffer, SocketIpStatus status) {
58 // A successful receive must have produced a buffer with backing data (size may be zero)
59 FW_ASSERT((status != SOCK_SUCCESS) || (buffer.getData() != nullptr));
60 Drv::ByteStreamStatus recvStatus = ByteStreamStatus::OTHER_ERROR;
61 if (status == SOCK_SUCCESS) {
62 recvStatus = ByteStreamStatus::OP_OK;
63 } else if (status == SOCK_NO_DATA_AVAILABLE) {
64 recvStatus = ByteStreamStatus::RECV_NO_DATA;
65 } else {
66 recvStatus = ByteStreamStatus::OTHER_ERROR;
67 }
68 this->recv_out(0, buffer, recvStatus);
69 }
70
71 void UdpComponentImpl::connected() {
72 if (isConnected_ready_OutputPort(0)) {
73 this->ready_out(0);
74 }
75 }
76
77 // ----------------------------------------------------------------------
78 // Handler implementations for user-defined typed input ports
79 // ----------------------------------------------------------------------
80
81 Drv::ByteStreamStatus UdpComponentImpl::send_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
82 Drv::SocketIpStatus status = send(fwBuffer.getData(), fwBuffer.getSize());
83 Drv::ByteStreamStatus returnStatus;
84 switch (status) {
85 case SOCK_INTERRUPTED_TRY_AGAIN:
86 returnStatus = ByteStreamStatus::SEND_RETRY;
87 break;
88 case SOCK_DISCONNECTED:
89 returnStatus = ByteStreamStatus::SEND_RETRY;
90 break;
91 case SOCK_SUCCESS:
92 returnStatus = ByteStreamStatus::OP_OK;
93 break;
94 default:
95 returnStatus = ByteStreamStatus::OTHER_ERROR;
96 break;
97 }
98 return returnStatus;
99 }
100
101 void UdpComponentImpl::recvReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) {
102 this->deallocate_out(0, fwBuffer);
103 }
104
105 } // end namespace Drv
106