2021-03-21 00:30:33 +01:00
|
|
|
#include "../common/tcpipHelpers.h"
|
2021-03-12 02:15:21 +01:00
|
|
|
#include <FSFWConfig.h>
|
|
|
|
|
2021-03-12 18:06:24 +01:00
|
|
|
#include "../../tasks/TaskFactory.h"
|
2021-03-12 02:15:21 +01:00
|
|
|
#include "../../serviceinterface/ServiceInterface.h"
|
|
|
|
|
2021-03-12 18:06:24 +01:00
|
|
|
|
2021-03-12 02:15:21 +01:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
void tcpip::handleError(Protocol protocol, ErrorSources errorSrc, dur_millis_t sleepDuration) {
|
2021-03-12 18:06:24 +01:00
|
|
|
#if FSFW_VERBOSE_LEVEL >= 1
|
2021-03-12 02:15:21 +01:00
|
|
|
int errCode = WSAGetLastError();
|
|
|
|
std::string protocolString;
|
|
|
|
std::string errorSrcString;
|
2021-03-12 18:06:24 +01:00
|
|
|
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
|
|
|
|
*/
|
2021-03-12 18:06:24 +01:00
|
|
|
infoString = "Error code: " + std::to_string(errCode);
|
2021-03-12 02:15:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-03-12 18:06:24 +01:00
|
|
|
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::warning << "tcpip::handleError: " << protocolString << " | " << errorSrcString <<
|
|
|
|
" | " << infoString << std::endl;
|
|
|
|
#else
|
|
|
|
sif::printWarning("tcpip::handleError: %s | %s | %s\n", protocolString,
|
|
|
|
errorSrcString, infoString);
|
2021-03-12 02:15:21 +01:00
|
|
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
2021-03-12 18:06:24 +01:00
|
|
|
|
|
|
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
|
|
|
|
2021-03-12 02:15:21 +01:00
|
|
|
if(sleepDuration > 0) {
|
2021-03-12 18:06:24 +01:00
|
|
|
TaskFactory::instance()->delayTask(sleepDuration);
|
2021-03-12 02:15:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|