From 72768a68152b3fb6778e7c90aead2b6f46d596ab Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 4 Jul 2020 00:51:49 +0200 Subject: [PATCH] started unix udp bridge --- osal/linux/TmTcUnixUdpBridge.cpp | 37 ++++++++++++++++++++++++++++++++ osal/linux/TmTcUnixUdpBridge.h | 28 ++++++++++++++++++++++++ tmtcservices/TmTcBridge.cpp | 6 +++--- tmtcservices/TmTcBridge.h | 2 +- 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 osal/linux/TmTcUnixUdpBridge.cpp create mode 100644 osal/linux/TmTcUnixUdpBridge.h diff --git a/osal/linux/TmTcUnixUdpBridge.cpp b/osal/linux/TmTcUnixUdpBridge.cpp new file mode 100644 index 00000000..02c17312 --- /dev/null +++ b/osal/linux/TmTcUnixUdpBridge.cpp @@ -0,0 +1,37 @@ +#include +#include + +TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId, + object_id_t ccsdsPacketDistributor): + TmTcBridge(objectId, ccsdsPacketDistributor) { + serverSocket = socket(AF_INET, SOCK_DGRAM, 0); + if(socket < 0) { + sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not open" + " UDP socket!" << std::endl; + // check errno here. + return; + } + + serverAddress.sin_family = AF_INET; + serverAddress.sin_addr.s_addr = htonl(INADDR_ANY); + serverAddress.sin_port = htons(UDP_SERVER_PORT); + setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &serverSocketOptions, + sizeof(serverSocketOptions)); + + int result = bind(serverSocket, + reinterpret_cast(&serverAddress), + sizeof(serverAddress)); + if(result== -1) { + sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not bind " + "local port " << UDP_SERVER_PORT << " to server socket!" + << std::endl; + // check errno here. + return; + } + + + +} + +TmTcUnixUdpBridge::~TmTcUnixUdpBridge() { +} diff --git a/osal/linux/TmTcUnixUdpBridge.h b/osal/linux/TmTcUnixUdpBridge.h new file mode 100644 index 00000000..b84d9fe1 --- /dev/null +++ b/osal/linux/TmTcUnixUdpBridge.h @@ -0,0 +1,28 @@ +#ifndef FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ +#define FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ + +#include +#include +#include +#include + +class TmTcUnixUdpBridge: public TmTcBridge { +public: + static constexpr int UDP_SERVER_PORT = 7; + static constexpr int UDP_CLIENT_PORT = 2008; + + TmTcUnixUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor); + virtual~ TmTcUnixUdpBridge(); + +protected: + +private: + int serverSocket = 0; + const int serverSocketOptions = 0; + struct sockaddr_in clientAddress; + struct sockaddr_in serverAddress; +}; + + + +#endif /* FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ */ diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index f9a7d3bc..092884bb 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -5,9 +5,9 @@ #include #include -TmTcBridge::TmTcBridge(object_id_t objectId_, - object_id_t ccsdsPacketDistributor_): SystemObject(objectId_), - ccsdsPacketDistributor(ccsdsPacketDistributor_) +TmTcBridge::TmTcBridge(object_id_t objectId, + object_id_t ccsdsPacketDistributor): SystemObject(objectId), + ccsdsPacketDistributor(ccsdsPacketDistributor) { TmTcReceptionQueue = QueueFactory::instance()-> createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH); diff --git a/tmtcservices/TmTcBridge.h b/tmtcservices/TmTcBridge.h index 3e0432d8..b50e9e1b 100644 --- a/tmtcservices/TmTcBridge.h +++ b/tmtcservices/TmTcBridge.h @@ -22,7 +22,7 @@ public: static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5; static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10; - TmTcBridge(object_id_t objectId_, object_id_t ccsdsPacketDistributor_); + TmTcBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor); virtual ~TmTcBridge(); /**