2021-03-08 23:00:53 +01:00
|
|
|
#ifndef FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
|
|
|
#define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
|
|
|
|
|
|
|
#include "../../objectmanager/SystemObject.h"
|
|
|
|
#include "../../tasks/ExecutableObjectIF.h"
|
|
|
|
|
2021-03-09 00:37:42 +01:00
|
|
|
#include <string>
|
2021-03-08 23:00:53 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2021-03-09 00:37:42 +01:00
|
|
|
//! Debugging preprocessor define.
|
|
|
|
#define FSFW_TCP_SERVER_WIRETAPPING_ENABLED 0
|
|
|
|
|
2021-03-09 00:42:50 +01:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2021-03-08 23:00:53 +01:00
|
|
|
class TcWinTcpServer:
|
|
|
|
public SystemObject,
|
|
|
|
public ExecutableObjectIF {
|
|
|
|
public:
|
|
|
|
/* The ports chosen here should not be used by any other process. */
|
2021-03-09 00:37:42 +01:00
|
|
|
static const std::string DEFAULT_TCP_SERVER_PORT;
|
|
|
|
static const std::string DEFAULT_TCP_CLIENT_PORT;
|
2021-03-08 23:00:53 +01:00
|
|
|
|
2021-03-08 23:55:58 +01:00
|
|
|
TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
2021-03-09 00:37:42 +01:00
|
|
|
std::string customTcpServerPort = "");
|
2021-03-08 23:00:53 +01:00
|
|
|
virtual~ TcWinTcpServer();
|
|
|
|
|
2021-03-08 23:55:58 +01:00
|
|
|
ReturnValue_t initialize() override;
|
|
|
|
ReturnValue_t performOperation(uint8_t opCode) override;
|
|
|
|
|
2021-03-08 23:00:53 +01:00
|
|
|
private:
|
|
|
|
|
2021-03-09 00:37:42 +01:00
|
|
|
std::string tcpPort;
|
|
|
|
SOCKET listenerTcpSocket = 0;
|
2021-03-08 23:55:58 +01:00
|
|
|
struct sockaddr_in tcpAddress;
|
|
|
|
int tcpAddrLen = sizeof(tcpAddress);
|
2021-03-09 00:37:42 +01:00
|
|
|
int currentBacklog = 3;
|
2021-03-08 23:00:53 +01:00
|
|
|
|
|
|
|
std::vector<uint8_t> receptionBuffer;
|
|
|
|
int tcpSockOpt = 0;
|
|
|
|
|
2021-03-08 23:14:10 +01:00
|
|
|
enum class ErrorSources {
|
2021-03-09 00:37:42 +01:00
|
|
|
GETADDRINFO_CALL,
|
2021-03-08 23:14:10 +01:00
|
|
|
SOCKET_CALL,
|
2021-03-08 23:55:58 +01:00
|
|
|
SETSOCKOPT_CALL,
|
|
|
|
BIND_CALL,
|
|
|
|
LISTEN_CALL,
|
|
|
|
ACCEPT_CALL
|
2021-03-08 23:14:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void handleError(ErrorSources errorSrc);
|
2021-03-08 23:00:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_ */
|