updated unix udp bridge

This commit is contained in:
Robin Müller 2020-08-28 17:14:20 +02:00
parent 6c0defed5e
commit aec557a8c0
6 changed files with 111 additions and 103 deletions

View File

@ -1,92 +1,99 @@
#include "timevalOperations.h"
timeval& operator+=(timeval& lhs, const timeval& rhs) {
int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec;
sum += rhs.tv_sec * 1000000. + rhs.tv_usec;
lhs.tv_sec = sum / 1000000;
lhs.tv_usec = sum - lhs.tv_sec * 1000000;
return lhs;
}
timeval operator+(timeval lhs, const timeval& rhs) {
lhs += rhs;
return lhs;
}
timeval& operator-=(timeval& lhs, const timeval& rhs) {
int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec;
sum -= rhs.tv_sec * 1000000. + rhs.tv_usec;
lhs.tv_sec = sum / 1000000;
lhs.tv_usec = sum - lhs.tv_sec * 1000000;
return lhs;
}
timeval operator-(timeval lhs, const timeval& rhs) {
lhs -= rhs;
return lhs;
}
double operator/(const timeval& lhs, const timeval& rhs) {
double lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
double rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
return lhs64 / rhs64;
}
timeval& operator/=(timeval& lhs, double scalar) {
int64_t product = lhs.tv_sec * 1000000. + lhs.tv_usec;
product /= scalar;
lhs.tv_sec = product / 1000000;
lhs.tv_usec = product - lhs.tv_sec * 1000000;
return lhs;
}
timeval operator/(timeval lhs, double scalar) {
lhs /= scalar;
return lhs;
}
timeval& operator*=(timeval& lhs, double scalar) {
int64_t product = lhs.tv_sec * 1000000. + lhs.tv_usec;
product *= scalar;
lhs.tv_sec = product / 1000000;
lhs.tv_usec = product - lhs.tv_sec * 1000000;
return lhs;
}
timeval operator*(timeval lhs, double scalar) {
lhs *= scalar;
return lhs;
}
timeval operator*(double scalar, timeval rhs) {
rhs *= scalar;
return rhs;
}
bool operator==(const timeval& lhs, const timeval& rhs) {
int64_t lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
int64_t rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
return lhs64 == rhs64;
}
bool operator!=(const timeval& lhs, const timeval& rhs) {
return !operator==(lhs, rhs);
}
bool operator<(const timeval& lhs, const timeval& rhs) {
int64_t lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
int64_t rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
return lhs64 < rhs64;
}
bool operator>(const timeval& lhs, const timeval& rhs) {
return operator<(rhs, lhs);
}
bool operator<=(const timeval& lhs, const timeval& rhs) {
return !operator>(lhs, rhs);
}
bool operator>=(const timeval& lhs, const timeval& rhs) {
return !operator<(lhs, rhs);
}
double timevalOperations::toDouble(const timeval timeval) {
double result = timeval.tv_sec * 1000000. + timeval.tv_usec;
return result / 1000000.;
}
#include "timevalOperations.h"
timeval& operator+=(timeval& lhs, const timeval& rhs) {
int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec;
sum += rhs.tv_sec * 1000000. + rhs.tv_usec;
lhs.tv_sec = sum / 1000000;
lhs.tv_usec = sum - lhs.tv_sec * 1000000;
return lhs;
}
timeval operator+(timeval lhs, const timeval& rhs) {
lhs += rhs;
return lhs;
}
timeval& operator-=(timeval& lhs, const timeval& rhs) {
int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec;
sum -= rhs.tv_sec * 1000000. + rhs.tv_usec;
lhs.tv_sec = sum / 1000000;
lhs.tv_usec = sum - lhs.tv_sec * 1000000;
return lhs;
}
timeval operator-(timeval lhs, const timeval& rhs) {
lhs -= rhs;
return lhs;
}
double operator/(const timeval& lhs, const timeval& rhs) {
double lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
double rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
return lhs64 / rhs64;
}
timeval& operator/=(timeval& lhs, double scalar) {
int64_t product = lhs.tv_sec * 1000000. + lhs.tv_usec;
product /= scalar;
lhs.tv_sec = product / 1000000;
lhs.tv_usec = product - lhs.tv_sec * 1000000;
return lhs;
}
timeval operator/(timeval lhs, double scalar) {
lhs /= scalar;
return lhs;
}
timeval& operator*=(timeval& lhs, double scalar) {
int64_t product = lhs.tv_sec * 1000000. + lhs.tv_usec;
product *= scalar;
lhs.tv_sec = product / 1000000;
lhs.tv_usec = product - lhs.tv_sec * 1000000;
return lhs;
}
timeval operator*(timeval lhs, double scalar) {
lhs *= scalar;
return lhs;
}
timeval operator*(double scalar, timeval rhs) {
rhs *= scalar;
return rhs;
}
bool operator==(const timeval& lhs, const timeval& rhs) {
int64_t lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
int64_t rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
return lhs64 == rhs64;
}
bool operator!=(const timeval& lhs, const timeval& rhs) {
return !operator==(lhs, rhs);
}
bool operator<(const timeval& lhs, const timeval& rhs) {
int64_t lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
int64_t rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
return lhs64 < rhs64;
}
bool operator>(const timeval& lhs, const timeval& rhs) {
return operator<(rhs, lhs);
}
bool operator<=(const timeval& lhs, const timeval& rhs) {
return !operator>(lhs, rhs);
}
bool operator>=(const timeval& lhs, const timeval& rhs) {
return !operator<(lhs, rhs);
}
double timevalOperations::toDouble(const timeval timeval) {
double result = timeval.tv_sec * 1000000. + timeval.tv_usec;
return result / 1000000.;
}
timeval timevalOperations::toTimeval(const double seconds) {
timeval tval;
tval.tv_sec = seconds;
tval.tv_usec = seconds *(double) 1e6 - (tval.tv_sec *1e6);
return tval;
}

View File

@ -41,6 +41,7 @@ namespace timevalOperations {
* @return seconds
*/
double toDouble(const timeval timeval);
timeval toTimeval(const double seconds);
}
#endif /* TIMEVALOPERATIONS_H_ */

View File

@ -1,5 +1,5 @@
#include <framework/osal/linux/TcUnixUdpPollingTask.h>
#include <framework/globalfunctions/arrayprinter.h>
#include "TcUnixUdpPollingTask.h"
#include "../../globalfunctions/arrayprinter.h"
TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId,
object_id_t tmtcUnixUdpBridge, size_t frameSize,

View File

@ -1,9 +1,9 @@
#ifndef FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_
#define FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_
#include <framework/objectmanager/SystemObject.h>
#include <framework/osal/linux/TmTcUnixUdpBridge.h>
#include <framework/tasks/ExecutableObjectIF.h>
#include "../../objectmanager/SystemObject.h"
#include "../../osal/linux/TmTcUnixUdpBridge.h"
#include "../../tasks/ExecutableObjectIF.h"
#include <sys/socket.h>
#include <vector>

View File

@ -1,6 +1,6 @@
#include <framework/osal/linux/TmTcUnixUdpBridge.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/ipc/MutexHelper.h>
#include "TmTcUnixUdpBridge.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../ipc/MutexHelper.h"
#include <errno.h>
#include <arpa/inet.h>
@ -85,7 +85,7 @@ ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
}
void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
MutexHelper lock(mutex, 10);
MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10);
// char ipAddress [15];
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,

View File

@ -1,8 +1,8 @@
#ifndef FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_
#define FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
#include <framework/tmtcservices/TmTcBridge.h>
#include "../../tmtcservices/AcceptsTelecommandsIF.h"
#include "../../tmtcservices/TmTcBridge.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/udp.h>