From e67ff6a937c155659ee49118bf80ad238093cc3b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Mar 2021 23:00:53 +0100 Subject: [PATCH 01/11] cleaner wiretapping handling --- osal/windows/CMakeLists.txt | 15 +++++---- osal/windows/TcWinTcpServer.cpp | 46 ++++++++++++++++++++++++++++ osal/windows/TcWinTcpServer.h | 30 ++++++++++++++++++ osal/windows/TcWinUdpPollingTask.cpp | 33 ++++++++++---------- osal/windows/TcWinUdpPollingTask.h | 6 ++-- osal/windows/TmTcWinUdpBridge.cpp | 40 ++++++++++++------------ osal/windows/TmTcWinUdpBridge.h | 5 ++- 7 files changed, 127 insertions(+), 48 deletions(-) create mode 100644 osal/windows/TcWinTcpServer.cpp create mode 100644 osal/windows/TcWinTcpServer.h diff --git a/osal/windows/CMakeLists.txt b/osal/windows/CMakeLists.txt index b6e76d6a3..889ea3396 100644 --- a/osal/windows/CMakeLists.txt +++ b/osal/windows/CMakeLists.txt @@ -1,11 +1,10 @@ -target_sources(${LIB_FSFW_NAME} - PRIVATE - TcWinUdpPollingTask.cpp - TmTcWinUdpBridge.cpp +target_sources(${LIB_FSFW_NAME} PRIVATE + TcWinUdpPollingTask.cpp + TmTcWinUdpBridge.cpp + TcWinTcpServer.cpp ) -target_link_libraries(${LIB_FSFW_NAME} - PRIVATE - wsock32 - ws2_32 +target_link_libraries(${LIB_FSFW_NAME} PRIVATE + wsock32 + ws2_32 ) \ No newline at end of file diff --git a/osal/windows/TcWinTcpServer.cpp b/osal/windows/TcWinTcpServer.cpp new file mode 100644 index 000000000..aebc0bee1 --- /dev/null +++ b/osal/windows/TcWinTcpServer.cpp @@ -0,0 +1,46 @@ +#include "TcWinTcpServer.h" +#include "../../serviceinterface/ServiceInterface.h" +#include + +TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge): + SystemObject(objectId) { + /* Open TCP socket */ + serverTcpSocket = socket(AF_INET, SOCK_STREAM, 0); + if(serverTcpSocket == 0) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TcWinTcpServer::TcWinTcpServer: Socket creation failed!" << std::endl; + handleSocketError(); +#endif + } + + setsockopt(serverTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST, + &tcpSockOpt, sizeof(tcpSockOpt)); +} + +TcWinTcpServer::~TcWinTcpServer() { +} + +void TcWinTcpServer::handleSocketError() { + int errCode = WSAGetLastError(); + switch(errCode) { + case(WSANOTINITIALISED): { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: WSAStartup" + " call necessary" << std::endl; +#endif + break; + } + default: { + /* + https://docs.microsoft.com/en-us/windows/win32/winsock/ + windows-sockets-error-codes-2 + */ +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TmTcWinUdpBridge::handleSocketError: Error code: " << errCode << std::endl; +#endif + break; + } + } +} + + diff --git a/osal/windows/TcWinTcpServer.h b/osal/windows/TcWinTcpServer.h new file mode 100644 index 000000000..3a17336aa --- /dev/null +++ b/osal/windows/TcWinTcpServer.h @@ -0,0 +1,30 @@ +#ifndef FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_ +#define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_ + +#include "../../objectmanager/SystemObject.h" +#include "../../tasks/ExecutableObjectIF.h" + +#include + +class TcWinTcpServer: + public SystemObject, + public ExecutableObjectIF { +public: + /* The ports chosen here should not be used by any other process. */ + static constexpr uint16_t DEFAULT_TCP_SERVER_PORT = 7301; + static constexpr uint16_t DEFAULT_TCP_CLIENT_PORT = 7302; + + TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge); + virtual~ TcWinTcpServer(); + +private: + + SOCKET serverTcpSocket = 0; + + std::vector receptionBuffer; + int tcpSockOpt = 0; + + void handleSocketError(); +}; + +#endif /* FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_ */ diff --git a/osal/windows/TcWinUdpPollingTask.cpp b/osal/windows/TcWinUdpPollingTask.cpp index f9b3753e6..32c217001 100644 --- a/osal/windows/TcWinUdpPollingTask.cpp +++ b/osal/windows/TcWinUdpPollingTask.cpp @@ -20,8 +20,8 @@ TcWinUdpPollingTask::TcWinUdpPollingTask(object_id_t objectId, 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! + /* 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); @@ -36,7 +36,7 @@ TcWinUdpPollingTask::TcWinUdpPollingTask(object_id_t objectId, TcWinUdpPollingTask::~TcWinUdpPollingTask() {} ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) { - // Poll for new UDP datagrams in permanent loop. + /* Poll for new UDP datagrams in permanent loop. */ while(true) { //! Sender Address is cached here. struct sockaddr_in senderAddress; @@ -46,7 +46,7 @@ ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) { receptionFlags, reinterpret_cast(&senderAddress), &senderAddressSize); if(bytesReceived == SOCKET_ERROR) { - // handle error + /* Handle error */ #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "TcWinUdpPollingTask::performOperation: Reception" " error." << std::endl; @@ -54,9 +54,9 @@ ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) { handleReadError(); continue; } -#if FSFW_CPP_OSTREAM_ENABLED == 1 - //sif::debug << "TcWinUdpPollingTask::performOperation: " << bytesReceived - // << " bytes received" << std::endl; +#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_WIRETAPPING_ENABLED == 1 + sif::debug << "TcWinUdpPollingTask::performOperation: " << bytesReceived << + " bytes received" << std::endl; #endif ReturnValue_t result = handleSuccessfullTcRead(bytesReceived); @@ -74,12 +74,14 @@ ReturnValue_t TcWinUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) { store_address_t storeId; ReturnValue_t result = tcStore->addData(&storeId, receptionBuffer.data(), bytesRead); - // arrayprinter::print(receptionBuffer.data(), bytesRead); +#if FSFW_UDP_WIRETAPPING_ENABLED == 1 + arrayprinter::print(receptionBuffer.data(), bytesRead);# +#endif if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TcSerialPollingTask::transferPusToSoftwareBus: Data " - "storage failed" << std::endl; - sif::error << "Packet size: " << bytesRead << std::endl; + sif::warning<< "TcSerialPollingTask::transferPusToSoftwareBus: Data " + "storage failed" << std::endl; + sif::warning << "Packet size: " << bytesRead << std::endl; #endif return HasReturnvaluesIF::RETURN_FAILED; } @@ -89,8 +91,7 @@ ReturnValue_t TcWinUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) { result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "Serial Polling: Sending message to queue failed" - << std::endl; + sif::warning << "Serial Polling: Sending message to queue failed" << std::endl; #endif tcStore->deleteData(storeId); } @@ -117,9 +118,9 @@ ReturnValue_t TcWinUdpPollingTask::initialize() { } serverUdpSocket = tmtcBridge->serverSocket; -#if FSFW_CPP_OSTREAM_ENABLED == 1 - //sif::info << "TcWinUdpPollingTask::initialize: Server UDP socket " - // << serverUdpSocket << std::endl; +#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_WIRETAPPING_ENABLED == 1 + sif::info << "TcWinUdpPollingTask::initialize: Server UDP socket " << serverUdpSocket << + std::endl; #endif return HasReturnvaluesIF::RETURN_OK; diff --git a/osal/windows/TcWinUdpPollingTask.h b/osal/windows/TcWinUdpPollingTask.h index 063a783e1..8a9cf51f6 100644 --- a/osal/windows/TcWinUdpPollingTask.h +++ b/osal/windows/TcWinUdpPollingTask.h @@ -8,6 +8,9 @@ #include +//! Debugging preprocessor define. +#define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0 + /** * @brief This class can be used to implement the polling of a Unix socket, * using UDP for now. @@ -51,8 +54,7 @@ private: //! 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 + //! Server socket, which is member of TMTC bridge and is assigned in constructor SOCKET serverUdpSocket = 0; std::vector receptionBuffer; diff --git a/osal/windows/TmTcWinUdpBridge.cpp b/osal/windows/TmTcWinUdpBridge.cpp index ac8901985..dce88bb22 100644 --- a/osal/windows/TmTcWinUdpBridge.cpp +++ b/osal/windows/TmTcWinUdpBridge.cpp @@ -85,13 +85,12 @@ TmTcWinUdpBridge::~TmTcWinUdpBridge() { ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { int flags = 0; - //clientAddress.sin_addr.s_addr = htons(INADDR_ANY); - //clientAddressLen = sizeof(serverAddress); - -// char ipAddress [15]; -#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET, -// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; +#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1 + clientAddress.sin_addr.s_addr = htons(INADDR_ANY); + clientAddressLen = sizeof(serverAddress); + 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, @@ -104,9 +103,9 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { #endif handleSendError(); } -#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were" -// " sent." << std::endl; +#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; } @@ -114,16 +113,16 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) { MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10); -// char ipAddress [15]; -#if FSFW_CPP_OSTREAM_ENABLED == 1 -// 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; +#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_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 if it has changed. + /* Set new IP address if it has changed. */ if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) { clientAddress.sin_addr.s_addr = newAddress.sin_addr.s_addr; clientAddressLen = sizeof(clientAddress); @@ -135,8 +134,8 @@ void TmTcWinUdpBridge::handleSocketError() { switch(errCode) { case(WSANOTINITIALISED): { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: " - << "WSAStartup(...) call necessary" << std::endl; + sif::warning << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: WSAStartup" + " call necessary" << std::endl; #endif break; } @@ -146,8 +145,7 @@ void TmTcWinUdpBridge::handleSocketError() { windows-sockets-error-codes-2 */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TmTcWinUdpBridge::handleSocketError: Error code: " - << errCode << std::endl; + sif::warning << "TmTcWinUdpBridge::handleSocketError: Error code: " << errCode << std::endl; #endif break; } diff --git a/osal/windows/TmTcWinUdpBridge.h b/osal/windows/TmTcWinUdpBridge.h index 8188039c0..b51c8c7ac 100644 --- a/osal/windows/TmTcWinUdpBridge.h +++ b/osal/windows/TmTcWinUdpBridge.h @@ -6,10 +6,13 @@ #include #include +//! Debugging preprocessor define. +#define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0 + class TmTcWinUdpBridge: public TmTcBridge { friend class TcWinUdpPollingTask; public: - // The ports chosen here should not be used by any other process. + /* The ports chosen here should not be used by any other process. */ static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301; static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302; From 4e5e6e145ecfe866b34a2ed1ef94de1e192a1053 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Mar 2021 23:02:06 +0100 Subject: [PATCH 02/11] added win sock --- osal/windows/TmTcWinUdpBridge.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osal/windows/TmTcWinUdpBridge.cpp b/osal/windows/TmTcWinUdpBridge.cpp index dce88bb22..07fedd024 100644 --- a/osal/windows/TmTcWinUdpBridge.cpp +++ b/osal/windows/TmTcWinUdpBridge.cpp @@ -38,8 +38,9 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, setClientPort = clientPort; } - // Set up UDP socket: https://man7.org/linux/man-pages/man7/ip.7.html - //clientSocket = socket(AF_INET, SOCK_DGRAM, 0); + /* Set up UDP socket: + https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-socket + */ serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(serverSocket == INVALID_SOCKET) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -52,7 +53,7 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, serverAddress.sin_family = AF_INET; - // Accept packets from any interface. (potentially insecure). + /* Accept packets from any interface. (potentially insecure). */ serverAddress.sin_addr.s_addr = htonl(INADDR_ANY); serverAddress.sin_port = htons(setServerPort); serverAddressLen = sizeof(serverAddress); From 8be4f45969ea46b73f10973dde548af84d9a3621 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Mar 2021 23:14:10 +0100 Subject: [PATCH 03/11] added generic error handler --- osal/windows/TcWinTcpServer.cpp | 35 ++++++++++++++++++++----------- osal/windows/TcWinTcpServer.h | 7 ++++++- osal/windows/TmTcWinUdpBridge.cpp | 19 +++++++++++------ osal/windows/TmTcWinUdpBridge.h | 5 +++++ 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/osal/windows/TcWinTcpServer.cpp b/osal/windows/TcWinTcpServer.cpp index aebc0bee1..756e77767 100644 --- a/osal/windows/TcWinTcpServer.cpp +++ b/osal/windows/TcWinTcpServer.cpp @@ -9,25 +9,39 @@ TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBrid if(serverTcpSocket == 0) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TcWinTcpServer::TcWinTcpServer: Socket creation failed!" << std::endl; - handleSocketError(); + handleError(ErrorSources::SOCKET_CALL); #endif } - setsockopt(serverTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST, - &tcpSockOpt, sizeof(tcpSockOpt)); + int retval = setsockopt(serverTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST, + reinterpret_cast(&tcpSockOpt), sizeof(tcpSockOpt)); + if(retval != 0) { + + } } TcWinTcpServer::~TcWinTcpServer() { } -void TcWinTcpServer::handleSocketError() { +void TcWinTcpServer::handleError(ErrorSources errorSrc) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 int errCode = WSAGetLastError(); + std::string errorSrcString; + if(errorSrc == ErrorSources::SETSOCKOPT_CALL) { + errorSrcString = "setsockopt call"; + } + else if(errorSrc == ErrorSources::SOCKET_CALL) { + errorSrcString = "socket call"; + } switch(errCode) { case(WSANOTINITIALISED): { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: WSAStartup" - " call necessary" << std::endl; -#endif + sif::warning << "TmTcWinUdpBridge::handleError: " << errorSrcString << " | " + "WSANOTINITIALISED: WSAStartup call necessary" << std::endl; + break; + } + case(WSAEINVAL): { + sif::warning << "TmTcWinUdpBridge::handleError: " << errorSrcString << " | " + "WSAEINVAL: Invalid parameters" << std::endl; break; } default: { @@ -35,12 +49,9 @@ void TcWinTcpServer::handleSocketError() { https://docs.microsoft.com/en-us/windows/win32/winsock/ windows-sockets-error-codes-2 */ -#if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TmTcWinUdpBridge::handleSocketError: Error code: " << errCode << std::endl; -#endif break; } } +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ } - - diff --git a/osal/windows/TcWinTcpServer.h b/osal/windows/TcWinTcpServer.h index 3a17336aa..4f53dda42 100644 --- a/osal/windows/TcWinTcpServer.h +++ b/osal/windows/TcWinTcpServer.h @@ -24,7 +24,12 @@ private: std::vector receptionBuffer; int tcpSockOpt = 0; - void handleSocketError(); + enum class ErrorSources { + SOCKET_CALL, + SETSOCKOPT_CALL + }; + + void handleError(ErrorSources errorSrc); }; #endif /* FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_ */ diff --git a/osal/windows/TmTcWinUdpBridge.cpp b/osal/windows/TmTcWinUdpBridge.cpp index 07fedd024..375e45e7c 100644 --- a/osal/windows/TmTcWinUdpBridge.cpp +++ b/osal/windows/TmTcWinUdpBridge.cpp @@ -44,8 +44,8 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(serverSocket == INVALID_SOCKET) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not open" - " UDP socket!" << std::endl; + sif::warning << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not open UDP socket!" << + std::endl; #endif handleSocketError(); return; @@ -57,16 +57,23 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, serverAddress.sin_addr.s_addr = htonl(INADDR_ANY); serverAddress.sin_port = htons(setServerPort); serverAddressLen = sizeof(serverAddress); - setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, + int result = setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&serverSocketOptions), sizeof(serverSocketOptions)); + if(result != 0) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not set socket options!" << + std::endl; +#endif + handleSocketError(); + } clientAddress.sin_family = AF_INET; clientAddress.sin_addr.s_addr = htonl(INADDR_ANY); clientAddress.sin_port = htons(setClientPort); clientAddressLen = sizeof(clientAddress); - int result = bind(serverSocket, + result = bind(serverSocket, reinterpret_cast(&serverAddress), serverAddressLen); if(result != 0) { @@ -159,14 +166,14 @@ void TmTcWinUdpBridge::handleBindError() { case(WSANOTINITIALISED): { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::info << "TmTcWinUdpBridge::handleBindError: WSANOTINITIALISED: " - << "WSAStartup(...) call " << "necessary" << std::endl; + << "WSAStartup call necessary" << std::endl; #endif break; } case(WSAEADDRINUSE): { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TmTcWinUdpBridge::handleBindError: WSAEADDRINUSE: " - << "Port is already in use!" << std::endl; + "Port is already in use!" << std::endl; #endif break; } diff --git a/osal/windows/TmTcWinUdpBridge.h b/osal/windows/TmTcWinUdpBridge.h index b51c8c7ac..143541398 100644 --- a/osal/windows/TmTcWinUdpBridge.h +++ b/osal/windows/TmTcWinUdpBridge.h @@ -41,6 +41,11 @@ private: //! by another task. MutexIF* mutex; + enum class ErrorSources { + SOCKET_CALL, + SETSOCKOPT_CALL + }; + void handleSocketError(); void handleBindError(); void handleSendError(); From 494dd0db324af343e1596a295506bc1748ed584f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Mar 2021 23:55:58 +0100 Subject: [PATCH 04/11] continued tcp server --- osal/windows/TcWinTcpServer.cpp | 76 +++++++++++++++++++++++++++++-- osal/windows/TcWinTcpServer.h | 14 +++++- osal/windows/TmTcWinUdpBridge.cpp | 3 +- 3 files changed, 87 insertions(+), 6 deletions(-) diff --git a/osal/windows/TcWinTcpServer.cpp b/osal/windows/TcWinTcpServer.cpp index 756e77767..d090df459 100644 --- a/osal/windows/TcWinTcpServer.cpp +++ b/osal/windows/TcWinTcpServer.cpp @@ -2,10 +2,32 @@ #include "../../serviceinterface/ServiceInterface.h" #include -TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge): + +TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge, + uint16_t customTcpServerPort): SystemObject(objectId) { - /* Open TCP socket */ + /* Initiates Winsock DLL. */ + WSAData wsaData; + WORD wVersionRequested = MAKEWORD(2, 2); + int err = WSAStartup(wVersionRequested, &wsaData); + if (err != 0) { + /* Tell the user that we could not find a usable */ + /* Winsock DLL. */ +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge:" + "WSAStartup failed with error: " << err << std::endl; +#endif + return; + } + + /* Open TCP (stream) socket */ serverTcpSocket = socket(AF_INET, SOCK_STREAM, 0); + uint16_t tcpPort = customTcpServerPort; + + if(customTcpServerPort == 0xffff) { + tcpPort = DEFAULT_TCP_SERVER_PORT; + } + if(serverTcpSocket == 0) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TcWinTcpServer::TcWinTcpServer: Socket creation failed!" << std::endl; @@ -16,11 +38,52 @@ TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBrid int retval = setsockopt(serverTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST, reinterpret_cast(&tcpSockOpt), sizeof(tcpSockOpt)); if(retval != 0) { - + sif::warning << "TcWinTcpServer::TcWinTcpServer: Setting socket options failed!" << + std::endl; + handleError(ErrorSources::SETSOCKOPT_CALL); } + tcpAddress.sin_family = AF_INET; + tcpAddress.sin_addr.s_addr = htonl(INADDR_ANY); + tcpAddress.sin_port = htons(tcpPort); + + retval = bind(serverTcpSocket, reinterpret_cast(&tcpAddress), + tcpAddrLen); + if(retval != 0) { + sif::warning << "TcWinTcpServer::TcWinTcpServer: Binding socket failed!" << + std::endl; + handleError(ErrorSources::BIND_CALL); + } + } TcWinTcpServer::~TcWinTcpServer() { + closesocket(serverTcpSocket); + WSACleanup(); +} + +ReturnValue_t TcWinTcpServer::initialize() { + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t TcWinTcpServer::performOperation(uint8_t opCode) { + /* If a connection is accepted, the corresponding scoket will be assigned to the new socket */ + SOCKET connectorSocket; + sockaddr_in connectorSockAddr; + int connectorSockAddrLen = 0; + /* Listen for connection requests permanently for lifetime of program */ + while(true) { + int retval = listen(serverTcpSocket, backlog); + if(retval != 0) { + handleError(ErrorSources::LISTEN_CALL); + } + + connectorSocket = accept(serverTcpSocket, reinterpret_cast(&connectorSockAddr), + &connectorSockAddrLen); + + if(connectorSocket) {}; + + } + return HasReturnvaluesIF::RETURN_OK; } void TcWinTcpServer::handleError(ErrorSources errorSrc) { @@ -33,6 +96,13 @@ void TcWinTcpServer::handleError(ErrorSources errorSrc) { else if(errorSrc == ErrorSources::SOCKET_CALL) { errorSrcString = "socket call"; } + else if(errorSrc == ErrorSources::LISTEN_CALL) { + errorSrcString = "listen call"; + } + else if(errorSrc == ErrorSources::ACCEPT_CALL) { + errorSrcString = "accept call"; + } + switch(errCode) { case(WSANOTINITIALISED): { sif::warning << "TmTcWinUdpBridge::handleError: " << errorSrcString << " | " diff --git a/osal/windows/TcWinTcpServer.h b/osal/windows/TcWinTcpServer.h index 4f53dda42..45d92ff80 100644 --- a/osal/windows/TcWinTcpServer.h +++ b/osal/windows/TcWinTcpServer.h @@ -14,19 +14,29 @@ public: static constexpr uint16_t DEFAULT_TCP_SERVER_PORT = 7301; static constexpr uint16_t DEFAULT_TCP_CLIENT_PORT = 7302; - TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge); + TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge, + uint16_t customTcpServerPort = 0xffff); virtual~ TcWinTcpServer(); + ReturnValue_t initialize() override; + ReturnValue_t performOperation(uint8_t opCode) override; + private: SOCKET serverTcpSocket = 0; + struct sockaddr_in tcpAddress; + int tcpAddrLen = sizeof(tcpAddress); + int backlog = 3; std::vector receptionBuffer; int tcpSockOpt = 0; enum class ErrorSources { SOCKET_CALL, - SETSOCKOPT_CALL + SETSOCKOPT_CALL, + BIND_CALL, + LISTEN_CALL, + ACCEPT_CALL }; void handleError(ErrorSources errorSrc); diff --git a/osal/windows/TmTcWinUdpBridge.cpp b/osal/windows/TmTcWinUdpBridge.cpp index 375e45e7c..d4467e441 100644 --- a/osal/windows/TmTcWinUdpBridge.cpp +++ b/osal/windows/TmTcWinUdpBridge.cpp @@ -14,7 +14,7 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, mutex = MutexFactory::instance()->createMutex(); communicationLinkUp = false; - // Initiates Winsock DLL. + /* Initiates Winsock DLL. */ WSAData wsaData; WORD wVersionRequested = MAKEWORD(2, 2); int err = WSAStartup(wVersionRequested, &wsaData); @@ -87,6 +87,7 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, } TmTcWinUdpBridge::~TmTcWinUdpBridge() { + closesocket(serverSocket); WSACleanup(); } From b6952424205a5a656294450ae365c54d7c5079a0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Mar 2021 00:37:42 +0100 Subject: [PATCH 05/11] contiued tcp and improved udp task --- osal/windows/TcWinTcpServer.cpp | 115 ++++++++++++++++++--------- osal/windows/TcWinTcpServer.h | 16 ++-- osal/windows/TcWinUdpPollingTask.cpp | 7 +- 3 files changed, 88 insertions(+), 50 deletions(-) diff --git a/osal/windows/TcWinTcpServer.cpp b/osal/windows/TcWinTcpServer.cpp index d090df459..1cf7ed1da 100644 --- a/osal/windows/TcWinTcpServer.cpp +++ b/osal/windows/TcWinTcpServer.cpp @@ -1,86 +1,120 @@ #include "TcWinTcpServer.h" #include "../../serviceinterface/ServiceInterface.h" #include +#include +const std::string TcWinTcpServer::DEFAULT_TCP_SERVER_PORT = "7301"; +const std::string TcWinTcpServer::DEFAULT_TCP_CLIENT_PORT = "7302"; TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge, - uint16_t customTcpServerPort): - SystemObject(objectId) { + std::string customTcpServerPort): + SystemObject(objectId), tcpPort(customTcpServerPort) { + if(tcpPort == "") { + tcpPort = DEFAULT_TCP_SERVER_PORT; + } +} + +ReturnValue_t TcWinTcpServer::initialize() { + int retval = 0; + struct addrinfo *addrResult = nullptr; + struct addrinfo hints; /* Initiates Winsock DLL. */ WSAData wsaData; WORD wVersionRequested = MAKEWORD(2, 2); int err = WSAStartup(wVersionRequested, &wsaData); if (err != 0) { - /* Tell the user that we could not find a usable */ - /* Winsock DLL. */ + /* Tell the user that we could not find a usable Winsock DLL. */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge:" - "WSAStartup failed with error: " << err << std::endl; + sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: WSAStartup failed with error: " << + err << std::endl; #endif - return; + return HasReturnvaluesIF::RETURN_FAILED; + } + + ZeroMemory(&hints, sizeof (hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + hints.ai_flags = AI_PASSIVE; + + retval = getaddrinfo(nullptr, tcpPort.c_str(), &hints, &addrResult); + if (retval != 0) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TcWinTcpServer::TcWinTcpServer: Retrieving address info failed!" << + std::endl; +#endif + handleError(ErrorSources::GETADDRINFO_CALL); + return HasReturnvaluesIF::RETURN_FAILED; } /* Open TCP (stream) socket */ - serverTcpSocket = socket(AF_INET, SOCK_STREAM, 0); - uint16_t tcpPort = customTcpServerPort; - - if(customTcpServerPort == 0xffff) { - tcpPort = DEFAULT_TCP_SERVER_PORT; - } - - if(serverTcpSocket == 0) { + listenerTcpSocket = socket(addrResult->ai_family, addrResult->ai_socktype, + addrResult->ai_protocol); + if(listenerTcpSocket == INVALID_SOCKET) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TcWinTcpServer::TcWinTcpServer: Socket creation failed!" << std::endl; - handleError(ErrorSources::SOCKET_CALL); #endif + freeaddrinfo(addrResult); + handleError(ErrorSources::SOCKET_CALL); + return HasReturnvaluesIF::RETURN_FAILED; } - int retval = setsockopt(serverTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST, - reinterpret_cast(&tcpSockOpt), sizeof(tcpSockOpt)); - if(retval != 0) { - sif::warning << "TcWinTcpServer::TcWinTcpServer: Setting socket options failed!" << - std::endl; - handleError(ErrorSources::SETSOCKOPT_CALL); - } - tcpAddress.sin_family = AF_INET; - tcpAddress.sin_addr.s_addr = htonl(INADDR_ANY); - tcpAddress.sin_port = htons(tcpPort); +// retval = setsockopt(listenerTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST, +// reinterpret_cast(&tcpSockOpt), sizeof(tcpSockOpt)); +// if(retval != 0) { +// sif::warning << "TcWinTcpServer::TcWinTcpServer: Setting socket options failed!" << +// std::endl; +// handleError(ErrorSources::SETSOCKOPT_CALL); +// return HasReturnvaluesIF::RETURN_FAILED; +// } +// tcpAddress.sin_family = AF_INET; +// tcpAddress.sin_addr.s_addr = htonl(INADDR_ANY); - retval = bind(serverTcpSocket, reinterpret_cast(&tcpAddress), + retval = bind(listenerTcpSocket, reinterpret_cast(&tcpAddress), tcpAddrLen); - if(retval != 0) { + if(retval == SOCKET_ERROR) { sif::warning << "TcWinTcpServer::TcWinTcpServer: Binding socket failed!" << std::endl; + freeaddrinfo(addrResult); handleError(ErrorSources::BIND_CALL); } + freeaddrinfo(addrResult); + return HasReturnvaluesIF::RETURN_OK; } + TcWinTcpServer::~TcWinTcpServer() { - closesocket(serverTcpSocket); + closesocket(listenerTcpSocket); WSACleanup(); } -ReturnValue_t TcWinTcpServer::initialize() { - return HasReturnvaluesIF::RETURN_OK; -} - ReturnValue_t TcWinTcpServer::performOperation(uint8_t opCode) { /* If a connection is accepted, the corresponding scoket will be assigned to the new socket */ - SOCKET connectorSocket; - sockaddr_in connectorSockAddr; + SOCKET clientSocket; + sockaddr_in clientSockAddr; int connectorSockAddrLen = 0; + int retval = 0; /* Listen for connection requests permanently for lifetime of program */ while(true) { - int retval = listen(serverTcpSocket, backlog); - if(retval != 0) { + retval = listen(listenerTcpSocket, currentBacklog); + if(retval == SOCKET_ERROR) { handleError(ErrorSources::LISTEN_CALL); + continue; } - connectorSocket = accept(serverTcpSocket, reinterpret_cast(&connectorSockAddr), + clientSocket = accept(listenerTcpSocket, reinterpret_cast(&clientSockAddr), &connectorSockAddrLen); - if(connectorSocket) {}; + if(clientSocket == INVALID_SOCKET) { + handleError(ErrorSources::ACCEPT_CALL); + continue; + }; + + retval = recv(clientSocket, reinterpret_cast(receptionBuffer.data()), + receptionBuffer.size(), 0); +#if FSFW_TCP_SERVER_WIRETAPPING_ENABLED == 1 +#endif } return HasReturnvaluesIF::RETURN_OK; @@ -102,6 +136,9 @@ void TcWinTcpServer::handleError(ErrorSources errorSrc) { else if(errorSrc == ErrorSources::ACCEPT_CALL) { errorSrcString = "accept call"; } + else if(errorSrc == ErrorSources::GETADDRINFO_CALL) { + errorSrcString = "getaddrinfo call"; + } switch(errCode) { case(WSANOTINITIALISED): { diff --git a/osal/windows/TcWinTcpServer.h b/osal/windows/TcWinTcpServer.h index 45d92ff80..7b679106e 100644 --- a/osal/windows/TcWinTcpServer.h +++ b/osal/windows/TcWinTcpServer.h @@ -4,18 +4,22 @@ #include "../../objectmanager/SystemObject.h" #include "../../tasks/ExecutableObjectIF.h" +#include #include +//! Debugging preprocessor define. +#define FSFW_TCP_SERVER_WIRETAPPING_ENABLED 0 + class TcWinTcpServer: public SystemObject, public ExecutableObjectIF { public: /* The ports chosen here should not be used by any other process. */ - static constexpr uint16_t DEFAULT_TCP_SERVER_PORT = 7301; - static constexpr uint16_t DEFAULT_TCP_CLIENT_PORT = 7302; + static const std::string DEFAULT_TCP_SERVER_PORT; + static const std::string DEFAULT_TCP_CLIENT_PORT; TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge, - uint16_t customTcpServerPort = 0xffff); + std::string customTcpServerPort = ""); virtual~ TcWinTcpServer(); ReturnValue_t initialize() override; @@ -23,15 +27,17 @@ public: private: - SOCKET serverTcpSocket = 0; + std::string tcpPort; + SOCKET listenerTcpSocket = 0; struct sockaddr_in tcpAddress; int tcpAddrLen = sizeof(tcpAddress); - int backlog = 3; + int currentBacklog = 3; std::vector receptionBuffer; int tcpSockOpt = 0; enum class ErrorSources { + GETADDRINFO_CALL, SOCKET_CALL, SETSOCKOPT_CALL, BIND_CALL, diff --git a/osal/windows/TcWinUdpPollingTask.cpp b/osal/windows/TcWinUdpPollingTask.cpp index 32c217001..06e75bd5b 100644 --- a/osal/windows/TcWinUdpPollingTask.cpp +++ b/osal/windows/TcWinUdpPollingTask.cpp @@ -3,11 +3,6 @@ #include "../../serviceinterface/ServiceInterfaceStream.h" #include -#include -#if defined(_MSC_VER) -#include -typedef SSIZE_T ssize_t; -#endif TcWinUdpPollingTask::TcWinUdpPollingTask(object_id_t objectId, object_id_t tmtcUnixUdpBridge, size_t frameSize, @@ -41,7 +36,7 @@ ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) { //! Sender Address is cached here. struct sockaddr_in senderAddress; int senderAddressSize = sizeof(senderAddress); - ssize_t bytesReceived = recvfrom(serverUdpSocket, + int bytesReceived = recvfrom(serverUdpSocket, reinterpret_cast(receptionBuffer.data()), frameSize, receptionFlags, reinterpret_cast(&senderAddress), &senderAddressSize); From d5a065eaa8c5e5e9472201c9914c8c932bcfdf36 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Mar 2021 00:42:50 +0100 Subject: [PATCH 06/11] continued tcp server --- osal/windows/TcWinTcpServer.cpp | 15 ++++++++++++++- osal/windows/TcWinTcpServer.h | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/osal/windows/TcWinTcpServer.cpp b/osal/windows/TcWinTcpServer.cpp index 1cf7ed1da..f85147f04 100644 --- a/osal/windows/TcWinTcpServer.cpp +++ b/osal/windows/TcWinTcpServer.cpp @@ -1,5 +1,6 @@ #include "TcWinTcpServer.h" #include "../../serviceinterface/ServiceInterface.h" + #include #include @@ -90,7 +91,7 @@ TcWinTcpServer::~TcWinTcpServer() { } ReturnValue_t TcWinTcpServer::performOperation(uint8_t opCode) { - /* If a connection is accepted, the corresponding scoket will be assigned to the new socket */ + /* If a connection is accepted, the corresponding socket will be assigned to the new socket */ SOCKET clientSocket; sockaddr_in clientSockAddr; int connectorSockAddrLen = 0; @@ -113,9 +114,21 @@ ReturnValue_t TcWinTcpServer::performOperation(uint8_t opCode) { retval = recv(clientSocket, reinterpret_cast(receptionBuffer.data()), receptionBuffer.size(), 0); + if(retval > 0) { #if FSFW_TCP_SERVER_WIRETAPPING_ENABLED == 1 + sif::info << "TcWinTcpServer::performOperation: Received " << retval << " bytes." + std::endl; #endif + } + else if(retval == 0) { + } + else { + + } + + /* Done, shut down connection */ + retval = shutdown(clientSocket, SD_SEND); } return HasReturnvaluesIF::RETURN_OK; } diff --git a/osal/windows/TcWinTcpServer.h b/osal/windows/TcWinTcpServer.h index 7b679106e..f8aebc530 100644 --- a/osal/windows/TcWinTcpServer.h +++ b/osal/windows/TcWinTcpServer.h @@ -10,6 +10,11 @@ //! Debugging preprocessor define. #define FSFW_TCP_SERVER_WIRETAPPING_ENABLED 0 +/** + * @brief Windows TCP server used to receive telecommands on a Windows Host + * @details + * Based on: https://docs.microsoft.com/en-us/windows/win32/winsock/complete-server-code + */ class TcWinTcpServer: public SystemObject, public ExecutableObjectIF { From 61affafecdd4777b84cd46c711e97aa696e951dc Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 9 Mar 2021 21:58:29 +0100 Subject: [PATCH 07/11] and now some test broke.. --- osal/linux/TaskFactory.cpp | 1 + unittest/tests/datapoollocal/DataSetTest.cpp | 6 +++--- unittest/tests/datapoollocal/LocalPoolManagerTest.cpp | 4 ++-- unittest/tests/datapoollocal/LocalPoolOwnerBase.h | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/osal/linux/TaskFactory.cpp b/osal/linux/TaskFactory.cpp index 935646477..80bf47b7c 100644 --- a/osal/linux/TaskFactory.cpp +++ b/osal/linux/TaskFactory.cpp @@ -2,6 +2,7 @@ #include "PeriodicPosixTask.h" #include "../../tasks/TaskFactory.h" +#include "../../serviceinterface/ServiceInterface.h" #include "../../returnvalues/HasReturnvaluesIF.h" //TODO: Different variant than the lazy loading in QueueFactory. What's better and why? diff --git a/unittest/tests/datapoollocal/DataSetTest.cpp b/unittest/tests/datapoollocal/DataSetTest.cpp index 561345951..920bbda22 100644 --- a/unittest/tests/datapoollocal/DataSetTest.cpp +++ b/unittest/tests/datapoollocal/DataSetTest.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include @@ -54,7 +54,7 @@ TEST_CASE("LocalDataSet" , "[LocDataSetTest]") { { /* Test read operation. Values should be all zeros */ - PoolReadHelper readHelper(&localSet); + PoolReadGuard readHelper(&localSet); REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); CHECK(not localSet.isValid()); CHECK(localSet.localPoolVarUint8.value == 0); @@ -82,7 +82,7 @@ TEST_CASE("LocalDataSet" , "[LocDataSetTest]") { { /* Now we read again and check whether our zeroed values were overwritten with the values in the pool */ - PoolReadHelper readHelper(&localSet); + PoolReadGuard readHelper(&localSet); REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); CHECK(localSet.isValid()); CHECK(localSet.localPoolVarUint8.value == 232); diff --git a/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp b/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp index a10b44999..cd3be9426 100644 --- a/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp +++ b/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include @@ -75,7 +75,7 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") { SECTION("SnapshotUpdateTests") { /* Set the variables in the set to certain values. These are checked later. */ { - PoolReadHelper readHelper(&poolOwner->dataset); + PoolReadGuard readHelper(&poolOwner->dataset); REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); poolOwner->dataset.localPoolVarUint8.value = 5; poolOwner->dataset.localPoolVarFloat.value = -12.242; diff --git a/unittest/tests/datapoollocal/LocalPoolOwnerBase.h b/unittest/tests/datapoollocal/LocalPoolOwnerBase.h index 5c277850f..8e6b07b00 100644 --- a/unittest/tests/datapoollocal/LocalPoolOwnerBase.h +++ b/unittest/tests/datapoollocal/LocalPoolOwnerBase.h @@ -1,16 +1,17 @@ #ifndef FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ #define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ +#include + #include #include #include #include #include #include -#include #include #include -#include "../../../datapool/PoolReadHelper.h" +#include namespace lpool { static constexpr lp_id_t uint8VarId = 0; From e5b3b6d75eaaa424f21aaf0120768ba0f94b18d3 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 9 Mar 2021 22:21:27 +0100 Subject: [PATCH 08/11] fixed unit test --- unittest/tests/action/TestActionHelper.cpp | 2 +- unittest/tests/datapoollocal/LocalPoolVectorTest.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/unittest/tests/action/TestActionHelper.cpp b/unittest/tests/action/TestActionHelper.cpp index a7adfc82d..d8bd58c99 100644 --- a/unittest/tests/action/TestActionHelper.cpp +++ b/unittest/tests/action/TestActionHelper.cpp @@ -70,7 +70,7 @@ TEST_CASE( "Action Helper" , "[ActionHelper]") { SECTION("Handle finish"){ CHECK(not testMqMock.wasMessageSent()); ReturnValue_t status = 0x9876; - actionHelper.finish(true, testMqMock.getId(), testActionId, status); + actionHelper.finish(false, testMqMock.getId(), testActionId, status); CHECK(testMqMock.wasMessageSent()); CommandMessage testMessage; REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast(HasReturnvaluesIF::RETURN_OK)); diff --git a/unittest/tests/datapoollocal/LocalPoolVectorTest.cpp b/unittest/tests/datapoollocal/LocalPoolVectorTest.cpp index 2bc47568f..db76fc00e 100644 --- a/unittest/tests/datapoollocal/LocalPoolVectorTest.cpp +++ b/unittest/tests/datapoollocal/LocalPoolVectorTest.cpp @@ -115,6 +115,7 @@ TEST_CASE("LocalPoolVector" , "[LocPoolVecTest]") { REQUIRE(readOnlyVec.commit() == static_cast(PoolVariableIF::INVALID_READ_WRITE_MODE)); } + poolOwner->reset(); } From bb5b7bed40eaf86293ebc9f631dc39ee2b844469 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 9 Mar 2021 23:18:53 +0100 Subject: [PATCH 09/11] made getter public --- datapoollocal/LocalPoolDataSetBase.h | 3 ++- unittest/tests/datapoollocal/DataSetTest.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/datapoollocal/LocalPoolDataSetBase.h b/datapoollocal/LocalPoolDataSetBase.h index 404509ae5..b9946aaf5 100644 --- a/datapoollocal/LocalPoolDataSetBase.h +++ b/datapoollocal/LocalPoolDataSetBase.h @@ -166,6 +166,8 @@ public: object_id_t getCreatorObjectId(); + bool getReportingEnabled() const; + protected: sid_t sid; //! This mutex is used if the data is created by one object only. @@ -180,7 +182,6 @@ protected: */ bool reportingEnabled = false; void setReportingEnabled(bool enabled); - bool getReportingEnabled() const; void initializePeriodicHelper(float collectionInterval, dur_millis_t minimumPeriodicInterval, diff --git a/unittest/tests/datapoollocal/DataSetTest.cpp b/unittest/tests/datapoollocal/DataSetTest.cpp index 920bbda22..101116cb2 100644 --- a/unittest/tests/datapoollocal/DataSetTest.cpp +++ b/unittest/tests/datapoollocal/DataSetTest.cpp @@ -21,6 +21,7 @@ TEST_CASE("LocalDataSet" , "[LocDataSetTest]") { SECTION("BasicTest") { /* Test some basic functions */ + CHECK(localSet.getReportingEnabled() == false); CHECK(localSet.getLocalPoolIdsSerializedSize(false) == 3 * sizeof(lp_id_t)); CHECK(localSet.getLocalPoolIdsSerializedSize(true) == 3 * sizeof(lp_id_t) + sizeof(uint8_t)); From 676c9ffcf39c648be8c5cb7fc7f630b585088365 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Mar 2021 16:32:24 +0100 Subject: [PATCH 10/11] added header amalagation --- datapoollocal/datapoollocal.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 datapoollocal/datapoollocal.h diff --git a/datapoollocal/datapoollocal.h b/datapoollocal/datapoollocal.h new file mode 100644 index 000000000..c5c470788 --- /dev/null +++ b/datapoollocal/datapoollocal.h @@ -0,0 +1,12 @@ +#ifndef FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ +#define FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ + +/* Collected related headers */ +#include "LocalPoolVariable.h" +#include "LocalPoolVector.h" +#include "StaticLocalDataSet.h" +#include "LocalDataSet.h" +#include "SharedLocalDataSet.h" + + +#endif /* FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ */ From 9ba7fabdeab72b71f325a8cf57d11ea089455656 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Mar 2021 16:38:54 +0100 Subject: [PATCH 11/11] removed commented out code --- unittest/tests/mocks/MessageQueueMockBase.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/unittest/tests/mocks/MessageQueueMockBase.h b/unittest/tests/mocks/MessageQueueMockBase.h index 7b810b41f..31146d34a 100644 --- a/unittest/tests/mocks/MessageQueueMockBase.h +++ b/unittest/tests/mocks/MessageQueueMockBase.h @@ -30,10 +30,7 @@ public: } virtual ReturnValue_t reply( MessageQueueMessageIF* message ) { - //messageSent = true; - //lastMessage = *(dynamic_cast(message)); return sendMessage(myQueueId, message); - return HasReturnvaluesIF::RETURN_OK; }; virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message, MessageQueueId_t *receivedFrom) { @@ -61,21 +58,13 @@ public: virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom, bool ignoreFault = false ) { - //messageSent = true; - //lastMessage = *(dynamic_cast(message)); - //return HasReturnvaluesIF::RETURN_OK; return sendMessage(sendTo, message); } virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message, MessageQueueId_t sentFrom, bool ignoreFault = false ) { - //messageSent = true; - //lastMessage = *(dynamic_cast(message)); - //return HasReturnvaluesIF::RETURN_OK; return sendMessage(myQueueId, message); } virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message ) { - //messageSent = true; - //lastMessage = *(dynamic_cast(message)); return sendMessage(myQueueId, message); } virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo, @@ -114,7 +103,6 @@ public: private: std::queue messagesSentQueue; - //MessageQueueMessage lastMessage; };