fsfw/src/fsfw/osal/common/TcpTmTcBridge.cpp

72 lines
2.1 KiB
C++
Raw Normal View History

2021-07-13 21:02:53 +02:00
#include "fsfw/osal/common/TcpTmTcBridge.h"
2021-05-05 12:59:42 +02:00
2021-07-13 21:02:53 +02:00
#include "fsfw/ipc/MutexGuard.h"
#include "fsfw/osal/common/TcpTmTcBridge.h"
2022-02-02 10:29:30 +01:00
#include "fsfw/platform.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
2021-05-05 12:59:42 +02:00
2021-07-13 21:02:53 +02:00
#ifdef PLATFORM_WIN
2021-05-05 12:59:42 +02:00
#include <ws2tcpip.h>
2021-07-13 21:02:53 +02:00
#elif defined PLATFORM_UNIX
2021-05-05 12:59:42 +02:00
#include <arpa/inet.h>
2022-02-02 10:29:30 +01:00
#include <netdb.h>
2021-05-05 12:59:42 +02:00
#endif
2022-02-02 10:29:30 +01:00
TcpTmTcBridge::TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination, object_id_t tmStoreId,
object_id_t tcStoreId)
: TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
mutex = MutexFactory::instance()->createMutex();
// Connection is always up, TM is requested by connecting to server and receiving packets
registerCommConnect();
2021-05-05 12:59:42 +02:00
}
ReturnValue_t TcpTmTcBridge::initialize() {
2022-02-02 10:29:30 +01:00
ReturnValue_t result = TmTcBridge::initialize();
2022-08-15 20:28:16 +02:00
if (result != returnvalue::OK) {
2021-05-05 12:59:42 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::error << "TcpTmTcBridge::initialize: TmTcBridge initialization failed!" << std::endl;
#else
2022-02-02 10:29:30 +01:00
sif::printError("TcpTmTcBridge::initialize: TmTcBridge initialization failed!\n");
2021-05-05 12:59:42 +02:00
#endif
2022-02-02 10:29:30 +01:00
return result;
}
2021-05-05 12:59:42 +02:00
2022-08-15 20:28:16 +02:00
return returnvalue::OK;
2021-05-05 12:59:42 +02:00
}
TcpTmTcBridge::~TcpTmTcBridge() {
2022-02-02 10:29:30 +01:00
if (mutex != nullptr) {
MutexFactory::instance()->deleteMutex(mutex);
}
2021-05-05 12:59:42 +02:00
}
ReturnValue_t TcpTmTcBridge::handleTm() {
2022-02-02 10:29:30 +01:00
// Simply store the telemetry in the FIFO, the server will use it to access the TM
MutexGuard guard(mutex, timeoutType, mutexTimeoutMs);
TmTcMessage message;
2022-08-15 20:28:16 +02:00
ReturnValue_t status = returnvalue::OK;
2022-02-02 10:29:30 +01:00
for (ReturnValue_t result = tmTcReceptionQueue->receiveMessage(&message);
2022-08-15 20:28:16 +02:00
result == returnvalue::OK;
2022-02-02 10:29:30 +01:00
result = tmTcReceptionQueue->receiveMessage(&message)) {
status = storeDownlinkData(&message);
2022-08-15 20:28:16 +02:00
if (status != returnvalue::OK) {
2022-02-02 10:29:30 +01:00
break;
}
2022-02-02 10:29:30 +01:00
}
2022-08-15 20:28:16 +02:00
return returnvalue::OK;
}
2021-05-05 12:59:42 +02:00
ReturnValue_t TcpTmTcBridge::sendTm(const uint8_t *data, size_t dataLen) {
2022-02-02 10:29:30 +01:00
// Not used. The Server uses the FIFO to access and send the telemetry.
2022-08-15 20:28:16 +02:00
return returnvalue::OK;
2021-05-05 12:59:42 +02:00
}
2022-02-02 10:29:30 +01:00
void TcpTmTcBridge::setMutexProperties(MutexIF::TimeoutType timeoutType, dur_millis_t timeoutMs) {
this->timeoutType = timeoutType;
this->mutexTimeoutMs = timeoutMs;
2021-05-05 12:59:42 +02:00
}