Merge remote-tracking branch 'upstream/mueller/master' into development
This commit is contained in:
commit
f2da31239c
@ -1,5 +1,13 @@
|
|||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
|
option(FSFW_GENERATE_SECTIONS
|
||||||
|
"Generate function and data sections. Required to remove unused code" ON
|
||||||
|
)
|
||||||
|
|
||||||
|
if(FSFW_GENERATE_SECTIONS)
|
||||||
|
option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON)
|
option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON)
|
||||||
# Options to exclude parts of the FSFW from compilation.
|
# Options to exclude parts of the FSFW from compilation.
|
||||||
option(FSFW_USE_RMAP "Compile with RMAP" ON)
|
option(FSFW_USE_RMAP "Compile with RMAP" ON)
|
||||||
@ -26,15 +34,22 @@ if(NOT OS_FSFW)
|
|||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(FSFW_OSAL_DEFINITION FSFW_HOST)
|
||||||
|
|
||||||
if(${OS_FSFW} STREQUAL host)
|
if(${OS_FSFW} STREQUAL host)
|
||||||
set(OS_FSFW_NAME "Host")
|
set(OS_FSFW_NAME "Host")
|
||||||
elseif(${OS_FSFW} STREQUAL linux)
|
elseif(${OS_FSFW} STREQUAL linux)
|
||||||
set(OS_FSFW_NAME "Linux")
|
set(OS_FSFW_NAME "Linux")
|
||||||
|
set(FSFW_OSAL_DEFINITION FSFW_LINUX)
|
||||||
elseif(${OS_FSFW} STREQUAL freertos)
|
elseif(${OS_FSFW} STREQUAL freertos)
|
||||||
set(OS_FSFW_NAME "FreeRTOS")
|
set(OS_FSFW_NAME "FreeRTOS")
|
||||||
target_link_libraries(${LIB_FSFW_NAME} ${LIB_OS_NAME})
|
set(FSFW_OSAL_DEFINITION FSFW_FREERTOS)
|
||||||
|
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
${LIB_OS_NAME}
|
||||||
|
)
|
||||||
elseif(${OS_FSFW} STREQUAL rtems)
|
elseif(${OS_FSFW} STREQUAL rtems)
|
||||||
set(OS_FSFW_NAME "RTEMS")
|
set(OS_FSFW_NAME "RTEMS")
|
||||||
|
set(FSFW_OSAL_DEFINITION FSFW_RTEMS)
|
||||||
else()
|
else()
|
||||||
message(WARNING
|
message(WARNING
|
||||||
"Invalid operating system for FSFW specified! Setting to host.."
|
"Invalid operating system for FSFW specified! Setting to host.."
|
||||||
@ -43,6 +58,14 @@ else()
|
|||||||
set(OS_FSFW "host")
|
set(OS_FSFW "host")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
target_compile_definitions(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
${FSFW_OSAL_DEFINITION}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(${LIB_FSFW_NAME} INTERFACE
|
||||||
|
${FSFW_OSAL_DEFINITION}
|
||||||
|
)
|
||||||
|
|
||||||
message(STATUS "Compiling FSFW for the ${OS_FSFW_NAME} operating system.")
|
message(STATUS "Compiling FSFW for the ${OS_FSFW_NAME} operating system.")
|
||||||
|
|
||||||
add_subdirectory(action)
|
add_subdirectory(action)
|
||||||
@ -88,6 +111,7 @@ add_subdirectory(timemanager)
|
|||||||
add_subdirectory(tmstorage)
|
add_subdirectory(tmstorage)
|
||||||
add_subdirectory(tmtcpacket)
|
add_subdirectory(tmtcpacket)
|
||||||
add_subdirectory(tmtcservices)
|
add_subdirectory(tmtcservices)
|
||||||
|
add_subdirectory(unittest)
|
||||||
|
|
||||||
# The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it.
|
# The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it.
|
||||||
# If this is not given, we include the default configuration and emit a warning.
|
# If this is not given, we include the default configuration and emit a warning.
|
||||||
@ -107,6 +131,21 @@ else()
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
foreach(INCLUDE_PATH ${FSFW_ADDITIONAL_INC_PATH})
|
||||||
|
if(IS_ABSOLUTE ${INCLUDE_PATH})
|
||||||
|
set(CURR_ABS_INC_PATH "${FREERTOS_PATH}")
|
||||||
|
else()
|
||||||
|
get_filename_component(CURR_ABS_INC_PATH
|
||||||
|
${INCLUDE_PATH} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_VERBOSE)
|
||||||
|
message(STATUS "FSFW include path: ${CURR_ABS_INC_PATH}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
list(APPEND FSFW_ADD_INC_PATHS_ABS ${CURR_ABS_INC_PATH})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
if(NOT DEFINED FSFW_WARNING_FLAGS)
|
if(NOT DEFINED FSFW_WARNING_FLAGS)
|
||||||
set(FSFW_WARNING_FLAGS
|
set(FSFW_WARNING_FLAGS
|
||||||
@ -117,7 +156,20 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|||||||
-Wno-psabi
|
-Wno-psabi
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(FSFW_GENERATE_SECTIONS)
|
||||||
|
target_compile_options(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
"-ffunction-sections"
|
||||||
|
"-fdata-sections"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FSFW_REMOVE_UNUSED_CODE)
|
||||||
|
target_link_options(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
"Wl,--gc-sections"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(FSFW_WARNING_SHADOW_LOCAL_GCC)
|
if(FSFW_WARNING_SHADOW_LOCAL_GCC)
|
||||||
list(APPEND WARNING_FLAGS "-Wshadow=local")
|
list(APPEND WARNING_FLAGS "-Wshadow=local")
|
||||||
endif()
|
endif()
|
||||||
@ -140,9 +192,14 @@ target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
|||||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}
|
${CMAKE_SOURCE_DIR}
|
||||||
${FSFW_CONFIG_PATH_ABSOLUTE}
|
${FSFW_CONFIG_PATH_ABSOLUTE}
|
||||||
|
${FSFW_ADD_INC_PATHS_ABS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(${LIB_FSFW_NAME} PRIVATE
|
target_compile_options(${LIB_FSFW_NAME} PRIVATE
|
||||||
${FSFW_WARNING_FLAGS}
|
${FSFW_WARNING_FLAGS}
|
||||||
${COMPILER_FLAGS}
|
${COMPILER_FLAGS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
${FSFW_ADDITIONAL_LINK_LIBS}
|
||||||
|
)
|
@ -64,11 +64,11 @@ ReturnValue_t PoolDataSetBase::read(MutexIF::TimeoutType timeoutType,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "DataSet::read(): Call made in wrong position. Don't forget to commit"
|
sif::warning << "PoolDataSetBase::read: Call made in wrong position. Don't forget to "
|
||||||
" member datasets!" << std::endl;
|
"commit member datasets!" << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printError("DataSet::read(): Call made in wrong position. Don't forget to commit"
|
sif::printWarning("PoolDataSetBase::read: Call made in wrong position. Don't forget to "
|
||||||
" member datasets!\n");
|
"commit member datasets!\n");
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
result = SET_WAS_ALREADY_READ;
|
result = SET_WAS_ALREADY_READ;
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,20 @@
|
|||||||
#include "../ipc/QueueFactory.h"
|
#include "../ipc/QueueFactory.h"
|
||||||
#include "../ipc/MutexFactory.h"
|
#include "../ipc/MutexFactory.h"
|
||||||
#include "../serviceinterface/ServiceInterface.h"
|
#include "../serviceinterface/ServiceInterface.h"
|
||||||
|
#include "../datapool/PoolReadGuard.h"
|
||||||
|
|
||||||
InternalErrorReporter::InternalErrorReporter(object_id_t setObjectId,
|
InternalErrorReporter::InternalErrorReporter(object_id_t setObjectId,
|
||||||
uint32_t messageQueueDepth): SystemObject(setObjectId),
|
uint32_t messageQueueDepth): SystemObject(setObjectId),
|
||||||
commandQueue(QueueFactory::instance()->
|
commandQueue(QueueFactory::instance()->
|
||||||
createMessageQueue(messageQueueDepth)),
|
createMessageQueue(messageQueueDepth)),
|
||||||
poolManager(this, commandQueue),
|
poolManager(this, commandQueue),
|
||||||
internalErrorSid(setObjectId, InternalErrorDataset::ERROR_SET_ID),
|
internalErrorSid(setObjectId, InternalErrorDataset::ERROR_SET_ID),
|
||||||
internalErrorDataset(this) {
|
internalErrorDataset(this) {
|
||||||
mutex = MutexFactory::instance()->createMutex();
|
mutex = MutexFactory::instance()->createMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
InternalErrorReporter::~InternalErrorReporter() {
|
InternalErrorReporter::~InternalErrorReporter() {
|
||||||
MutexFactory::instance()->deleteMutex(mutex);
|
MutexFactory::instance()->deleteMutex(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InternalErrorReporter::setDiagnosticPrintout(bool enable) {
|
void InternalErrorReporter::setDiagnosticPrintout(bool enable) {
|
||||||
@ -23,126 +24,128 @@ void InternalErrorReporter::setDiagnosticPrintout(bool enable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t InternalErrorReporter::performOperation(uint8_t opCode) {
|
ReturnValue_t InternalErrorReporter::performOperation(uint8_t opCode) {
|
||||||
internalErrorDataset.read(timeoutType, timeoutMs);
|
CommandMessage message;
|
||||||
|
ReturnValue_t result = commandQueue->receiveMessage(&message);
|
||||||
|
if(result != MessageQueueIF::EMPTY) {
|
||||||
|
poolManager.handleHousekeepingMessage(&message);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t newQueueHits = getAndResetQueueHits();
|
uint32_t newQueueHits = getAndResetQueueHits();
|
||||||
uint32_t newTmHits = getAndResetTmHits();
|
uint32_t newTmHits = getAndResetTmHits();
|
||||||
uint32_t newStoreHits = getAndResetStoreHits();
|
uint32_t newStoreHits = getAndResetStoreHits();
|
||||||
|
|
||||||
#if FSFW_VERBOSE_LEVEL == 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
if(diagnosticPrintout) {
|
if(diagnosticPrintout) {
|
||||||
if((newQueueHits > 0) or (newTmHits > 0) or (newStoreHits > 0)) {
|
if((newQueueHits > 0) or (newTmHits > 0) or (newStoreHits > 0)) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::debug << "InternalErrorReporter::performOperation: Errors "
|
sif::debug << "InternalErrorReporter::performOperation: Errors "
|
||||||
<< "occured!" << std::endl;
|
<< "occured!" << std::endl;
|
||||||
sif::debug << "Queue errors: " << newQueueHits << std::endl;
|
sif::debug << "Queue errors: " << newQueueHits << std::endl;
|
||||||
sif::debug << "TM errors: " << newTmHits << std::endl;
|
sif::debug << "TM errors: " << newTmHits << std::endl;
|
||||||
sif::debug << "Store errors: " << newStoreHits << std::endl;
|
sif::debug << "Store errors: " << newStoreHits << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printDebug("InternalErrorReporter::performOperation: Errors occured!\n");
|
sif::printDebug("InternalErrorReporter::performOperation: Errors occured!\n");
|
||||||
sif::printDebug("Queue errors: %lu\n", static_cast<unsigned int>(newQueueHits));
|
sif::printDebug("Queue errors: %lu\n", static_cast<unsigned int>(newQueueHits));
|
||||||
sif::printDebug("TM errors: %lu\n", static_cast<unsigned int>(newTmHits));
|
sif::printDebug("TM errors: %lu\n", static_cast<unsigned int>(newTmHits));
|
||||||
sif::printDebug("Store errors: %lu\n", static_cast<unsigned int>(newStoreHits));
|
sif::printDebug("Store errors: %lu\n", static_cast<unsigned int>(newStoreHits));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
internalErrorDataset.queueHits.value += newQueueHits;
|
{
|
||||||
internalErrorDataset.storeHits.value += newStoreHits;
|
PoolReadGuard readGuard(&internalErrorDataset);
|
||||||
internalErrorDataset.tmHits.value += newTmHits;
|
if(readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
internalErrorDataset.setValidity(true, true);
|
internalErrorDataset.queueHits.value += newQueueHits;
|
||||||
internalErrorDataset.commit(timeoutType, timeoutMs);
|
internalErrorDataset.storeHits.value += newStoreHits;
|
||||||
|
internalErrorDataset.tmHits.value += newTmHits;
|
||||||
|
internalErrorDataset.setValidity(true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
poolManager.performHkOperation();
|
poolManager.performHkOperation();
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
CommandMessage message;
|
|
||||||
ReturnValue_t result = commandQueue->receiveMessage(&message);
|
|
||||||
if(result != MessageQueueIF::EMPTY) {
|
|
||||||
poolManager.handleHousekeepingMessage(&message);
|
|
||||||
}
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InternalErrorReporter::queueMessageNotSent() {
|
void InternalErrorReporter::queueMessageNotSent() {
|
||||||
incrementQueueHits();
|
incrementQueueHits();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InternalErrorReporter::lostTm() {
|
void InternalErrorReporter::lostTm() {
|
||||||
incrementTmHits();
|
incrementTmHits();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t InternalErrorReporter::getAndResetQueueHits() {
|
uint32_t InternalErrorReporter::getAndResetQueueHits() {
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
mutex->lockMutex(timeoutType, timeoutMs);
|
mutex->lockMutex(timeoutType, timeoutMs);
|
||||||
value = queueHits;
|
value = queueHits;
|
||||||
queueHits = 0;
|
queueHits = 0;
|
||||||
mutex->unlockMutex();
|
mutex->unlockMutex();
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t InternalErrorReporter::getQueueHits() {
|
uint32_t InternalErrorReporter::getQueueHits() {
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
mutex->lockMutex(timeoutType, timeoutMs);
|
mutex->lockMutex(timeoutType, timeoutMs);
|
||||||
value = queueHits;
|
value = queueHits;
|
||||||
mutex->unlockMutex();
|
mutex->unlockMutex();
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InternalErrorReporter::incrementQueueHits() {
|
void InternalErrorReporter::incrementQueueHits() {
|
||||||
mutex->lockMutex(timeoutType, timeoutMs);
|
mutex->lockMutex(timeoutType, timeoutMs);
|
||||||
queueHits++;
|
queueHits++;
|
||||||
mutex->unlockMutex();
|
mutex->unlockMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t InternalErrorReporter::getAndResetTmHits() {
|
uint32_t InternalErrorReporter::getAndResetTmHits() {
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
mutex->lockMutex(timeoutType, timeoutMs);
|
mutex->lockMutex(timeoutType, timeoutMs);
|
||||||
value = tmHits;
|
value = tmHits;
|
||||||
tmHits = 0;
|
tmHits = 0;
|
||||||
mutex->unlockMutex();
|
mutex->unlockMutex();
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t InternalErrorReporter::getTmHits() {
|
uint32_t InternalErrorReporter::getTmHits() {
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
mutex->lockMutex(timeoutType, timeoutMs);
|
mutex->lockMutex(timeoutType, timeoutMs);
|
||||||
value = tmHits;
|
value = tmHits;
|
||||||
mutex->unlockMutex();
|
mutex->unlockMutex();
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InternalErrorReporter::incrementTmHits() {
|
void InternalErrorReporter::incrementTmHits() {
|
||||||
mutex->lockMutex(timeoutType, timeoutMs);
|
mutex->lockMutex(timeoutType, timeoutMs);
|
||||||
tmHits++;
|
tmHits++;
|
||||||
mutex->unlockMutex();
|
mutex->unlockMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InternalErrorReporter::storeFull() {
|
void InternalErrorReporter::storeFull() {
|
||||||
incrementStoreHits();
|
incrementStoreHits();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t InternalErrorReporter::getAndResetStoreHits() {
|
uint32_t InternalErrorReporter::getAndResetStoreHits() {
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
mutex->lockMutex(timeoutType, timeoutMs);
|
mutex->lockMutex(timeoutType, timeoutMs);
|
||||||
value = storeHits;
|
value = storeHits;
|
||||||
storeHits = 0;
|
storeHits = 0;
|
||||||
mutex->unlockMutex();
|
mutex->unlockMutex();
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t InternalErrorReporter::getStoreHits() {
|
uint32_t InternalErrorReporter::getStoreHits() {
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
mutex->lockMutex(timeoutType, timeoutMs);
|
mutex->lockMutex(timeoutType, timeoutMs);
|
||||||
value = storeHits;
|
value = storeHits;
|
||||||
mutex->unlockMutex();
|
mutex->unlockMutex();
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InternalErrorReporter::incrementStoreHits() {
|
void InternalErrorReporter::incrementStoreHits() {
|
||||||
mutex->lockMutex(timeoutType, timeoutMs);
|
mutex->lockMutex(timeoutType, timeoutMs);
|
||||||
storeHits++;
|
storeHits++;
|
||||||
mutex->unlockMutex();
|
mutex->unlockMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
object_id_t InternalErrorReporter::getObjectId() const {
|
object_id_t InternalErrorReporter::getObjectId() const {
|
||||||
@ -155,14 +158,11 @@ MessageQueueId_t InternalErrorReporter::getCommandQueue() const {
|
|||||||
|
|
||||||
ReturnValue_t InternalErrorReporter::initializeLocalDataPool(
|
ReturnValue_t InternalErrorReporter::initializeLocalDataPool(
|
||||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
||||||
localDataPoolMap.emplace(errorPoolIds::TM_HITS,
|
localDataPoolMap.emplace(errorPoolIds::TM_HITS, new PoolEntry<uint32_t>());
|
||||||
new PoolEntry<uint32_t>());
|
localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS, new PoolEntry<uint32_t>());
|
||||||
localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS,
|
localDataPoolMap.emplace(errorPoolIds::STORE_HITS, new PoolEntry<uint32_t>());
|
||||||
new PoolEntry<uint32_t>());
|
poolManager.subscribeForPeriodicPacket(internalErrorSid, false, getPeriodicOperationFrequency(),
|
||||||
localDataPoolMap.emplace(errorPoolIds::STORE_HITS,
|
true);
|
||||||
new PoolEntry<uint32_t>());
|
|
||||||
poolManager.subscribeForPeriodicPacket(internalErrorSid, false,
|
|
||||||
getPeriodicOperationFrequency(), true);
|
|
||||||
internalErrorDataset.setValidity(true, true);
|
internalErrorDataset.setValidity(true, true);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
@ -192,9 +192,9 @@ ReturnValue_t InternalErrorReporter::initializeAfterTaskCreation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InternalErrorReporter::setMutexTimeout(MutexIF::TimeoutType timeoutType,
|
void InternalErrorReporter::setMutexTimeout(MutexIF::TimeoutType timeoutType,
|
||||||
uint32_t timeoutMs) {
|
uint32_t timeoutMs) {
|
||||||
this->timeoutType = timeoutType;
|
this->timeoutType = timeoutType;
|
||||||
this->timeoutMs = timeoutMs;
|
this->timeoutMs = timeoutMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalDataPoolManager* InternalErrorReporter::getHkManagerHandle() {
|
LocalDataPoolManager* InternalErrorReporter::getHkManagerHandle() {
|
||||||
|
@ -17,77 +17,78 @@
|
|||||||
* All functions were kept virtual so this class can be extended easily
|
* All functions were kept virtual so this class can be extended easily
|
||||||
* to store custom internal errors (e.g. communication interface errors).
|
* to store custom internal errors (e.g. communication interface errors).
|
||||||
*/
|
*/
|
||||||
class InternalErrorReporter: public SystemObject,
|
class InternalErrorReporter:
|
||||||
public ExecutableObjectIF,
|
public SystemObject,
|
||||||
public InternalErrorReporterIF,
|
public ExecutableObjectIF,
|
||||||
public HasLocalDataPoolIF {
|
public InternalErrorReporterIF,
|
||||||
|
public HasLocalDataPoolIF {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
InternalErrorReporter(object_id_t setObjectId,
|
InternalErrorReporter(object_id_t setObjectId,
|
||||||
uint32_t messageQueueDepth = 5);
|
uint32_t messageQueueDepth = 5);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable diagnostic printout. Please note that this feature will
|
* Enable diagnostic printout. Please note that this feature will
|
||||||
* only work if DEBUG has been supplied to the build defines.
|
* only work if DEBUG has been supplied to the build defines.
|
||||||
* @param enable
|
* @param enable
|
||||||
*/
|
*/
|
||||||
void setDiagnosticPrintout(bool enable);
|
void setDiagnosticPrintout(bool enable);
|
||||||
|
|
||||||
void setMutexTimeout(MutexIF::TimeoutType timeoutType,
|
void setMutexTimeout(MutexIF::TimeoutType timeoutType,
|
||||||
uint32_t timeoutMs);
|
uint32_t timeoutMs);
|
||||||
|
|
||||||
virtual ~InternalErrorReporter();
|
virtual ~InternalErrorReporter();
|
||||||
|
|
||||||
virtual object_id_t getObjectId() const override;
|
virtual object_id_t getObjectId() const override;
|
||||||
virtual MessageQueueId_t getCommandQueue() const override;
|
virtual MessageQueueId_t getCommandQueue() const override;
|
||||||
virtual ReturnValue_t initializeLocalDataPool(
|
virtual ReturnValue_t initializeLocalDataPool(
|
||||||
localpool::DataPool& localDataPoolMap,
|
localpool::DataPool& localDataPoolMap,
|
||||||
LocalDataPoolManager& poolManager) override;
|
LocalDataPoolManager& poolManager) override;
|
||||||
virtual dur_millis_t getPeriodicOperationFrequency() const override;
|
virtual dur_millis_t getPeriodicOperationFrequency() const override;
|
||||||
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
|
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
|
||||||
LocalDataPoolManager* getHkManagerHandle() override;
|
LocalDataPoolManager* getHkManagerHandle() override;
|
||||||
|
|
||||||
virtual ReturnValue_t initialize() override;
|
virtual ReturnValue_t initialize() override;
|
||||||
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
||||||
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
||||||
|
|
||||||
virtual void queueMessageNotSent();
|
virtual void queueMessageNotSent();
|
||||||
|
|
||||||
virtual void lostTm();
|
virtual void lostTm();
|
||||||
|
|
||||||
virtual void storeFull();
|
virtual void storeFull();
|
||||||
|
|
||||||
virtual void setTaskIF(PeriodicTaskIF* task) override;
|
virtual void setTaskIF(PeriodicTaskIF* task) override;
|
||||||
protected:
|
protected:
|
||||||
MessageQueueIF* commandQueue;
|
MessageQueueIF* commandQueue;
|
||||||
LocalDataPoolManager poolManager;
|
LocalDataPoolManager poolManager;
|
||||||
|
|
||||||
PeriodicTaskIF* executingTask = nullptr;
|
PeriodicTaskIF* executingTask = nullptr;
|
||||||
|
|
||||||
MutexIF* mutex = nullptr;
|
MutexIF* mutex = nullptr;
|
||||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
||||||
uint32_t timeoutMs = 20;
|
uint32_t timeoutMs = 20;
|
||||||
|
|
||||||
sid_t internalErrorSid;
|
sid_t internalErrorSid;
|
||||||
InternalErrorDataset internalErrorDataset;
|
InternalErrorDataset internalErrorDataset;
|
||||||
|
|
||||||
bool diagnosticPrintout = true;
|
bool diagnosticPrintout = true;
|
||||||
|
|
||||||
uint32_t queueHits = 0;
|
uint32_t queueHits = 0;
|
||||||
uint32_t tmHits = 0;
|
uint32_t tmHits = 0;
|
||||||
uint32_t storeHits = 0;
|
uint32_t storeHits = 0;
|
||||||
|
|
||||||
uint32_t getAndResetQueueHits();
|
uint32_t getAndResetQueueHits();
|
||||||
uint32_t getQueueHits();
|
uint32_t getQueueHits();
|
||||||
void incrementQueueHits();
|
void incrementQueueHits();
|
||||||
|
|
||||||
uint32_t getAndResetTmHits();
|
uint32_t getAndResetTmHits();
|
||||||
uint32_t getTmHits();
|
uint32_t getTmHits();
|
||||||
void incrementTmHits();
|
void incrementTmHits();
|
||||||
|
|
||||||
uint32_t getAndResetStoreHits();
|
uint32_t getAndResetStoreHits();
|
||||||
uint32_t getStoreHits();
|
uint32_t getStoreHits();
|
||||||
void incrementStoreHits();
|
void incrementStoreHits();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,3 +1,16 @@
|
|||||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
if(DEFINED WIN32 OR DEFINED UNIX)
|
||||||
tcpipCommon.cpp
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
)
|
tcpipCommon.cpp
|
||||||
|
TcpIpBase.cpp
|
||||||
|
UdpTcPollingTask.cpp
|
||||||
|
UdpTmTcBridge.cpp
|
||||||
|
TcpTmTcServer.cpp
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
wsock32
|
||||||
|
ws2_32
|
||||||
|
)
|
||||||
|
endif()
|
54
osal/common/TcpIpBase.cpp
Normal file
54
osal/common/TcpIpBase.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include "TcpIpBase.h"
|
||||||
|
|
||||||
|
#ifdef __unix__
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TcpIpBase::TcpIpBase() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t TcpIpBase::initialize() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
/* 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
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpIpBase::~TcpIpBase() {
|
||||||
|
closeSocket(serverSocket);
|
||||||
|
#ifdef _WIN32
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int TcpIpBase::closeSocket(socket_t socket) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return closesocket(socket);
|
||||||
|
#elif defined(__unix__)
|
||||||
|
return close(socket);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int TcpIpBase::getLastSocketError() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return WSAGetLastError();
|
||||||
|
#elif defined(__unix__)
|
||||||
|
return errno;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
50
osal/common/TcpIpBase.h
Normal file
50
osal/common/TcpIpBase.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#ifndef FSFW_OSAL_COMMON_TCPIPIF_H_
|
||||||
|
#define FSFW_OSAL_COMMON_TCPIPIF_H_
|
||||||
|
|
||||||
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#include <winsock2.h>
|
||||||
|
|
||||||
|
#elif defined(__unix__)
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class TcpIpBase {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
static constexpr int SHUT_RECV = SD_RECEIVE;
|
||||||
|
static constexpr int SHUT_SEND = SD_SEND;
|
||||||
|
static constexpr int SHUT_BOTH = SD_BOTH;
|
||||||
|
|
||||||
|
using socket_t = SOCKET;
|
||||||
|
#elif defined(__unix__)
|
||||||
|
using socket_t = int;
|
||||||
|
|
||||||
|
static constexpr int INVALID_SOCKET = -1;
|
||||||
|
static constexpr int SOCKET_ERROR = -1;
|
||||||
|
|
||||||
|
static constexpr int SHUT_RECV = SHUT_RD;
|
||||||
|
static constexpr int SHUT_SEND = SHUT_WR;
|
||||||
|
static constexpr int SHUT_BOTH = SHUT_RDWR;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TcpIpBase();
|
||||||
|
virtual ~TcpIpBase();
|
||||||
|
|
||||||
|
ReturnValue_t initialize();
|
||||||
|
|
||||||
|
int closeSocket(socket_t socket);
|
||||||
|
|
||||||
|
int getLastSocketError();
|
||||||
|
|
||||||
|
socket_t serverSocket = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_OSAL_COMMON_TCPIPIF_H_ */
|
@ -1,14 +1,21 @@
|
|||||||
#include "TcWinTcpServer.h"
|
#include "TcpTmTcServer.h"
|
||||||
#include "tcpipHelpers.h"
|
#include "tcpipHelpers.h"
|
||||||
#include "../../serviceinterface/ServiceInterface.h"
|
#include "../../serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
const std::string TcWinTcpServer::DEFAULT_TCP_SERVER_PORT = "7301";
|
#elif defined(__unix__)
|
||||||
const std::string TcWinTcpServer::DEFAULT_TCP_CLIENT_PORT = "7302";
|
|
||||||
|
|
||||||
TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
#include <netdb.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const std::string TcpTmTcServer::DEFAULT_TCP_SERVER_PORT = "7301";
|
||||||
|
const std::string TcpTmTcServer::DEFAULT_TCP_CLIENT_PORT = "7302";
|
||||||
|
|
||||||
|
TcpTmTcServer::TcpTmTcServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
||||||
std::string customTcpServerPort):
|
std::string customTcpServerPort):
|
||||||
SystemObject(objectId), tcpPort(customTcpServerPort) {
|
SystemObject(objectId), tcpPort(customTcpServerPort) {
|
||||||
if(tcpPort == "") {
|
if(tcpPort == "") {
|
||||||
@ -16,25 +23,18 @@ TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBrid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TcWinTcpServer::initialize() {
|
ReturnValue_t TcpTmTcServer::initialize() {
|
||||||
using namespace tcpip;
|
using namespace tcpip;
|
||||||
int retval = 0;
|
|
||||||
struct addrinfo *addrResult = nullptr;
|
ReturnValue_t result = TcpIpBase::initialize();
|
||||||
struct addrinfo hints;
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
/* Initiates Winsock DLL. */
|
return result;
|
||||||
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
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZeroMemory(&hints, sizeof (hints));
|
int retval = 0;
|
||||||
|
struct addrinfo *addrResult = nullptr;
|
||||||
|
struct addrinfo hints = {};
|
||||||
|
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_protocol = IPPROTO_TCP;
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
@ -43,7 +43,7 @@ ReturnValue_t TcWinTcpServer::initialize() {
|
|||||||
retval = getaddrinfo(nullptr, tcpPort.c_str(), &hints, &addrResult);
|
retval = getaddrinfo(nullptr, tcpPort.c_str(), &hints, &addrResult);
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "TcWinTcpServer::TcWinTcpServer: Retrieving address info failed!" <<
|
sif::warning << "TcWinTcpServer::TcpTmTcServer: Retrieving address info failed!" <<
|
||||||
std::endl;
|
std::endl;
|
||||||
#endif
|
#endif
|
||||||
handleError(Protocol::TCP, ErrorSources::GETADDRINFO_CALL);
|
handleError(Protocol::TCP, ErrorSources::GETADDRINFO_CALL);
|
||||||
@ -65,7 +65,7 @@ ReturnValue_t TcWinTcpServer::initialize() {
|
|||||||
retval = bind(listenerTcpSocket, addrResult->ai_addr, static_cast<int>(addrResult->ai_addrlen));
|
retval = bind(listenerTcpSocket, addrResult->ai_addr, static_cast<int>(addrResult->ai_addrlen));
|
||||||
if(retval == SOCKET_ERROR) {
|
if(retval == SOCKET_ERROR) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "TcWinTcpServer::TcWinTcpServer: Binding socket failed!" <<
|
sif::warning << "TcWinTcpServer::TcpTmTcServer: Binding socket failed!" <<
|
||||||
std::endl;
|
std::endl;
|
||||||
#endif
|
#endif
|
||||||
freeaddrinfo(addrResult);
|
freeaddrinfo(addrResult);
|
||||||
@ -77,17 +77,16 @@ ReturnValue_t TcWinTcpServer::initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TcWinTcpServer::~TcWinTcpServer() {
|
TcpTmTcServer::~TcpTmTcServer() {
|
||||||
closesocket(listenerTcpSocket);
|
closeSocket(listenerTcpSocket);
|
||||||
WSACleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TcWinTcpServer::performOperation(uint8_t opCode) {
|
ReturnValue_t TcpTmTcServer::performOperation(uint8_t opCode) {
|
||||||
using namespace tcpip;
|
using namespace tcpip;
|
||||||
/* If a connection is accepted, the corresponding socket will be assigned to the new socket */
|
/* If a connection is accepted, the corresponding socket will be assigned to the new socket */
|
||||||
SOCKET clientSocket;
|
socket_t clientSocket;
|
||||||
sockaddr_in clientSockAddr;
|
sockaddr clientSockAddr;
|
||||||
int connectorSockAddrLen = 0;
|
socklen_t connectorSockAddrLen = 0;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
/* Listen for connection requests permanently for lifetime of program */
|
/* Listen for connection requests permanently for lifetime of program */
|
||||||
@ -98,8 +97,7 @@ ReturnValue_t TcWinTcpServer::performOperation(uint8_t opCode) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
clientSocket = accept(listenerTcpSocket, reinterpret_cast<sockaddr*>(&clientSockAddr),
|
clientSocket = accept(listenerTcpSocket, &clientSockAddr, &connectorSockAddrLen);
|
||||||
&connectorSockAddrLen);
|
|
||||||
|
|
||||||
if(clientSocket == INVALID_SOCKET) {
|
if(clientSocket == INVALID_SOCKET) {
|
||||||
handleError(Protocol::TCP, ErrorSources::ACCEPT_CALL, 500);
|
handleError(Protocol::TCP, ErrorSources::ACCEPT_CALL, 500);
|
||||||
@ -110,7 +108,7 @@ ReturnValue_t TcWinTcpServer::performOperation(uint8_t opCode) {
|
|||||||
receptionBuffer.size(), 0);
|
receptionBuffer.size(), 0);
|
||||||
if(retval > 0) {
|
if(retval > 0) {
|
||||||
#if FSFW_TCP_RCV_WIRETAPPING_ENABLED == 1
|
#if FSFW_TCP_RCV_WIRETAPPING_ENABLED == 1
|
||||||
sif::info << "TcWinTcpServer::performOperation: Received " << retval << " bytes."
|
sif::info << "TcpTmTcServer::performOperation: Received " << retval << " bytes."
|
||||||
std::endl;
|
std::endl;
|
||||||
#endif
|
#endif
|
||||||
handleError(Protocol::TCP, ErrorSources::RECV_CALL, 500);
|
handleError(Protocol::TCP, ErrorSources::RECV_CALL, 500);
|
||||||
@ -123,7 +121,7 @@ ReturnValue_t TcWinTcpServer::performOperation(uint8_t opCode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Done, shut down connection */
|
/* Done, shut down connection */
|
||||||
retval = shutdown(clientSocket, SD_SEND);
|
retval = shutdown(clientSocket, SHUT_SEND);
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
@ -1,9 +1,14 @@
|
|||||||
#ifndef FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
#ifndef FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
||||||
#define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
#define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
||||||
|
|
||||||
|
#include "TcpIpBase.h"
|
||||||
#include "../../objectmanager/SystemObject.h"
|
#include "../../objectmanager/SystemObject.h"
|
||||||
#include "../../tasks/ExecutableObjectIF.h"
|
#include "../../tasks/ExecutableObjectIF.h"
|
||||||
|
|
||||||
|
#ifdef __unix__
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -15,17 +20,18 @@
|
|||||||
* @details
|
* @details
|
||||||
* Based on: https://docs.microsoft.com/en-us/windows/win32/winsock/complete-server-code
|
* Based on: https://docs.microsoft.com/en-us/windows/win32/winsock/complete-server-code
|
||||||
*/
|
*/
|
||||||
class TcWinTcpServer:
|
class TcpTmTcServer:
|
||||||
public SystemObject,
|
public SystemObject,
|
||||||
|
public TcpIpBase,
|
||||||
public ExecutableObjectIF {
|
public ExecutableObjectIF {
|
||||||
public:
|
public:
|
||||||
/* The ports chosen here should not be used by any other process. */
|
/* The ports chosen here should not be used by any other process. */
|
||||||
static const std::string DEFAULT_TCP_SERVER_PORT;
|
static const std::string DEFAULT_TCP_SERVER_PORT;
|
||||||
static const std::string DEFAULT_TCP_CLIENT_PORT;
|
static const std::string DEFAULT_TCP_CLIENT_PORT;
|
||||||
|
|
||||||
TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
TcpTmTcServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
||||||
std::string customTcpServerPort = "");
|
std::string customTcpServerPort = "");
|
||||||
virtual~ TcWinTcpServer();
|
virtual~ TcpTmTcServer();
|
||||||
|
|
||||||
ReturnValue_t initialize() override;
|
ReturnValue_t initialize() override;
|
||||||
ReturnValue_t performOperation(uint8_t opCode) override;
|
ReturnValue_t performOperation(uint8_t opCode) override;
|
||||||
@ -33,8 +39,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
std::string tcpPort;
|
std::string tcpPort;
|
||||||
SOCKET listenerTcpSocket = 0;
|
socket_t listenerTcpSocket = 0;
|
||||||
struct sockaddr_in tcpAddress;
|
struct sockaddr tcpAddress;
|
||||||
int tcpAddrLen = sizeof(tcpAddress);
|
int tcpAddrLen = sizeof(tcpAddress);
|
||||||
int currentBacklog = 3;
|
int currentBacklog = 3;
|
||||||
|
|
177
osal/common/UdpTcPollingTask.cpp
Normal file
177
osal/common/UdpTcPollingTask.cpp
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
#include "UdpTcPollingTask.h"
|
||||||
|
#include "tcpipHelpers.h"
|
||||||
|
#include "../../globalfunctions/arrayprinter.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#include <winsock2.h>
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//! Debugging preprocessor define.
|
||||||
|
#define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0
|
||||||
|
|
||||||
|
UdpTcPollingTask::UdpTcPollingTask(object_id_t objectId,
|
||||||
|
object_id_t tmtcUnixUdpBridge, size_t maxRecvSize,
|
||||||
|
double timeoutSeconds): SystemObject(objectId),
|
||||||
|
tmtcBridgeId(tmtcUnixUdpBridge) {
|
||||||
|
if(frameSize > 0) {
|
||||||
|
this->frameSize = frameSize;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->frameSize = DEFAULT_MAX_RECV_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set up reception buffer with specified frame size.
|
||||||
|
For now, it is assumed that only one frame is held in the buffer! */
|
||||||
|
receptionBuffer.reserve(this->frameSize);
|
||||||
|
receptionBuffer.resize(this->frameSize);
|
||||||
|
|
||||||
|
if(timeoutSeconds == -1) {
|
||||||
|
receptionTimeout = DEFAULT_TIMEOUT;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
receptionTimeout = timevalOperations::toTimeval(timeoutSeconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UdpTcPollingTask::~UdpTcPollingTask() {}
|
||||||
|
|
||||||
|
ReturnValue_t UdpTcPollingTask::performOperation(uint8_t opCode) {
|
||||||
|
/* Sender Address is cached here. */
|
||||||
|
struct sockaddr senderAddress;
|
||||||
|
socklen_t senderAddressSize = sizeof(senderAddress);
|
||||||
|
|
||||||
|
/* Poll for new UDP datagrams in permanent loop. */
|
||||||
|
while(true) {
|
||||||
|
int bytesReceived = recvfrom(
|
||||||
|
this->serverSocket,
|
||||||
|
reinterpret_cast<char*>(receptionBuffer.data()),
|
||||||
|
frameSize,
|
||||||
|
receptionFlags,
|
||||||
|
&senderAddress,
|
||||||
|
&senderAddressSize
|
||||||
|
);
|
||||||
|
if(bytesReceived == SOCKET_ERROR) {
|
||||||
|
/* Handle error */
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "UdpTcPollingTask::performOperation: Reception error." << std::endl;
|
||||||
|
#endif
|
||||||
|
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::RECVFROM_CALL, 1000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
||||||
|
sif::debug << "UdpTcPollingTask::performOperation: " << bytesReceived <<
|
||||||
|
" bytes received" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_FAILED) {
|
||||||
|
|
||||||
|
}
|
||||||
|
tmtcBridge->checkAndSetClientAddress(senderAddress);
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t UdpTcPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
||||||
|
store_address_t storeId;
|
||||||
|
|
||||||
|
#if FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
||||||
|
arrayprinter::print(receptionBuffer.data(), bytesRead);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ReturnValue_t result = tcStore->addData(&storeId, receptionBuffer.data(), bytesRead);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning<< "UdpTcPollingTask::transferPusToSoftwareBus: Data storage failed." <<
|
||||||
|
std::endl;
|
||||||
|
sif::warning << "Packet size: " << bytesRead << std::endl;
|
||||||
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
TmTcMessage message(storeId);
|
||||||
|
|
||||||
|
result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "UdpTcPollingTask::handleSuccessfullTcRead: "
|
||||||
|
" Sending message to queue failed" << std::endl;
|
||||||
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
|
tcStore->deleteData(storeId);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t UdpTcPollingTask::initialize() {
|
||||||
|
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
||||||
|
if (tcStore == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "UdpTcPollingTask::initialize: TC store uninitialized!" << std::endl;
|
||||||
|
#endif
|
||||||
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmtcBridge = objectManager->get<UdpTmTcBridge>(tmtcBridgeId);
|
||||||
|
if(tmtcBridge == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "UdpTcPollingTask::initialize: Invalid TMTC bridge object!" <<
|
||||||
|
std::endl;
|
||||||
|
#endif
|
||||||
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t result = TcpIpBase::initialize();
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t UdpTcPollingTask::initializeAfterTaskCreation() {
|
||||||
|
/* Initialize the destination after task creation. This ensures
|
||||||
|
that the destination has already been set in the TMTC bridge. */
|
||||||
|
targetTcDestination = tmtcBridge->getRequestQueue();
|
||||||
|
/* The server socket is set up in the bridge intialization. Calling this function here
|
||||||
|
ensures that it is set up regardless of which class was initialized first */
|
||||||
|
this->serverSocket = tmtcBridge->serverSocket;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UdpTcPollingTask::setTimeout(double timeoutSeconds) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
DWORD timeoutMs = timeoutSeconds * 1000.0;
|
||||||
|
int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO,
|
||||||
|
reinterpret_cast<const char*>(&timeoutMs), sizeof(DWORD));
|
||||||
|
if(result == -1) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "TcWinUdpPollingTask::TcSocketPollingTask: Setting "
|
||||||
|
"receive timeout failed with " << strerror(errno) << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#elif defined(__unix__)
|
||||||
|
timeval tval;
|
||||||
|
tval = timevalOperations::toTimeval(timeoutSeconds);
|
||||||
|
int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO,
|
||||||
|
&tval, sizeof(receptionTimeout));
|
||||||
|
if(result == -1) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "TcSocketPollingTask::TcSocketPollingTask: Setting "
|
||||||
|
"receive timeout failed with " << strerror(errno) << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef FSFW_OSAL_WINDOWS_TCSOCKETPOLLINGTASK_H_
|
#ifndef FSFW_OSAL_WINDOWS_TCSOCKETPOLLINGTASK_H_
|
||||||
#define FSFW_OSAL_WINDOWS_TCSOCKETPOLLINGTASK_H_
|
#define FSFW_OSAL_WINDOWS_TCSOCKETPOLLINGTASK_H_
|
||||||
|
|
||||||
#include "TmTcWinUdpBridge.h"
|
#include "UdpTmTcBridge.h"
|
||||||
#include "../../objectmanager/SystemObject.h"
|
#include "../../objectmanager/SystemObject.h"
|
||||||
#include "../../tasks/ExecutableObjectIF.h"
|
#include "../../tasks/ExecutableObjectIF.h"
|
||||||
#include "../../storagemanager/StorageManagerIF.h"
|
#include "../../storagemanager/StorageManagerIF.h"
|
||||||
@ -9,25 +9,22 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class can be used to implement the polling of a Unix socket,
|
* @brief This class should be used with the UdpTmTcBridge to implement a UDP server
|
||||||
* using UDP for now.
|
* for receiving and sending PUS TMTC.
|
||||||
* @details
|
|
||||||
* The task will be blocked while the specified number of bytes has not been
|
|
||||||
* received, so TC reception is handled inside a separate task.
|
|
||||||
* This class caches the IP address of the sender. It is assumed there
|
|
||||||
* is only one sender for now.
|
|
||||||
*/
|
*/
|
||||||
class TcWinUdpPollingTask: public SystemObject,
|
class UdpTcPollingTask:
|
||||||
|
public TcpIpBase,
|
||||||
|
public SystemObject,
|
||||||
public ExecutableObjectIF {
|
public ExecutableObjectIF {
|
||||||
friend class TmTcWinUdpBridge;
|
friend class TmTcWinUdpBridge;
|
||||||
public:
|
public:
|
||||||
static constexpr size_t DEFAULT_MAX_FRAME_SIZE = 2048;
|
static constexpr size_t DEFAULT_MAX_RECV_SIZE = 1500;
|
||||||
//! 0.5 default milliseconds timeout for now.
|
//! 0.5 default milliseconds timeout for now.
|
||||||
static constexpr timeval DEFAULT_TIMEOUT = {0, 500};
|
static constexpr timeval DEFAULT_TIMEOUT = {0, 500};
|
||||||
|
|
||||||
TcWinUdpPollingTask(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
UdpTcPollingTask(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
||||||
size_t frameSize = 0, double timeoutSeconds = -1);
|
size_t maxRecvSize = 0, double timeoutSeconds = -1);
|
||||||
virtual~ TcWinUdpPollingTask();
|
virtual~ UdpTcPollingTask();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn on optional timeout for UDP polling. In the default mode,
|
* Turn on optional timeout for UDP polling. In the default mode,
|
||||||
@ -46,16 +43,12 @@ protected:
|
|||||||
private:
|
private:
|
||||||
//! TMTC bridge is cached.
|
//! TMTC bridge is cached.
|
||||||
object_id_t tmtcBridgeId = objects::NO_OBJECT;
|
object_id_t tmtcBridgeId = objects::NO_OBJECT;
|
||||||
TmTcWinUdpBridge* tmtcBridge = nullptr;
|
UdpTmTcBridge* tmtcBridge = nullptr;
|
||||||
MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE;
|
MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE;
|
||||||
|
|
||||||
//! See: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom
|
//! See: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom
|
||||||
int receptionFlags = 0;
|
int receptionFlags = 0;
|
||||||
|
|
||||||
//! Server socket, which is member of TMTC bridge.
|
|
||||||
//! Will be cached shortly after SW intialization.
|
|
||||||
SOCKET serverUdpSocket = 0;
|
|
||||||
|
|
||||||
std::vector<uint8_t> receptionBuffer;
|
std::vector<uint8_t> receptionBuffer;
|
||||||
|
|
||||||
size_t frameSize = 0;
|
size_t frameSize = 0;
|
@ -1,16 +1,26 @@
|
|||||||
#include "TmTcWinUdpBridge.h"
|
|
||||||
#include "tcpipHelpers.h"
|
#include "tcpipHelpers.h"
|
||||||
|
|
||||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||||
#include <fsfw/ipc/MutexGuard.h>
|
#include <fsfw/ipc/MutexGuard.h>
|
||||||
|
#include <fsfw/osal/common/UdpTmTcBridge.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
|
#elif defined(__unix__)
|
||||||
|
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//! Debugging preprocessor define.
|
//! Debugging preprocessor define.
|
||||||
#define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0
|
#define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0
|
||||||
|
|
||||||
const std::string TmTcWinUdpBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_UDP_SERVER_PORT;
|
const std::string UdpTmTcBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT;
|
||||||
|
|
||||||
TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, object_id_t tcDestination,
|
UdpTmTcBridge::UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||||
object_id_t tmStoreId, object_id_t tcStoreId, std::string udpServerPort):
|
object_id_t tmStoreId, object_id_t tcStoreId, std::string udpServerPort):
|
||||||
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
|
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
|
||||||
if(udpServerPort == "") {
|
if(udpServerPort == "") {
|
||||||
@ -24,16 +34,18 @@ TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, object_id_t tcDestinati
|
|||||||
communicationLinkUp = false;
|
communicationLinkUp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TmTcWinUdpBridge::initialize() {
|
ReturnValue_t UdpTmTcBridge::initialize() {
|
||||||
ReturnValue_t result = TmTcBridge::initialize();
|
ReturnValue_t result = TmTcBridge::initialize();
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "TmTcWinUdpBridge::initialize: TmTcBridge initialization failed!"
|
sif::error << "TmTcUdpBridge::initialize: TmTcBridge initialization failed!"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
/* Initiates Winsock DLL. */
|
/* Initiates Winsock DLL. */
|
||||||
WSAData wsaData;
|
WSAData wsaData;
|
||||||
WORD wVersionRequested = MAKEWORD(2, 2);
|
WORD wVersionRequested = MAKEWORD(2, 2);
|
||||||
@ -42,26 +54,22 @@ ReturnValue_t TmTcWinUdpBridge::initialize() {
|
|||||||
/* Tell the user that we could not find a usable */
|
/* Tell the user that we could not find a usable */
|
||||||
/* Winsock DLL. */
|
/* Winsock DLL. */
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: WSAStartup failed with error: " <<
|
sif::error << "TmTcUdpBridge::TmTcUdpBridge: WSAStartup failed with error: " <<
|
||||||
err << std::endl;
|
err << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printError("TmTcWinUdpBridge::TmTcWinUdpBridge: WSAStartup failed with error: %d\n",
|
sif::printError("TmTcUdpBridge::TmTcUdpBridge: WSAStartup failed with error: %d\n",
|
||||||
err);
|
err);
|
||||||
#endif
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct addrinfo *addrResult = nullptr;
|
struct addrinfo *addrResult = nullptr;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints = {};
|
||||||
|
|
||||||
ZeroMemory(&hints, sizeof (hints));
|
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_DGRAM;
|
hints.ai_socktype = SOCK_DGRAM;
|
||||||
hints.ai_protocol = IPPROTO_UDP;
|
hints.ai_protocol = IPPROTO_UDP;
|
||||||
/* See:
|
|
||||||
https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo
|
|
||||||
for information about AI_PASSIVE. */
|
|
||||||
hints.ai_flags = AI_PASSIVE;
|
|
||||||
|
|
||||||
/* Set up UDP socket:
|
/* Set up UDP socket:
|
||||||
https://en.wikipedia.org/wiki/Getaddrinfo
|
https://en.wikipedia.org/wiki/Getaddrinfo
|
||||||
@ -70,7 +78,7 @@ ReturnValue_t TmTcWinUdpBridge::initialize() {
|
|||||||
int retval = getaddrinfo(nullptr, udpServerPort.c_str(), &hints, &addrResult);
|
int retval = getaddrinfo(nullptr, udpServerPort.c_str(), &hints, &addrResult);
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "TmTcWinUdpBridge::TmTcWinUdpBridge: Retrieving address info failed!" <<
|
sif::warning << "TmTcUdpBridge::TmTcUdpBridge: Retrieving address info failed!" <<
|
||||||
std::endl;
|
std::endl;
|
||||||
#endif
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
@ -79,7 +87,7 @@ ReturnValue_t TmTcWinUdpBridge::initialize() {
|
|||||||
serverSocket = socket(addrResult->ai_family, addrResult->ai_socktype, addrResult->ai_protocol);
|
serverSocket = socket(addrResult->ai_family, addrResult->ai_socktype, addrResult->ai_protocol);
|
||||||
if(serverSocket == INVALID_SOCKET) {
|
if(serverSocket == INVALID_SOCKET) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "TmTcWinUdpBridge::TmTcWinUdpBridge: Could not open UDP socket!" <<
|
sif::warning << "TmTcUdpBridge::TmTcUdpBridge: Could not open UDP socket!" <<
|
||||||
std::endl;
|
std::endl;
|
||||||
#endif
|
#endif
|
||||||
freeaddrinfo(addrResult);
|
freeaddrinfo(addrResult);
|
||||||
@ -90,7 +98,7 @@ ReturnValue_t TmTcWinUdpBridge::initialize() {
|
|||||||
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 << "TmTcUdpBridge::TmTcUdpBridge: Could not bind "
|
||||||
"local port (" << udpServerPort << ") to server socket!" << std::endl;
|
"local port (" << udpServerPort << ") to server socket!" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
freeaddrinfo(addrResult);
|
freeaddrinfo(addrResult);
|
||||||
@ -100,15 +108,13 @@ ReturnValue_t TmTcWinUdpBridge::initialize() {
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
TmTcWinUdpBridge::~TmTcWinUdpBridge() {
|
UdpTmTcBridge::~UdpTmTcBridge() {
|
||||||
if(mutex != nullptr) {
|
if(mutex != nullptr) {
|
||||||
MutexFactory::instance()->deleteMutex(mutex);
|
MutexFactory::instance()->deleteMutex(mutex);
|
||||||
}
|
}
|
||||||
closesocket(serverSocket);
|
|
||||||
WSACleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
ReturnValue_t UdpTmTcBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
/* The target address can be set by different threads so this lock ensures thread-safety */
|
/* The target address can be set by different threads so this lock ensures thread-safety */
|
||||||
@ -125,23 +131,23 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
|||||||
reinterpret_cast<const char*>(data),
|
reinterpret_cast<const char*>(data),
|
||||||
dataLen,
|
dataLen,
|
||||||
flags,
|
flags,
|
||||||
reinterpret_cast<sockaddr*>(&clientAddress),
|
&clientAddress,
|
||||||
clientAddressLen
|
clientAddressLen
|
||||||
);
|
);
|
||||||
if(bytesSent == SOCKET_ERROR) {
|
if(bytesSent == SOCKET_ERROR) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "TmTcWinUdpBridge::sendTm: Send operation failed." << std::endl;
|
sif::warning << "TmTcUdpBridge::sendTm: Send operation failed." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::SENDTO_CALL);
|
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::SENDTO_CALL);
|
||||||
}
|
}
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||||
sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
|
sif::debug << "TmTcUdpBridge::sendTm: " << bytesSent << " bytes were"
|
||||||
" sent." << std::endl;
|
" sent." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in& newAddress) {
|
void UdpTmTcBridge::checkAndSetClientAddress(sockaddr& newAddress) {
|
||||||
/* The target address can be set by different threads so this lock ensures thread-safety */
|
/* The target address can be set by different threads so this lock ensures thread-safety */
|
||||||
MutexGuard lock(mutex, timeoutType, mutexTimeoutMs);
|
MutexGuard lock(mutex, timeoutType, mutexTimeoutMs);
|
||||||
|
|
||||||
@ -159,7 +165,7 @@ void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in& newAddress) {
|
|||||||
clientAddressLen = sizeof(clientAddress);
|
clientAddressLen = sizeof(clientAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TmTcWinUdpBridge::setMutexProperties(MutexIF::TimeoutType timeoutType,
|
void UdpTmTcBridge::setMutexProperties(MutexIF::TimeoutType timeoutType,
|
||||||
dur_millis_t timeoutMs) {
|
dur_millis_t timeoutMs) {
|
||||||
this->timeoutType = timeoutType;
|
this->timeoutType = timeoutType;
|
||||||
this->mutexTimeoutMs = timeoutMs;
|
this->mutexTimeoutMs = timeoutMs;
|
@ -1,20 +1,36 @@
|
|||||||
#ifndef FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
|
#ifndef FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
|
||||||
#define FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
|
#define FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
|
||||||
|
|
||||||
|
#include "TcpIpBase.h"
|
||||||
#include "../../tmtcservices/TmTcBridge.h"
|
#include "../../tmtcservices/TmTcBridge.h"
|
||||||
|
|
||||||
#include <string>
|
#ifdef _WIN32
|
||||||
#include <winsock2.h>
|
|
||||||
|
|
||||||
class TmTcWinUdpBridge: public TmTcBridge {
|
#include <ws2tcpip.h>
|
||||||
friend class TcWinUdpPollingTask;
|
|
||||||
|
#elif defined(__unix__)
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This class should be used with the UdpTcPollingTask to implement a UDP server
|
||||||
|
* for receiving and sending PUS TMTC.
|
||||||
|
*/
|
||||||
|
class UdpTmTcBridge:
|
||||||
|
public TmTcBridge,
|
||||||
|
public TcpIpBase {
|
||||||
|
friend class UdpTcPollingTask;
|
||||||
public:
|
public:
|
||||||
/* The ports chosen here should not be used by any other process. */
|
/* The ports chosen here should not be used by any other process. */
|
||||||
static const std::string DEFAULT_UDP_SERVER_PORT;
|
static const std::string DEFAULT_UDP_SERVER_PORT;
|
||||||
|
|
||||||
TmTcWinUdpBridge(object_id_t objectId, object_id_t tcDestination,
|
UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||||
object_id_t tmStoreId, object_id_t tcStoreId, std::string udpServerPort = "");
|
object_id_t tmStoreId, object_id_t tcStoreId, std::string udpServerPort = "");
|
||||||
virtual~ TmTcWinUdpBridge();
|
virtual~ UdpTmTcBridge();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set properties of internal mutex.
|
* Set properties of internal mutex.
|
||||||
@ -23,17 +39,16 @@ public:
|
|||||||
|
|
||||||
ReturnValue_t initialize() override;
|
ReturnValue_t initialize() override;
|
||||||
|
|
||||||
void checkAndSetClientAddress(sockaddr_in& clientAddress);
|
void checkAndSetClientAddress(sockaddr& 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;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SOCKET serverSocket = 0;
|
|
||||||
std::string udpServerPort;
|
std::string udpServerPort;
|
||||||
|
|
||||||
struct sockaddr_in clientAddress;
|
struct sockaddr clientAddress;
|
||||||
int clientAddressLen = 0;
|
socklen_t clientAddressLen = 0;
|
||||||
|
|
||||||
//! Access to the client address is mutex protected as it is set by another task.
|
//! Access to the client address is mutex protected as it is set by another task.
|
||||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
@ -6,8 +6,7 @@
|
|||||||
|
|
||||||
namespace tcpip {
|
namespace tcpip {
|
||||||
|
|
||||||
const char* const DEFAULT_UDP_SERVER_PORT = "7301";
|
const char* const DEFAULT_SERVER_PORT = "7301";
|
||||||
const char* const DEFAULT_TCP_SERVER_PORT = "7303";
|
|
||||||
|
|
||||||
enum class Protocol {
|
enum class Protocol {
|
||||||
UDP,
|
UDP,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define FSFW_OSAL_WINDOWS_TCPIPHELPERS_H_
|
#define FSFW_OSAL_WINDOWS_TCPIPHELPERS_H_
|
||||||
|
|
||||||
#include "../../timemanager/clockDefinitions.h"
|
#include "../../timemanager/clockDefinitions.h"
|
||||||
#include "../common/tcpipCommon.h"
|
#include "tcpipCommon.h"
|
||||||
|
|
||||||
namespace tcpip {
|
namespace tcpip {
|
||||||
|
|
@ -10,6 +10,7 @@ target_sources(${LIB_FSFW_NAME}
|
|||||||
QueueMapManager.cpp
|
QueueMapManager.cpp
|
||||||
SemaphoreFactory.cpp
|
SemaphoreFactory.cpp
|
||||||
TaskFactory.cpp
|
TaskFactory.cpp
|
||||||
|
taskHelpers.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
|
#include "taskHelpers.h"
|
||||||
#include "../../osal/host/FixedTimeslotTask.h"
|
#include "../../osal/host/FixedTimeslotTask.h"
|
||||||
|
|
||||||
#include "../../ipc/MutexFactory.h"
|
#include "../../ipc/MutexFactory.h"
|
||||||
#include "../../osal/host/Mutex.h"
|
#include "../../osal/host/Mutex.h"
|
||||||
#include "../../osal/host/FixedTimeslotTask.h"
|
#include "../../osal/host/FixedTimeslotTask.h"
|
||||||
|
|
||||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
#include "../../tasks/ExecutableObjectIF.h"
|
#include "../../tasks/ExecutableObjectIF.h"
|
||||||
|
|
||||||
@ -12,6 +11,7 @@
|
|||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include "../windows/winTaskHelpers.h"
|
||||||
#elif defined(LINUX)
|
#elif defined(LINUX)
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
@ -24,34 +24,12 @@ FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority,
|
|||||||
// It is propably possible to set task priorities by using the native
|
// It is propably possible to set task priorities by using the native
|
||||||
// task handles for Windows / Linux
|
// task handles for Windows / Linux
|
||||||
mainThread = std::thread(&FixedTimeslotTask::taskEntryPoint, this, this);
|
mainThread = std::thread(&FixedTimeslotTask::taskEntryPoint, this, this);
|
||||||
#if defined(WIN32)
|
#if defined(_WIN32)
|
||||||
/* List of possible priority classes:
|
tasks::setTaskPriority(reinterpret_cast<HANDLE>(mainThread.native_handle()), setPriority);
|
||||||
* https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/
|
#elif defined(__unix__)
|
||||||
* nf-processthreadsapi-setpriorityclass
|
// TODO: We could reuse existing code here.
|
||||||
* And respective thread priority numbers:
|
|
||||||
* https://docs.microsoft.com/en-us/windows/
|
|
||||||
* win32/procthread/scheduling-priorities */
|
|
||||||
int result = SetPriorityClass(
|
|
||||||
reinterpret_cast<HANDLE>(mainThread.native_handle()),
|
|
||||||
ABOVE_NORMAL_PRIORITY_CLASS);
|
|
||||||
if(result != 0) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code "
|
|
||||||
<< GetLastError() << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
result = SetThreadPriority(
|
|
||||||
reinterpret_cast<HANDLE>(mainThread.native_handle()),
|
|
||||||
THREAD_PRIORITY_NORMAL);
|
|
||||||
if(result != 0) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code "
|
|
||||||
<< GetLastError() << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#elif defined(LINUX)
|
|
||||||
// TODO: we can just copy and paste the code from the linux OSAL here.
|
|
||||||
#endif
|
#endif
|
||||||
|
tasks::insertTaskName(mainThread.get_id(), taskName);
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedTimeslotTask::~FixedTimeslotTask(void) {
|
FixedTimeslotTask::~FixedTimeslotTask(void) {
|
||||||
|
@ -63,8 +63,6 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
|
|||||||
if(messageQueue.empty()) {
|
if(messageQueue.empty()) {
|
||||||
return MessageQueueIF::EMPTY;
|
return MessageQueueIF::EMPTY;
|
||||||
}
|
}
|
||||||
// not sure this will work..
|
|
||||||
//*message = std::move(messageQueue.front());
|
|
||||||
MutexGuard mutexLock(queueLock, MutexIF::TimeoutType::WAITING, 20);
|
MutexGuard mutexLock(queueLock, MutexIF::TimeoutType::WAITING, 20);
|
||||||
MessageQueueMessage* currentMessage = &messageQueue.front();
|
MessageQueueMessage* currentMessage = &messageQueue.front();
|
||||||
std::copy(currentMessage->getBuffer(),
|
std::copy(currentMessage->getBuffer(),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "Mutex.h"
|
#include "Mutex.h"
|
||||||
#include "PeriodicTask.h"
|
#include "PeriodicTask.h"
|
||||||
|
#include "taskHelpers.h"
|
||||||
|
|
||||||
#include "../../ipc/MutexFactory.h"
|
#include "../../ipc/MutexFactory.h"
|
||||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
@ -10,7 +11,8 @@
|
|||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
#include <processthreadsapi.h>
|
#include <processthreadsapi.h>
|
||||||
#elif defined(LINUX)
|
#include <fsfw/osal/windows/winTaskHelpers.h>
|
||||||
|
#elif defined(__unix__)
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -22,34 +24,12 @@ PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
|
|||||||
// It is propably possible to set task priorities by using the native
|
// It is propably possible to set task priorities by using the native
|
||||||
// task handles for Windows / Linux
|
// task handles for Windows / Linux
|
||||||
mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this);
|
mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this);
|
||||||
#if defined(WIN32)
|
#if defined(_WIN32)
|
||||||
/* List of possible priority classes:
|
tasks::setTaskPriority(reinterpret_cast<HANDLE>(mainThread.native_handle()), setPriority);
|
||||||
* https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/
|
#elif defined(__unix__)
|
||||||
* nf-processthreadsapi-setpriorityclass
|
// TODO: We could reuse existing code here.
|
||||||
* And respective thread priority numbers:
|
|
||||||
* https://docs.microsoft.com/en-us/windows/
|
|
||||||
* win32/procthread/scheduling-priorities */
|
|
||||||
int result = SetPriorityClass(
|
|
||||||
reinterpret_cast<HANDLE>(mainThread.native_handle()),
|
|
||||||
ABOVE_NORMAL_PRIORITY_CLASS);
|
|
||||||
if(result != 0) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "PeriodicTask: Windows SetPriorityClass failed with code "
|
|
||||||
<< GetLastError() << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
result = SetThreadPriority(
|
|
||||||
reinterpret_cast<HANDLE>(mainThread.native_handle()),
|
|
||||||
THREAD_PRIORITY_NORMAL);
|
|
||||||
if(result != 0) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "PeriodicTask: Windows SetPriorityClass failed with code "
|
|
||||||
<< GetLastError() << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#elif defined(LINUX)
|
|
||||||
// we can just copy and paste the code from linux here.
|
|
||||||
#endif
|
#endif
|
||||||
|
tasks::insertTaskName(mainThread.get_id(), taskName);
|
||||||
}
|
}
|
||||||
|
|
||||||
PeriodicTask::~PeriodicTask(void) {
|
PeriodicTask::~PeriodicTask(void) {
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
|
#include "taskHelpers.h"
|
||||||
|
#include "../../tasks/TaskFactory.h"
|
||||||
#include "../../osal/host/FixedTimeslotTask.h"
|
#include "../../osal/host/FixedTimeslotTask.h"
|
||||||
#include "../../osal/host/PeriodicTask.h"
|
#include "../../osal/host/PeriodicTask.h"
|
||||||
#include "../../tasks/TaskFactory.h"
|
|
||||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include "../../tasks/PeriodicTaskIF.h"
|
#include "../../tasks/PeriodicTaskIF.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
TaskFactory* TaskFactory::factoryInstance = new TaskFactory();
|
TaskFactory* TaskFactory::factoryInstance = new TaskFactory();
|
||||||
|
|
||||||
// Will propably not be used for hosted implementation
|
// Not used for the host implementation for now because C++ thread abstraction is used
|
||||||
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = 0;
|
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = 0;
|
||||||
|
|
||||||
TaskFactory::TaskFactory() {
|
TaskFactory::TaskFactory() {
|
||||||
@ -49,8 +51,12 @@ ReturnValue_t TaskFactory::delayTask(uint32_t delayMs){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TaskFactory::printMissedDeadline() {
|
void TaskFactory::printMissedDeadline() {
|
||||||
/* TODO: Implement */
|
std::string name = tasks::getTaskName(std::this_thread::get_id());
|
||||||
return;
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "TaskFactory::printMissedDeadline: " << name << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("TaskFactory::printMissedDeadline: %s\n", name);
|
||||||
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
27
osal/host/taskHelpers.cpp
Normal file
27
osal/host/taskHelpers.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "taskHelpers.h"
|
||||||
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
std::mutex nameMapLock;
|
||||||
|
std::map<std::thread::id, std::string> taskNameMap;
|
||||||
|
|
||||||
|
ReturnValue_t tasks::insertTaskName(std::thread::id threadId, std::string taskName) {
|
||||||
|
std::lock_guard<std::mutex> lg(nameMapLock);
|
||||||
|
auto returnPair = taskNameMap.emplace(threadId, taskName);
|
||||||
|
if(not returnPair.second) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string tasks::getTaskName(std::thread::id threadId) {
|
||||||
|
std::lock_guard<std::mutex> lg(nameMapLock);
|
||||||
|
auto resultIter = taskNameMap.find(threadId);
|
||||||
|
if(resultIter != taskNameMap.end()) {
|
||||||
|
return resultIter->second;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "Unknown task";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
16
osal/host/taskHelpers.h
Normal file
16
osal/host/taskHelpers.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef FSFW_OSAL_HOST_TASKHELPERS_H_
|
||||||
|
#define FSFW_OSAL_HOST_TASKHELPERS_H_
|
||||||
|
|
||||||
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
namespace tasks {
|
||||||
|
|
||||||
|
ReturnValue_t insertTaskName(std::thread::id threadId, std::string taskName);
|
||||||
|
std::string getTaskName(std::thread::id threadId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_OSAL_HOST_TASKHELPERS_H_ */
|
@ -13,8 +13,6 @@ target_sources(${LIB_FSFW_NAME}
|
|||||||
QueueFactory.cpp
|
QueueFactory.cpp
|
||||||
SemaphoreFactory.cpp
|
SemaphoreFactory.cpp
|
||||||
TaskFactory.cpp
|
TaskFactory.cpp
|
||||||
TcUnixUdpPollingTask.cpp
|
|
||||||
TmTcUnixUdpBridge.cpp
|
|
||||||
Timer.cpp
|
Timer.cpp
|
||||||
tcpipHelpers.cpp
|
tcpipHelpers.cpp
|
||||||
)
|
)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
PosixThread::PosixThread(const char* name_, int priority_, size_t stackSize_):
|
PosixThread::PosixThread(const char* name_, int priority_, size_t stackSize_):
|
||||||
thread(0),priority(priority_),stackSize(stackSize_) {
|
thread(0), priority(priority_), stackSize(stackSize_) {
|
||||||
name[0] = '\0';
|
name[0] = '\0';
|
||||||
std::strncat(name, name_, PTHREAD_MAX_NAMELEN - 1);
|
std::strncat(name, name_, PTHREAD_MAX_NAMELEN - 1);
|
||||||
}
|
}
|
||||||
@ -63,33 +63,33 @@ void PosixThread::resume(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool PosixThread::delayUntil(uint64_t* const prevoiusWakeTime_ms,
|
bool PosixThread::delayUntil(uint64_t* const prevoiusWakeTime_ms,
|
||||||
const uint64_t delayTime_ms) {
|
const uint64_t delayTime_ms) {
|
||||||
uint64_t nextTimeToWake_ms;
|
uint64_t nextTimeToWake_ms;
|
||||||
bool shouldDelay = false;
|
bool shouldDelay = false;
|
||||||
/* Get current Time */
|
//Get current Time
|
||||||
const uint64_t currentTime_ms = getCurrentMonotonicTimeMs();
|
const uint64_t currentTime_ms = getCurrentMonotonicTimeMs();
|
||||||
/* Generate the tick time at which the task wants to wake. */
|
/* Generate the tick time at which the task wants to wake. */
|
||||||
nextTimeToWake_ms = (*prevoiusWakeTime_ms) + delayTime_ms;
|
nextTimeToWake_ms = (*prevoiusWakeTime_ms) + delayTime_ms;
|
||||||
|
|
||||||
if (currentTime_ms < *prevoiusWakeTime_ms) {
|
if (currentTime_ms < *prevoiusWakeTime_ms) {
|
||||||
/* The tick count has overflowed since this function was
|
/* The tick count has overflowed since this function was
|
||||||
lasted called. In this case the only time we should ever
|
lasted called. In this case the only time we should ever
|
||||||
actually delay is if the wake time has also overflowed,
|
actually delay is if the wake time has also overflowed,
|
||||||
and the wake time is greater than the tick time. When this
|
and the wake time is greater than the tick time. When this
|
||||||
is the case it is as if neither time had overflowed. */
|
is the case it is as if neither time had overflowed. */
|
||||||
if ((nextTimeToWake_ms < *prevoiusWakeTime_ms)
|
if ((nextTimeToWake_ms < *prevoiusWakeTime_ms)
|
||||||
&& (nextTimeToWake_ms > currentTime_ms)) {
|
&& (nextTimeToWake_ms > currentTime_ms)) {
|
||||||
shouldDelay = true;
|
shouldDelay = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* The tick time has not overflowed. In this case we will
|
/* The tick time has not overflowed. In this case we will
|
||||||
delay if either the wake time has overflowed, and/or the
|
delay if either the wake time has overflowed, and/or the
|
||||||
tick time is less than the wake time. */
|
tick time is less than the wake time. */
|
||||||
if ((nextTimeToWake_ms < *prevoiusWakeTime_ms)
|
if ((nextTimeToWake_ms < *prevoiusWakeTime_ms)
|
||||||
|| (nextTimeToWake_ms > currentTime_ms)) {
|
|| (nextTimeToWake_ms > currentTime_ms)) {
|
||||||
shouldDelay = true;
|
shouldDelay = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the wake time ready for the next call. */
|
/* Update the wake time ready for the next call. */
|
||||||
|
|
||||||
|
@ -1,152 +0,0 @@
|
|||||||
#include "TcUnixUdpPollingTask.h"
|
|
||||||
#include "tcpipHelpers.h"
|
|
||||||
|
|
||||||
#include "../../globalfunctions/arrayprinter.h"
|
|
||||||
|
|
||||||
#define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0
|
|
||||||
|
|
||||||
TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId,
|
|
||||||
object_id_t tmtcUnixUdpBridge, size_t frameSize,
|
|
||||||
double timeoutSeconds): SystemObject(objectId),
|
|
||||||
tmtcBridgeId(tmtcUnixUdpBridge) {
|
|
||||||
|
|
||||||
if(frameSize > 0) {
|
|
||||||
this->frameSize = frameSize;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->frameSize = DEFAULT_MAX_FRAME_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set up reception buffer with specified frame size.
|
|
||||||
For now, it is assumed that only one frame is held in the buffer! */
|
|
||||||
receptionBuffer.reserve(this->frameSize);
|
|
||||||
receptionBuffer.resize(this->frameSize);
|
|
||||||
|
|
||||||
if(timeoutSeconds == -1) {
|
|
||||||
receptionTimeout = DEFAULT_TIMEOUT;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
receptionTimeout = timevalOperations::toTimeval(timeoutSeconds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TcUnixUdpPollingTask::~TcUnixUdpPollingTask() {}
|
|
||||||
|
|
||||||
ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
|
|
||||||
/* Sender Address is cached here. */
|
|
||||||
struct sockaddr_in senderAddress;
|
|
||||||
socklen_t senderAddressSize = sizeof(senderAddress);
|
|
||||||
|
|
||||||
/* Poll for new UDP datagrams in permanent loop. */
|
|
||||||
while(true) {
|
|
||||||
ssize_t bytesReceived = recvfrom(
|
|
||||||
serverUdpSocket,
|
|
||||||
receptionBuffer.data(),
|
|
||||||
frameSize,
|
|
||||||
receptionFlags,
|
|
||||||
reinterpret_cast<sockaddr*>(&senderAddress),
|
|
||||||
&senderAddressSize
|
|
||||||
);
|
|
||||||
if(bytesReceived < 0) {
|
|
||||||
/* Handle error */
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "TcSocketPollingTask::performOperation: Reception error." << std::endl;
|
|
||||||
#endif
|
|
||||||
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::RECVFROM_CALL, 500);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
|
||||||
sif::debug << "TcSocketPollingTask::performOperation: " << bytesReceived
|
|
||||||
<< " bytes received" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
|
||||||
if(result != HasReturnvaluesIF::RETURN_FAILED) {
|
|
||||||
|
|
||||||
}
|
|
||||||
tmtcBridge->checkAndSetClientAddress(senderAddress);
|
|
||||||
}
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t TcUnixUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
|
||||||
store_address_t storeId;
|
|
||||||
|
|
||||||
#if FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
|
||||||
arrayprinter::print(receptionBuffer.data(), bytesRead);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ReturnValue_t result = tcStore->addData(&storeId, receptionBuffer.data(), bytesRead);
|
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "TcUnixUdpPollingTask::handleSuccessfullTcRead: Data "
|
|
||||||
"storage failed" << std::endl;
|
|
||||||
sif::error << "Packet size: " << bytesRead << std::endl;
|
|
||||||
#else
|
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
TmTcMessage message(storeId);
|
|
||||||
|
|
||||||
result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message);
|
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "TcUnixUdpPollingTask::handleSuccessfullTcRead: Sending message to queue "
|
|
||||||
"failed" << std::endl;
|
|
||||||
#else
|
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
|
||||||
tcStore->deleteData(storeId);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t TcUnixUdpPollingTask::initialize() {
|
|
||||||
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
|
||||||
if (tcStore == nullptr) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "TcSerialPollingTask::initialize: TC Store uninitialized!"
|
|
||||||
<< std::endl;
|
|
||||||
#endif
|
|
||||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmtcBridge = objectManager->get<TmTcUnixUdpBridge>(tmtcBridgeId);
|
|
||||||
if(tmtcBridge == nullptr) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "TcSocketPollingTask::TcSocketPollingTask: Invalid"
|
|
||||||
" TMTC bridge object!" << std::endl;
|
|
||||||
#endif
|
|
||||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t TcUnixUdpPollingTask::initializeAfterTaskCreation() {
|
|
||||||
/* Initialize the destination after task creation. This ensures
|
|
||||||
that the destination has already been set in the TMTC bridge. */
|
|
||||||
targetTcDestination = tmtcBridge->getRequestQueue();
|
|
||||||
/* The server socket is set up in the bridge intialization. Calling this function here
|
|
||||||
ensures that it is set up properly in any case*/
|
|
||||||
serverUdpSocket = tmtcBridge->serverSocket;
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TcUnixUdpPollingTask::setTimeout(double timeoutSeconds) {
|
|
||||||
timeval tval;
|
|
||||||
tval = timevalOperations::toTimeval(timeoutSeconds);
|
|
||||||
int result = setsockopt(serverUdpSocket, SOL_SOCKET, SO_RCVTIMEO,
|
|
||||||
&tval, sizeof(receptionTimeout));
|
|
||||||
if(result == -1) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "TcSocketPollingTask::TcSocketPollingTask: Setting "
|
|
||||||
"receive timeout failed with " << strerror(errno) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
#ifndef FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_
|
|
||||||
#define FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_
|
|
||||||
|
|
||||||
#include "../../objectmanager/SystemObject.h"
|
|
||||||
#include "../../osal/linux/TmTcUnixUdpBridge.h"
|
|
||||||
#include "../../tasks/ExecutableObjectIF.h"
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This class can be used to implement the polling of a Unix socket,
|
|
||||||
* using UDP for now.
|
|
||||||
* @details
|
|
||||||
* The task will be blocked while the specified number of bytes has not been
|
|
||||||
* received, so TC reception is handled inside a separate task.
|
|
||||||
* This class caches the IP address of the sender. It is assumed there
|
|
||||||
* is only one sender for now.
|
|
||||||
*/
|
|
||||||
class TcUnixUdpPollingTask: public SystemObject,
|
|
||||||
public ExecutableObjectIF {
|
|
||||||
friend class TmTcUnixUdpBridge;
|
|
||||||
public:
|
|
||||||
static constexpr size_t DEFAULT_MAX_FRAME_SIZE = 2048;
|
|
||||||
//! 0.5 default milliseconds timeout for now.
|
|
||||||
static constexpr timeval DEFAULT_TIMEOUT = {.tv_sec = 0, .tv_usec = 500};
|
|
||||||
|
|
||||||
TcUnixUdpPollingTask(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
|
||||||
size_t frameSize = 0, double timeoutSeconds = -1);
|
|
||||||
virtual~ TcUnixUdpPollingTask();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Turn on optional timeout for UDP polling. In the default mode,
|
|
||||||
* the receive function will block until a packet is received.
|
|
||||||
* @param timeoutSeconds
|
|
||||||
*/
|
|
||||||
void setTimeout(double timeoutSeconds);
|
|
||||||
|
|
||||||
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
|
||||||
virtual ReturnValue_t initialize() override;
|
|
||||||
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
StorageManagerIF* tcStore = nullptr;
|
|
||||||
|
|
||||||
private:
|
|
||||||
//! TMTC bridge is cached.
|
|
||||||
object_id_t tmtcBridgeId = objects::NO_OBJECT;
|
|
||||||
TmTcUnixUdpBridge* tmtcBridge = nullptr;
|
|
||||||
MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE;
|
|
||||||
|
|
||||||
//! Reception flags: https://linux.die.net/man/2/recvfrom.
|
|
||||||
int receptionFlags = 0;
|
|
||||||
|
|
||||||
//! Server socket, which is member of TMTC bridge and is assigned in
|
|
||||||
//! constructor
|
|
||||||
int serverUdpSocket = 0;
|
|
||||||
|
|
||||||
std::vector<uint8_t> receptionBuffer;
|
|
||||||
|
|
||||||
size_t frameSize = 0;
|
|
||||||
timeval receptionTimeout;
|
|
||||||
|
|
||||||
ReturnValue_t handleSuccessfullTcRead(size_t bytesRead);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ */
|
|
@ -1,4 +1,4 @@
|
|||||||
#include "tcpipHelpers.h"
|
#include "../common/tcpipHelpers.h"
|
||||||
|
|
||||||
#include "../../tasks/TaskFactory.h"
|
#include "../../tasks/TaskFactory.h"
|
||||||
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
#ifndef FSFW_OSAL_LINUX_TCPIPHELPERS_H_
|
|
||||||
#define FSFW_OSAL_LINUX_TCPIPHELPERS_H_
|
|
||||||
|
|
||||||
#include "../../timemanager/clockDefinitions.h"
|
|
||||||
#include "../common/tcpipCommon.h"
|
|
||||||
|
|
||||||
namespace tcpip {
|
|
||||||
|
|
||||||
|
|
||||||
void handleError(Protocol protocol, ErrorSources errorSrc, dur_millis_t sleepDuration = 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* FSFW_OSAL_LINUX_TCPIPHELPERS_H_ */
|
|
@ -1,11 +1,4 @@
|
|||||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
TcWinUdpPollingTask.cpp
|
|
||||||
TmTcWinUdpBridge.cpp
|
|
||||||
TcWinTcpServer.cpp
|
|
||||||
tcpipHelpers.cpp
|
tcpipHelpers.cpp
|
||||||
|
winTaskHelpers.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
|
||||||
wsock32
|
|
||||||
ws2_32
|
|
||||||
)
|
|
@ -1,149 +0,0 @@
|
|||||||
#include "TcWinUdpPollingTask.h"
|
|
||||||
#include "tcpipHelpers.h"
|
|
||||||
#include "../../globalfunctions/arrayprinter.h"
|
|
||||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
|
||||||
|
|
||||||
#include <winsock2.h>
|
|
||||||
|
|
||||||
//! Debugging preprocessor define.
|
|
||||||
#define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0
|
|
||||||
|
|
||||||
TcWinUdpPollingTask::TcWinUdpPollingTask(object_id_t objectId,
|
|
||||||
object_id_t tmtcUnixUdpBridge, size_t frameSize,
|
|
||||||
double timeoutSeconds): SystemObject(objectId),
|
|
||||||
tmtcBridgeId(tmtcUnixUdpBridge) {
|
|
||||||
if(frameSize > 0) {
|
|
||||||
this->frameSize = frameSize;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->frameSize = DEFAULT_MAX_FRAME_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set up reception buffer with specified frame size.
|
|
||||||
For now, it is assumed that only one frame is held in the buffer! */
|
|
||||||
receptionBuffer.reserve(this->frameSize);
|
|
||||||
receptionBuffer.resize(this->frameSize);
|
|
||||||
|
|
||||||
if(timeoutSeconds == -1) {
|
|
||||||
receptionTimeout = DEFAULT_TIMEOUT;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
receptionTimeout = timevalOperations::toTimeval(timeoutSeconds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TcWinUdpPollingTask::~TcWinUdpPollingTask() {}
|
|
||||||
|
|
||||||
ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) {
|
|
||||||
/* Sender Address is cached here. */
|
|
||||||
struct sockaddr_in senderAddress;
|
|
||||||
int senderAddressSize = sizeof(senderAddress);
|
|
||||||
|
|
||||||
/* Poll for new UDP datagrams in permanent loop. */
|
|
||||||
while(true) {
|
|
||||||
int bytesReceived = recvfrom(
|
|
||||||
serverUdpSocket,
|
|
||||||
reinterpret_cast<char*>(receptionBuffer.data()),
|
|
||||||
frameSize,
|
|
||||||
receptionFlags,
|
|
||||||
reinterpret_cast<sockaddr*>(&senderAddress),
|
|
||||||
&senderAddressSize
|
|
||||||
);
|
|
||||||
if(bytesReceived == SOCKET_ERROR) {
|
|
||||||
/* Handle error */
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "TcWinUdpPollingTask::performOperation: Reception error." << std::endl;
|
|
||||||
#endif
|
|
||||||
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::RECVFROM_CALL, 1000);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
|
||||||
sif::debug << "TcWinUdpPollingTask::performOperation: " << bytesReceived <<
|
|
||||||
" bytes received" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
|
||||||
if(result != HasReturnvaluesIF::RETURN_FAILED) {
|
|
||||||
|
|
||||||
}
|
|
||||||
tmtcBridge->checkAndSetClientAddress(senderAddress);
|
|
||||||
}
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t TcWinUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
|
||||||
store_address_t storeId;
|
|
||||||
|
|
||||||
#if FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
|
|
||||||
arrayprinter::print(receptionBuffer.data(), bytesRead);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ReturnValue_t result = tcStore->addData(&storeId, receptionBuffer.data(), bytesRead);
|
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::warning<< "TcWinUdpPollingTask::transferPusToSoftwareBus: Data storage failed." <<
|
|
||||||
std::endl;
|
|
||||||
sif::warning << "Packet size: " << bytesRead << std::endl;
|
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
TmTcMessage message(storeId);
|
|
||||||
|
|
||||||
result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message);
|
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::warning << "TcWinUdpPollingTask::handleSuccessfullTcRead: "
|
|
||||||
" Sending message to queue failed" << std::endl;
|
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
|
||||||
tcStore->deleteData(storeId);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t TcWinUdpPollingTask::initialize() {
|
|
||||||
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
|
||||||
if (tcStore == nullptr) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "TcWinUdpPollingTask::initialize: TC store uninitialized!" << std::endl;
|
|
||||||
#endif
|
|
||||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmtcBridge = objectManager->get<TmTcWinUdpBridge>(tmtcBridgeId);
|
|
||||||
if(tmtcBridge == nullptr) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "TcWinUdpPollingTask::initialize: Invalid TMTC bridge object!" <<
|
|
||||||
std::endl;
|
|
||||||
#endif
|
|
||||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
||||||
}
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t TcWinUdpPollingTask::initializeAfterTaskCreation() {
|
|
||||||
/* Initialize the destination after task creation. This ensures
|
|
||||||
that the destination has already been set in the TMTC bridge. */
|
|
||||||
targetTcDestination = tmtcBridge->getRequestQueue();
|
|
||||||
/* The server socket is set up in the bridge intialization. Calling this function here
|
|
||||||
ensures that it is set up properly in any case*/
|
|
||||||
serverUdpSocket = tmtcBridge->serverSocket;
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TcWinUdpPollingTask::setTimeout(double timeoutSeconds) {
|
|
||||||
DWORD timeoutMs = timeoutSeconds * 1000.0;
|
|
||||||
int result = setsockopt(serverUdpSocket, SOL_SOCKET, SO_RCVTIMEO,
|
|
||||||
reinterpret_cast<const char*>(&timeoutMs), sizeof(DWORD));
|
|
||||||
if(result == -1) {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "TcWinUdpPollingTask::TcSocketPollingTask: Setting "
|
|
||||||
"receive timeout failed with " << strerror(errno) << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
#include "tcpipHelpers.h"
|
#include "../common/tcpipHelpers.h"
|
||||||
#include <FSFWConfig.h>
|
#include <FSFWConfig.h>
|
||||||
|
|
||||||
#include "../../tasks/TaskFactory.h"
|
#include "../../tasks/TaskFactory.h"
|
||||||
|
107
osal/windows/winTaskHelpers.cpp
Normal file
107
osal/windows/winTaskHelpers.cpp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#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
osal/windows/winTaskHelpers.h
Normal file
37
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
|
||||||
|
|
@ -22,9 +22,26 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Creates a new periodic task and returns the interface pointer.
|
* Creates a new periodic task and returns the interface pointer.
|
||||||
* @param name_ Name of the task
|
* @param name_ Name of the task
|
||||||
* @param taskPriority_ Priority of the task
|
* @param taskPriority_
|
||||||
|
* Priority of the task. This value might have different ranges for the various OSALs.
|
||||||
|
* - Linux Value ranging from 0 to 99 with 99 being the highest value.
|
||||||
|
* - Host For Windows, the value can be retrieved by using the #tasks::makeWinPriority
|
||||||
|
* function. For Linux, same priority system as specified above. MacOS not tested
|
||||||
|
* yet
|
||||||
|
* - FreeRTOS Value depends on the FreeRTOS configuration, higher number means higher priority
|
||||||
|
* - RTEMS Values ranging from 0 to 99 with 99 being the highest value.
|
||||||
|
*
|
||||||
* @param stackSize_ Stack Size of the task
|
* @param stackSize_ Stack Size of the task
|
||||||
|
* This value might have different recommended ranges for the various OSALs.
|
||||||
|
* - Linux Lowest limit is the PeriodicTaskIF::MINIMUM_STACK_SIZE value
|
||||||
|
* - Host Value is ignored for now because the C++ threading abstraction layer is used.
|
||||||
|
* - FreeRTOS Stack size in bytes. It is recommended to specify at least 1kB of stack for
|
||||||
|
* FSFW tasks, but the lowest possible size is specified in the
|
||||||
|
* FreeRTOSConfig.h file.
|
||||||
|
* - RTEMS Lowest limit is specified the PeriodicTaskIF::MINIMUM_STACK_SIZE value.
|
||||||
|
*
|
||||||
* @param period_ Period of the task
|
* @param period_ Period of the task
|
||||||
|
*
|
||||||
* @param deadLineMissedFunction_ Function to be called if a deadline was missed
|
* @param deadLineMissedFunction_ Function to be called if a deadline was missed
|
||||||
* @return PeriodicTaskIF* Pointer to the newly created Task
|
* @return PeriodicTaskIF* Pointer to the newly created Task
|
||||||
*/
|
*/
|
||||||
@ -34,7 +51,8 @@ public:
|
|||||||
TaskDeadlineMissedFunction deadLineMissedFunction_);
|
TaskDeadlineMissedFunction deadLineMissedFunction_);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* The meaning for the variables for fixed timeslot tasks is the same as for periodic tasks.
|
||||||
|
* See #createPeriodicTask documentation.
|
||||||
* @param name_ Name of the task
|
* @param name_ Name of the task
|
||||||
* @param taskPriority_ Priority of the task
|
* @param taskPriority_ Priority of the task
|
||||||
* @param stackSize_ Stack Size of the task
|
* @param stackSize_ Stack Size of the task
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define FRAMEWORK_TASKS_TYPEDEF_H_
|
#define FRAMEWORK_TASKS_TYPEDEF_H_
|
||||||
|
|
||||||
typedef const char* TaskName;
|
typedef const char* TaskName;
|
||||||
typedef uint8_t TaskPriority;
|
typedef uint32_t TaskPriority;
|
||||||
typedef size_t TaskStackSize;
|
typedef size_t TaskStackSize;
|
||||||
typedef double TaskPeriod;
|
typedef double TaskPeriod;
|
||||||
typedef void (*TaskDeadlineMissedFunction)();
|
typedef void (*TaskDeadlineMissedFunction)();
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "../serviceinterface/ServiceInterface.h"
|
#include "../serviceinterface/ServiceInterface.h"
|
||||||
#include "../globalfunctions/arrayprinter.h"
|
#include "../globalfunctions/arrayprinter.h"
|
||||||
|
|
||||||
|
#define TMTCBRIDGE_WIRETAPPING 0
|
||||||
|
|
||||||
TmTcBridge::TmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
TmTcBridge::TmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||||
object_id_t tmStoreId, object_id_t tcStoreId):
|
object_id_t tmStoreId, object_id_t tcStoreId):
|
||||||
SystemObject(objectId),tmStoreId(tmStoreId), tcStoreId(tcStoreId),
|
SystemObject(objectId),tmStoreId(tmStoreId), tcStoreId(tcStoreId),
|
||||||
@ -234,17 +236,11 @@ ReturnValue_t TmTcBridge::handleStoredTm() {
|
|||||||
|
|
||||||
void TmTcBridge::registerCommConnect() {
|
void TmTcBridge::registerCommConnect() {
|
||||||
if(not communicationLinkUp) {
|
if(not communicationLinkUp) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
//sif::info << "TMTC Bridge: Registered Comm Link Connect" << std::endl;
|
|
||||||
#endif
|
|
||||||
communicationLinkUp = true;
|
communicationLinkUp = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TmTcBridge::registerCommDisconnect() {
|
void TmTcBridge::registerCommDisconnect() {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
//sif::info << "TMTC Bridge: Registered Comm Link Disconnect" << std::endl;
|
|
||||||
#endif
|
|
||||||
if(communicationLinkUp) {
|
if(communicationLinkUp) {
|
||||||
communicationLinkUp = false;
|
communicationLinkUp = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user