trying to fuse header / inc
This commit is contained in:
4
src/fsfw/osal/windows/CMakeLists.txt
Normal file
4
src/fsfw/osal/windows/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
tcpipHelpers.cpp
|
||||
winTaskHelpers.cpp
|
||||
)
|
||||
63
src/fsfw/osal/windows/tcpipHelpers.cpp
Normal file
63
src/fsfw/osal/windows/tcpipHelpers.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/osal/common/tcpipHelpers.h"
|
||||
|
||||
#include "fsfw/tasks/TaskFactory.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <string>
|
||||
|
||||
void tcpip::handleError(Protocol protocol, ErrorSources errorSrc, dur_millis_t sleepDuration) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
int errCode = WSAGetLastError();
|
||||
std::string protocolString;
|
||||
std::string errorSrcString;
|
||||
determineErrorStrings(protocol, errorSrc, protocolString, errorSrcString);
|
||||
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#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.c_str(),
|
||||
errorSrcString.c_str(), infoString.c_str());
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
|
||||
if(sleepDuration > 0) {
|
||||
TaskFactory::instance()->delayTask(sleepDuration);
|
||||
}
|
||||
}
|
||||
|
||||
108
src/fsfw/osal/windows/winTaskHelpers.cpp
Normal file
108
src/fsfw/osal/windows/winTaskHelpers.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
#include "fsfw/osal/windows/winTaskHelpers.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
TaskPriority tasks::makeWinPriority(PriorityClass prioClass, PriorityNumber prioNumber) {
|
||||
return (static_cast<uint16_t>(prioClass) << 16) | static_cast<uint16_t> (prioNumber);
|
||||
}
|
||||
|
||||
void tasks::getWinPriorityParameters(TaskPriority priority,
|
||||
DWORD& priorityClass, int& priorityNumber) {
|
||||
PriorityClass classInternal = static_cast<PriorityClass>(priority >> 16 & 0xff);
|
||||
PriorityNumber numberInternal = static_cast<PriorityNumber>(priority & 0xff);
|
||||
switch(classInternal) {
|
||||
case(CLASS_IDLE): {
|
||||
priorityClass = IDLE_PRIORITY_CLASS;
|
||||
break;
|
||||
}
|
||||
case(CLASS_BELOW_NORMAL): {
|
||||
priorityClass = BELOW_NORMAL_PRIORITY_CLASS;
|
||||
break;
|
||||
}
|
||||
case(CLASS_NORMAL): {
|
||||
priorityClass = NORMAL_PRIORITY_CLASS;
|
||||
break;
|
||||
}
|
||||
case(CLASS_ABOVE_NORMAL): {
|
||||
priorityClass = ABOVE_NORMAL_PRIORITY_CLASS;
|
||||
break;
|
||||
}
|
||||
case(CLASS_HIGH): {
|
||||
priorityClass = HIGH_PRIORITY_CLASS;
|
||||
break;
|
||||
}
|
||||
case(CLASS_REALTIME): {
|
||||
priorityClass = REALTIME_PRIORITY_CLASS;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
priorityClass = NORMAL_PRIORITY_CLASS;
|
||||
}
|
||||
}
|
||||
|
||||
switch(numberInternal) {
|
||||
case(IDLE): {
|
||||
priorityNumber = THREAD_PRIORITY_IDLE;
|
||||
break;
|
||||
}
|
||||
case(LOWEST): {
|
||||
priorityNumber = THREAD_PRIORITY_LOWEST;
|
||||
break;
|
||||
}
|
||||
case(BELOW_NORMAL): {
|
||||
priorityNumber = THREAD_PRIORITY_BELOW_NORMAL;
|
||||
break;
|
||||
}
|
||||
case(NORMAL): {
|
||||
priorityNumber = THREAD_PRIORITY_NORMAL;
|
||||
break;
|
||||
}
|
||||
case(ABOVE_NORMAL): {
|
||||
priorityNumber = THREAD_PRIORITY_ABOVE_NORMAL;
|
||||
break;
|
||||
}
|
||||
case(HIGHEST): {
|
||||
priorityNumber = THREAD_PRIORITY_HIGHEST;
|
||||
break;
|
||||
}
|
||||
case(CRITICAL): {
|
||||
priorityNumber = THREAD_PRIORITY_TIME_CRITICAL;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
priorityNumber = THREAD_PRIORITY_NORMAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t tasks::setTaskPriority(HANDLE nativeHandle, TaskPriority priority) {
|
||||
/* List of possible priority classes:
|
||||
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setpriorityclass
|
||||
And respective thread priority numbers:
|
||||
https://docs.microsoft.com/en-us/windows/win32/procthread/scheduling-priorities
|
||||
*/
|
||||
DWORD dwPriorityClass = 0;
|
||||
int nPriorityNumber = 0;
|
||||
tasks::getWinPriorityParameters(priority, dwPriorityClass, nPriorityNumber);
|
||||
int result = SetPriorityClass(
|
||||
reinterpret_cast<HANDLE>(nativeHandle),
|
||||
dwPriorityClass);
|
||||
if(result != 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "PeriodicTask: Windows SetPriorityClass failed with code "
|
||||
<< GetLastError() << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
#endif
|
||||
}
|
||||
result = SetThreadPriority(
|
||||
reinterpret_cast<HANDLE>(nativeHandle),
|
||||
nPriorityNumber);
|
||||
if(result != 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "PeriodicTask: Windows SetPriorityClass failed with code "
|
||||
<< GetLastError() << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
#endif
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
37
src/fsfw/osal/windows/winTaskHelpers.h
Normal file
37
src/fsfw/osal/windows/winTaskHelpers.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "../../tasks/TaskFactory.h"
|
||||
|
||||
#include <thread>
|
||||
#include <map>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
namespace tasks {
|
||||
|
||||
enum PriorityClass: uint16_t {
|
||||
CLASS_IDLE,
|
||||
CLASS_BELOW_NORMAL,
|
||||
CLASS_NORMAL,
|
||||
CLASS_ABOVE_NORMAL,
|
||||
CLASS_HIGH,
|
||||
CLASS_REALTIME
|
||||
};
|
||||
enum PriorityNumber: uint16_t {
|
||||
IDLE,
|
||||
LOWEST,
|
||||
BELOW_NORMAL,
|
||||
NORMAL,
|
||||
ABOVE_NORMAL,
|
||||
HIGHEST,
|
||||
CRITICAL
|
||||
};
|
||||
TaskPriority makeWinPriority(PriorityClass prioClass = PriorityClass::CLASS_NORMAL,
|
||||
PriorityNumber prioNumber = PriorityNumber::NORMAL);
|
||||
void getWinPriorityParameters(TaskPriority priority, DWORD& priorityClass,
|
||||
int& priorityNumber);
|
||||
|
||||
ReturnValue_t setTaskPriority(HANDLE nativeHandle, TaskPriority priority);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user