added windows udp bridge
This commit is contained in:
parent
f698275a0b
commit
08ffbfefae
@ -1,9 +1,7 @@
|
||||
#include "../../osal/host/FixedTimeslotTask.h"
|
||||
#include "FixedTimeslotTask.h"
|
||||
#include "Mutex.h"
|
||||
|
||||
#include "../../ipc/MutexFactory.h"
|
||||
#include "../../osal/host/Mutex.h"
|
||||
#include "../../osal/host/FixedTimeslotTask.h"
|
||||
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
|
||||
@ -35,15 +33,15 @@ FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority,
|
||||
reinterpret_cast<HANDLE>(mainThread.native_handle()),
|
||||
ABOVE_NORMAL_PRIORITY_CLASS);
|
||||
if(result != 0) {
|
||||
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code "
|
||||
<< GetLastError() << std::endl;
|
||||
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with "
|
||||
<< "code " << GetLastError() << std::endl;
|
||||
}
|
||||
result = SetThreadPriority(
|
||||
reinterpret_cast<HANDLE>(mainThread.native_handle()),
|
||||
THREAD_PRIORITY_NORMAL);
|
||||
if(result != 0) {
|
||||
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code "
|
||||
<< GetLastError() << std::endl;
|
||||
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with "
|
||||
"code " << GetLastError() << std::endl;
|
||||
}
|
||||
#elif defined(LINUX)
|
||||
// we can just copy and paste the code from linux here.
|
||||
@ -60,7 +58,8 @@ FixedTimeslotTask::~FixedTimeslotTask(void) {
|
||||
}
|
||||
|
||||
void FixedTimeslotTask::taskEntryPoint(void* argument) {
|
||||
FixedTimeslotTask *originalTask(reinterpret_cast<FixedTimeslotTask*>(argument));
|
||||
FixedTimeslotTask *originalTask(
|
||||
reinterpret_cast<FixedTimeslotTask*>(argument));
|
||||
|
||||
if (not originalTask->started) {
|
||||
// we have to suspend/block here until the task is started.
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef FSFW_OSAL_HOSTED_MUTEX_H_
|
||||
#define FSFW_OSAL_HOSTED_MUTEX_H_
|
||||
#ifndef FSFW_OSAL_HOST_MUTEX_H_
|
||||
#define FSFW_OSAL_HOST_MUTEX_H_
|
||||
|
||||
#include "../../ipc/MutexIF.h"
|
||||
|
||||
@ -26,4 +26,4 @@ private:
|
||||
std::timed_mutex mutex;
|
||||
};
|
||||
|
||||
#endif /* FSFW_OSAL_HOSTED_MUTEX_H_ */
|
||||
#endif /* FSFW_OSAL_HOST_MUTEX_H_ */
|
||||
|
57
osal/host/TmTcWinUdpBridge.cpp
Normal file
57
osal/host/TmTcWinUdpBridge.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "TmTcWinUdpBridge.h"
|
||||
|
||||
TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId,
|
||||
object_id_t tcDestination, object_id_t tmStoreId, object_id_t tcStoreId,
|
||||
uint16_t serverPort, uint16_t clientPort):
|
||||
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
|
||||
uint16_t setServerPort = DEFAULT_UDP_SERVER_PORT;
|
||||
if(serverPort != 0xFFFF) {
|
||||
setServerPort = serverPort;
|
||||
}
|
||||
|
||||
uint16_t setClientPort = DEFAULT_UDP_CLIENT_PORT;
|
||||
if(clientPort != 0xFFFF) {
|
||||
setClientPort = clientPort;
|
||||
}
|
||||
|
||||
// Set up UDP socket: https://man7.org/linux/man-pages/man7/ip.7.html
|
||||
//clientSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if(socket < 0) {
|
||||
sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not open"
|
||||
" UDP socket!" << std::endl;
|
||||
handleSocketError();
|
||||
return;
|
||||
}
|
||||
|
||||
serverAddress.sin_family = AF_INET;
|
||||
|
||||
// Accept packets from any interface.
|
||||
//serverAddress.sin_addr.s_addr = inet_addr("127.73.73.0");
|
||||
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
serverAddress.sin_port = htons(setServerPort);
|
||||
//serverAddressLen = sizeof(serverAddress);
|
||||
setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR,
|
||||
reinterpret_cast<const char*>(&serverSocketOptions),
|
||||
sizeof(serverSocketOptions));
|
||||
|
||||
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,
|
||||
reinterpret_cast<struct sockaddr*>(&serverAddress),
|
||||
serverAddressLen);
|
||||
if(result == -1) {
|
||||
sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not bind "
|
||||
"local port " << setServerPort << " to server socket!"
|
||||
<< std::endl;
|
||||
handleBindError();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
47
osal/host/TmTcWinUdpBridge.h
Normal file
47
osal/host/TmTcWinUdpBridge.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_
|
||||
#define FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_
|
||||
|
||||
#include "../../tmtcservices/TmTcBridge.h"
|
||||
#include <Winsock.h>
|
||||
|
||||
class TmTcWinUdpBridge: public TmTcBridge {
|
||||
friend class TcWinUdpPollingTask;
|
||||
public:
|
||||
// The ports chosen here should not be used by any other process.
|
||||
// List of used ports on Linux: /etc/services
|
||||
static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301;
|
||||
static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302;
|
||||
|
||||
TmTcWinUdpBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
object_id_t tmStoreId, object_id_t tcStoreId,
|
||||
uint16_t serverPort = 0xFFFF,uint16_t clientPort = 0xFFFF);
|
||||
virtual~ TmTcWinUdpBridge();
|
||||
|
||||
void checkAndSetClientAddress(sockaddr_in clientAddress);
|
||||
|
||||
protected:
|
||||
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
|
||||
|
||||
private:
|
||||
SOCKET serverSocket = 0;
|
||||
|
||||
const int serverSocketOptions = 0;
|
||||
|
||||
struct sockaddr_in clientAddress;
|
||||
//socklen_t clientAddressLen = 0;
|
||||
|
||||
struct sockaddr_in serverAddress;
|
||||
//socklen_t serverAddressLen = 0;
|
||||
|
||||
//! Access to the client address is mutex protected as it is set
|
||||
//! by another task.
|
||||
MutexIF* mutex;
|
||||
|
||||
void handleSocketError();
|
||||
void handleBindError();
|
||||
void handleSendError();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_OSAL_HOST_TMTCWINUDPBRIDGE_H_ */
|
@ -24,7 +24,7 @@ TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId,
|
||||
// Set up UDP socket: https://man7.org/linux/man-pages/man7/ip.7.html
|
||||
//clientSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if(socket < 0) {
|
||||
if(serverSocket < 0) {
|
||||
sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not open"
|
||||
" UDP socket!" << std::endl;
|
||||
handleSocketError();
|
||||
|
Loading…
Reference in New Issue
Block a user