2021-05-05 12:59:42 +02:00
|
|
|
#ifndef FSFW_OSAL_COMMON_UDPTCPOLLINGTASK_H_
|
|
|
|
#define FSFW_OSAL_COMMON_UDPTCPOLLINGTASK_H_
|
2020-09-06 15:46:49 +02:00
|
|
|
|
2021-03-21 00:30:33 +01:00
|
|
|
#include "UdpTmTcBridge.h"
|
2020-09-06 15:46:49 +02:00
|
|
|
#include "../../objectmanager/SystemObject.h"
|
|
|
|
#include "../../tasks/ExecutableObjectIF.h"
|
|
|
|
#include "../../storagemanager/StorageManagerIF.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
/**
|
2021-03-23 14:25:50 +01:00
|
|
|
* @brief This class should be used with the UdpTmTcBridge to implement a UDP server
|
|
|
|
* for receiving and sending PUS TMTC.
|
2020-09-06 15:46:49 +02:00
|
|
|
*/
|
2021-03-21 00:30:33 +01:00
|
|
|
class UdpTcPollingTask:
|
|
|
|
public TcpIpBase,
|
|
|
|
public SystemObject,
|
2020-09-06 15:46:49 +02:00
|
|
|
public ExecutableObjectIF {
|
|
|
|
friend class TmTcWinUdpBridge;
|
|
|
|
public:
|
2021-03-21 13:02:14 +01:00
|
|
|
static constexpr size_t DEFAULT_MAX_RECV_SIZE = 1500;
|
2020-09-06 15:46:49 +02:00
|
|
|
//! 0.5 default milliseconds timeout for now.
|
2021-03-07 01:35:55 +01:00
|
|
|
static constexpr timeval DEFAULT_TIMEOUT = {0, 500};
|
2020-09-06 15:46:49 +02:00
|
|
|
|
2021-05-05 12:59:42 +02:00
|
|
|
UdpTcPollingTask(object_id_t objectId, object_id_t tmtcUdpBridge,
|
2021-03-21 13:02:14 +01:00
|
|
|
size_t maxRecvSize = 0, double timeoutSeconds = -1);
|
2021-03-21 00:30:33 +01:00
|
|
|
virtual~ UdpTcPollingTask();
|
2020-09-06 15:46:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn on optional timeout for UDP polling. In the default mode,
|
|
|
|
* the receive function will block until a packet is received.
|
|
|
|
* @param timeoutSeconds
|
|
|
|
*/
|
|
|
|
void setTimeout(double timeoutSeconds);
|
|
|
|
|
|
|
|
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
|
|
|
virtual ReturnValue_t initialize() override;
|
|
|
|
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
StorageManagerIF* tcStore = nullptr;
|
|
|
|
|
|
|
|
private:
|
|
|
|
//! TMTC bridge is cached.
|
|
|
|
object_id_t tmtcBridgeId = objects::NO_OBJECT;
|
2021-03-21 00:30:33 +01:00
|
|
|
UdpTmTcBridge* tmtcBridge = nullptr;
|
2020-09-06 15:46:49 +02:00
|
|
|
MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE;
|
2021-03-12 02:15:21 +01:00
|
|
|
|
|
|
|
//! See: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom
|
2020-09-06 15:46:49 +02:00
|
|
|
int receptionFlags = 0;
|
|
|
|
|
|
|
|
std::vector<uint8_t> receptionBuffer;
|
|
|
|
|
|
|
|
size_t frameSize = 0;
|
|
|
|
timeval receptionTimeout;
|
|
|
|
|
|
|
|
ReturnValue_t handleSuccessfullTcRead(size_t bytesRead);
|
|
|
|
};
|
|
|
|
|
2021-05-05 12:59:42 +02:00
|
|
|
#endif /* FSFW_OSAL_COMMON_UDPTCPOLLINGTASK_H_ */
|