Merge branch 'mueller/master' of https://egit.irs.uni-stuttgart.de/fsfw/fsfw into mueller/master
This commit is contained in:
commit
596d3bc68a
@ -166,6 +166,8 @@ public:
|
||||
|
||||
object_id_t getCreatorObjectId();
|
||||
|
||||
bool getReportingEnabled() const;
|
||||
|
||||
protected:
|
||||
sid_t sid;
|
||||
//! This mutex is used if the data is created by one object only.
|
||||
@ -180,7 +182,6 @@ protected:
|
||||
*/
|
||||
bool reportingEnabled = false;
|
||||
void setReportingEnabled(bool enabled);
|
||||
bool getReportingEnabled() const;
|
||||
|
||||
void initializePeriodicHelper(float collectionInterval,
|
||||
dur_millis_t minimumPeriodicInterval,
|
||||
|
12
datapoollocal/datapoollocal.h
Normal file
12
datapoollocal/datapoollocal.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_
|
||||
#define FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_
|
||||
|
||||
/* Collected related headers */
|
||||
#include "LocalPoolVariable.h"
|
||||
#include "LocalPoolVector.h"
|
||||
#include "StaticLocalDataSet.h"
|
||||
#include "LocalDataSet.h"
|
||||
#include "SharedLocalDataSet.h"
|
||||
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ */
|
@ -2,6 +2,7 @@
|
||||
#include "PeriodicPosixTask.h"
|
||||
|
||||
#include "../../tasks/TaskFactory.h"
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
//TODO: Different variant than the lazy loading in QueueFactory. What's better and why?
|
||||
|
@ -1,11 +1,10 @@
|
||||
target_sources(${LIB_FSFW_NAME}
|
||||
PRIVATE
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
TcWinUdpPollingTask.cpp
|
||||
TmTcWinUdpBridge.cpp
|
||||
TcWinTcpServer.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${LIB_FSFW_NAME}
|
||||
PRIVATE
|
||||
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||
wsock32
|
||||
ws2_32
|
||||
)
|
177
osal/windows/TcWinTcpServer.cpp
Normal file
177
osal/windows/TcWinTcpServer.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
#include "TcWinTcpServer.h"
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
const std::string TcWinTcpServer::DEFAULT_TCP_SERVER_PORT = "7301";
|
||||
const std::string TcWinTcpServer::DEFAULT_TCP_CLIENT_PORT = "7302";
|
||||
|
||||
TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
||||
std::string customTcpServerPort):
|
||||
SystemObject(objectId), tcpPort(customTcpServerPort) {
|
||||
if(tcpPort == "") {
|
||||
tcpPort = DEFAULT_TCP_SERVER_PORT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t TcWinTcpServer::initialize() {
|
||||
int retval = 0;
|
||||
struct addrinfo *addrResult = nullptr;
|
||||
struct addrinfo hints;
|
||||
/* Initiates Winsock DLL. */
|
||||
WSAData wsaData;
|
||||
WORD wVersionRequested = MAKEWORD(2, 2);
|
||||
int err = WSAStartup(wVersionRequested, &wsaData);
|
||||
if (err != 0) {
|
||||
/* Tell the user that we could not find a usable Winsock DLL. */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: WSAStartup failed with error: " <<
|
||||
err << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ZeroMemory(&hints, sizeof (hints));
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
||||
retval = getaddrinfo(nullptr, tcpPort.c_str(), &hints, &addrResult);
|
||||
if (retval != 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TcWinTcpServer::TcWinTcpServer: Retrieving address info failed!" <<
|
||||
std::endl;
|
||||
#endif
|
||||
handleError(ErrorSources::GETADDRINFO_CALL);
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
/* 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(ErrorSources::SOCKET_CALL);
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
// retval = setsockopt(listenerTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST,
|
||||
// reinterpret_cast<const char*>(&tcpSockOpt), sizeof(tcpSockOpt));
|
||||
// if(retval != 0) {
|
||||
// sif::warning << "TcWinTcpServer::TcWinTcpServer: Setting socket options failed!" <<
|
||||
// std::endl;
|
||||
// handleError(ErrorSources::SETSOCKOPT_CALL);
|
||||
// return HasReturnvaluesIF::RETURN_FAILED;
|
||||
// }
|
||||
// tcpAddress.sin_family = AF_INET;
|
||||
// tcpAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
retval = bind(listenerTcpSocket, reinterpret_cast<const sockaddr*>(&tcpAddress),
|
||||
tcpAddrLen);
|
||||
if(retval == SOCKET_ERROR) {
|
||||
sif::warning << "TcWinTcpServer::TcWinTcpServer: Binding socket failed!" <<
|
||||
std::endl;
|
||||
freeaddrinfo(addrResult);
|
||||
handleError(ErrorSources::BIND_CALL);
|
||||
}
|
||||
|
||||
freeaddrinfo(addrResult);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
TcWinTcpServer::~TcWinTcpServer() {
|
||||
closesocket(listenerTcpSocket);
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
ReturnValue_t TcWinTcpServer::performOperation(uint8_t opCode) {
|
||||
/* If a connection is accepted, the corresponding socket will be assigned to the new socket */
|
||||
SOCKET clientSocket;
|
||||
sockaddr_in clientSockAddr;
|
||||
int connectorSockAddrLen = 0;
|
||||
int retval = 0;
|
||||
/* Listen for connection requests permanently for lifetime of program */
|
||||
while(true) {
|
||||
retval = listen(listenerTcpSocket, currentBacklog);
|
||||
if(retval == SOCKET_ERROR) {
|
||||
handleError(ErrorSources::LISTEN_CALL);
|
||||
continue;
|
||||
}
|
||||
|
||||
clientSocket = accept(listenerTcpSocket, reinterpret_cast<sockaddr*>(&clientSockAddr),
|
||||
&connectorSockAddrLen);
|
||||
|
||||
if(clientSocket == INVALID_SOCKET) {
|
||||
handleError(ErrorSources::ACCEPT_CALL);
|
||||
continue;
|
||||
};
|
||||
|
||||
retval = recv(clientSocket, reinterpret_cast<char*>(receptionBuffer.data()),
|
||||
receptionBuffer.size(), 0);
|
||||
if(retval > 0) {
|
||||
#if FSFW_TCP_SERVER_WIRETAPPING_ENABLED == 1
|
||||
sif::info << "TcWinTcpServer::performOperation: Received " << retval << " bytes."
|
||||
std::endl;
|
||||
#endif
|
||||
}
|
||||
else if(retval == 0) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
/* Done, shut down connection */
|
||||
retval = shutdown(clientSocket, SD_SEND);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void TcWinTcpServer::handleError(ErrorSources errorSrc) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
int errCode = WSAGetLastError();
|
||||
std::string errorSrcString;
|
||||
if(errorSrc == ErrorSources::SETSOCKOPT_CALL) {
|
||||
errorSrcString = "setsockopt call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::SOCKET_CALL) {
|
||||
errorSrcString = "socket call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::LISTEN_CALL) {
|
||||
errorSrcString = "listen call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::ACCEPT_CALL) {
|
||||
errorSrcString = "accept call";
|
||||
}
|
||||
else if(errorSrc == ErrorSources::GETADDRINFO_CALL) {
|
||||
errorSrcString = "getaddrinfo call";
|
||||
}
|
||||
|
||||
switch(errCode) {
|
||||
case(WSANOTINITIALISED): {
|
||||
sif::warning << "TmTcWinUdpBridge::handleError: " << errorSrcString << " | "
|
||||
"WSANOTINITIALISED: WSAStartup call necessary" << std::endl;
|
||||
break;
|
||||
}
|
||||
case(WSAEINVAL): {
|
||||
sif::warning << "TmTcWinUdpBridge::handleError: " << errorSrcString << " | "
|
||||
"WSAEINVAL: Invalid parameters" << std::endl;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
/*
|
||||
https://docs.microsoft.com/en-us/windows/win32/winsock/
|
||||
windows-sockets-error-codes-2
|
||||
*/
|
||||
sif::warning << "TmTcWinUdpBridge::handleSocketError: Error code: " << errCode << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
}
|
56
osal/windows/TcWinTcpServer.h
Normal file
56
osal/windows/TcWinTcpServer.h
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
||||
#define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
||||
|
||||
#include "../../objectmanager/SystemObject.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
//! Debugging preprocessor define.
|
||||
#define FSFW_TCP_SERVER_WIRETAPPING_ENABLED 0
|
||||
|
||||
/**
|
||||
* @brief Windows TCP server used to receive telecommands on a Windows Host
|
||||
* @details
|
||||
* Based on: https://docs.microsoft.com/en-us/windows/win32/winsock/complete-server-code
|
||||
*/
|
||||
class TcWinTcpServer:
|
||||
public SystemObject,
|
||||
public ExecutableObjectIF {
|
||||
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;
|
||||
|
||||
TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
||||
std::string customTcpServerPort = "");
|
||||
virtual~ TcWinTcpServer();
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
ReturnValue_t performOperation(uint8_t opCode) override;
|
||||
|
||||
private:
|
||||
|
||||
std::string tcpPort;
|
||||
SOCKET listenerTcpSocket = 0;
|
||||
struct sockaddr_in tcpAddress;
|
||||
int tcpAddrLen = sizeof(tcpAddress);
|
||||
int currentBacklog = 3;
|
||||
|
||||
std::vector<uint8_t> receptionBuffer;
|
||||
int tcpSockOpt = 0;
|
||||
|
||||
enum class ErrorSources {
|
||||
GETADDRINFO_CALL,
|
||||
SOCKET_CALL,
|
||||
SETSOCKOPT_CALL,
|
||||
BIND_CALL,
|
||||
LISTEN_CALL,
|
||||
ACCEPT_CALL
|
||||
};
|
||||
|
||||
void handleError(ErrorSources errorSrc);
|
||||
};
|
||||
|
||||
#endif /* FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_ */
|
@ -3,11 +3,6 @@
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#if defined(_MSC_VER)
|
||||
#include <BaseTsd.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#endif
|
||||
|
||||
TcWinUdpPollingTask::TcWinUdpPollingTask(object_id_t objectId,
|
||||
object_id_t tmtcUnixUdpBridge, size_t frameSize,
|
||||
@ -20,8 +15,8 @@ TcWinUdpPollingTask::TcWinUdpPollingTask(object_id_t objectId,
|
||||
this->frameSize = DEFAULT_MAX_FRAME_SIZE;
|
||||
}
|
||||
|
||||
// Set up reception buffer with specified frame size.
|
||||
// For now, it is assumed that only one frame is held in the buffer!
|
||||
/* Set up reception buffer with specified frame size.
|
||||
For now, it is assumed that only one frame is held in the buffer! */
|
||||
receptionBuffer.reserve(this->frameSize);
|
||||
receptionBuffer.resize(this->frameSize);
|
||||
|
||||
@ -36,17 +31,17 @@ TcWinUdpPollingTask::TcWinUdpPollingTask(object_id_t objectId,
|
||||
TcWinUdpPollingTask::~TcWinUdpPollingTask() {}
|
||||
|
||||
ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) {
|
||||
// Poll for new UDP datagrams in permanent loop.
|
||||
/* Poll for new UDP datagrams in permanent loop. */
|
||||
while(true) {
|
||||
//! Sender Address is cached here.
|
||||
struct sockaddr_in senderAddress;
|
||||
int senderAddressSize = sizeof(senderAddress);
|
||||
ssize_t bytesReceived = recvfrom(serverUdpSocket,
|
||||
int bytesReceived = recvfrom(serverUdpSocket,
|
||||
reinterpret_cast<char*>(receptionBuffer.data()), frameSize,
|
||||
receptionFlags, reinterpret_cast<sockaddr*>(&senderAddress),
|
||||
&senderAddressSize);
|
||||
if(bytesReceived == SOCKET_ERROR) {
|
||||
// handle error
|
||||
/* Handle error */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TcWinUdpPollingTask::performOperation: Reception"
|
||||
" error." << std::endl;
|
||||
@ -54,9 +49,9 @@ ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) {
|
||||
handleReadError();
|
||||
continue;
|
||||
}
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
//sif::debug << "TcWinUdpPollingTask::performOperation: " << bytesReceived
|
||||
// << " bytes received" << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_WIRETAPPING_ENABLED == 1
|
||||
sif::debug << "TcWinUdpPollingTask::performOperation: " << bytesReceived <<
|
||||
" bytes received" << std::endl;
|
||||
#endif
|
||||
|
||||
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
||||
@ -74,12 +69,14 @@ ReturnValue_t TcWinUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
||||
store_address_t storeId;
|
||||
ReturnValue_t result = tcStore->addData(&storeId,
|
||||
receptionBuffer.data(), bytesRead);
|
||||
// arrayprinter::print(receptionBuffer.data(), bytesRead);
|
||||
#if FSFW_UDP_WIRETAPPING_ENABLED == 1
|
||||
arrayprinter::print(receptionBuffer.data(), bytesRead);#
|
||||
#endif
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TcSerialPollingTask::transferPusToSoftwareBus: Data "
|
||||
sif::warning<< "TcSerialPollingTask::transferPusToSoftwareBus: Data "
|
||||
"storage failed" << std::endl;
|
||||
sif::error << "Packet size: " << bytesRead << std::endl;
|
||||
sif::warning << "Packet size: " << bytesRead << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
@ -89,8 +86,7 @@ ReturnValue_t TcWinUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
||||
result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "Serial Polling: Sending message to queue failed"
|
||||
<< std::endl;
|
||||
sif::warning << "Serial Polling: Sending message to queue failed" << std::endl;
|
||||
#endif
|
||||
tcStore->deleteData(storeId);
|
||||
}
|
||||
@ -117,9 +113,9 @@ ReturnValue_t TcWinUdpPollingTask::initialize() {
|
||||
}
|
||||
|
||||
serverUdpSocket = tmtcBridge->serverSocket;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
//sif::info << "TcWinUdpPollingTask::initialize: Server UDP socket "
|
||||
// << serverUdpSocket << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_WIRETAPPING_ENABLED == 1
|
||||
sif::info << "TcWinUdpPollingTask::initialize: Server UDP socket " << serverUdpSocket <<
|
||||
std::endl;
|
||||
#endif
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
@ -8,6 +8,9 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
//! Debugging preprocessor define.
|
||||
#define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0
|
||||
|
||||
/**
|
||||
* @brief This class can be used to implement the polling of a Unix socket,
|
||||
* using UDP for now.
|
||||
@ -51,8 +54,7 @@ private:
|
||||
//! Reception flags: https://linux.die.net/man/2/recvfrom.
|
||||
int receptionFlags = 0;
|
||||
|
||||
//! Server socket, which is member of TMTC bridge and is assigned in
|
||||
//! constructor
|
||||
//! Server socket, which is member of TMTC bridge and is assigned in constructor
|
||||
SOCKET serverUdpSocket = 0;
|
||||
|
||||
std::vector<uint8_t> receptionBuffer;
|
||||
|
@ -14,7 +14,7 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId,
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
communicationLinkUp = false;
|
||||
|
||||
// Initiates Winsock DLL.
|
||||
/* Initiates Winsock DLL. */
|
||||
WSAData wsaData;
|
||||
WORD wVersionRequested = MAKEWORD(2, 2);
|
||||
int err = WSAStartup(wVersionRequested, &wsaData);
|
||||
@ -38,13 +38,14 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId,
|
||||
setClientPort = clientPort;
|
||||
}
|
||||
|
||||
// Set up UDP socket: https://man7.org/linux/man-pages/man7/ip.7.html
|
||||
//clientSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
/* Set up UDP socket:
|
||||
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-socket
|
||||
*/
|
||||
serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if(serverSocket == INVALID_SOCKET) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not open"
|
||||
" UDP socket!" << std::endl;
|
||||
sif::warning << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not open UDP socket!" <<
|
||||
std::endl;
|
||||
#endif
|
||||
handleSocketError();
|
||||
return;
|
||||
@ -52,20 +53,27 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId,
|
||||
|
||||
serverAddress.sin_family = AF_INET;
|
||||
|
||||
// Accept packets from any interface. (potentially insecure).
|
||||
/* Accept packets from any interface. (potentially insecure). */
|
||||
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
serverAddress.sin_port = htons(setServerPort);
|
||||
serverAddressLen = sizeof(serverAddress);
|
||||
setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR,
|
||||
int result = setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR,
|
||||
reinterpret_cast<const char*>(&serverSocketOptions),
|
||||
sizeof(serverSocketOptions));
|
||||
if(result != 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not set socket options!" <<
|
||||
std::endl;
|
||||
#endif
|
||||
handleSocketError();
|
||||
}
|
||||
|
||||
clientAddress.sin_family = AF_INET;
|
||||
clientAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
clientAddress.sin_port = htons(setClientPort);
|
||||
clientAddressLen = sizeof(clientAddress);
|
||||
|
||||
int result = bind(serverSocket,
|
||||
result = bind(serverSocket,
|
||||
reinterpret_cast<struct sockaddr*>(&serverAddress),
|
||||
serverAddressLen);
|
||||
if(result != 0) {
|
||||
@ -79,19 +87,19 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId,
|
||||
}
|
||||
|
||||
TmTcWinUdpBridge::~TmTcWinUdpBridge() {
|
||||
closesocket(serverSocket);
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
||||
int flags = 0;
|
||||
|
||||
//clientAddress.sin_addr.s_addr = htons(INADDR_ANY);
|
||||
//clientAddressLen = sizeof(serverAddress);
|
||||
|
||||
// char ipAddress [15];
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
||||
// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||
clientAddress.sin_addr.s_addr = htons(INADDR_ANY);
|
||||
clientAddressLen = sizeof(serverAddress);
|
||||
char ipAddress [15];
|
||||
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
||||
&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||
#endif
|
||||
|
||||
ssize_t bytesSent = sendto(serverSocket,
|
||||
@ -104,9 +112,9 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
||||
#endif
|
||||
handleSendError();
|
||||
}
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
// sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
|
||||
// " sent." << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||
sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
|
||||
" sent." << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
@ -114,16 +122,16 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
||||
void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
|
||||
MutexGuard lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
||||
|
||||
// char ipAddress [15];
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
||||
// &newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||
// sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
|
||||
// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||
char ipAddress [15];
|
||||
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
||||
&newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||
sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
|
||||
&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||
#endif
|
||||
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) {
|
||||
clientAddress.sin_addr.s_addr = newAddress.sin_addr.s_addr;
|
||||
clientAddressLen = sizeof(clientAddress);
|
||||
@ -135,8 +143,8 @@ void TmTcWinUdpBridge::handleSocketError() {
|
||||
switch(errCode) {
|
||||
case(WSANOTINITIALISED): {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: "
|
||||
<< "WSAStartup(...) call necessary" << std::endl;
|
||||
sif::warning << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: WSAStartup"
|
||||
" call necessary" << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
@ -146,8 +154,7 @@ void TmTcWinUdpBridge::handleSocketError() {
|
||||
windows-sockets-error-codes-2
|
||||
*/
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TmTcWinUdpBridge::handleSocketError: Error code: "
|
||||
<< errCode << std::endl;
|
||||
sif::warning << "TmTcWinUdpBridge::handleSocketError: Error code: " << errCode << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
@ -160,14 +167,14 @@ void TmTcWinUdpBridge::handleBindError() {
|
||||
case(WSANOTINITIALISED): {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TmTcWinUdpBridge::handleBindError: WSANOTINITIALISED: "
|
||||
<< "WSAStartup(...) call " << "necessary" << std::endl;
|
||||
<< "WSAStartup call necessary" << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case(WSAEADDRINUSE): {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TmTcWinUdpBridge::handleBindError: WSAEADDRINUSE: "
|
||||
<< "Port is already in use!" << std::endl;
|
||||
"Port is already in use!" << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
@ -6,10 +6,13 @@
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
|
||||
//! Debugging preprocessor define.
|
||||
#define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0
|
||||
|
||||
class TmTcWinUdpBridge: public TmTcBridge {
|
||||
friend class TcWinUdpPollingTask;
|
||||
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. */
|
||||
static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301;
|
||||
static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302;
|
||||
|
||||
@ -38,6 +41,11 @@ private:
|
||||
//! by another task.
|
||||
MutexIF* mutex;
|
||||
|
||||
enum class ErrorSources {
|
||||
SOCKET_CALL,
|
||||
SETSOCKOPT_CALL
|
||||
};
|
||||
|
||||
void handleSocketError();
|
||||
void handleBindError();
|
||||
void handleSendError();
|
||||
|
@ -70,7 +70,7 @@ TEST_CASE( "Action Helper" , "[ActionHelper]") {
|
||||
SECTION("Handle finish"){
|
||||
CHECK(not testMqMock.wasMessageSent());
|
||||
ReturnValue_t status = 0x9876;
|
||||
actionHelper.finish(true, testMqMock.getId(), testActionId, status);
|
||||
actionHelper.finish(false, testMqMock.getId(), testActionId, status);
|
||||
CHECK(testMqMock.wasMessageSent());
|
||||
CommandMessage testMessage;
|
||||
REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast<uint32_t>(HasReturnvaluesIF::RETURN_OK));
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/datapool/PoolReadHelper.h>
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include <fsfw/globalfunctions/bitutility.h>
|
||||
|
||||
#include <unittest/core/CatchDefinitions.h>
|
||||
@ -21,6 +21,7 @@ TEST_CASE("LocalDataSet" , "[LocDataSetTest]") {
|
||||
|
||||
SECTION("BasicTest") {
|
||||
/* Test some basic functions */
|
||||
CHECK(localSet.getReportingEnabled() == false);
|
||||
CHECK(localSet.getLocalPoolIdsSerializedSize(false) == 3 * sizeof(lp_id_t));
|
||||
CHECK(localSet.getLocalPoolIdsSerializedSize(true) ==
|
||||
3 * sizeof(lp_id_t) + sizeof(uint8_t));
|
||||
@ -54,7 +55,7 @@ TEST_CASE("LocalDataSet" , "[LocDataSetTest]") {
|
||||
|
||||
{
|
||||
/* Test read operation. Values should be all zeros */
|
||||
PoolReadHelper readHelper(&localSet);
|
||||
PoolReadGuard readHelper(&localSet);
|
||||
REQUIRE(readHelper.getReadResult() == retval::CATCH_OK);
|
||||
CHECK(not localSet.isValid());
|
||||
CHECK(localSet.localPoolVarUint8.value == 0);
|
||||
@ -82,7 +83,7 @@ TEST_CASE("LocalDataSet" , "[LocDataSetTest]") {
|
||||
{
|
||||
/* Now we read again and check whether our zeroed values were overwritten with
|
||||
the values in the pool */
|
||||
PoolReadHelper readHelper(&localSet);
|
||||
PoolReadGuard readHelper(&localSet);
|
||||
REQUIRE(readHelper.getReadResult() == retval::CATCH_OK);
|
||||
CHECK(localSet.isValid());
|
||||
CHECK(localSet.localPoolVarUint8.value == 232);
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
|
||||
#include <fsfw/datapool/PoolReadHelper.h>
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/housekeeping/HousekeepingSnapshot.h>
|
||||
@ -75,7 +75,7 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
||||
SECTION("SnapshotUpdateTests") {
|
||||
/* Set the variables in the set to certain values. These are checked later. */
|
||||
{
|
||||
PoolReadHelper readHelper(&poolOwner->dataset);
|
||||
PoolReadGuard readHelper(&poolOwner->dataset);
|
||||
REQUIRE(readHelper.getReadResult() == retval::CATCH_OK);
|
||||
poolOwner->dataset.localPoolVarUint8.value = 5;
|
||||
poolOwner->dataset.localPoolVarFloat.value = -12.242;
|
||||
|
@ -1,13 +1,14 @@
|
||||
#ifndef FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
|
||||
#define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
|
||||
|
||||
#include <testcfg/objects/systemObjectList.h>
|
||||
|
||||
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <fsfw/datapoollocal/LocalDataSet.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
||||
#include <fsfw/datapoollocal/LocalPoolVector.h>
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
#include <testcfg/objects/systemObjectList.h>
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/unittest/tests/mocks/MessageQueueMockBase.h>
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
|
@ -115,6 +115,7 @@ TEST_CASE("LocalPoolVector" , "[LocPoolVecTest]") {
|
||||
REQUIRE(readOnlyVec.commit() ==
|
||||
static_cast<int>(PoolVariableIF::INVALID_READ_WRITE_MODE));
|
||||
}
|
||||
poolOwner->reset();
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,10 +30,7 @@ public:
|
||||
}
|
||||
|
||||
virtual ReturnValue_t reply( MessageQueueMessageIF* message ) {
|
||||
//messageSent = true;
|
||||
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
||||
return sendMessage(myQueueId, message);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
};
|
||||
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
|
||||
MessageQueueId_t *receivedFrom) {
|
||||
@ -61,21 +58,13 @@ public:
|
||||
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault = false ) {
|
||||
//messageSent = true;
|
||||
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
||||
//return HasReturnvaluesIF::RETURN_OK;
|
||||
return sendMessage(sendTo, message);
|
||||
}
|
||||
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault = false ) {
|
||||
//messageSent = true;
|
||||
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
||||
//return HasReturnvaluesIF::RETURN_OK;
|
||||
return sendMessage(myQueueId, message);
|
||||
}
|
||||
virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message ) {
|
||||
//messageSent = true;
|
||||
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
||||
return sendMessage(myQueueId, message);
|
||||
}
|
||||
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo,
|
||||
@ -114,7 +103,6 @@ public:
|
||||
|
||||
private:
|
||||
std::queue<MessageQueueMessage> messagesSentQueue;
|
||||
//MessageQueueMessage lastMessage;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user