From b5a14bb9dfbb57dbfcc89c8fab19a244c5396598 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 21 Mar 2021 13:02:14 +0100 Subject: [PATCH] deleted old linux code --- osal/common/UdpTcPollingTask.cpp | 172 +++++++++++++++------------- osal/common/UdpTcPollingTask.h | 4 +- osal/common/UdpTmTcBridge.cpp | 14 ++- osal/linux/TcUnixUdpPollingTask.cpp | 152 ------------------------ osal/linux/TcUnixUdpPollingTask.h | 67 ----------- osal/linux/TmTcUnixUdpBridge.cpp | 167 --------------------------- osal/linux/TmTcUnixUdpBridge.h | 53 --------- osal/linux/tcpipHelpers.cpp | 2 +- osal/linux/tcpipHelpers.h | 14 --- 9 files changed, 102 insertions(+), 543 deletions(-) delete mode 100644 osal/linux/TcUnixUdpPollingTask.cpp delete mode 100644 osal/linux/TcUnixUdpPollingTask.h delete mode 100644 osal/linux/TmTcUnixUdpBridge.cpp delete mode 100644 osal/linux/TmTcUnixUdpBridge.h delete mode 100644 osal/linux/tcpipHelpers.h diff --git a/osal/common/UdpTcPollingTask.cpp b/osal/common/UdpTcPollingTask.cpp index 3d51e118..bace593f 100644 --- a/osal/common/UdpTcPollingTask.cpp +++ b/osal/common/UdpTcPollingTask.cpp @@ -18,27 +18,27 @@ #define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0 UdpTcPollingTask::UdpTcPollingTask(object_id_t objectId, - object_id_t tmtcUnixUdpBridge, size_t frameSize, - double timeoutSeconds): SystemObject(objectId), - tmtcBridgeId(tmtcUnixUdpBridge) { - if(frameSize > 0) { - this->frameSize = frameSize; - } - else { - this->frameSize = DEFAULT_MAX_FRAME_SIZE; - } + object_id_t tmtcUnixUdpBridge, size_t maxRecvSize, + double timeoutSeconds): SystemObject(objectId), + tmtcBridgeId(tmtcUnixUdpBridge) { + if(frameSize > 0) { + this->frameSize = frameSize; + } + else { + this->frameSize = DEFAULT_MAX_RECV_SIZE; + } - /* Set up reception buffer with specified frame size. + /* Set up reception buffer with specified frame size. For now, it is assumed that only one frame is held in the buffer! */ - receptionBuffer.reserve(this->frameSize); - receptionBuffer.resize(this->frameSize); + receptionBuffer.reserve(this->frameSize); + receptionBuffer.resize(this->frameSize); - if(timeoutSeconds == -1) { - receptionTimeout = DEFAULT_TIMEOUT; - } - else { - receptionTimeout = timevalOperations::toTimeval(timeoutSeconds); - } + if(timeoutSeconds == -1) { + receptionTimeout = DEFAULT_TIMEOUT; + } + else { + receptionTimeout = timevalOperations::toTimeval(timeoutSeconds); + } } UdpTcPollingTask::~UdpTcPollingTask() {} @@ -48,120 +48,130 @@ ReturnValue_t UdpTcPollingTask::performOperation(uint8_t opCode) { struct sockaddr senderAddress; socklen_t senderAddressSize = sizeof(senderAddress); - /* Poll for new UDP datagrams in permanent loop. */ - while(true) { - int bytesReceived = recvfrom( - this->serverSocket, - reinterpret_cast(receptionBuffer.data()), - frameSize, - receptionFlags, - &senderAddress, - &senderAddressSize - ); - if(bytesReceived == SOCKET_ERROR) { - /* Handle error */ + /* Poll for new UDP datagrams in permanent loop. */ + while(true) { + int bytesReceived = recvfrom( + this->serverSocket, + reinterpret_cast(receptionBuffer.data()), + frameSize, + receptionFlags, + &senderAddress, + &senderAddressSize + ); + if(bytesReceived == SOCKET_ERROR) { + /* Handle error */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "UdpTcPollingTask::performOperation: Reception error." << std::endl; + sif::error << "UdpTcPollingTask::performOperation: Reception error." << std::endl; #endif - tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::RECVFROM_CALL, 1000); - continue; - } + tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::RECVFROM_CALL, 1000); + continue; + } #if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1 - sif::debug << "UdpTcPollingTask::performOperation: " << bytesReceived << - " bytes received" << std::endl; + sif::debug << "UdpTcPollingTask::performOperation: " << bytesReceived << + " bytes received" << std::endl; #endif - ReturnValue_t result = handleSuccessfullTcRead(bytesReceived); - if(result != HasReturnvaluesIF::RETURN_FAILED) { + ReturnValue_t result = handleSuccessfullTcRead(bytesReceived); + if(result != HasReturnvaluesIF::RETURN_FAILED) { - } - tmtcBridge->checkAndSetClientAddress(senderAddress); - } - return HasReturnvaluesIF::RETURN_OK; + } + tmtcBridge->checkAndSetClientAddress(senderAddress); + } + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t UdpTcPollingTask::handleSuccessfullTcRead(size_t bytesRead) { - store_address_t storeId; + store_address_t storeId; #if FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1 arrayprinter::print(receptionBuffer.data(), bytesRead); #endif - ReturnValue_t result = tcStore->addData(&storeId, receptionBuffer.data(), bytesRead); - if (result != HasReturnvaluesIF::RETURN_OK) { + ReturnValue_t result = tcStore->addData(&storeId, receptionBuffer.data(), bytesRead); + if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning<< "UdpTcPollingTask::transferPusToSoftwareBus: Data storage failed." << - std::endl; - sif::warning << "Packet size: " << bytesRead << std::endl; + sif::warning<< "UdpTcPollingTask::transferPusToSoftwareBus: Data storage failed." << + std::endl; + sif::warning << "Packet size: " << bytesRead << std::endl; #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_VERBOSE_LEVEL >= 1 */ - return HasReturnvaluesIF::RETURN_FAILED; - } + return HasReturnvaluesIF::RETURN_FAILED; + } - TmTcMessage message(storeId); + TmTcMessage message(storeId); - result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message); - if (result != HasReturnvaluesIF::RETURN_OK) { + result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message); + if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "UdpTcPollingTask::handleSuccessfullTcRead: " - " Sending message to queue failed" << std::endl; + sif::warning << "UdpTcPollingTask::handleSuccessfullTcRead: " + " Sending message to queue failed" << std::endl; #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_VERBOSE_LEVEL >= 1 */ - tcStore->deleteData(storeId); - } - return result; + tcStore->deleteData(storeId); + } + return result; } ReturnValue_t UdpTcPollingTask::initialize() { - tcStore = objectManager->get(objects::TC_STORE); - if (tcStore == nullptr) { + tcStore = objectManager->get(objects::TC_STORE); + if (tcStore == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "UdpTcPollingTask::initialize: TC store uninitialized!" << std::endl; + sif::error << "UdpTcPollingTask::initialize: TC store uninitialized!" << std::endl; #endif - return ObjectManagerIF::CHILD_INIT_FAILED; - } + return ObjectManagerIF::CHILD_INIT_FAILED; + } - tmtcBridge = objectManager->get(tmtcBridgeId); - if(tmtcBridge == nullptr) { + tmtcBridge = objectManager->get(tmtcBridgeId); + if(tmtcBridge == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "UdpTcPollingTask::initialize: Invalid TMTC bridge object!" << - std::endl; + sif::error << "UdpTcPollingTask::initialize: Invalid TMTC bridge object!" << + std::endl; #endif - return ObjectManagerIF::CHILD_INIT_FAILED; - } + return ObjectManagerIF::CHILD_INIT_FAILED; + } ReturnValue_t result = TcpIpBase::initialize(); if(result != HasReturnvaluesIF::RETURN_OK) { return result; } - return HasReturnvaluesIF::RETURN_OK; + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t UdpTcPollingTask::initializeAfterTaskCreation() { - /* Initialize the destination after task creation. This ensures + /* Initialize the destination after task creation. This ensures that the destination has already been set in the TMTC bridge. */ - targetTcDestination = tmtcBridge->getRequestQueue(); - /* The server socket is set up in the bridge intialization. Calling this function here + targetTcDestination = tmtcBridge->getRequestQueue(); + /* The server socket is set up in the bridge intialization. Calling this function here ensures that it is set up regardless of which class was initialized first */ this->serverSocket = tmtcBridge->serverSocket; - return HasReturnvaluesIF::RETURN_OK; + return HasReturnvaluesIF::RETURN_OK; } void UdpTcPollingTask::setTimeout(double timeoutSeconds) { #ifdef _WIN32 - DWORD timeoutMs = timeoutSeconds * 1000.0; - int result = setsockopt(serverUdpSocket, SOL_SOCKET, SO_RCVTIMEO, - reinterpret_cast(&timeoutMs), sizeof(DWORD)); - if(result == -1) { + DWORD timeoutMs = timeoutSeconds * 1000.0; + int result = setsockopt(serverUdpSocket, SOL_SOCKET, SO_RCVTIMEO, + reinterpret_cast(&timeoutMs), sizeof(DWORD)); + if(result == -1) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TcWinUdpPollingTask::TcSocketPollingTask: Setting " - "receive timeout failed with " << strerror(errno) << std::endl; + sif::error << "TcWinUdpPollingTask::TcSocketPollingTask: Setting " + "receive timeout failed with " << strerror(errno) << std::endl; #endif - } + } #elif defined(__unix__) + timeval tval; + tval = timevalOperations::toTimeval(timeoutSeconds); + int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO, + &tval, sizeof(receptionTimeout)); + if(result == -1) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "TcSocketPollingTask::TcSocketPollingTask: Setting " + "receive timeout failed with " << strerror(errno) << std::endl; +#endif + } #endif } diff --git a/osal/common/UdpTcPollingTask.h b/osal/common/UdpTcPollingTask.h index 4df62b94..ae1c4c44 100644 --- a/osal/common/UdpTcPollingTask.h +++ b/osal/common/UdpTcPollingTask.h @@ -23,12 +23,12 @@ class UdpTcPollingTask: public ExecutableObjectIF { friend class TmTcWinUdpBridge; public: - static constexpr size_t DEFAULT_MAX_FRAME_SIZE = 2048; + static constexpr size_t DEFAULT_MAX_RECV_SIZE = 1500; //! 0.5 default milliseconds timeout for now. static constexpr timeval DEFAULT_TIMEOUT = {0, 500}; UdpTcPollingTask(object_id_t objectId, object_id_t tmtcUnixUdpBridge, - size_t frameSize = 0, double timeoutSeconds = -1); + size_t maxRecvSize = 0, double timeoutSeconds = -1); virtual~ UdpTcPollingTask(); /** diff --git a/osal/common/UdpTmTcBridge.cpp b/osal/common/UdpTmTcBridge.cpp index a8975c0e..ae74e94b 100644 --- a/osal/common/UdpTmTcBridge.cpp +++ b/osal/common/UdpTmTcBridge.cpp @@ -70,12 +70,14 @@ ReturnValue_t UdpTmTcBridge::initialize() { hints.ai_family = AF_INET; hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = IPPROTO_UDP; -#ifdef _WIN32 - /* See: - https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo - for information about AI_PASSIVE. */ - hints.ai_flags = AI_PASSIVE; -#endif +//#ifdef _WIN32 +// /* See: +// https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo +// and +// +// for information about AI_PASSIVE. */ +// hints.ai_flags = AI_PASSIVE; +//#endif /* Set up UDP socket: https://en.wikipedia.org/wiki/Getaddrinfo diff --git a/osal/linux/TcUnixUdpPollingTask.cpp b/osal/linux/TcUnixUdpPollingTask.cpp deleted file mode 100644 index ec3687b9..00000000 --- a/osal/linux/TcUnixUdpPollingTask.cpp +++ /dev/null @@ -1,152 +0,0 @@ -//#include "TcUnixUdpPollingTask.h" -//#include "tcpipHelpers.h" -// -//#include "../../globalfunctions/arrayprinter.h" -// -//#define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0 -// -//TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId, -// object_id_t tmtcUnixUdpBridge, size_t frameSize, -// double timeoutSeconds): SystemObject(objectId), -// tmtcBridgeId(tmtcUnixUdpBridge) { -// -// if(frameSize > 0) { -// this->frameSize = frameSize; -// } -// else { -// this->frameSize = DEFAULT_MAX_FRAME_SIZE; -// } -// -// /* Set up reception buffer with specified frame size. -// For now, it is assumed that only one frame is held in the buffer! */ -// receptionBuffer.reserve(this->frameSize); -// receptionBuffer.resize(this->frameSize); -// -// if(timeoutSeconds == -1) { -// receptionTimeout = DEFAULT_TIMEOUT; -// } -// else { -// receptionTimeout = timevalOperations::toTimeval(timeoutSeconds); -// } -//} -// -//TcUnixUdpPollingTask::~TcUnixUdpPollingTask() {} -// -//ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) { -// /* Sender Address is cached here. */ -// struct sockaddr_in senderAddress; -// socklen_t senderAddressSize = sizeof(senderAddress); -// -// /* Poll for new UDP datagrams in permanent loop. */ -// while(true) { -// ssize_t bytesReceived = recvfrom( -// serverUdpSocket, -// receptionBuffer.data(), -// frameSize, -// receptionFlags, -// reinterpret_cast(&senderAddress), -// &senderAddressSize -// ); -// if(bytesReceived < 0) { -// /* Handle error */ -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::error << "TcSocketPollingTask::performOperation: Reception error." << std::endl; -//#endif -// tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::RECVFROM_CALL, 500); -// continue; -// } -//#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1 -// sif::debug << "TcSocketPollingTask::performOperation: " << bytesReceived -// << " bytes received" << std::endl; -//#endif -// -// ReturnValue_t result = handleSuccessfullTcRead(bytesReceived); -// if(result != HasReturnvaluesIF::RETURN_FAILED) { -// -// } -// tmtcBridge->checkAndSetClientAddress(senderAddress); -// } -// return HasReturnvaluesIF::RETURN_OK; -//} -// -// -//ReturnValue_t TcUnixUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) { -// store_address_t storeId; -// -//#if FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1 -// arrayprinter::print(receptionBuffer.data(), bytesRead); -//#endif -// -// ReturnValue_t result = tcStore->addData(&storeId, receptionBuffer.data(), bytesRead); -// if (result != HasReturnvaluesIF::RETURN_OK) { -//#if FSFW_VERBOSE_LEVEL >= 1 -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::error << "TcUnixUdpPollingTask::handleSuccessfullTcRead: Data " -// "storage failed" << std::endl; -// sif::error << "Packet size: " << bytesRead << std::endl; -//#else -//#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ -//#endif /* FSFW_VERBOSE_LEVEL >= 1 */ -// return HasReturnvaluesIF::RETURN_FAILED; -// } -// -// TmTcMessage message(storeId); -// -// result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message); -// if (result != HasReturnvaluesIF::RETURN_OK) { -//#if FSFW_VERBOSE_LEVEL >= 1 -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::error << "TcUnixUdpPollingTask::handleSuccessfullTcRead: Sending message to queue " -// "failed" << std::endl; -//#else -//#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ -//#endif /* FSFW_VERBOSE_LEVEL >= 1 */ -// tcStore->deleteData(storeId); -// } -// return result; -//} -// -//ReturnValue_t TcUnixUdpPollingTask::initialize() { -// tcStore = objectManager->get(objects::TC_STORE); -// if (tcStore == nullptr) { -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::error << "TcSerialPollingTask::initialize: TC Store uninitialized!" -// << std::endl; -//#endif -// return ObjectManagerIF::CHILD_INIT_FAILED; -// } -// -// tmtcBridge = objectManager->get(tmtcBridgeId); -// if(tmtcBridge == nullptr) { -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::error << "TcSocketPollingTask::TcSocketPollingTask: Invalid" -// " TMTC bridge object!" << std::endl; -//#endif -// return ObjectManagerIF::CHILD_INIT_FAILED; -// } -// -// return HasReturnvaluesIF::RETURN_OK; -//} -// -//ReturnValue_t TcUnixUdpPollingTask::initializeAfterTaskCreation() { -// /* Initialize the destination after task creation. This ensures -// that the destination has already been set in the TMTC bridge. */ -// targetTcDestination = tmtcBridge->getRequestQueue(); -// /* The server socket is set up in the bridge intialization. Calling this function here -// ensures that it is set up properly in any case*/ -// serverUdpSocket = tmtcBridge->serverSocket; -// return HasReturnvaluesIF::RETURN_OK; -//} -// -//void TcUnixUdpPollingTask::setTimeout(double timeoutSeconds) { -// timeval tval; -// tval = timevalOperations::toTimeval(timeoutSeconds); -// int result = setsockopt(serverUdpSocket, SOL_SOCKET, SO_RCVTIMEO, -// &tval, sizeof(receptionTimeout)); -// if(result == -1) { -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::error << "TcSocketPollingTask::TcSocketPollingTask: Setting " -// "receive timeout failed with " << strerror(errno) << std::endl; -//#endif -// } -//} diff --git a/osal/linux/TcUnixUdpPollingTask.h b/osal/linux/TcUnixUdpPollingTask.h deleted file mode 100644 index 1040d1a2..00000000 --- a/osal/linux/TcUnixUdpPollingTask.h +++ /dev/null @@ -1,67 +0,0 @@ -//#ifndef FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ -//#define FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ -// -//#include "../../objectmanager/SystemObject.h" -//#include "../../osal/linux/TmTcUnixUdpBridge.h" -//#include "../../tasks/ExecutableObjectIF.h" -// -//#include -//#include -// -///** -// * @brief This class can be used to implement the polling of a Unix socket, -// * using UDP for now. -// * @details -// * The task will be blocked while the specified number of bytes has not been -// * received, so TC reception is handled inside a separate task. -// * This class caches the IP address of the sender. It is assumed there -// * is only one sender for now. -// */ -//class TcUnixUdpPollingTask: public SystemObject, -// public ExecutableObjectIF { -// friend class TmTcUnixUdpBridge; -//public: -// static constexpr size_t DEFAULT_MAX_FRAME_SIZE = 2048; -// //! 0.5 default milliseconds timeout for now. -// static constexpr timeval DEFAULT_TIMEOUT = {.tv_sec = 0, .tv_usec = 500}; -// -// TcUnixUdpPollingTask(object_id_t objectId, object_id_t tmtcUnixUdpBridge, -// size_t frameSize = 0, double timeoutSeconds = -1); -// virtual~ TcUnixUdpPollingTask(); -// -// /** -// * Turn on optional timeout for UDP polling. In the default mode, -// * the receive function will block until a packet is received. -// * @param timeoutSeconds -// */ -// void setTimeout(double timeoutSeconds); -// -// virtual ReturnValue_t performOperation(uint8_t opCode) override; -// virtual ReturnValue_t initialize() override; -// virtual ReturnValue_t initializeAfterTaskCreation() override; -// -//protected: -// StorageManagerIF* tcStore = nullptr; -// -//private: -// //! TMTC bridge is cached. -// object_id_t tmtcBridgeId = objects::NO_OBJECT; -// TmTcUnixUdpBridge* tmtcBridge = nullptr; -// MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE; -// -// //! Reception flags: https://linux.die.net/man/2/recvfrom. -// int receptionFlags = 0; -// -// //! Server socket, which is member of TMTC bridge and is assigned in -// //! constructor -// int serverUdpSocket = 0; -// -// std::vector receptionBuffer; -// -// size_t frameSize = 0; -// timeval receptionTimeout; -// -// ReturnValue_t handleSuccessfullTcRead(size_t bytesRead); -//}; -// -//#endif /* FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ */ diff --git a/osal/linux/TmTcUnixUdpBridge.cpp b/osal/linux/TmTcUnixUdpBridge.cpp deleted file mode 100644 index c0cd6877..00000000 --- a/osal/linux/TmTcUnixUdpBridge.cpp +++ /dev/null @@ -1,167 +0,0 @@ -//#include "TmTcUnixUdpBridge.h" -//#include "tcpipHelpers.h" -//#include "../../serviceinterface/ServiceInterface.h" -//#include "../../ipc/MutexGuard.h" -// -//#include -//#include -//#include -// -//#include -// -////! Debugging preprocessor define. -//#define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0 -// -//const std::string TmTcUnixUdpBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_UDP_SERVER_PORT; -// -//TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId, object_id_t tcDestination, -// object_id_t tmStoreId, object_id_t tcStoreId, std::string udpServerPort): -// TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) { -// if(udpServerPort == "") { -// this->udpServerPort = DEFAULT_UDP_SERVER_PORT; -// } -// else { -// this->udpServerPort = udpServerPort; -// } -// -// mutex = MutexFactory::instance()->createMutex(); -// communicationLinkUp = false; -//} -// -//ReturnValue_t TmTcUnixUdpBridge::initialize() { -// using namespace tcpip; -// -// ReturnValue_t result = TmTcBridge::initialize(); -// if(result != HasReturnvaluesIF::RETURN_OK) { -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::error << "TmTcUnixUdpBridge::initialize: TmTcBridge initialization failed!" -// << std::endl; -//#endif -// return result; -// } -// -// struct addrinfo *addrResult = nullptr; -// struct addrinfo hints; -// -// std::memset(&hints, 0, sizeof(hints)); -// hints.ai_family = AF_INET; -// hints.ai_socktype = SOCK_DGRAM; -// hints.ai_protocol = IPPROTO_UDP; -// hints.ai_flags = AI_PASSIVE; -// -// /* Set up UDP socket: -// https://man7.org/linux/man-pages/man3/getaddrinfo.3.html -// Passing nullptr as the first parameter and specifying AI_PASSIVE in hints will cause -// getaddrinfo to assign the address 0.0.0.0 (any address) */ -// int retval = getaddrinfo(nullptr, udpServerPort.c_str(), &hints, &addrResult); -// if (retval != 0) { -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::warning << "TmTcWinUdpBridge::TmTcWinUdpBridge: Retrieving address info failed!" << -// std::endl; -//#endif -// return HasReturnvaluesIF::RETURN_FAILED; -// } -// -// /* Set up UDP socket: https://man7.org/linux/man-pages/man7/ip.7.html */ -// serverSocket = socket(addrResult->ai_family, addrResult->ai_socktype, addrResult->ai_protocol); -// if(serverSocket < 0) { -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not open UDP socket!" << -// std::endl; -//#else -// sif::printError("TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not open UDP socket!\n"); -//#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ -// freeaddrinfo(addrResult); -// handleError(Protocol::UDP, ErrorSources::SOCKET_CALL); -// return HasReturnvaluesIF::RETURN_FAILED; -// } -// -// retval = bind(serverSocket, addrResult->ai_addr, static_cast(addrResult->ai_addrlen)); -// if(retval != 0) { -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::warning << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not bind " -// "local port (" << udpServerPort << ") to server socket!" << std::endl; -//#endif -// freeaddrinfo(addrResult); -// handleError(Protocol::UDP, ErrorSources::BIND_CALL); -// return HasReturnvaluesIF::RETURN_FAILED; -// } -// -// return HasReturnvaluesIF::RETURN_OK; -//} -// -//TmTcUnixUdpBridge::~TmTcUnixUdpBridge() { -// if(mutex != nullptr) { -// MutexFactory::instance()->deleteMutex(mutex); -// } -// close(serverSocket); -//} -// -//ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { -// int flags = 0; -// -// /* The target address can be set by different threads so this lock ensures thread-safety */ -// MutexGuard lock(mutex, timeoutType, mutexTimeoutMs); -// -// if(ipAddrAnySet){ -// clientAddress.sin_addr.s_addr = htons(INADDR_ANY); -// clientAddressLen = sizeof(clientAddress); -// } -// -//#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1 -// char ipAddress [15]; -// sif::debug << "IP Address Sender: "<< -// inet_ntop(AF_INET,&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; -//#endif -// -// ssize_t bytesSent = sendto( -// serverSocket, -// data, -// dataLen, -// flags, -// reinterpret_cast(&clientAddress), -// clientAddressLen -// ); -// if(bytesSent < 0) { -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::warning << "TmTcUnixUdpBridge::sendTm: Send operation failed." << std::endl; -//#endif -// tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::SENDTO_CALL); -// } -// -//#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1 -// sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were" -// " sent." << std::endl; -//#endif -// -// return HasReturnvaluesIF::RETURN_OK; -//} -// -//void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in& newAddress) { -// /* The target address can be set by different threads so this lock ensures thread-safety */ -// MutexGuard lock(mutex, timeoutType, mutexTimeoutMs); -// -//#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1 -// char ipAddress [15]; -// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET, -// &newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; -// sif::debug << "IP Address Old: " << inet_ntop(AF_INET, -// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; -//#endif -// registerCommConnect(); -// -// /* Set new IP address to reply to. */ -// clientAddress = newAddress; -// clientAddressLen = sizeof(clientAddress); -//} -// -//void TmTcUnixUdpBridge::setMutexProperties(MutexIF::TimeoutType timeoutType, -// dur_millis_t timeoutMs) { -// this->timeoutType = timeoutType; -// this->mutexTimeoutMs = timeoutMs; -//} -// -//void TmTcUnixUdpBridge::setClientAddressToAny(bool ipAddrAnySet){ -// this->ipAddrAnySet = ipAddrAnySet; -//} -// diff --git a/osal/linux/TmTcUnixUdpBridge.h b/osal/linux/TmTcUnixUdpBridge.h deleted file mode 100644 index b4b00950..00000000 --- a/osal/linux/TmTcUnixUdpBridge.h +++ /dev/null @@ -1,53 +0,0 @@ -//#ifndef FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ -//#define FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ -// -//#include "../../tmtcservices/AcceptsTelecommandsIF.h" -//#include "../../tmtcservices/TmTcBridge.h" -//#include -//#include -//#include -// -//class TmTcUnixUdpBridge: -// public TmTcBridge { -// friend class TcUnixUdpPollingTask; -//public: -// -// /* The ports chosen here should not be used by any other process. -// List of used ports on Linux: /etc/services */ -// static const std::string DEFAULT_UDP_SERVER_PORT; -// -// TmTcUnixUdpBridge(object_id_t objectId, object_id_t tcDestination, -// object_id_t tmStoreId, object_id_t tcStoreId, -// std::string serverPort = ""); -// virtual~ TmTcUnixUdpBridge(); -// -// /** -// * Set properties of internal mutex. -// */ -// void setMutexProperties(MutexIF::TimeoutType timeoutType, dur_millis_t timeoutMs); -// -// ReturnValue_t initialize() override; -// -// void checkAndSetClientAddress(sockaddr_in& clientAddress); -// -// void setClientAddressToAny(bool ipAddrAnySet); -// -//protected: -// virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override; -// -//private: -// int serverSocket = 0; -// std::string udpServerPort; -// -// struct sockaddr_in clientAddress; -// socklen_t clientAddressLen = 0; -// -// bool ipAddrAnySet = false; -// -// //! Access to the client address is mutex protected as it is set by another task. -// MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; -// dur_millis_t mutexTimeoutMs = 20; -// MutexIF* mutex; -//}; -// -//#endif /* FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ */ diff --git a/osal/linux/tcpipHelpers.cpp b/osal/linux/tcpipHelpers.cpp index 1c380769..4c1b9a78 100644 --- a/osal/linux/tcpipHelpers.cpp +++ b/osal/linux/tcpipHelpers.cpp @@ -1,4 +1,4 @@ -#include "tcpipHelpers.h" +#include "../common/tcpipHelpers.h" #include "../../tasks/TaskFactory.h" diff --git a/osal/linux/tcpipHelpers.h b/osal/linux/tcpipHelpers.h deleted file mode 100644 index 6b337c62..00000000 --- a/osal/linux/tcpipHelpers.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef FSFW_OSAL_LINUX_TCPIPHELPERS_H_ -#define FSFW_OSAL_LINUX_TCPIPHELPERS_H_ - -#include "../../timemanager/clockDefinitions.h" -#include "../common/tcpipCommon.h" - -namespace tcpip { - - -void handleError(Protocol protocol, ErrorSources errorSrc, dur_millis_t sleepDuration = 0); - -} - -#endif /* FSFW_OSAL_LINUX_TCPIPHELPERS_H_ */