fsfw/src/fsfw/osal/common/UdpTmTcBridge.h

64 lines
1.9 KiB
C
Raw Normal View History

2021-05-05 12:59:42 +02:00
#ifndef FSFW_OSAL_COMMON_TMTCUDPBRIDGE_H_
#define FSFW_OSAL_COMMON_TMTCUDPBRIDGE_H_
2020-09-06 15:46:49 +02:00
#include "TcpIpBase.h"
#include "fsfw/platform.h"
#include "fsfw/tmtcservices/TmTcBridge.h"
2020-09-06 15:46:49 +02:00
2021-05-12 16:47:53 +02:00
#ifdef PLATFORM_WIN
#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 can be used with the UdpTcPollingTask to implement a UDP server
2021-03-23 14:25:50 +01:00
* for receiving and sending PUS TMTC.
* @details
* This bridge task will take care of sending telemetry back to a UDP client if a connection
* was established and store them in a FIFO if this was not done yet. It is also be the default
* destination for telecommands, but the telecommands will be relayed to a specified tcDestination
* directly.
2021-03-23 14:25:50 +01:00
*/
2022-02-02 10:29:30 +01:00
class UdpTmTcBridge : public TmTcBridge, public TcpIpBase {
friend class UdpTcPollingTask;
2020-09-06 15:46:49 +02:00
2022-02-02 10:29:30 +01:00
public:
/* The ports chosen here should not be used by any other process. */
static const std::string DEFAULT_SERVER_PORT;
2020-09-06 15:46:49 +02:00
2022-05-14 11:32:51 +02:00
UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
const std::string& udpServerPort = "", object_id_t tmStoreId = objects::TM_STORE,
2022-02-02 10:29:30 +01:00
object_id_t tcStoreId = objects::TC_STORE);
2022-05-01 17:48:49 +02:00
~UdpTmTcBridge() override;
2021-03-12 18:12:38 +01:00
2022-02-02 10:29:30 +01:00
/**
* Set properties of internal mutex.
*/
void setMutexProperties(MutexIF::TimeoutType timeoutType, dur_millis_t timeoutMs);
2021-03-12 00:34:30 +01:00
2022-02-02 10:29:30 +01:00
ReturnValue_t initialize() override;
2020-09-06 15:46:49 +02:00
2022-02-02 10:29:30 +01:00
void checkAndSetClientAddress(sockaddr& clientAddress);
2021-08-09 18:22:22 +02:00
2022-02-02 10:29:30 +01:00
std::string getUdpPort() const;
2020-09-06 15:46:49 +02:00
2022-02-02 10:29:30 +01:00
protected:
2022-05-01 17:48:49 +02:00
ReturnValue_t sendTm(const uint8_t* data, size_t dataLen) override;
2020-09-06 15:46:49 +02:00
2022-02-02 10:29:30 +01:00
private:
std::string udpServerPort;
2020-09-06 15:46:49 +02:00
2022-05-01 17:48:49 +02:00
struct sockaddr clientAddress = {};
2022-02-02 10:29:30 +01:00
socklen_t clientAddressLen = 0;
//! Access to the client address is mutex protected as it is set by another task.
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
dur_millis_t mutexTimeoutMs = 20;
MutexIF* mutex;
2020-09-06 15:46:49 +02:00
};
2021-05-05 12:59:42 +02:00
#endif /* FSFW_OSAL_COMMON_TMTCUDPBRIDGE_H_ */