cleaned up a bit, removed unused fields

This commit is contained in:
Robin Müller 2021-03-12 18:30:36 +01:00
parent 7bc04014e8
commit 703dfe9854
5 changed files with 69 additions and 79 deletions

View File

@ -6,6 +6,9 @@
namespace tcpip { namespace tcpip {
const char* const DEFAULT_UDP_SERVER_PORT = "7301";
const char* const DEFAULT_TCP_SERVER_PORT = "7303";
enum class Protocol { enum class Protocol {
UDP, UDP,
TCP TCP

View File

@ -125,7 +125,6 @@ ReturnValue_t TcUnixUdpPollingTask::initialize() {
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -12,25 +12,17 @@
//! Debugging preprocessor define. //! Debugging preprocessor define.
#define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0 #define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0
const std::string TmTcUnixUdpBridge::DEFAULT_UDP_SERVER_PORT = "7301"; const std::string TmTcUnixUdpBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_UDP_SERVER_PORT;
const std::string TmTcUnixUdpBridge::DEFAULT_UDP_CLIENT_PORT = "7302";
TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId, TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tcDestination, object_id_t tmStoreId, object_id_t tcStoreId, object_id_t tmStoreId, object_id_t tcStoreId, std::string udpServerPort):
std::string udpServerPort, std::string udpClientPort):
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) { TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
if(udpServerPort == "") { if(udpServerPort == "") {
this->udpServerPort = DEFAULT_UDP_SERVER_PORT; this->udpServerPort = DEFAULT_UDP_SERVER_PORT;
} }
else { else {
this->udpServerPort = udpServerPort; this->udpServerPort = udpServerPort;
} }
if(udpClientPort == "") {
this->udpClientPort = DEFAULT_UDP_CLIENT_PORT;
}
else {
this->udpClientPort = udpClientPort;
}
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
communicationLinkUp = false; communicationLinkUp = false;
@ -106,43 +98,43 @@ TmTcUnixUdpBridge::~TmTcUnixUdpBridge() {
} }
ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
int flags = 0; int flags = 0;
/* The target address can be set by different threads so this lock ensures thread-safety */ /* The target address can be set by different threads so this lock ensures thread-safety */
MutexGuard lock(mutex, timeoutType, mutexTimeoutMs); MutexGuard lock(mutex, timeoutType, mutexTimeoutMs);
if(ipAddrAnySet){ if(ipAddrAnySet){
clientAddress.sin_addr.s_addr = htons(INADDR_ANY); clientAddress.sin_addr.s_addr = htons(INADDR_ANY);
clientAddressLen = sizeof(serverAddress); clientAddressLen = sizeof(clientAddress);
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
char ipAddress [15]; char ipAddress [15];
sif::debug << "IP Address Sender: "<< sif::debug << "IP Address Sender: "<<
inet_ntop(AF_INET,&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; inet_ntop(AF_INET,&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
#endif #endif
ssize_t bytesSent = sendto( ssize_t bytesSent = sendto(
serverSocket, serverSocket,
data, data,
dataLen, dataLen,
flags, flags,
reinterpret_cast<sockaddr*>(&clientAddress), reinterpret_cast<sockaddr*>(&clientAddress),
clientAddressLen clientAddressLen
); );
if(bytesSent < 0) { if(bytesSent < 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TmTcUnixUdpBridge::sendTm: Send operation failed." << std::endl; sif::warning << "TmTcUnixUdpBridge::sendTm: Send operation failed." << std::endl;
#endif #endif
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::SENDTO_CALL); tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::SENDTO_CALL);
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were" sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
" sent." << std::endl; " sent." << std::endl;
#endif #endif
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in& newAddress) { void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in& newAddress) {
@ -151,18 +143,18 @@ void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in& newAddress) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
char ipAddress [15]; char ipAddress [15];
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET, sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
&newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; &newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
sif::debug << "IP Address Old: " << inet_ntop(AF_INET, sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
#endif #endif
registerCommConnect(); registerCommConnect();
/* Set new IP address if it has changed. */ /* Set new IP address if it has changed. */
if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) { if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) {
clientAddress = newAddress; clientAddress = newAddress;
clientAddressLen = sizeof(clientAddress); clientAddressLen = sizeof(clientAddress);
} }
} }
void TmTcUnixUdpBridge::setMutexProperties(MutexIF::TimeoutType timeoutType, void TmTcUnixUdpBridge::setMutexProperties(MutexIF::TimeoutType timeoutType,
@ -172,6 +164,6 @@ void TmTcUnixUdpBridge::setMutexProperties(MutexIF::TimeoutType timeoutType,
} }
void TmTcUnixUdpBridge::setClientAddressToAny(bool ipAddrAnySet){ void TmTcUnixUdpBridge::setClientAddressToAny(bool ipAddrAnySet){
this->ipAddrAnySet = ipAddrAnySet; this->ipAddrAnySet = ipAddrAnySet;
} }

View File

@ -7,51 +7,47 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/udp.h> #include <netinet/udp.h>
class TmTcUnixUdpBridge: public TmTcBridge { class TmTcUnixUdpBridge:
friend class TcUnixUdpPollingTask; public TmTcBridge {
friend class TcUnixUdpPollingTask;
public: public:
/* The ports chosen here should not be used by any other process.
/* The ports chosen here should not be used by any other process.
List of used ports on Linux: /etc/services */ List of used ports on Linux: /etc/services */
static const std::string DEFAULT_UDP_SERVER_PORT; static const std::string DEFAULT_UDP_SERVER_PORT;
static const std::string DEFAULT_UDP_CLIENT_PORT;
TmTcUnixUdpBridge(object_id_t objectId, object_id_t tcDestination, TmTcUnixUdpBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId, object_id_t tmStoreId, object_id_t tcStoreId,
std::string serverPort = "", std::string clientPort = ""); std::string serverPort = "");
virtual~ TmTcUnixUdpBridge(); virtual~ TmTcUnixUdpBridge();
/** /**
* Set properties of internal mutex. * Set properties of internal mutex.
*/ */
void setMutexProperties(MutexIF::TimeoutType timeoutType, dur_millis_t timeoutMs); void setMutexProperties(MutexIF::TimeoutType timeoutType, dur_millis_t timeoutMs);
ReturnValue_t initialize() override; ReturnValue_t initialize() override;
void checkAndSetClientAddress(sockaddr_in& clientAddress); void checkAndSetClientAddress(sockaddr_in& clientAddress);
void setClientAddressToAny(bool ipAddrAnySet);
void setClientAddressToAny(bool ipAddrAnySet);
protected: protected:
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override; virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
private: private:
int serverSocket = 0; int serverSocket = 0;
std::string udpServerPort; std::string udpServerPort;
std::string udpClientPort;
const int serverSocketOptions = 0; struct sockaddr_in clientAddress;
socklen_t clientAddressLen = 0;
struct sockaddr_in clientAddress; bool ipAddrAnySet = false;
socklen_t clientAddressLen = 0;
struct sockaddr_in serverAddress; //! Access to the client address is mutex protected as it is set by another task.
socklen_t serverAddressLen = 0; MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
dur_millis_t mutexTimeoutMs = 20;
bool ipAddrAnySet = false; MutexIF* mutex;
//! 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;
}; };
#endif /* FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ */ #endif /* FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ */

View File

@ -8,7 +8,7 @@
//! Debugging preprocessor define. //! Debugging preprocessor define.
#define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0 #define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0
const std::string TmTcWinUdpBridge::DEFAULT_UDP_SERVER_PORT = "7301"; const std::string TmTcWinUdpBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_UDP_SERVER_PORT;
TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, object_id_t tcDestination, TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId, std::string udpServerPort): object_id_t tmStoreId, object_id_t tcStoreId, std::string udpServerPort):