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 
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 
40 
42  return this->m_socket.getRecvPort();
43 }
44 
45 // ----------------------------------------------------------------------
46 // Implementations for socket read task virtual methods
47 // ----------------------------------------------------------------------
48 
50  return m_socket;
51 }
52 
54  return allocate_out(0, m_allocation_size);
55 }
56 
59  if (status == SOCK_SUCCESS) {
60  recvStatus = ByteStreamStatus::OP_OK;
61  } else if (status == SOCK_NO_DATA_AVAILABLE) {
62  recvStatus = ByteStreamStatus::RECV_NO_DATA;
63  } else {
64  recvStatus = ByteStreamStatus::OTHER_ERROR;
65  }
66  this->recv_out(0, buffer, recvStatus);
67 }
68 
71  this->ready_out(0);
72  }
73 }
74 
75 // ----------------------------------------------------------------------
76 // Handler implementations for user-defined typed input ports
77 // ----------------------------------------------------------------------
78 
79 Drv::ByteStreamStatus UdpComponentImpl::send_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
80  Drv::SocketIpStatus status = send(fwBuffer.getData(), fwBuffer.getSize());
81  Drv::ByteStreamStatus returnStatus;
82  switch (status) {
84  returnStatus = ByteStreamStatus::SEND_RETRY;
85  break;
86  case SOCK_DISCONNECTED:
87  returnStatus = ByteStreamStatus::SEND_RETRY;
88  break;
89  case SOCK_SUCCESS:
90  returnStatus = ByteStreamStatus::OP_OK;
91  break;
92  default:
93  returnStatus = ByteStreamStatus::OTHER_ERROR;
94  break;
95  }
96  return returnStatus;
97 }
98 
99 void UdpComponentImpl::recvReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) {
100  this->deallocate_out(0, fwBuffer);
101 }
102 
103 } // end namespace Drv
void recv_out(FwIndexType portNum, Fw::Buffer &buffer, const Drv::ByteStreamStatus &status) const
Invoke output port recv.
void ready_out(FwIndexType portNum) const
Invoke output port ready.
U16 getRecvPort()
get the port being received on
U16 getRecvPort()
get the port being received on
Definition: UdpSocket.cpp:92
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 FwSizeType size)
send data to the IP socket from the given buffer
SocketIpStatus configureRecv(const char *const ipv4_address, const U16 port)
configure the udp socket for incoming transmissions
Definition: UdpSocket.cpp:71
U8 * getData() const
Definition: Buffer.cpp:56
Error occurred, retrying may succeed.
UdpComponentImpl(const char *const compName)
construct the TcpClient component.
Receive worked, but there was no data.
void connected() override
called when the IPv4 system has been connected
Status returned by the send call.
SocketIpStatus configureSend(const char *const ipv4_address, 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.
Socket operation successful.
Definition: IpSocket.hpp:30
Fw::Buffer getBuffer() override
returns a buffer to fill with data
SocketIpStatus configureSend(const char *const ipv4_address, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the udp socket for outgoing transmissions
Definition: UdpSocket.cpp:61
Operation worked as expected.
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer) const
Invoke output port deallocate.
FwSizeType getSize() const
Definition: Buffer.cpp:60
IpSocket & getSocketHandler() override
returns a reference to the socket handler
SocketIpStatus configureRecv(const char *const ipv4_address, const U16 port, FwSizeType buffer_size=1024)
Configures the Udp receive settings but does not open the connection.
PlatformIndexType FwIndexType
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status) override
sends a buffer to be filled with data
Fw::Buffer allocate_out(FwIndexType portNum, FwSizeType size) const
Invoke output port allocate.
Auto-generated base for Udp component.
SocketIpStatus
Status enumeration for socket return values.
Definition: IpSocket.hpp:29
~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
bool isConnected_ready_OutputPort(FwIndexType portNum) const