fsfw/osal/linux/TmTcUnixUdpBridge.h

49 lines
1.4 KiB
C
Raw Normal View History

2020-07-04 00:51:49 +02:00
#ifndef FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_
#define FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
2020-07-04 00:51:49 +02:00
#include <framework/tmtcservices/TmTcBridge.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/udp.h>
class TmTcUnixUdpBridge: public TmTcBridge {
friend class TcUnixUdpPollingTask;
2020-07-04 00:51:49 +02:00
public:
2020-07-05 18:22:39 +02:00
// The ports chosen here should not be used by any other process.
// List of used ports on Linux: /etc/services
static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301;
static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302;
2020-07-04 00:51:49 +02:00
2020-07-08 15:06:46 +02:00
TmTcUnixUdpBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId,
uint16_t serverPort = 0xFFFF,uint16_t clientPort = 0xFFFF);
2020-07-04 00:51:49 +02:00
virtual~ TmTcUnixUdpBridge();
void checkAndSetClientAddress(sockaddr_in clientAddress);
2020-07-04 00:51:49 +02:00
protected:
2020-07-04 23:52:44 +02:00
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
2020-07-04 00:51:49 +02:00
private:
int serverSocket = 0;
2020-07-08 15:06:46 +02:00
2020-07-04 00:51:49 +02:00
const int serverSocketOptions = 0;
2020-07-04 00:51:49 +02:00
struct sockaddr_in clientAddress;
2020-07-08 15:06:46 +02:00
socklen_t clientAddressLen = 0;
2020-07-04 00:51:49 +02:00
struct sockaddr_in serverAddress;
2020-07-08 15:06:46 +02:00
socklen_t serverAddressLen = 0;
//! Access to the client address is mutex protected as it is set
//! by another task.
MutexIF* mutex;
2020-07-05 15:31:02 +02:00
void handleSocketError();
2020-07-05 18:22:39 +02:00
void handleBindError();
2020-07-08 15:06:46 +02:00
void handleSendError();
2020-07-04 00:51:49 +02:00
};
#endif /* FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ */