From 517d52f55df804ef22fab9c7be6708e2560b180d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 16 Aug 2021 11:27:46 +0200 Subject: [PATCH 1/3] using better defines --- .../src/fsfw_tests/internal/InternalUnitTester.cpp | 9 ++++++--- tests/src/fsfw_tests/internal/InternalUnitTester.h | 1 + tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp | 11 ++++++----- .../fsfw_tests/internal/osal/IntTestSemaphore.cpp | 13 +++++++------ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/tests/src/fsfw_tests/internal/InternalUnitTester.cpp b/tests/src/fsfw_tests/internal/InternalUnitTester.cpp index f9fc1932..20998d64 100644 --- a/tests/src/fsfw_tests/internal/InternalUnitTester.cpp +++ b/tests/src/fsfw_tests/internal/InternalUnitTester.cpp @@ -16,15 +16,18 @@ InternalUnitTester::~InternalUnitTester() {} ReturnValue_t InternalUnitTester::performTests( const struct InternalUnitTester::TestConfig& testConfig) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Running internal unit tests.." << std::endl; + sif::info << "Running internal unit tests.. Error messages might follow" << + std::endl; #else sif::printInfo("Running internal unit tests..\n"); #endif testserialize::test_serialization(); testmq::testMq(); - testsemaph::testBinSemaph(); - testsemaph::testCountingSemaph(); + if(testConfig.testSemaphores) { + testsemaph::testBinSemaph(); + testsemaph::testCountingSemaph(); + } testmutex::testMutex(); if(testConfig.testArrayPrinter) { arrayprinter::testArrayPrinter(); diff --git a/tests/src/fsfw_tests/internal/InternalUnitTester.h b/tests/src/fsfw_tests/internal/InternalUnitTester.h index 50c89d77..433a0f1f 100644 --- a/tests/src/fsfw_tests/internal/InternalUnitTester.h +++ b/tests/src/fsfw_tests/internal/InternalUnitTester.h @@ -18,6 +18,7 @@ class InternalUnitTester: public HasReturnvaluesIF { public: struct TestConfig { bool testArrayPrinter = false; + bool testSemaphores = true; }; InternalUnitTester(); diff --git a/tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp b/tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp index b1699a46..d9184cd8 100644 --- a/tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp +++ b/tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp @@ -1,10 +1,12 @@ #include "fsfw_tests/internal/osal/IntTestMutex.h" #include "fsfw_tests/internal/UnittDefinitions.h" +#include "fsfw/platform.h" #include -#if defined(WIN32) || defined(UNIX) -#include +#if defined PLATFORM_WIN || defined PLATFORM_UNIX +#include "fsfw/osal/host/Mutex.h" + #include #include #endif @@ -20,7 +22,7 @@ void testmutex::testMutex() { // timed_mutex from the C++ library specifies undefined behaviour if // the timed mutex is locked twice from the same thread. // TODO: we should pass a define like FSFW_OSAL_HOST to the build. -#if defined(WIN32) || defined(UNIX) +#if defined PLATFORM_WIN || defined PLATFORM_UNIX // This calls the function from // another thread and stores the returnvalue in a future. auto future = std::async(&MutexIF::lockMutex, mutex, MutexIF::TimeoutType::WAITING, 1); @@ -37,8 +39,7 @@ void testmutex::testMutex() { unitt::put_error(id); } - // TODO: we should pass a define like FSFW_OSAL_HOST to the build. -#if !defined(WIN32) && !defined(UNIX) +#if !defined PLATFORM_WIN && !defined PLATFORM_UNIX result = mutex->unlockMutex(); if(result != MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX) { unitt::put_error(id); diff --git a/tests/src/fsfw_tests/internal/osal/IntTestSemaphore.cpp b/tests/src/fsfw_tests/internal/osal/IntTestSemaphore.cpp index 8b79f33b..4b28f961 100644 --- a/tests/src/fsfw_tests/internal/osal/IntTestSemaphore.cpp +++ b/tests/src/fsfw_tests/internal/osal/IntTestSemaphore.cpp @@ -1,9 +1,10 @@ +#include "fsfw/FSFW.h" #include "fsfw_tests/internal/osal/IntTestSemaphore.h" #include "fsfw_tests/internal/UnittDefinitions.h" -#include -#include -#include +#include "fsfw/tasks/SemaphoreFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/timemanager/Stopwatch.h" #include @@ -16,7 +17,7 @@ void testsemaph::testBinSemaph() { } testBinSemaphoreImplementation(binSemaph, id); SemaphoreFactory::instance()->deleteSemaphore(binSemaph); -#if defined(freeRTOS) +#if defined FSFW_OSAL_FREERTOS SemaphoreIF* binSemaphUsingTask = SemaphoreFactory::instance()->createBinarySemaphore(1); testBinSemaphoreImplementation(binSemaphUsingTask, id); @@ -36,7 +37,7 @@ void testsemaph::testCountingSemaph() { } testBinSemaphoreImplementation(countingSemaph, id); SemaphoreFactory::instance()->deleteSemaphore(countingSemaph); -#if defined(freeRTOS) +#if defined FSFW_OSAL_FREERTOS countingSemaph = SemaphoreFactory::instance()-> createCountingSemaphore(1, 1, 1); testBinSemaphoreImplementation(countingSemaph, id); @@ -50,7 +51,7 @@ void testsemaph::testCountingSemaph() { createCountingSemaphore(3,3); testCountingSemaphImplementation(countingSemaph, id); SemaphoreFactory::instance()->deleteSemaphore(countingSemaph); -#if defined(freeRTOS) +#if defined FSFW_OSAL_FREERTOS countingSemaph = SemaphoreFactory::instance()-> createCountingSemaphore(3, 0, 1); uint8_t semaphCount = countingSemaph->getSemaphoreCounter(); From 21b5eaa891c58f3e52de3acbf138c3ec128a1789 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 15 Sep 2021 17:09:42 +0200 Subject: [PATCH 2/3] Some changes and improvements for DHB 1. Renamed getCommanderId to getCommanderQueueId. 2. Some indentation 3. Correct preprocessor define for warning printout used now --- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 28 ++++++++++----- src/fsfw/devicehandlers/DeviceHandlerBase.h | 34 +++++++++---------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index c3fc023e..535113fd 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -461,7 +461,7 @@ size_t DeviceHandlerBase::getNextReplyLength(DeviceCommandId_t commandId){ return iter->second.replyLen; }else{ return 0; - } + } } ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceReply, @@ -612,15 +612,15 @@ void DeviceHandlerBase::replyToReply(const DeviceCommandId_t command, DeviceRepl } DeviceCommandInfo* info = &replyInfo.command->second; if (info == nullptr){ - printWarningOrError(sif::OutputTypes::OUT_ERROR, - "replyToReply", HasReturnvaluesIF::RETURN_FAILED, - "Command pointer not found"); - return; + printWarningOrError(sif::OutputTypes::OUT_ERROR, + "replyToReply", HasReturnvaluesIF::RETURN_FAILED, + "Command pointer not found"); + return; } if (info->expectedReplies > 0){ - // Check before to avoid underflow - info->expectedReplies--; + // Check before to avoid underflow + info->expectedReplies--; } // Check if more replies are expected. If so, do nothing. if (info->expectedReplies == 0) { @@ -1355,10 +1355,20 @@ void DeviceHandlerBase::buildInternalCommand(void) { DeviceCommandMap::iterator iter = deviceCommandMap.find( deviceCommandId); if (iter == deviceCommandMap.end()) { +#if FSFW_VERBOSE_LEVEL >= 1 + char output[36]; + sprintf(output, "Command 0x%08x unknown", + static_cast(deviceCommandId)); + // so we can track misconfigurations + printWarningOrError(sif::OutputTypes::OUT_WARNING, + "buildInternalCommand", + COMMAND_NOT_SUPPORTED, + output); +#endif result = COMMAND_NOT_SUPPORTED; } else if (iter->second.isExecuting) { -#if FSFW_DISABLE_PRINTOUT == 0 +#if FSFW_VERBOSE_LEVEL >= 1 char output[36]; sprintf(output, "Command 0x%08x is executing", static_cast(deviceCommandId)); @@ -1569,7 +1579,7 @@ LocalDataPoolManager* DeviceHandlerBase::getHkManagerHandle() { return &poolManager; } -MessageQueueId_t DeviceHandlerBase::getCommanderId(DeviceCommandId_t replyId) const { +MessageQueueId_t DeviceHandlerBase::getCommanderQueueId(DeviceCommandId_t replyId) const { auto commandIter = deviceCommandMap.find(replyId); if(commandIter == deviceCommandMap.end()) { return MessageQueueIF::NO_QUEUE; diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index 30d36ef0..b182b611 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -6,22 +6,22 @@ #include "DeviceHandlerFailureIsolation.h" #include "DeviceHandlerThermalSet.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../serviceinterface/serviceInterfaceDefintions.h" -#include "../objectmanager/SystemObject.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../action/HasActionsIF.h" -#include "../datapool/PoolVariableIF.h" -#include "../modes/HasModesIF.h" -#include "../power/PowerSwitchIF.h" -#include "../ipc/MessageQueueIF.h" -#include "../tasks/PeriodicTaskIF.h" -#include "../action/ActionHelper.h" -#include "../health/HealthHelper.h" -#include "../parameters/ParameterHelper.h" -#include "../datapoollocal/HasLocalDataPoolIF.h" -#include "../datapoollocal/LocalDataPoolManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/serviceinterface/serviceInterfaceDefintions.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/action/HasActionsIF.h" +#include "fsfw/datapool/PoolVariableIF.h" +#include "fsfw/modes/HasModesIF.h" +#include "fsfw/power/PowerSwitchIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/tasks/PeriodicTaskIF.h" +#include "fsfw/action/ActionHelper.h" +#include "fsfw/health/HealthHelper.h" +#include "fsfw/parameters/ParameterHelper.h" +#include "fsfw/datapoollocal/HasLocalDataPoolIF.h" +#include "fsfw/datapoollocal/LocalDataPoolManager.h" #include @@ -399,7 +399,7 @@ protected: */ virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) = 0; - MessageQueueId_t getCommanderId(DeviceCommandId_t replyId) const; + MessageQueueId_t getCommanderQueueId(DeviceCommandId_t replyId) const; /** * Helper function to get pending command. This is useful for devices * like SPI sensors to identify the last sent command. From e5db64cbb91bc72c63f0f3963bba9d89df9e1e6c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 15 Sep 2021 17:15:18 +0200 Subject: [PATCH 3/3] set transfer size to 0, better name --- hal/src/fsfw_hal/linux/spi/SpiComIF.cpp | 8 ++------ hal/src/fsfw_hal/linux/spi/SpiComIF.h | 1 + hal/src/fsfw_hal/linux/spi/SpiCookie.cpp | 2 +- hal/src/fsfw_hal/linux/spi/SpiCookie.h | 6 ++---- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/hal/src/fsfw_hal/linux/spi/SpiComIF.cpp b/hal/src/fsfw_hal/linux/spi/SpiComIF.cpp index 48bf7449..6cf6675f 100644 --- a/hal/src/fsfw_hal/linux/spi/SpiComIF.cpp +++ b/hal/src/fsfw_hal/linux/spi/SpiComIF.cpp @@ -15,11 +15,6 @@ #include #include -/* Can be used for low-level debugging of the SPI bus */ -#ifndef FSFW_HAL_LINUX_SPI_WIRETAPPING -#define FSFW_HAL_LINUX_SPI_WIRETAPPING 0 -#endif - SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF): SystemObject(objectId), gpioComIF(gpioComIF) { if(gpioComIF == nullptr) { @@ -193,7 +188,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const spiCookie->getSpiParameters(spiMode, spiSpeed, nullptr); setSpiSpeedAndMode(fileDescriptor, spiMode, spiSpeed); spiCookie->assignWriteBuffer(sendData); - spiCookie->assignTransferSize(sendLen); + spiCookie->setTransferSize(sendLen); bool fullDuplex = spiCookie->isFullDuplex(); gpioId_t gpioId = spiCookie->getChipSelectPin(); @@ -335,6 +330,7 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, *buffer = rxBuf; *size = spiCookie->getCurrentTransferSize(); + spiCookie->setTransferSize(0); return HasReturnvaluesIF::RETURN_OK; } diff --git a/hal/src/fsfw_hal/linux/spi/SpiComIF.h b/hal/src/fsfw_hal/linux/spi/SpiComIF.h index d43e2505..bcca7462 100644 --- a/hal/src/fsfw_hal/linux/spi/SpiComIF.h +++ b/hal/src/fsfw_hal/linux/spi/SpiComIF.h @@ -1,6 +1,7 @@ #ifndef LINUX_SPI_SPICOMIF_H_ #define LINUX_SPI_SPICOMIF_H_ +#include "fsfw/FSFW.h" #include "spiDefinitions.h" #include "returnvalues/classIds.h" #include "fsfw_hal/common/gpio/GpioIF.h" diff --git a/hal/src/fsfw_hal/linux/spi/SpiCookie.cpp b/hal/src/fsfw_hal/linux/spi/SpiCookie.cpp index 54d8aa16..f07954e9 100644 --- a/hal/src/fsfw_hal/linux/spi/SpiCookie.cpp +++ b/hal/src/fsfw_hal/linux/spi/SpiCookie.cpp @@ -121,7 +121,7 @@ bool SpiCookie::isFullDuplex() const { return not this->halfDuplex; } -void SpiCookie::assignTransferSize(size_t transferSize) { +void SpiCookie::setTransferSize(size_t transferSize) { spiTransferStruct.len = transferSize; } diff --git a/hal/src/fsfw_hal/linux/spi/SpiCookie.h b/hal/src/fsfw_hal/linux/spi/SpiCookie.h index acf7c77c..844fd421 100644 --- a/hal/src/fsfw_hal/linux/spi/SpiCookie.h +++ b/hal/src/fsfw_hal/linux/spi/SpiCookie.h @@ -103,10 +103,10 @@ public: void assignReadBuffer(uint8_t* rx); void assignWriteBuffer(const uint8_t* tx); /** - * Assign size for the next transfer. + * Set size for the next transfer. Set to 0 for no transfer * @param transferSize */ - void assignTransferSize(size_t transferSize); + void setTransferSize(size_t transferSize); size_t getCurrentTransferSize() const; struct UncommonParameters { @@ -158,8 +158,6 @@ private: std::string spiDev, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed, spi::send_callback_function_t callback, void* args); - size_t currentTransferSize = 0; - address_t spiAddress; gpioId_t chipSelectPin; std::string spiDevice;