fsfw/osal/linux/TmTcUnixUdpBridge.h

56 lines
1.5 KiB
C
Raw Normal View History

2020-07-13 13:33:12 +02:00
#ifndef FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_
#define FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_
2020-08-28 17:14:20 +02:00
#include "../../tmtcservices/AcceptsTelecommandsIF.h"
#include "../../tmtcservices/TmTcBridge.h"
2020-07-13 13:33:12 +02:00
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/udp.h>
class TmTcUnixUdpBridge: public TmTcBridge {
friend class TcUnixUdpPollingTask;
public:
2021-03-12 17:15:53 +01:00
/* The ports chosen here should not be used by any other process.
List of used ports on Linux: /etc/services */
static const std::string DEFAULT_UDP_SERVER_PORT;
static const std::string DEFAULT_UDP_CLIENT_PORT;
2020-07-13 13:33:12 +02:00
TmTcUnixUdpBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId,
2021-03-12 17:15:53 +01:00
std::string serverPort = "", std::string clientPort = "");
2020-07-13 13:33:12 +02:00
virtual~ TmTcUnixUdpBridge();
2021-03-12 17:15:53 +01:00
ReturnValue_t initialize() override;
2020-11-07 20:30:42 +01:00
void checkAndSetClientAddress(sockaddr_in& clientAddress);
2020-07-13 13:33:12 +02:00
2020-11-07 20:30:42 +01:00
void setClientAddressToAny(bool ipAddrAnySet);
2020-07-13 13:33:12 +02:00
protected:
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
private:
int serverSocket = 0;
2021-03-12 17:15:53 +01:00
std::string udpServerPort;
std::string udpClientPort;
2020-07-13 13:33:12 +02:00
const int serverSocketOptions = 0;
struct sockaddr_in clientAddress;
socklen_t clientAddressLen = 0;
struct sockaddr_in serverAddress;
socklen_t serverAddressLen = 0;
2020-11-07 20:30:42 +01:00
bool ipAddrAnySet = false;
2020-07-13 13:33:12 +02:00
//! Access to the client address is mutex protected as it is set
//! by another task.
MutexIF* mutex;
void handleSocketError();
void handleBindError();
void handleSendError();
};
#endif /* FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ */