mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
* Initial FprimeFramer and FprimePacketizer * Code clarity + set up UTs * Rework ComQueue and ComStub to use DataWithContext * Add packets to RefPackets.fppi * Fix ComQueue tests * Add hotfix to FileDownlink instead of ComQueue * Fix cancelPacket as well * Fix ComQueue UTs by removing hotfix * Refactor DataWithContext to use an FPP object for context instead of Fw.Buffer * Touch up testing * Add docs * more docs * More docs * Rework buffer deallocation pattern to pass-through ComQueue * Update ComStub UTs * Restore original FileDownlink.cpp * Formatting tweak * Update deprecated getSerializeRepr() calls * deserialization methods * Fix spelling * add cast for safety * CMakefile change * Bump ComQueue depth * Update RPI deployment with new Downlink stack * Rename comQueueIn port to comPktQueueIn * Fix comQueueIn to comPktQueueIn change * Remove legacy Svc.Framer * Fix CMake UTs * Fix RPI topology config * Fix FprimeProtocol.fpp module * Fix namespacing * Use const reference for FrameContext port * Review comments EXCEPT port passback refactor * Rework ComStub with new ByteStream * New ByteStream - ComInterface model * Rework TcpClient / TcpServer with new bytestream * Adapt UDP component for new ByteStream * Adapt FrameAccumulator for new ByteStream * Adapt FprimeFramer for new ByteStream * Update Ref topology with new ByteStream model * Remove all legacy deallocates from Drivers; reintroduce DEPRECATED model types * Fix spelling and include error * More spelling.... * RPI and RpiDemo fixes * Fix conversion warning on RPI * static_cast for short int on RPI * Standardize port names * Remove legacy Drv types and merge RECV/SEND enum type, delete StreamCrossover * Update SDDs * Update SDDs * Fix ComInterface <-> Framer interfaction, clarify comments and fix annotations * Switch ComStub from ASSERT to log failure and return buffer * Add history size check + clarify test handler overrides * Fix RPI topology to wire comStub on Uplink * Rename comm to comDriver in RPI topology * Update communication adapter interface docs
98 lines
3.6 KiB
C++
98 lines
3.6 KiB
C++
// ======================================================================
|
|
// \title TcpClientComponentImpl.cpp
|
|
// \author mstarch
|
|
// \brief cpp file for TcpClientComponentImpl component implementation class
|
|
//
|
|
// \copyright
|
|
// Copyright 2009-2020, by the California Institute of Technology.
|
|
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
|
// acknowledged.
|
|
//
|
|
// ======================================================================
|
|
|
|
#include <limits>
|
|
#include <Drv/TcpClient/TcpClientComponentImpl.hpp>
|
|
#include <Fw/FPrimeBasicTypes.hpp>
|
|
#include "Fw/Types/Assert.hpp"
|
|
|
|
|
|
namespace Drv {
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Construction, initialization, and destruction
|
|
// ----------------------------------------------------------------------
|
|
|
|
TcpClientComponentImpl::TcpClientComponentImpl(const char* const compName)
|
|
: TcpClientComponentBase(compName) {}
|
|
|
|
SocketIpStatus TcpClientComponentImpl::configure(const char* hostname,
|
|
const U16 port,
|
|
const U32 send_timeout_seconds,
|
|
const U32 send_timeout_microseconds,
|
|
FwSizeType buffer_size) {
|
|
|
|
// Check that ensures the configured buffer size fits within the limits fixed-width type, U32
|
|
FW_ASSERT(buffer_size <= std::numeric_limits<U32>::max(), static_cast<FwAssertArgType>(buffer_size));
|
|
m_allocation_size = buffer_size; // Store the buffer size
|
|
return m_socket.configure(hostname, port, send_timeout_seconds, send_timeout_microseconds);
|
|
}
|
|
|
|
TcpClientComponentImpl::~TcpClientComponentImpl() {}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Implementations for socket read task virtual methods
|
|
// ----------------------------------------------------------------------
|
|
|
|
IpSocket& TcpClientComponentImpl::getSocketHandler() {
|
|
return m_socket;
|
|
}
|
|
|
|
Fw::Buffer TcpClientComponentImpl::getBuffer() {
|
|
return allocate_out(0, static_cast<U32>(m_allocation_size));
|
|
}
|
|
|
|
void TcpClientComponentImpl::sendBuffer(Fw::Buffer buffer, SocketIpStatus status) {
|
|
Drv::ByteStreamStatus recvStatus = ByteStreamStatus::OTHER_ERROR;
|
|
if (status == SOCK_SUCCESS) {
|
|
recvStatus = ByteStreamStatus::OP_OK;
|
|
}
|
|
else if (status == SOCK_NO_DATA_AVAILABLE) {
|
|
recvStatus = ByteStreamStatus::RECV_NO_DATA;
|
|
}
|
|
else {
|
|
recvStatus = ByteStreamStatus::OTHER_ERROR;
|
|
}
|
|
this->recv_out(0, buffer, recvStatus);
|
|
}
|
|
|
|
void TcpClientComponentImpl::connected() {
|
|
if (isConnected_ready_OutputPort(0)) {
|
|
this->ready_out(0);
|
|
}
|
|
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Handler implementations for user-defined typed input ports
|
|
// ----------------------------------------------------------------------
|
|
|
|
void TcpClientComponentImpl::send_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
|
|
Drv::SocketIpStatus status = send(fwBuffer.getData(), fwBuffer.getSize());
|
|
Drv::ByteStreamStatus returnStatus;
|
|
switch (status) {
|
|
case SOCK_INTERRUPTED_TRY_AGAIN:
|
|
returnStatus = ByteStreamStatus::SEND_RETRY;
|
|
break;
|
|
case SOCK_SUCCESS:
|
|
returnStatus = ByteStreamStatus::OP_OK;
|
|
break;
|
|
default:
|
|
returnStatus = ByteStreamStatus::OTHER_ERROR;
|
|
break;
|
|
}
|
|
// Return the buffer and status to the caller
|
|
this->dataReturnOut_out(0, fwBuffer, returnStatus);
|
|
}
|
|
|
|
} // end namespace Drv
|