continued win sockets

This commit is contained in:
Robin Müller 2020-09-06 10:36:39 +02:00
parent 0c85b05aca
commit b7c4f5ce05
4 changed files with 73 additions and 15 deletions

View File

@ -1,4 +1,4 @@
#include "../../osal/linux/TcUnixUdpPollingTask.h" #include "TcUnixUdpPollingTask.h"
#include "../../globalfunctions/arrayprinter.h" #include "../../globalfunctions/arrayprinter.h"
TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId, TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId,

View File

@ -1,10 +1,11 @@
#include "../../osal/linux/TmTcUnixUdpBridge.h" #include "TmTcUnixUdpBridge.h"
#include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../ipc/MutexHelper.h" #include "../../ipc/MutexHelper.h"
#include <errno.h> #include <errno.h>
#include <arpa/inet.h> #include <arpa/inet.h>
TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId, TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId,
object_id_t tcDestination, object_id_t tmStoreId, object_id_t tcStoreId, object_id_t tcDestination, object_id_t tmStoreId, object_id_t tcStoreId,
uint16_t serverPort, uint16_t clientPort): uint16_t serverPort, uint16_t clientPort):

View File

@ -6,6 +6,18 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId,
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) { TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
mutex = MutexFactory::instance()->createMutex(); 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; uint16_t setServerPort = DEFAULT_UDP_SERVER_PORT;
if(serverPort != 0xFFFF) { if(serverPort != 0xFFFF) {
setServerPort = serverPort; setServerPort = serverPort;
@ -45,8 +57,8 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId,
int result = bind(serverSocket, int result = bind(serverSocket,
reinterpret_cast<struct sockaddr*>(&serverAddress), reinterpret_cast<struct sockaddr*>(&serverAddress),
serverAddressLen); serverAddressLen);
if(result == -1) { if(result != 0) {
sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not bind " sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not bind "
"local port " << setServerPort << " to server socket!" "local port " << setServerPort << " to server socket!"
<< std::endl; << std::endl;
handleBindError(); handleBindError();
@ -54,12 +66,8 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId,
} }
} }
TmTcWinUdpBridge::~TmTcWinUdpBridge() {} TmTcWinUdpBridge::~TmTcWinUdpBridge() {
WSACleanup();
void TmTcWinUdpBridge::handleSocketError() {
}
void TmTcWinUdpBridge::handleBindError() {
} }
ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { 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::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

View File

@ -1,14 +1,15 @@
#ifndef FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_ #ifndef FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
#define FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_ #define FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
#include "../../tmtcservices/TmTcBridge.h" #include "../../tmtcservices/TmTcBridge.h"
#include <Winsock.h>
#include <winsock2.h>
#include <windows.h>
class TmTcWinUdpBridge: public TmTcBridge { class TmTcWinUdpBridge: public TmTcBridge {
friend class TcWinUdpPollingTask; friend class TcWinUdpPollingTask;
public: 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.
// List of used ports on Linux: /etc/services
static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301; static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301;
static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302; static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302;
@ -45,3 +46,4 @@ private:
#endif /* FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_ */ #endif /* FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_ */