diff --git a/osal/linux/TcUnixUdpPollingTask.cpp b/osal/linux/TcUnixUdpPollingTask.cpp index d8a39869..95910b02 100644 --- a/osal/linux/TcUnixUdpPollingTask.cpp +++ b/osal/linux/TcUnixUdpPollingTask.cpp @@ -1,4 +1,4 @@ -#include "../../osal/linux/TcUnixUdpPollingTask.h" +#include "TcUnixUdpPollingTask.h" #include "../../globalfunctions/arrayprinter.h" TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId, diff --git a/osal/linux/TmTcUnixUdpBridge.cpp b/osal/linux/TmTcUnixUdpBridge.cpp index d0c9517f..2549a4b7 100644 --- a/osal/linux/TmTcUnixUdpBridge.cpp +++ b/osal/linux/TmTcUnixUdpBridge.cpp @@ -1,10 +1,11 @@ -#include "../../osal/linux/TmTcUnixUdpBridge.h" +#include "TmTcUnixUdpBridge.h" #include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../ipc/MutexHelper.h" #include #include + TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId, object_id_t tcDestination, object_id_t tmStoreId, object_id_t tcStoreId, uint16_t serverPort, uint16_t clientPort): diff --git a/osal/host/TmTcWinUdpBridge.cpp b/osal/windows/TmTcWinUdpBridge.cpp similarity index 54% rename from osal/host/TmTcWinUdpBridge.cpp rename to osal/windows/TmTcWinUdpBridge.cpp index 4bb9a3b1..c5902e88 100644 --- a/osal/host/TmTcWinUdpBridge.cpp +++ b/osal/windows/TmTcWinUdpBridge.cpp @@ -6,6 +6,18 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) { mutex = MutexFactory::instance()->createMutex(); + // 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. */ + sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge:" + "WSAStartup failed with error: " << err << std::endl; + return; + } + uint16_t setServerPort = DEFAULT_UDP_SERVER_PORT; if(serverPort != 0xFFFF) { setServerPort = serverPort; @@ -45,8 +57,8 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, int result = bind(serverSocket, reinterpret_cast(&serverAddress), serverAddressLen); - if(result == -1) { - sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not bind " + if(result != 0) { + sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not bind " "local port " << setServerPort << " to server socket!" << std::endl; handleBindError(); @@ -54,12 +66,8 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, } } -TmTcWinUdpBridge::~TmTcWinUdpBridge() {} - -void TmTcWinUdpBridge::handleSocketError() { -} - -void TmTcWinUdpBridge::handleBindError() { +TmTcWinUdpBridge::~TmTcWinUdpBridge() { + WSACleanup(); } ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { @@ -69,5 +77,52 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in clientAddress) { } -void TmTcWinUdpBridge::handleSendError() { +void TmTcWinUdpBridge::handleSocketError() { + int errCode = WSAGetLastError(); + switch(errCode) { + case(WSANOTINITIALISED): { + sif::info << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: " + << "WSAStartup(...) call " << "necessary" << std::endl; + break; + } + default: { + sif::info << "TmTcWinUdpBridge::handleSocketError: Error code: " + << errCode << std::endl; + break; + } + } } + +void TmTcWinUdpBridge::handleBindError() { + int errCode = WSAGetLastError(); + switch(errCode) { + case(WSANOTINITIALISED): { + sif::info << "TmTcWinUdpBridge::handleBindError: WSANOTINITIALISED: " + << "WSAStartup(...) call " << "necessary" << std::endl; + break; + } + default: { + sif::info << "TmTcWinUdpBridge::handleBindError: Error code: " + << errCode << std::endl; + break; + } + } +} + +void TmTcWinUdpBridge::handleSendError() { + int errCode = WSAGetLastError(); + switch(errCode) { + case(WSANOTINITIALISED): { + sif::info << "TmTcWinUdpBridge::handleSendError: WSANOTINITIALISED: " + << "WSAStartup(...) call " << "necessary" << std::endl; + break; + } + default: { + sif::info << "TmTcWinUdpBridge::handleSendError: Error code: " + << errCode << std::endl; + break; + } + } +} + +#endif diff --git a/osal/host/TmTcWinUdpBridge.h b/osal/windows/TmTcWinUdpBridge.h similarity index 88% rename from osal/host/TmTcWinUdpBridge.h rename to osal/windows/TmTcWinUdpBridge.h index 8e6bb0fd..8188039c 100644 --- a/osal/host/TmTcWinUdpBridge.h +++ b/osal/windows/TmTcWinUdpBridge.h @@ -1,14 +1,15 @@ -#ifndef FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_ -#define FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_ +#ifndef FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_ +#define FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_ #include "../../tmtcservices/TmTcBridge.h" -#include + +#include +#include class TmTcWinUdpBridge: public TmTcBridge { friend class TcWinUdpPollingTask; public: // The ports chosen here should not be used by any other process. - // List of used ports on Linux: /etc/services static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301; static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302; @@ -45,3 +46,4 @@ private: #endif /* FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_ */ +