F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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 <IpCfg.hpp>
15#include <FpConfig.hpp>
16#include "Fw/Types/Assert.hpp"
17
18
19namespace Drv {
20
21// ----------------------------------------------------------------------
22// Construction, initialization, and destruction
23// ----------------------------------------------------------------------
24
25UdpComponentImpl::UdpComponentImpl(const char* const compName)
26 : ByteStreamDriverModelComponentBase(compName),
28
30 ByteStreamDriverModelComponentBase::init(instance);
31}
32
34 const U16 port,
35 const U32 send_timeout_seconds,
36 const U32 send_timeout_microseconds) {
37 return m_socket.configureSend(hostname, port, send_timeout_seconds, send_timeout_microseconds);
38}
39
40SocketIpStatus UdpComponentImpl::configureRecv(const char* hostname, const U16 port) {
41 return m_socket.configureRecv(hostname, port);
42}
43
45
46// ----------------------------------------------------------------------
47// Implementations for socket read task virtual methods
48// ----------------------------------------------------------------------
49
51 return m_socket;
52}
53
55 return allocate_out(0, 1024);
56}
57
59 Drv::RecvStatus recvStatus = (status == SOCK_SUCCESS) ? RecvStatus::RECV_OK : RecvStatus::RECV_ERROR;
60 this->recv_out(0, buffer, recvStatus);
61}
62
64 if (isConnected_ready_OutputPort(0)) {
65 this->ready_out(0);
66 }
67}
68
69// ----------------------------------------------------------------------
70// Handler implementations for user-defined typed input ports
71// ----------------------------------------------------------------------
72
73Drv::SendStatus UdpComponentImpl::send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
74 Drv::SocketIpStatus status = m_socket.send(fwBuffer.getData(), fwBuffer.getSize());
75 // Always return the buffer
76 deallocate_out(0, fwBuffer);
77 if ((status == SOCK_DISCONNECTED) || (status == SOCK_INTERRUPTED_TRY_AGAIN)) {
78 return SendStatus::SEND_RETRY;
79 } else if (status != SOCK_SUCCESS) {
80 return SendStatus::SEND_ERROR;
81 }
82 return SendStatus::SEND_OK;
83}
84
85Drv::PollStatus UdpComponentImpl::poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
86 FW_ASSERT(0); // It is an error to call this handler on IP drivers
87 return PollStatus::POLL_ERROR;
88}
89
90} // end namespace Drv
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
C++-compatible configuration header for fprime configuration.
Helper base-class for setting up Berkley sockets.
Definition IpSocket.hpp:45
SocketIpStatus send(const U8 *const data, const U32 size)
send data out the IP socket from the given buffer
Definition IpSocket.cpp:138
supports a task to read a given socket adaptation
SocketIpStatus configureRecv(const char *hostname, const U16 port)
Configures the Udp receive settings but does not open the connection.
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status)
sends a buffer to be filled with data
Fw::Buffer getBuffer()
returns a buffer to fill with data
IpSocket & getSocketHandler()
returns a reference to the socket handler
void connected()
called when the IPv4 system has been connected
Drv::PollStatus poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer &fwBuffer)
not supported
~UdpComponentImpl()
Destroy the component.
UdpComponentImpl(const char *const compName)
construct the TcpClient component.
void init(const NATIVE_INT_TYPE instance=0)
Initialize this component.
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.
SocketIpStatus configureRecv(const char *hostname, const U16 port)
configure the udp socket for incoming transmissions
Definition UdpSocket.cpp:67
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:62
U8 * getData() const
Definition Buffer.cpp:60
U32 getSize() const
Definition Buffer.cpp:64
SocketIpStatus
Status enumeration for socket return values.
Definition IpSocket.hpp:23
@ SOCK_SUCCESS
Socket operation successful.
Definition IpSocket.hpp:24
@ SOCK_DISCONNECTED
Failed to read socket with disconnect.
Definition IpSocket.hpp:32
@ SOCK_INTERRUPTED_TRY_AGAIN
Interrupted status for retries.
Definition IpSocket.hpp:30