fsfw/osal/windows/tcpipHelpers.cpp

64 lines
1.7 KiB
C++
Raw Normal View History

#include "../common/tcpipHelpers.h"
2021-03-12 02:15:21 +01:00
#include <FSFWConfig.h>
#include "../../tasks/TaskFactory.h"
2021-03-12 02:15:21 +01:00
#include "../../serviceinterface/ServiceInterface.h"
2021-03-12 02:15:21 +01:00
#include <winsock2.h>
#include <string>
void tcpip::handleError(Protocol protocol, ErrorSources errorSrc, dur_millis_t sleepDuration) {
#if FSFW_VERBOSE_LEVEL >= 1
2021-03-12 02:15:21 +01:00
int errCode = WSAGetLastError();
std::string protocolString;
std::string errorSrcString;
determineErrorStrings(protocol, errorSrc, protocolString, errorSrcString);
2021-03-12 02:15:21 +01:00
std::string infoString;
switch(errCode) {
case(WSANOTINITIALISED): {
infoString = "WSANOTINITIALISED";
break;
}
case(WSAEADDRINUSE): {
infoString = "WSAEADDRINUSE";
break;
}
case(WSAEFAULT): {
infoString = "WSAEFAULT";
break;
}
case(WSAEADDRNOTAVAIL): {
infoString = "WSAEADDRNOTAVAIL";
break;
}
case(WSAEINVAL): {
infoString = "WSAEINVAL";
break;
}
default: {
/*
https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
*/
infoString = "Error code: " + std::to_string(errCode);
2021-03-12 02:15:21 +01:00
break;
}
}
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "tcpip::handleError: " << protocolString << " | " << errorSrcString <<
" | " << infoString << std::endl;
#else
2021-05-13 22:17:21 +02:00
sif::printWarning("tcpip::handleError: %s | %s | %s\n", protocolString.c_str(),
errorSrcString.c_str(), infoString.c_str());
2021-03-12 02:15:21 +01:00
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
2021-03-12 02:15:21 +01:00
if(sleepDuration > 0) {
TaskFactory::instance()->delayTask(sleepDuration);
2021-03-12 02:15:21 +01:00
}
}