2020-09-06 15:46:49 +02:00
|
|
|
#ifndef FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
|
|
|
|
#define FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
|
|
|
|
|
2021-03-21 00:30:33 +01:00
|
|
|
#include "TcpIpBase.h"
|
2021-05-12 16:47:53 +02:00
|
|
|
#include "../../platform.h"
|
2020-09-06 15:46:49 +02:00
|
|
|
#include "../../tmtcservices/TmTcBridge.h"
|
|
|
|
|
2021-05-12 16:47:53 +02:00
|
|
|
#ifdef PLATFORM_WIN
|
2021-03-21 14:38:28 +01:00
|
|
|
#include <ws2tcpip.h>
|
2021-05-12 16:47:53 +02:00
|
|
|
#elif defined(PLATFORM_UNIX)
|
2021-03-21 12:51:28 +01:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
|
2021-03-17 15:43:01 +01:00
|
|
|
#include <string>
|
2020-09-06 15:46:49 +02:00
|
|
|
|
2021-03-23 14:25:50 +01:00
|
|
|
/**
|
|
|
|
* @brief This class should be used with the UdpTcPollingTask to implement a UDP server
|
|
|
|
* for receiving and sending PUS TMTC.
|
|
|
|
*/
|
2021-03-21 00:30:33 +01:00
|
|
|
class UdpTmTcBridge:
|
|
|
|
public TmTcBridge,
|
|
|
|
public TcpIpBase {
|
|
|
|
friend class UdpTcPollingTask;
|
2020-09-06 15:46:49 +02:00
|
|
|
public:
|
2021-03-08 23:00:53 +01:00
|
|
|
/* The ports chosen here should not be used by any other process. */
|
2021-03-12 00:34:30 +01:00
|
|
|
static const std::string DEFAULT_UDP_SERVER_PORT;
|
2020-09-06 15:46:49 +02:00
|
|
|
|
2021-03-21 00:30:33 +01:00
|
|
|
UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
2021-03-12 18:20:54 +01:00
|
|
|
object_id_t tmStoreId, object_id_t tcStoreId, std::string udpServerPort = "");
|
2021-03-21 00:30:33 +01:00
|
|
|
virtual~ UdpTmTcBridge();
|
2020-09-06 15:46:49 +02:00
|
|
|
|
2021-03-12 18:12:38 +01:00
|
|
|
/**
|
|
|
|
* Set properties of internal mutex.
|
|
|
|
*/
|
|
|
|
void setMutexProperties(MutexIF::TimeoutType timeoutType, dur_millis_t timeoutMs);
|
|
|
|
|
2021-03-12 00:34:30 +01:00
|
|
|
ReturnValue_t initialize() override;
|
|
|
|
|
2021-03-21 12:51:28 +01:00
|
|
|
void checkAndSetClientAddress(sockaddr& clientAddress);
|
2020-09-06 15:46:49 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
|
|
|
|
|
|
|
|
private:
|
2021-03-12 00:34:30 +01:00
|
|
|
std::string udpServerPort;
|
2020-09-06 15:46:49 +02:00
|
|
|
|
2021-03-21 12:51:28 +01:00
|
|
|
struct sockaddr clientAddress;
|
|
|
|
socklen_t clientAddressLen = 0;
|
2020-09-06 15:46:49 +02:00
|
|
|
|
2021-03-12 02:15:21 +01:00
|
|
|
//! Access to the client address is mutex protected as it is set by another task.
|
2021-03-12 18:12:38 +01:00
|
|
|
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
|
|
|
dur_millis_t mutexTimeoutMs = 20;
|
2020-09-06 15:46:49 +02:00
|
|
|
MutexIF* mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_ */
|
|
|
|
|