F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
UdpComponentImpl.cpp
Go to the documentation of this file.
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 
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 
28  const U16 port,
29  const U32 send_timeout_seconds,
30  const U32 send_timeout_microseconds) {
31  return m_socket.configureSend(hostname, port, send_timeout_seconds, send_timeout_microseconds);
32 }
33 
34 SocketIpStatus UdpComponentImpl::configureRecv(const char* hostname, const U16 port, FwSizeType buffer_size) {
35  FW_ASSERT(buffer_size <= std::numeric_limits<U32>::max(), static_cast<FwAssertArgType>(buffer_size));
36  m_allocation_size = buffer_size; // Store the buffer size
37 
38  return m_socket.configureRecv(hostname, port);
39 }
40 
42 
44  return this->m_socket.getRecvPort();
45 }
46 
47 // ----------------------------------------------------------------------
48 // Implementations for socket read task virtual methods
49 // ----------------------------------------------------------------------
50 
52  return m_socket;
53 }
54 
56  return allocate_out(0, static_cast<U32>(m_allocation_size));
57 }
58 
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 
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  FW_ASSERT_NO_OVERFLOW(fwBuffer.getSize(), U32);
83  Drv::SocketIpStatus status = send(fwBuffer.getData(), static_cast<U32>(fwBuffer.getSize()));
84  Drv::ByteStreamStatus returnStatus;
85  switch (status) {
87  returnStatus = ByteStreamStatus::SEND_RETRY;
88  break;
89  case SOCK_DISCONNECTED:
90  returnStatus = ByteStreamStatus::SEND_RETRY;
91  break;
92  case SOCK_SUCCESS:
93  returnStatus = ByteStreamStatus::OP_OK;
94  break;
95  default:
96  returnStatus = ByteStreamStatus::OTHER_ERROR;
97  break;
98  }
99  return returnStatus;
100 }
101 
102 void UdpComponentImpl::recvReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) {
103  this->deallocate_out(0, fwBuffer);
104 }
105 
106 } // end namespace Drv
void recv_out(FwIndexType portNum, Fw::Buffer &buffer, const Drv::ByteStreamStatus &status)
Invoke output port recv.
U16 getRecvPort()
get the port being received on
U16 getRecvPort()
get the port being received on
Definition: UdpSocket.cpp:87
Failed to read socket with disconnect.
Definition: IpSocket.hpp:38
Interrupted status for retries.
Definition: IpSocket.hpp:36
PlatformSizeType FwSizeType
SocketIpStatus send(const U8 *const data, const U32 size)
send data to the IP socket from the given buffer
U8 * getData() const
Definition: Buffer.cpp:56
SocketIpStatus configureRecv(const char *hostname, const U16 port)
configure the udp socket for incoming transmissions
Definition: UdpSocket.cpp:67
Error occurred, retrying may succeed.
UdpComponentImpl(const char *const compName)
construct the TcpClient component.
Receive worked, but there was no data.
SocketIpStatus configureRecv(const char *hostname, const U16 port, FwSizeType buffer_size=1024)
Configures the Udp receive settings but does not open the connection.
Fw::Buffer allocate_out(FwIndexType portNum, FwSizeType size)
Invoke output port allocate.
void connected() override
called when the IPv4 system has been connected
Status returned by the send call.
Socket operation successful.
Definition: IpSocket.hpp:30
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.
Fw::Buffer getBuffer() override
returns a buffer to fill with data
SocketIpStatus configureSend(const char *hostname, const U16 port, const U32 send_timeout_seconds=SOCKET_SEND_TIMEOUT_SECONDS, const U32 send_timeout_microseconds=SOCKET_SEND_TIMEOUT_MICROSECONDS)
Configures the Udp send settings but does not open the connection.
Operation worked as expected.
bool isConnected_ready_OutputPort(FwIndexType portNum)
SocketIpStatus configureSend(const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the udp socket for outgoing transmissions
Definition: UdpSocket.cpp:57
FwSizeType getSize() const
Definition: Buffer.cpp:60
IpSocket & getSocketHandler() override
returns a reference to the socket handler
PlatformIndexType FwIndexType
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status) override
sends a buffer to be filled with data
Auto-generated base for Udp component.
#define FW_ASSERT_NO_OVERFLOW(value, T)
Definition: Assert.hpp:49
SocketIpStatus
Status enumeration for socket return values.
Definition: IpSocket.hpp:29
void ready_out(FwIndexType portNum)
Invoke output port ready.
~UdpComponentImpl()
Destroy the component.
Helper base-class for setting up Berkeley sockets.
Definition: IpSocket.hpp:57
No data available or read operation would block.
Definition: IpSocket.hpp:45
#define FW_ASSERT(...)
Definition: Assert.hpp:14