fsfw/osal/common/TcpTmTcServer.h

72 lines
2.1 KiB
C
Raw Normal View History

2021-03-11 14:47:47 +01:00
#ifndef FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
#define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
#include "TcpIpBase.h"
2021-05-05 12:59:42 +02:00
#include "../../ipc/messageQueueDefinitions.h"
#include "../../ipc/MessageQueueIF.h"
#include "../../objectmanager/frameworkObjects.h"
2021-03-11 14:47:47 +01:00
#include "../../objectmanager/SystemObject.h"
2021-05-05 12:59:42 +02:00
#include "../../storagemanager/StorageManagerIF.h"
2021-03-11 14:47:47 +01:00
#include "../../tasks/ExecutableObjectIF.h"
2021-03-21 12:51:28 +01:00
#ifdef __unix__
#include <sys/socket.h>
#endif
2021-03-11 14:47:47 +01:00
#include <string>
#include <vector>
2021-05-05 12:59:42 +02:00
class TcpTmTcBridge;
//class SharedRingBuffer;
2021-03-11 14:47:47 +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
*/
class TcpTmTcServer:
2021-03-11 14:47:47 +01:00
public SystemObject,
public TcpIpBase,
2021-03-11 14:47:47 +01:00
public ExecutableObjectIF {
public:
/* The ports chosen here should not be used by any other process. */
static const std::string DEFAULT_TCP_SERVER_PORT;
static const std::string DEFAULT_TCP_CLIENT_PORT;
2021-05-05 12:59:42 +02:00
static constexpr size_t ETHERNET_MTU_SIZE = 1500;
2021-03-11 14:47:47 +01:00
2021-05-05 12:59:42 +02:00
TcpTmTcServer(object_id_t objectId, object_id_t tmtcTcpBridge /*, SharedRingBuffer* tcpRingBuffer*/,
size_t receptionBufferSize = ETHERNET_MTU_SIZE,
2021-03-11 14:47:47 +01:00
std::string customTcpServerPort = "");
virtual~ TcpTmTcServer();
2021-03-11 14:47:47 +01:00
ReturnValue_t initialize() override;
ReturnValue_t performOperation(uint8_t opCode) override;
2021-05-05 12:59:42 +02:00
ReturnValue_t initializeAfterTaskCreation() override;
protected:
StorageManagerIF* tcStore = nullptr;
2021-03-11 14:47:47 +01:00
private:
2021-05-05 12:59:42 +02:00
//! TMTC bridge is cached.
object_id_t tmtcBridgeId = objects::NO_OBJECT;
TcpTmTcBridge* tmtcBridge = nullptr;
2021-03-11 14:47:47 +01:00
std::string tcpPort;
2021-05-05 12:59:42 +02:00
int tcpFlags = 0;
socket_t listenerTcpSocket = 0;
2021-03-21 12:51:28 +01:00
struct sockaddr tcpAddress;
2021-05-05 12:59:42 +02:00
MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE;
2021-03-11 14:47:47 +01:00
int tcpAddrLen = sizeof(tcpAddress);
int currentBacklog = 3;
std::vector<uint8_t> receptionBuffer;
2021-05-05 12:59:42 +02:00
//SharedRingBuffer* tcpRingBuffer;
2021-03-11 14:47:47 +01:00
int tcpSockOpt = 0;
2021-05-05 12:59:42 +02:00
void handleServerOperation(socket_t connSocket);
ReturnValue_t handleTcReception(size_t bytesRecvd);
2021-03-11 14:47:47 +01:00
};
#endif /* FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_ */