Updated FSFW to upstream development #5
@ -49,7 +49,7 @@ ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) {
|
|||||||
handleReadError();
|
handleReadError();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_WIRETAPPING_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
||||||
sif::debug << "TcWinUdpPollingTask::performOperation: " << bytesReceived <<
|
sif::debug << "TcWinUdpPollingTask::performOperation: " << bytesReceived <<
|
||||||
" bytes received" << std::endl;
|
" bytes received" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -58,7 +58,6 @@ ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) {
|
|||||||
if(result != HasReturnvaluesIF::RETURN_FAILED) {
|
if(result != HasReturnvaluesIF::RETURN_FAILED) {
|
||||||
|
|
||||||
}
|
}
|
||||||
tmtcBridge->registerCommConnect();
|
|
||||||
tmtcBridge->checkAndSetClientAddress(senderAddress);
|
tmtcBridge->checkAndSetClientAddress(senderAddress);
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
@ -69,8 +68,8 @@ ReturnValue_t TcWinUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
|||||||
store_address_t storeId;
|
store_address_t storeId;
|
||||||
ReturnValue_t result = tcStore->addData(&storeId,
|
ReturnValue_t result = tcStore->addData(&storeId,
|
||||||
receptionBuffer.data(), bytesRead);
|
receptionBuffer.data(), bytesRead);
|
||||||
#if FSFW_UDP_WIRETAPPING_ENABLED == 1
|
#if FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
||||||
arrayprinter::print(receptionBuffer.data(), bytesRead);#
|
arrayprinter::print(receptionBuffer.data(), bytesRead);
|
||||||
#endif
|
#endif
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
@ -113,7 +112,7 @@ ReturnValue_t TcWinUdpPollingTask::initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serverUdpSocket = tmtcBridge->serverSocket;
|
serverUdpSocket = tmtcBridge->serverSocket;
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_WIRETAPPING_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
||||||
sif::info << "TcWinUdpPollingTask::initialize: Server UDP socket " << serverUdpSocket <<
|
sif::info << "TcWinUdpPollingTask::initialize: Server UDP socket " << serverUdpSocket <<
|
||||||
std::endl;
|
std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,13 +12,13 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId,
|
|||||||
std::string udpServerPort, std::string udpClientPort):
|
std::string udpServerPort, std::string udpClientPort):
|
||||||
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
|
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
|
||||||
if(udpServerPort == "") {
|
if(udpServerPort == "") {
|
||||||
udpServerPort = DEFAULT_UDP_SERVER_PORT;
|
this->udpServerPort = DEFAULT_UDP_SERVER_PORT;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->udpServerPort = udpServerPort;
|
this->udpServerPort = udpServerPort;
|
||||||
}
|
}
|
||||||
if(udpClientPort == "") {
|
if(udpClientPort == "") {
|
||||||
udpClientPort = DEFAULT_UDP_CLIENT_PORT;
|
this->udpClientPort = DEFAULT_UDP_CLIENT_PORT;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->udpClientPort = udpClientPort;
|
this->udpClientPort = udpClientPort;
|
||||||
@ -60,6 +60,7 @@ ReturnValue_t TmTcWinUdpBridge::initialize() {
|
|||||||
hints.ai_protocol = IPPROTO_UDP;
|
hints.ai_protocol = IPPROTO_UDP;
|
||||||
hints.ai_flags = AI_PASSIVE;
|
hints.ai_flags = AI_PASSIVE;
|
||||||
|
|
||||||
|
sif::info << udpServerPort << std::endl;
|
||||||
/* Set up UDP socket:
|
/* Set up UDP socket:
|
||||||
https://en.wikipedia.org/wiki/Getaddrinfo
|
https://en.wikipedia.org/wiki/Getaddrinfo
|
||||||
Passing nullptr as the first parameter and specifying AI_PASSIVE in hints will cause
|
Passing nullptr as the first parameter and specifying AI_PASSIVE in hints will cause
|
||||||
@ -80,40 +81,22 @@ ReturnValue_t TmTcWinUdpBridge::initialize() {
|
|||||||
sif::warning << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not open UDP socket!" <<
|
sif::warning << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not open UDP socket!" <<
|
||||||
std::endl;
|
std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
freeaddrinfo(addrResult);
|
||||||
handleSocketError();
|
handleSocketError();
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// serverAddress.sin_family = AF_INET;
|
|
||||||
//
|
|
||||||
// /* Accept packets from any interface. (potentially insecure). */
|
|
||||||
// serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
||||||
// serverAddress.sin_port = htons(setServerPort);
|
|
||||||
// serverAddressLen = sizeof(serverAddress);
|
|
||||||
// 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(7302);
|
|
||||||
clientAddressLen = sizeof(clientAddress);
|
|
||||||
|
|
||||||
retval = bind(serverSocket, addrResult->ai_addr, static_cast<int>(addrResult->ai_addrlen));
|
retval = bind(serverSocket, addrResult->ai_addr, static_cast<int>(addrResult->ai_addrlen));
|
||||||
if(retval != 0) {
|
if(retval != 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not bind "
|
sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not bind "
|
||||||
"local port " << udpServerPort << " to server socket!" << std::endl;
|
"local port " << udpServerPort << " to server socket!" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
freeaddrinfo(addrResult);
|
||||||
handleBindError();
|
handleBindError();
|
||||||
}
|
}
|
||||||
|
freeaddrinfo(addrResult);
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +109,7 @@ TmTcWinUdpBridge::~TmTcWinUdpBridge() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
||||||
|
MutexGuard lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||||
@ -153,7 +137,7 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
|
void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in& newAddress) {
|
||||||
MutexGuard lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
MutexGuard lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
||||||
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||||
@ -167,7 +151,7 @@ void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
|
|||||||
|
|
||||||
/* 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) {
|
if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) {
|
||||||
clientAddress.sin_addr.s_addr = newAddress.sin_addr.s_addr;
|
clientAddress = newAddress;
|
||||||
clientAddressLen = sizeof(clientAddress);
|
clientAddressLen = sizeof(clientAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,3 +241,69 @@ void TmTcWinUdpBridge::handleSendError() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t TmTcWinUdpBridge::oldSetup() {
|
||||||
|
ReturnValue_t result = TmTcBridge::initialize();
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t setServerPort = 7301;
|
||||||
|
uint16_t setClientPort = 7302;
|
||||||
|
|
||||||
|
// 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(serverSocket == INVALID_SOCKET) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not open"
|
||||||
|
" UDP socket!" << std::endl;
|
||||||
|
#endif
|
||||||
|
handleSocketError();
|
||||||
|
}
|
||||||
|
|
||||||
|
serverAddress.sin_family = AF_INET;
|
||||||
|
|
||||||
|
// Accept packets from any interface. (potentially insecure).
|
||||||
|
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
serverAddress.sin_port = htons(setServerPort);
|
||||||
|
serverAddressLen = sizeof(serverAddress);
|
||||||
|
|
||||||
|
// sif::info << serverAddress.sin_addr.s_addr << std::endl;
|
||||||
|
// sif::info << serverAddress.sin_port << std::endl;
|
||||||
|
|
||||||
|
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 retval = bind(serverSocket,
|
||||||
|
reinterpret_cast<struct sockaddr*>(&serverAddress),
|
||||||
|
serverAddressLen);
|
||||||
|
if(retval != 0) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not bind "
|
||||||
|
"local port " << setServerPort << " to server socket!"
|
||||||
|
<< std::endl;
|
||||||
|
#endif
|
||||||
|
handleBindError();
|
||||||
|
}
|
||||||
|
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
|
|
||||||
ReturnValue_t initialize() override;
|
ReturnValue_t initialize() override;
|
||||||
|
|
||||||
void checkAndSetClientAddress(sockaddr_in clientAddress);
|
void checkAndSetClientAddress(sockaddr_in& clientAddress);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
|
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
|
||||||
@ -53,6 +53,8 @@ private:
|
|||||||
void handleSocketError();
|
void handleSocketError();
|
||||||
void handleBindError();
|
void handleBindError();
|
||||||
void handleSendError();
|
void handleSendError();
|
||||||
|
|
||||||
|
ReturnValue_t oldSetup();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user