Merge remote-tracking branch 'ksat/mueller/master' into mueller/master
This commit is contained in:
commit
ff6b4134a5
@ -1,15 +1,23 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
ipc/missionMessageTypes.cpp
|
||||
objects/FsfwFactory.cpp
|
||||
pollingsequence/PollingSequenceFactory.cpp
|
||||
)
|
||||
|
||||
# Should be added to include path
|
||||
target_include_directories(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
if(NOT FSFW_CONFIG_PATH)
|
||||
set(FSFW_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
ipc/missionMessageTypes.cpp
|
||||
pollingsequence/PollingSequenceFactory.cpp
|
||||
objects/FsfwFactory.cpp
|
||||
)
|
||||
|
||||
# If a special translation file for object IDs exists, compile it.
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
objects/translateObjects.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
# If a special translation file for events exists, compile it.
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
events/translateEvents.cpp
|
||||
)
|
||||
endif()
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "EventManager.h"
|
||||
#include "EventMessage.h"
|
||||
|
||||
#include <FSFWConfig.h>
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
#include "../ipc/MutexFactory.h"
|
||||
|
||||
@ -115,53 +113,6 @@ ReturnValue_t EventManager::unsubscribeFromEventRange(MessageQueueId_t listener,
|
||||
return result;
|
||||
}
|
||||
|
||||
#if FSFW_OBJ_EVENT_TRANSLATION == 1
|
||||
|
||||
void EventManager::printEvent(EventMessage* message) {
|
||||
const char *string = 0;
|
||||
switch (message->getSeverity()) {
|
||||
case severity::INFO:
|
||||
#if DEBUG_INFO_EVENT == 1
|
||||
string = translateObject(message->getReporter());
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "EVENT: ";
|
||||
if (string != 0) {
|
||||
sif::info << string;
|
||||
} else {
|
||||
sif::info << "0x" << std::hex << message->getReporter() << std::dec;
|
||||
}
|
||||
sif::info << " reported " << translateEvents(message->getEvent()) << " ("
|
||||
<< std::dec << message->getEventId() << std::hex << ") P1: 0x"
|
||||
<< message->getParameter1() << " P2: 0x"
|
||||
<< message->getParameter2() << std::dec << std::endl;
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* DEBUG_INFO_EVENT == 1 */
|
||||
break;
|
||||
default:
|
||||
string = translateObject(message->getReporter());
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "EventManager: ";
|
||||
if (string != 0) {
|
||||
sif::debug << string;
|
||||
}
|
||||
else {
|
||||
sif::debug << "0x" << std::hex << message->getReporter() << std::dec;
|
||||
}
|
||||
sif::debug << " reported " << translateEvents(message->getEvent())
|
||||
<< " (" << std::dec << message->getEventId() << ") "
|
||||
<< std::endl;
|
||||
sif::debug << std::hex << "P1 Hex: 0x" << message->getParameter1()
|
||||
<< ", P1 Dec: " << std::dec << message->getParameter1()
|
||||
<< std::endl;
|
||||
sif::debug << std::hex << "P2 Hex: 0x" << message->getParameter2()
|
||||
<< ", P2 Dec: " << std::dec << message->getParameter2()
|
||||
<< std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void EventManager::lockMutex() {
|
||||
mutex->lockMutex(timeoutType, timeoutMs);
|
||||
}
|
||||
@ -175,3 +126,85 @@ void EventManager::setMutexTimeout(MutexIF::TimeoutType timeoutType,
|
||||
this->timeoutType = timeoutType;
|
||||
this->timeoutMs = timeoutMs;
|
||||
}
|
||||
|
||||
#if FSFW_OBJ_EVENT_TRANSLATION == 1
|
||||
|
||||
void EventManager::printEvent(EventMessage* message) {
|
||||
switch (message->getSeverity()) {
|
||||
case severity::INFO: {
|
||||
#if FSFW_DEBUG_INFO == 1
|
||||
printUtility(sif::OutputTypes::OUT_INFO, message);
|
||||
#endif /* DEBUG_INFO_EVENT == 1 */
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printUtility(sif::OutputTypes::OUT_DEBUG, message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::printUtility(sif::OutputTypes printType, EventMessage *message) {
|
||||
const char *string = 0;
|
||||
if(printType == sif::OutputTypes::OUT_INFO) {
|
||||
string = translateObject(message->getReporter());
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "EventManager: ";
|
||||
if (string != 0) {
|
||||
sif::info << string;
|
||||
}
|
||||
else {
|
||||
sif::info << "0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||
message->getReporter() << std::setfill(' ') << std::dec;
|
||||
}
|
||||
sif::info << " report event with ID " << message->getEventId() << std::endl;
|
||||
sif::info << std::hex << "P1 Hex: 0x" << message->getParameter1() <<
|
||||
" | P1 Dec: " << std::dec << message->getParameter1() << std::hex <<
|
||||
" | P2 Hex: 0x" << message->getParameter2() << " | P2 Dec: " << std::dec <<
|
||||
message->getParameter2() << std::endl;
|
||||
#else
|
||||
if (string != 0) {
|
||||
sif::printInfo("Event Manager: %s reported event with ID %d\n", string,
|
||||
message->getEventId());
|
||||
}
|
||||
else {
|
||||
sif::printInfo("Event Manager: Reporter ID 0x%08x reported event with ID %d\n",
|
||||
message->getReporter(), message->getEventId());
|
||||
}
|
||||
sif::printInfo("P1 Hex: 0x%x | P1 Dec: %d | P2 Hex: 0x%x | P2 Dec: %d\n",
|
||||
message->getParameter1(), message->getParameter1(),
|
||||
message->getParameter2(), message->getParameter2());
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */
|
||||
}
|
||||
else {
|
||||
string = translateObject(message->getReporter());
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "EventManager: ";
|
||||
if (string != 0) {
|
||||
sif::debug << string;
|
||||
}
|
||||
else {
|
||||
sif::debug << "0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||
message->getReporter() << std::setfill(' ') << std::dec;
|
||||
}
|
||||
sif::debug << " report event with ID " << message->getEventId() << std::endl;
|
||||
sif::debug << std::hex << "P1 Hex: 0x" << message->getParameter1() <<
|
||||
" | P1 Dec: " << std::dec << message->getParameter1() << std::hex <<
|
||||
" | P2 Hex: 0x" << message->getParameter2() << " | P2 Dec: " << std::dec <<
|
||||
message->getParameter2() << std::endl;
|
||||
#else
|
||||
if (string != 0) {
|
||||
sif::printDebug("Event Manager: %s reported event with ID %d\n", string,
|
||||
message->getEventId());
|
||||
}
|
||||
else {
|
||||
sif::printDebug("Event Manager: Reporter ID 0x%08x reported event with ID %d\n",
|
||||
message->getReporter(), message->getEventId());
|
||||
}
|
||||
sif::printDebug("P1 Hex: 0x%x | P1 Dec: %d | P2 Hex: 0x%x | P2 Dec: %d\n",
|
||||
message->getParameter1(), message->getParameter1(),
|
||||
message->getParameter2(), message->getParameter2());
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* FSFW_OBJ_EVENT_TRANSLATION == 1 */
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <FSFWConfig.h>
|
||||
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
#include "../storagemanager/LocalPool.h"
|
||||
#include "../tasks/ExecutableObjectIF.h"
|
||||
@ -67,6 +68,7 @@ protected:
|
||||
|
||||
#if FSFW_OBJ_EVENT_TRANSLATION == 1
|
||||
void printEvent(EventMessage *message);
|
||||
void printUtility(sif::OutputTypes printType, EventMessage* message);
|
||||
#endif
|
||||
|
||||
void lockMutex();
|
||||
|
@ -22,11 +22,11 @@ public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MESSAGE_QUEUE_IF;
|
||||
//! No new messages on the queue
|
||||
static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(1);
|
||||
//! No space left for more messages
|
||||
//! [EXPORT] : [COMMENT] No space left for more messages
|
||||
static const ReturnValue_t FULL = MAKE_RETURN_CODE(2);
|
||||
//! Returned if a reply method was called without partner
|
||||
//! [EXPORT] : [COMMENT] Returned if a reply method was called without partner
|
||||
static const ReturnValue_t NO_REPLY_PARTNER = MAKE_RETURN_CODE(3);
|
||||
//! Returned if the target destination is invalid.
|
||||
//! [EXPORT] : [COMMENT] Returned if the target destination is invalid.
|
||||
static constexpr ReturnValue_t DESTINATION_INVALID = MAKE_RETURN_CODE(4);
|
||||
|
||||
virtual ~MessageQueueIF() {}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "frameworkObjects.h"
|
||||
#include "SystemObjectIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
|
||||
/**
|
||||
* @brief This class provides an interface to the global object manager.
|
||||
|
@ -5,6 +5,7 @@ if(DEFINED WIN32 OR DEFINED UNIX)
|
||||
UdpTcPollingTask.cpp
|
||||
UdpTmTcBridge.cpp
|
||||
TcpTmTcServer.cpp
|
||||
TcpTmTcBridge.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
#include "TcpIpBase.h"
|
||||
#include "../../platform.h"
|
||||
|
||||
#ifdef __unix__
|
||||
|
||||
#ifdef PLATFORM_UNIX
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#endif
|
||||
|
||||
TcpIpBase::TcpIpBase() {
|
||||
@ -37,17 +36,17 @@ TcpIpBase::~TcpIpBase() {
|
||||
}
|
||||
|
||||
int TcpIpBase::closeSocket(socket_t socket) {
|
||||
#ifdef _WIN32
|
||||
#ifdef PLATFORM_WIN
|
||||
return closesocket(socket);
|
||||
#elif defined(__unix__)
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
return close(socket);
|
||||
#endif
|
||||
}
|
||||
|
||||
int TcpIpBase::getLastSocketError() {
|
||||
#ifdef _WIN32
|
||||
#ifdef PLATFORM_WIN
|
||||
return WSAGetLastError();
|
||||
#elif defined(__unix__)
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
return errno;
|
||||
#endif
|
||||
}
|
||||
|
@ -1,28 +1,25 @@
|
||||
#ifndef FSFW_OSAL_COMMON_TCPIPIF_H_
|
||||
#define FSFW_OSAL_COMMON_TCPIPIF_H_
|
||||
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../../platform.h"
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <winsock2.h>
|
||||
|
||||
#elif defined(__unix__)
|
||||
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <sys/socket.h>
|
||||
|
||||
#endif
|
||||
|
||||
class TcpIpBase {
|
||||
protected:
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef PLATFORM_WIN
|
||||
static constexpr int SHUT_RECV = SD_RECEIVE;
|
||||
static constexpr int SHUT_SEND = SD_SEND;
|
||||
static constexpr int SHUT_BOTH = SD_BOTH;
|
||||
|
||||
using socket_t = SOCKET;
|
||||
#elif defined(__unix__)
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
using socket_t = int;
|
||||
|
||||
static constexpr int INVALID_SOCKET = -1;
|
||||
|
77
osal/common/TcpTmTcBridge.cpp
Normal file
77
osal/common/TcpTmTcBridge.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include "TcpTmTcBridge.h"
|
||||
#include "tcpipHelpers.h"
|
||||
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
#include <fsfw/ipc/MutexGuard.h>
|
||||
#include <fsfw/osal/common/TcpTmTcBridge.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#elif defined(__unix__)
|
||||
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#endif
|
||||
|
||||
const std::string TcpTmTcBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
ReturnValue_t TcpTmTcBridge::initialize() {
|
||||
ReturnValue_t result = TmTcBridge::initialize();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TcpTmTcBridge::initialize: TmTcBridge initialization failed!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printError("TcpTmTcBridge::initialize: TmTcBridge initialization failed!\n");
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
TcpTmTcBridge::~TcpTmTcBridge() {
|
||||
if(mutex != nullptr) {
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t TcpTmTcBridge::handleTm() {
|
||||
// Simply store the telemetry in the FIFO, the server will use it to access the TM
|
||||
MutexGuard guard(mutex, timeoutType, mutexTimeoutMs);
|
||||
TmTcMessage message;
|
||||
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
|
||||
for (ReturnValue_t result = tmTcReceptionQueue->receiveMessage(&message);
|
||||
result == HasReturnvaluesIF::RETURN_OK;
|
||||
result = tmTcReceptionQueue->receiveMessage(&message))
|
||||
{
|
||||
status = storeDownlinkData(&message);
|
||||
if(status != HasReturnvaluesIF::RETURN_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TcpTmTcBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
||||
// Not used. The Server uses the FIFO to access and send the telemetry.
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
void TcpTmTcBridge::setMutexProperties(MutexIF::TimeoutType timeoutType,
|
||||
dur_millis_t timeoutMs) {
|
||||
this->timeoutType = timeoutType;
|
||||
this->mutexTimeoutMs = timeoutMs;
|
||||
}
|
71
osal/common/TcpTmTcBridge.h
Normal file
71
osal/common/TcpTmTcBridge.h
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef FSFW_OSAL_COMMON_TCPTMTCBRIDGE_H_
|
||||
#define FSFW_OSAL_COMMON_TCPTMTCBRIDGE_H_
|
||||
|
||||
#include "TcpIpBase.h"
|
||||
#include "../../tmtcservices/TmTcBridge.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#elif defined(__unix__)
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* @brief This class should be used with the TcpTmTcServer to implement a TCP server
|
||||
* for receiving and sending PUS telemetry and telecommands (TMTC)
|
||||
* @details
|
||||
* This bridge tasks takes care of filling a FIFO which generated telemetry. The TcpTmTcServer
|
||||
* will take care of sending the telemetry stored in the FIFO if a client connects to the
|
||||
* server. This bridge will also be the default destination for telecommands, but the telecommands
|
||||
* will be relayed to a specified tcDestination directly.
|
||||
*/
|
||||
class TcpTmTcBridge:
|
||||
public TmTcBridge {
|
||||
friend class TcpTmTcServer;
|
||||
public:
|
||||
/* The ports chosen here should not be used by any other process. */
|
||||
static const std::string DEFAULT_UDP_SERVER_PORT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param objectId Object ID of the TcpTmTcBridge.
|
||||
* @param tcDestination Destination for received TC packets. Any received telecommands will
|
||||
* be sent there directly. The destination object needs to implement
|
||||
* AcceptsTelecommandsIF.
|
||||
* @param tmStoreId TM store object ID. It is recommended to the default object ID
|
||||
* @param tcStoreId TC store object ID. It is recommended to the default object ID
|
||||
*/
|
||||
TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
object_id_t tmStoreId = objects::TM_STORE,
|
||||
object_id_t tcStoreId = objects::TC_STORE);
|
||||
virtual~ TcpTmTcBridge();
|
||||
|
||||
/**
|
||||
* Set properties of internal mutex.
|
||||
*/
|
||||
void setMutexProperties(MutexIF::TimeoutType timeoutType, dur_millis_t timeoutMs);
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
|
||||
|
||||
protected:
|
||||
ReturnValue_t handleTm() override;
|
||||
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
|
||||
|
||||
private:
|
||||
|
||||
//! Access to the FIFO needs to be mutex protected because it is used by the bridge and
|
||||
//! the server.
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
||||
dur_millis_t mutexTimeoutMs = 20;
|
||||
MutexIF* mutex;
|
||||
};
|
||||
|
||||
#endif /* FSFW_OSAL_COMMON_TCPTMTCBRIDGE_H_ */
|
||||
|
@ -1,23 +1,33 @@
|
||||
#include "TcpTmTcServer.h"
|
||||
#include "TcpTmTcBridge.h"
|
||||
#include "tcpipHelpers.h"
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "../../platform.h"
|
||||
#include "../../container/SharedRingBuffer.h"
|
||||
#include "../../ipc/MessageQueueSenderIF.h"
|
||||
#include "../../ipc/MutexGuard.h"
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
#include "../../tmtcservices/TmTcMessage.h"
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#elif defined(__unix__)
|
||||
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <netdb.h>
|
||||
|
||||
#endif
|
||||
|
||||
const std::string TcpTmTcServer::DEFAULT_TCP_SERVER_PORT = "7301";
|
||||
const std::string TcpTmTcServer::DEFAULT_TCP_CLIENT_PORT = "7302";
|
||||
#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED
|
||||
#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0
|
||||
#endif
|
||||
|
||||
TcpTmTcServer::TcpTmTcServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
||||
std::string customTcpServerPort):
|
||||
SystemObject(objectId), tcpPort(customTcpServerPort) {
|
||||
const std::string TcpTmTcServer::DEFAULT_TCP_SERVER_PORT = "7303";
|
||||
|
||||
TcpTmTcServer::TcpTmTcServer(object_id_t objectId, object_id_t tmtcTcpBridge,
|
||||
size_t receptionBufferSize, std::string customTcpServerPort):
|
||||
SystemObject(objectId), tmtcBridgeId(tmtcTcpBridge),
|
||||
tcpPort(customTcpServerPort), receptionBuffer(receptionBufferSize) {
|
||||
if(tcpPort == "") {
|
||||
tcpPort = DEFAULT_TCP_SERVER_PORT;
|
||||
}
|
||||
@ -31,6 +41,18 @@ ReturnValue_t TcpTmTcServer::initialize() {
|
||||
return result;
|
||||
}
|
||||
|
||||
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
||||
if (tcStore == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TcpTmTcServer::initialize: TC store uninitialized!" << std::endl;
|
||||
#else
|
||||
sif::printError("TcpTmTcServer::initialize: TC store uninitialized!\n");
|
||||
#endif
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
tmtcBridge = objectManager->get<TcpTmTcBridge>(tmtcBridgeId);
|
||||
|
||||
int retval = 0;
|
||||
struct addrinfo *addrResult = nullptr;
|
||||
struct addrinfo hints = {};
|
||||
@ -40,34 +62,25 @@ ReturnValue_t TcpTmTcServer::initialize() {
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
||||
// Listen to all addresses (0.0.0.0) by using AI_PASSIVE in the hint flags
|
||||
retval = getaddrinfo(nullptr, tcpPort.c_str(), &hints, &addrResult);
|
||||
if (retval != 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TcWinTcpServer::TcpTmTcServer: Retrieving address info failed!" <<
|
||||
std::endl;
|
||||
#endif
|
||||
handleError(Protocol::TCP, ErrorSources::GETADDRINFO_CALL);
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
/* Open TCP (stream) socket */
|
||||
// Open TCP (stream) socket
|
||||
listenerTcpSocket = socket(addrResult->ai_family, addrResult->ai_socktype,
|
||||
addrResult->ai_protocol);
|
||||
if(listenerTcpSocket == INVALID_SOCKET) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TcWinTcpServer::TcWinTcpServer: Socket creation failed!" << std::endl;
|
||||
#endif
|
||||
freeaddrinfo(addrResult);
|
||||
handleError(Protocol::TCP, ErrorSources::SOCKET_CALL);
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
// Bind to the address found by getaddrinfo
|
||||
retval = bind(listenerTcpSocket, addrResult->ai_addr, static_cast<int>(addrResult->ai_addrlen));
|
||||
if(retval == SOCKET_ERROR) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TcWinTcpServer::TcpTmTcServer: Binding socket failed!" <<
|
||||
std::endl;
|
||||
#endif
|
||||
freeaddrinfo(addrResult);
|
||||
handleError(Protocol::TCP, ErrorSources::BIND_CALL);
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
@ -84,49 +97,130 @@ TcpTmTcServer::~TcpTmTcServer() {
|
||||
|
||||
ReturnValue_t TcpTmTcServer::performOperation(uint8_t opCode) {
|
||||
using namespace tcpip;
|
||||
/* If a connection is accepted, the corresponding socket will be assigned to the new socket */
|
||||
socket_t clientSocket = 0;
|
||||
sockaddr clientSockAddr = {};
|
||||
socklen_t connectorSockAddrLen = 0;
|
||||
// If a connection is accepted, the corresponding socket will be assigned to the new socket
|
||||
socket_t connSocket = 0;
|
||||
// sockaddr clientSockAddr = {};
|
||||
// socklen_t connectorSockAddrLen = 0;
|
||||
int retval = 0;
|
||||
|
||||
/* Listen for connection requests permanently for lifetime of program */
|
||||
// Listen for connection requests permanently for lifetime of program
|
||||
while(true) {
|
||||
retval = listen(listenerTcpSocket, currentBacklog);
|
||||
retval = listen(listenerTcpSocket, tcpBacklog);
|
||||
if(retval == SOCKET_ERROR) {
|
||||
handleError(Protocol::TCP, ErrorSources::LISTEN_CALL, 500);
|
||||
continue;
|
||||
}
|
||||
|
||||
clientSocket = accept(listenerTcpSocket, &clientSockAddr, &connectorSockAddrLen);
|
||||
//connSocket = accept(listenerTcpSocket, &clientSockAddr, &connectorSockAddrLen);
|
||||
connSocket = accept(listenerTcpSocket, nullptr, nullptr);
|
||||
|
||||
if(clientSocket == INVALID_SOCKET) {
|
||||
if(connSocket == INVALID_SOCKET) {
|
||||
handleError(Protocol::TCP, ErrorSources::ACCEPT_CALL, 500);
|
||||
closeSocket(clientSocket);
|
||||
closeSocket(connSocket);
|
||||
continue;
|
||||
};
|
||||
|
||||
retval = recv(clientSocket, reinterpret_cast<char*>(receptionBuffer.data()),
|
||||
receptionBuffer.size(), 0);
|
||||
if(retval > 0) {
|
||||
#if FSFW_TCP_RCV_WIRETAPPING_ENABLED == 1
|
||||
sif::info << "TcpTmTcServer::performOperation: Received " << retval << " bytes."
|
||||
std::endl;
|
||||
#endif
|
||||
handleError(Protocol::TCP, ErrorSources::RECV_CALL, 500);
|
||||
}
|
||||
else if(retval == 0) {
|
||||
handleServerOperation(connSocket);
|
||||
|
||||
// Done, shut down connection and go back to listening for client requests
|
||||
retval = shutdown(connSocket, SHUT_SEND);
|
||||
if(retval != 0) {
|
||||
handleError(Protocol::TCP, ErrorSources::SHUTDOWN_CALL);
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
/* Done, shut down connection */
|
||||
retval = shutdown(clientSocket, SHUT_SEND);
|
||||
closeSocket(clientSocket);
|
||||
closeSocket(connSocket);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TcpTmTcServer::initializeAfterTaskCreation() {
|
||||
if(tmtcBridge == nullptr) {
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
/* Initialize the destination after task creation. This ensures
|
||||
that the destination has already been set in the TMTC bridge. */
|
||||
targetTcDestination = tmtcBridge->getRequestQueue();
|
||||
tcStore = tmtcBridge->tcStore;
|
||||
tmStore = tmtcBridge->tmStore;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void TcpTmTcServer::handleServerOperation(socket_t connSocket) {
|
||||
int retval = 0;
|
||||
do {
|
||||
// Read all telecommands sent by the client
|
||||
retval = recv(connSocket,
|
||||
reinterpret_cast<char*>(receptionBuffer.data()),
|
||||
receptionBuffer.capacity(),
|
||||
tcpFlags);
|
||||
if (retval > 0) {
|
||||
handleTcReception(retval);
|
||||
}
|
||||
else if(retval == 0) {
|
||||
// Client has finished sending telecommands, send telemetry now
|
||||
handleTmSending(connSocket);
|
||||
}
|
||||
else {
|
||||
// Should not happen
|
||||
tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::RECV_CALL);
|
||||
}
|
||||
} while(retval > 0);
|
||||
}
|
||||
|
||||
ReturnValue_t TcpTmTcServer::handleTcReception(size_t bytesRecvd) {
|
||||
#if FSFW_TCP_RECV_WIRETAPPING_ENABLED == 1
|
||||
arrayprinter::print(receptionBuffer.data(), bytesRead);
|
||||
#endif
|
||||
store_address_t storeId;
|
||||
ReturnValue_t result = tcStore->addData(&storeId, receptionBuffer.data(), bytesRecvd);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning<< "TcpTmTcServer::handleServerOperation: Data storage failed." << std::endl;
|
||||
sif::warning << "Packet size: " << bytesRecvd << std::endl;
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
}
|
||||
|
||||
TmTcMessage message(storeId);
|
||||
|
||||
result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UdpTcPollingTask::handleSuccessfullTcRead: "
|
||||
" Sending message to queue failed" << std::endl;
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
tcStore->deleteData(storeId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void TcpTmTcServer::setTcpBacklog(uint8_t tcpBacklog) {
|
||||
this->tcpBacklog = tcpBacklog;
|
||||
}
|
||||
|
||||
ReturnValue_t TcpTmTcServer::handleTmSending(socket_t connSocket) {
|
||||
// Access to the FIFO is mutex protected because it is filled by the bridge
|
||||
MutexGuard(tmtcBridge->mutex, tmtcBridge->timeoutType, tmtcBridge->mutexTimeoutMs);
|
||||
store_address_t storeId;
|
||||
while((not tmtcBridge->tmFifo->empty()) and
|
||||
(tmtcBridge->packetSentCounter < tmtcBridge->sentPacketsPerCycle)) {
|
||||
tmtcBridge->tmFifo->retrieve(&storeId);
|
||||
|
||||
// Using the store accessor will take care of deleting TM from the store automatically
|
||||
ConstStorageAccessor storeAccessor(storeId);
|
||||
ReturnValue_t result = tmStore->getData(storeId, storeAccessor);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
int retval = send(connSocket,
|
||||
reinterpret_cast<const char*>(storeAccessor.data()),
|
||||
storeAccessor.size(),
|
||||
tcpTmFlags);
|
||||
if(retval != static_cast<int>(storeAccessor.size())) {
|
||||
tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::SEND_CALL);
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -1,24 +1,40 @@
|
||||
#ifndef FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
||||
#define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
||||
#ifndef FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_
|
||||
#define FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_
|
||||
|
||||
#include "TcpIpBase.h"
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "../../ipc/messageQueueDefinitions.h"
|
||||
#include "../../ipc/MessageQueueIF.h"
|
||||
#include "../../objectmanager/frameworkObjects.h"
|
||||
#include "../../objectmanager/SystemObject.h"
|
||||
#include "../../storagemanager/StorageManagerIF.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
|
||||
#ifdef __unix__
|
||||
#ifdef PLATFORM_UNIX
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
//! Debugging preprocessor define.
|
||||
#define FSFW_TCP_RCV_WIRETAPPING_ENABLED 0
|
||||
class TcpTmTcBridge;
|
||||
|
||||
/**
|
||||
* @brief Windows TCP server used to receive telecommands on a Windows Host
|
||||
* @brief TCP server implementation
|
||||
* @details
|
||||
* Based on: https://docs.microsoft.com/en-us/windows/win32/winsock/complete-server-code
|
||||
* This server will run for the whole program lifetime and will take care of serving client
|
||||
* requests on a specified TCP server port. This server was written in a generic way and
|
||||
* can be used on Unix and on Windows systems.
|
||||
*
|
||||
* If a connection is accepted, the server will read all telecommands sent by a client and then
|
||||
* send all telemetry currently found in the TMTC bridge FIFO.
|
||||
*
|
||||
* Reading telemetry without sending telecommands is possible by connecting, shutting down the
|
||||
* send operation immediately and then reading the telemetry. It is therefore recommended to
|
||||
* connect to the server regularly, even if no telecommands need to be sent.
|
||||
*
|
||||
* The server will listen to a specific port on all addresses (0.0.0.0).
|
||||
*/
|
||||
class TcpTmTcServer:
|
||||
public SystemObject,
|
||||
@ -27,27 +43,51 @@ class TcpTmTcServer:
|
||||
public:
|
||||
/* The ports chosen here should not be used by any other process. */
|
||||
static const std::string DEFAULT_TCP_SERVER_PORT;
|
||||
static const std::string DEFAULT_TCP_CLIENT_PORT;
|
||||
|
||||
TcpTmTcServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
||||
static constexpr size_t ETHERNET_MTU_SIZE = 1500;
|
||||
|
||||
/**
|
||||
* TCP Server Constructor
|
||||
* @param objectId Object ID of the TCP Server
|
||||
* @param tmtcTcpBridge Object ID of the TCP TMTC Bridge object
|
||||
* @param receptionBufferSize This will be the size of the reception buffer. Default buffer
|
||||
* size will be the Ethernet MTU size
|
||||
* @param customTcpServerPort The user can specify another port than the default (7301) here.
|
||||
*/
|
||||
TcpTmTcServer(object_id_t objectId, object_id_t tmtcTcpBridge,
|
||||
size_t receptionBufferSize = ETHERNET_MTU_SIZE + 1,
|
||||
std::string customTcpServerPort = "");
|
||||
virtual~ TcpTmTcServer();
|
||||
|
||||
void setTcpBacklog(uint8_t tcpBacklog);
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
ReturnValue_t performOperation(uint8_t opCode) override;
|
||||
ReturnValue_t initializeAfterTaskCreation() override;
|
||||
|
||||
protected:
|
||||
StorageManagerIF* tcStore = nullptr;
|
||||
StorageManagerIF* tmStore = nullptr;
|
||||
private:
|
||||
//! TMTC bridge is cached.
|
||||
object_id_t tmtcBridgeId = objects::NO_OBJECT;
|
||||
TcpTmTcBridge* tmtcBridge = nullptr;
|
||||
|
||||
std::string tcpPort;
|
||||
int tcpFlags = 0;
|
||||
socket_t listenerTcpSocket = 0;
|
||||
struct sockaddr tcpAddress;
|
||||
MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE;
|
||||
int tcpAddrLen = sizeof(tcpAddress);
|
||||
int currentBacklog = 3;
|
||||
int tcpBacklog = 3;
|
||||
|
||||
std::vector<uint8_t> receptionBuffer;
|
||||
int tcpSockOpt = 0;
|
||||
int tcpTmFlags = 0;
|
||||
|
||||
|
||||
void handleServerOperation(socket_t connSocket);
|
||||
ReturnValue_t handleTcReception(size_t bytesRecvd);
|
||||
ReturnValue_t handleTmSending(socket_t connSocket);
|
||||
};
|
||||
|
||||
#endif /* FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_ */
|
||||
#endif /* FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_ */
|
||||
|
@ -1,26 +1,23 @@
|
||||
#include "UdpTcPollingTask.h"
|
||||
#include "tcpipHelpers.h"
|
||||
#include "../../platform.h"
|
||||
#include "../../globalfunctions/arrayprinter.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <winsock2.h>
|
||||
|
||||
#else
|
||||
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#endif
|
||||
|
||||
//! Debugging preprocessor define.
|
||||
#define FSFW_UDP_RECV_WIRETAPPING_ENABLED 0
|
||||
|
||||
UdpTcPollingTask::UdpTcPollingTask(object_id_t objectId,
|
||||
object_id_t tmtcUnixUdpBridge, size_t maxRecvSize,
|
||||
object_id_t tmtcUdpBridge, size_t maxRecvSize,
|
||||
double timeoutSeconds): SystemObject(objectId),
|
||||
tmtcBridgeId(tmtcUnixUdpBridge) {
|
||||
tmtcBridgeId(tmtcUdpBridge) {
|
||||
if(frameSize > 0) {
|
||||
this->frameSize = frameSize;
|
||||
}
|
||||
@ -155,7 +152,7 @@ ReturnValue_t UdpTcPollingTask::initializeAfterTaskCreation() {
|
||||
}
|
||||
|
||||
void UdpTcPollingTask::setTimeout(double timeoutSeconds) {
|
||||
#ifdef _WIN32
|
||||
#ifdef PLATFORM_WIN
|
||||
DWORD timeoutMs = timeoutSeconds * 1000.0;
|
||||
int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO,
|
||||
reinterpret_cast<const char*>(&timeoutMs), sizeof(DWORD));
|
||||
@ -165,7 +162,7 @@ void UdpTcPollingTask::setTimeout(double timeoutSeconds) {
|
||||
"receive timeout failed with " << strerror(errno) << std::endl;
|
||||
#endif
|
||||
}
|
||||
#elif defined(__unix__)
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
timeval tval;
|
||||
tval = timevalOperations::toTimeval(timeoutSeconds);
|
||||
int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO,
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef FSFW_OSAL_WINDOWS_TCSOCKETPOLLINGTASK_H_
|
||||
#define FSFW_OSAL_WINDOWS_TCSOCKETPOLLINGTASK_H_
|
||||
#ifndef FSFW_OSAL_COMMON_UDPTCPOLLINGTASK_H_
|
||||
#define FSFW_OSAL_COMMON_UDPTCPOLLINGTASK_H_
|
||||
|
||||
#include "UdpTmTcBridge.h"
|
||||
#include "../../objectmanager/SystemObject.h"
|
||||
@ -9,8 +9,11 @@
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* @brief This class should be used with the UdpTmTcBridge to implement a UDP server
|
||||
* @brief This class can be used with the UdpTmTcBridge to implement a UDP server
|
||||
* for receiving and sending PUS TMTC.
|
||||
* @details
|
||||
* This task is exclusively used to poll telecommands from a given socket and transfer them
|
||||
* to the FSFW software bus. It used the blocking recvfrom call to do this.
|
||||
*/
|
||||
class UdpTcPollingTask:
|
||||
public TcpIpBase,
|
||||
@ -22,7 +25,7 @@ public:
|
||||
//! 0.5 default milliseconds timeout for now.
|
||||
static constexpr timeval DEFAULT_TIMEOUT = {0, 500};
|
||||
|
||||
UdpTcPollingTask(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
||||
UdpTcPollingTask(object_id_t objectId, object_id_t tmtcUdpBridge,
|
||||
size_t maxRecvSize = 0, double timeoutSeconds = -1);
|
||||
virtual~ UdpTcPollingTask();
|
||||
|
||||
@ -45,8 +48,6 @@ private:
|
||||
object_id_t tmtcBridgeId = objects::NO_OBJECT;
|
||||
UdpTmTcBridge* tmtcBridge = nullptr;
|
||||
MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE;
|
||||
|
||||
//! See: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom
|
||||
int receptionFlags = 0;
|
||||
|
||||
std::vector<uint8_t> receptionBuffer;
|
||||
@ -57,4 +58,4 @@ private:
|
||||
ReturnValue_t handleSuccessfullTcRead(size_t bytesRead);
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ */
|
||||
#endif /* FSFW_OSAL_COMMON_UDPTCPOLLINGTASK_H_ */
|
||||
|
@ -1,22 +1,21 @@
|
||||
#include "UdpTmTcBridge.h"
|
||||
#include "tcpipHelpers.h"
|
||||
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
#include <fsfw/ipc/MutexGuard.h>
|
||||
#include <fsfw/osal/common/UdpTmTcBridge.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "../../platform.h"
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
#include "../../ipc/MutexGuard.h"
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#elif defined(__unix__)
|
||||
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#endif
|
||||
|
||||
//! Debugging preprocessor define.
|
||||
#ifndef FSFW_UDP_SEND_WIRETAPPING_ENABLED
|
||||
#define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0
|
||||
#endif
|
||||
|
||||
const std::string UdpTmTcBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT;
|
||||
|
||||
@ -38,7 +37,7 @@ ReturnValue_t UdpTmTcBridge::initialize() {
|
||||
ReturnValue_t result = TmTcBridge::initialize();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TmTcUdpBridge::initialize: TmTcBridge initialization failed!"
|
||||
sif::error << "UdpTmTcBridge::initialize: TmTcBridge initialization failed!"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return result;
|
||||
@ -54,10 +53,10 @@ ReturnValue_t UdpTmTcBridge::initialize() {
|
||||
/* Tell the user that we could not find a usable */
|
||||
/* Winsock DLL. */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TmTcUdpBridge::TmTcUdpBridge: WSAStartup failed with error: " <<
|
||||
sif::error << "UdpTmTcBridge::UdpTmTcBridge: WSAStartup failed with error: " <<
|
||||
err << std::endl;
|
||||
#else
|
||||
sif::printError("TmTcUdpBridge::TmTcUdpBridge: WSAStartup failed with error: %d\n",
|
||||
sif::printError("UdpTmTcBridge::UdpTmTcBridge: WSAStartup failed with error: %d\n",
|
||||
err);
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
@ -78,19 +77,12 @@ ReturnValue_t UdpTmTcBridge::initialize() {
|
||||
getaddrinfo to assign the address 0.0.0.0 (any address) */
|
||||
int retval = getaddrinfo(nullptr, udpServerPort.c_str(), &hints, &addrResult);
|
||||
if (retval != 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TmTcUdpBridge::TmTcUdpBridge: Retrieving address info failed!" <<
|
||||
std::endl;
|
||||
#endif
|
||||
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::GETADDRINFO_CALL);
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
serverSocket = socket(addrResult->ai_family, addrResult->ai_socktype, addrResult->ai_protocol);
|
||||
if(serverSocket == INVALID_SOCKET) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TmTcUdpBridge::TmTcUdpBridge: Could not open UDP socket!" <<
|
||||
std::endl;
|
||||
#endif
|
||||
freeaddrinfo(addrResult);
|
||||
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::SOCKET_CALL);
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
@ -102,10 +94,6 @@ ReturnValue_t UdpTmTcBridge::initialize() {
|
||||
|
||||
retval = bind(serverSocket, addrResult->ai_addr, static_cast<int>(addrResult->ai_addrlen));
|
||||
if(retval != 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TmTcUdpBridge::TmTcUdpBridge: Could not bind "
|
||||
"local port (" << udpServerPort << ") to server socket!" << std::endl;
|
||||
#endif
|
||||
freeaddrinfo(addrResult);
|
||||
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::BIND_CALL);
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
|
@ -1,24 +1,26 @@
|
||||
#ifndef FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
|
||||
#define FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
|
||||
#ifndef FSFW_OSAL_COMMON_TMTCUDPBRIDGE_H_
|
||||
#define FSFW_OSAL_COMMON_TMTCUDPBRIDGE_H_
|
||||
|
||||
#include "TcpIpBase.h"
|
||||
#include "../../platform.h"
|
||||
#include "../../tmtcservices/TmTcBridge.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#elif defined(__unix__)
|
||||
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <sys/socket.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* @brief This class should be used with the UdpTcPollingTask to implement a UDP server
|
||||
* @brief This class can be used with the UdpTcPollingTask to implement a UDP server
|
||||
* for receiving and sending PUS TMTC.
|
||||
* @details
|
||||
* This bridge task will take care of sending telemetry back to a UDP client if a connection
|
||||
* was established and store them in a FIFO if this was not done yet. It is also be the default
|
||||
* destination for telecommands, but the telecommands will be relayed to a specified tcDestination
|
||||
* directly.
|
||||
*/
|
||||
class UdpTmTcBridge:
|
||||
public TmTcBridge,
|
||||
@ -28,8 +30,9 @@ public:
|
||||
/* The ports chosen here should not be used by any other process. */
|
||||
static const std::string DEFAULT_UDP_SERVER_PORT;
|
||||
|
||||
UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination, std::string udpServerPort = "",
|
||||
object_id_t tmStoreId = objects::TM_STORE, object_id_t tcStoreId = objects::TC_STORE);
|
||||
UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
std::string udpServerPort = "", object_id_t tmStoreId = objects::TM_STORE,
|
||||
object_id_t tcStoreId = objects::TC_STORE);
|
||||
virtual~ UdpTmTcBridge();
|
||||
|
||||
/**
|
||||
@ -56,5 +59,5 @@ private:
|
||||
MutexIF* mutex;
|
||||
};
|
||||
|
||||
#endif /* FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_ */
|
||||
#endif /* FSFW_OSAL_COMMON_TMTCUDPBRIDGE_H_ */
|
||||
|
||||
|
@ -32,9 +32,18 @@ void tcpip::determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std:
|
||||
else if(errorSrc == ErrorSources::RECVFROM_CALL) {
|
||||
srcString = "recvfrom call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::SEND_CALL) {
|
||||
srcString = "send call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::SENDTO_CALL) {
|
||||
srcString = "sendto call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::GETADDRINFO_CALL) {
|
||||
srcString = "getaddrinfo call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::SHUTDOWN_CALL) {
|
||||
srcString = "shutdown call";
|
||||
}
|
||||
else {
|
||||
srcString = "unknown call";
|
||||
}
|
||||
|
@ -29,7 +29,9 @@ enum class ErrorSources {
|
||||
RECVFROM_CALL,
|
||||
LISTEN_CALL,
|
||||
ACCEPT_CALL,
|
||||
SENDTO_CALL
|
||||
SEND_CALL,
|
||||
SENDTO_CALL,
|
||||
SHUTDOWN_CALL
|
||||
};
|
||||
|
||||
void determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std::string& protStr,
|
||||
|
@ -1,10 +1,12 @@
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
#include "../../timemanager/Clock.h"
|
||||
#include "../../platform.h"
|
||||
|
||||
#include <chrono>
|
||||
#if defined(WIN32)
|
||||
|
||||
#if defined(PLATFORM_WIN)
|
||||
#include <sysinfoapi.h>
|
||||
#elif defined(LINUX)
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
@ -46,7 +48,7 @@ ReturnValue_t Clock::setClock(const timeval* time) {
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
||||
#if defined(WIN32)
|
||||
#if defined(PLATFORM_WIN)
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto secondsChrono = std::chrono::time_point_cast<std::chrono::seconds>(now);
|
||||
auto epoch = now.time_since_epoch();
|
||||
@ -54,7 +56,7 @@ ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
||||
auto fraction = now - secondsChrono;
|
||||
time->tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(fraction).count();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
#elif defined(LINUX)
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
timespec timeUnix;
|
||||
int status = clock_gettime(CLOCK_REALTIME,&timeUnix);
|
||||
if(status!=0){
|
||||
@ -85,14 +87,14 @@ ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
|
||||
|
||||
timeval Clock::getUptime() {
|
||||
timeval timeval;
|
||||
#if defined(WIN32)
|
||||
#if defined(PLATFORM_WIN)
|
||||
auto uptime = std::chrono::milliseconds(GetTickCount64());
|
||||
auto secondsChrono = std::chrono::duration_cast<std::chrono::seconds>(uptime);
|
||||
timeval.tv_sec = secondsChrono.count();
|
||||
auto fraction = uptime - secondsChrono;
|
||||
timeval.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
fraction).count();
|
||||
#elif defined(LINUX)
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
double uptimeSeconds;
|
||||
if (std::ifstream("/proc/uptime", std::ios::in) >> uptimeSeconds)
|
||||
{
|
||||
@ -119,7 +121,6 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
|
||||
/* Do some magic with chrono (C++20!) */
|
||||
/* Right now, the library doesn't have the new features to get the required values yet.
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "taskHelpers.h"
|
||||
#include "../../platform.h"
|
||||
#include "../../osal/host/FixedTimeslotTask.h"
|
||||
#include "../../ipc/MutexFactory.h"
|
||||
#include "../../osal/host/Mutex.h"
|
||||
@ -9,10 +10,10 @@
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#if defined(WIN32)
|
||||
#if defined(PLATFORM_WIN)
|
||||
#include <windows.h>
|
||||
#include "../windows/winTaskHelpers.h"
|
||||
#elif defined(LINUX)
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "PeriodicTask.h"
|
||||
#include "taskHelpers.h"
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "../../ipc/MutexFactory.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
@ -9,10 +10,10 @@
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#if defined(WIN32)
|
||||
#if defined(PLATFORM_WIN)
|
||||
#include <processthreadsapi.h>
|
||||
#include <fsfw/osal/windows/winTaskHelpers.h>
|
||||
#elif defined(__unix__)
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
@ -24,9 +25,9 @@ PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
|
||||
// It is probably possible to set task priorities by using the native
|
||||
// task handles for Windows / Linux
|
||||
mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this);
|
||||
#if defined(_WIN32)
|
||||
#if defined(PLATFORM_WIN)
|
||||
tasks::setTaskPriority(reinterpret_cast<HANDLE>(mainThread.native_handle()), setPriority);
|
||||
#elif defined(__unix__)
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
// TODO: We could reuse existing code here.
|
||||
#endif
|
||||
tasks::insertTaskName(mainThread.get_id(), taskName);
|
||||
|
@ -50,8 +50,8 @@ void tcpip::handleError(Protocol protocol, ErrorSources errorSrc, dur_millis_t s
|
||||
sif::warning << "tcpip::handleError: " << protocolString << " | " << errorSrcString <<
|
||||
" | " << infoString << std::endl;
|
||||
#else
|
||||
sif::printWarning("tcpip::handleError: %s | %s | %s\n", protocolString,
|
||||
errorSrcString, infoString);
|
||||
sif::printWarning("tcpip::handleError: %s | %s | %s\n", protocolString.c_str(),
|
||||
errorSrcString.c_str(), infoString.c_str());
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
|
10
platform.h
Normal file
10
platform.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef FSFW_PLATFORM_H_
|
||||
#define FSFW_PLATFORM_H_
|
||||
|
||||
#if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
|
||||
#define PLATFORM_UNIX
|
||||
#elif defined(_WIN32)
|
||||
#define PLATFORM_WIN
|
||||
#endif
|
||||
|
||||
#endif /* FSFW_PLATFORM_H_ */
|
@ -5,9 +5,9 @@
|
||||
#include "serviceInterfaceDefintions.h"
|
||||
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include "ServiceInterfaceStream.h"
|
||||
#else
|
||||
#include <fsfw/serviceinterface/ServiceInterfacePrinter.h>
|
||||
#include "ServiceInterfacePrinter.h"
|
||||
#endif
|
||||
|
||||
#endif /* FSFW_SERVICEINTERFACE_SERVICEINTERFACE_H_ */
|
||||
|
@ -183,8 +183,11 @@ ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
|
||||
|
||||
if(tmFifo->full()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "TmTcBridge::storeDownlinkData: TM downlink max. number "
|
||||
<< "of stored packet IDs reached! " << std::endl;
|
||||
sif::warning << "TmTcBridge::storeDownlinkData: TM downlink max. number "
|
||||
"of stored packet IDs reached!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("TmTcBridge::storeDownlinkData: TM downlink max. number "
|
||||
"of stored packet IDs reached!\n");
|
||||
#endif
|
||||
if(overwriteOld) {
|
||||
tmFifo->retrieve(&storeId);
|
||||
|
@ -150,8 +150,7 @@ protected:
|
||||
void printData(uint8_t * data, size_t dataLen);
|
||||
|
||||
/**
|
||||
* This fifo can be used to store downlink data
|
||||
* which can not be sent at the moment.
|
||||
* This FIFO can be used to store downlink data which can not be sent at the moment.
|
||||
*/
|
||||
DynamicFIFO<store_address_t>* tmFifo = nullptr;
|
||||
uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE;
|
||||
|