| 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 |
2/2✓ Branch 10 taken 7 times.
✓ Branch 21 taken 7 times.
|
7 | UdpComponentImpl::UdpComponentImpl(const char* const compName) : UdpComponentBase(compName) {} |
| 26 | |||
| 27 | 6 | 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 | 6 | return m_socket.configureSend(ipv4_address, port, send_timeout_seconds, send_timeout_microseconds); | |
| 32 | } | ||
| 33 | |||
| 34 | 4 | SocketIpStatus UdpComponentImpl::configureRecv(const char* const ipv4_address, const U16 port, FwSizeType buffer_size) { | |
| 35 | 4 | m_allocation_size = buffer_size; // Store the buffer size | |
| 36 | 4 | return m_socket.configureRecv(ipv4_address, port); | |
| 37 | } | ||
| 38 | |||
| 39 | 14 | 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 | 934 | IpSocket& UdpComponentImpl::getSocketHandler() { | |
| 50 | 934 | return m_socket; | |
| 51 | } | ||
| 52 | |||
| 53 | 69 | Fw::Buffer UdpComponentImpl::getBuffer() { | |
| 54 | 69 | return allocate_out(0, m_allocation_size); | |
| 55 | } | ||
| 56 | |||
| 57 | 69 | 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 | 69 | FW_ASSERT((status != SOCK_SUCCESS) || (buffer.getData() != nullptr)); | |
| 60 |
1/1✓ Branch 2 taken 69 times.
|
69 | Drv::ByteStreamStatus recvStatus = ByteStreamStatus::OTHER_ERROR; |
| 61 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 56 times.
|
69 | if (status == SOCK_SUCCESS) { |
| 62 |
1/1✓ Branch 2 taken 13 times.
|
13 | recvStatus = ByteStreamStatus::OP_OK; |
| 63 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | } else if (status == SOCK_NO_DATA_AVAILABLE) { |
| 64 |
1/1✓ Branch 2 taken 56 times.
|
56 | recvStatus = ByteStreamStatus::RECV_NO_DATA; |
| 65 | } else { | ||
| 66 | ✗ | recvStatus = ByteStreamStatus::OTHER_ERROR; | |
| 67 | } | ||
| 68 |
1/1✓ Branch 5 taken 69 times.
|
69 | this->recv_out(0, buffer, recvStatus); |
| 69 | 138 | } | |
| 70 | |||
| 71 | 213 | void UdpComponentImpl::connected() { | |
| 72 |
1/2✓ Branch 5 taken 213 times.
✗ Branch 6 not taken.
|
213 | if (isConnected_ready_OutputPort(0)) { |
| 73 | 213 | this->ready_out(0); | |
| 74 | } | ||
| 75 | 213 | } | |
| 76 | |||
| 77 | // ---------------------------------------------------------------------- | ||
| 78 | // Handler implementations for user-defined typed input ports | ||
| 79 | // ---------------------------------------------------------------------- | ||
| 80 | |||
| 81 | 213 | Drv::ByteStreamStatus UdpComponentImpl::send_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) { | |
| 82 | 213 | Drv::SocketIpStatus status = send(fwBuffer.getData(), fwBuffer.getSize()); | |
| 83 | 213 | Drv::ByteStreamStatus returnStatus; | |
| 84 |
1/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 213 times.
✗ Branch 3 not taken.
|
213 | 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 | 213 | case SOCK_SUCCESS: | |
| 92 |
1/1✓ Branch 3 taken 213 times.
|
213 | returnStatus = ByteStreamStatus::OP_OK; |
| 93 | 213 | break; | |
| 94 | ✗ | default: | |
| 95 | ✗ | returnStatus = ByteStreamStatus::OTHER_ERROR; | |
| 96 | ✗ | break; | |
| 97 | } | ||
| 98 | 213 | return returnStatus; | |
| 99 | ✗ | } | |
| 100 | |||
| 101 | 1 | void UdpComponentImpl::recvReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) { | |
| 102 | 1 | this->deallocate_out(0, fwBuffer); | |
| 103 | 1 | } | |
| 104 | |||
| 105 | } // end namespace Drv | ||
| 106 |