WIP: Update DHB command and reply map helpers #103

Closed
muellerr wants to merge 7 commits from mueller/update-cmd-reply-maps-refactoring into develop
26 changed files with 208 additions and 89 deletions
Showing only changes of commit 0df27fdc71 - Show all commits

View File

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="fsfw-tests_coverage" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="fsfw-tests" TARGET_NAME="fsfw-tests_coverage" CONFIG_NAME="Debug Unittest" RUN_TARGET_PROJECT_NAME="fsfw-tests" RUN_TARGET_NAME="fsfw-tests">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>

View File

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="fsfw" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="fsfw-tests" TARGET_NAME="fsfw" CONFIG_NAME="Debug Unittest" RUN_TARGET_PROJECT_NAME="fsfw-tests" RUN_TARGET_NAME="fsfw-tests">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>

View File

@ -183,7 +183,10 @@ if(FSFW_BUILD_UNITTESTS)
endif() endif()
endif() endif()
message(STATUS "${MSG_PREFIX} Finding and/or providing ETL library") message(
STATUS
"${MSG_PREFIX} Finding and/or providing etl library with version ${FSFW_ETL_LIB_MAJOR_VERSION}"
)
# Check whether the user has already installed ETL first # Check whether the user has already installed ETL first
find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} QUIET) find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} QUIET)
@ -191,7 +194,7 @@ find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} QUIET)
if(NOT ${FSFW_ETL_LIB_NAME}_FOUND) if(NOT ${FSFW_ETL_LIB_NAME}_FOUND)
message( message(
STATUS STATUS
"No ETL installation was found with find_package. Installing and providing " "${MSG_PREFIX} No ETL installation was found with find_package. Installing and providing "
"etl with FindPackage") "etl with FindPackage")
include(FetchContent) include(FetchContent)

View File

@ -252,6 +252,7 @@ ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(localpool::DataPool &l
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Y, new PoolEntry<float>({0.0})); localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Y, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Z, new PoolEntry<float>({0.0})); localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Z, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(L3GD20H::TEMPERATURE, new PoolEntry<float>({0.0})); localDataPoolMap.emplace(L3GD20H::TEMPERATURE, new PoolEntry<float>({0.0}));
poolManager.subscribeForPeriodicPacket(dataset.getSid(), false, 10.0, false);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -475,6 +475,7 @@ ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &lo
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0})); localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0})); localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, new PoolEntry<float>({0.0})); localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, new PoolEntry<float>({0.0}));
poolManager.subscribeForPeriodicPacket(dataset.getSid(), false, 10.0, false);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -312,6 +312,7 @@ ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &loc
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry<float>({0.0})); localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0})); localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0})); localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
poolManager.subscribeForPeriodicPacket(primaryDataset.getSid(), false, 10.0, false);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -0,0 +1,43 @@
#pragma once
#include "fsfw/ipc/MutexIF.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw_hal/common/gpio/GpioIF.h"
class ManualCsLockWrapper : public HasReturnvaluesIF {
public:
ManualCsLockWrapper(MutexIF* lock, GpioIF* gpioIF, SpiCookie* cookie,
MutexIF::TimeoutType type = MutexIF::TimeoutType::BLOCKING,
uint32_t timeoutMs = 0)
: lock(lock), gpioIF(gpioIF), cookie(cookie), type(type), timeoutMs(timeoutMs) {
if (cookie == nullptr) {
// TODO: Error? Or maybe throw exception..
return;
}
cookie->setCsLockManual(true);
lockResult = lock->lockMutex(type, timeoutMs);
if (lockResult != RETURN_OK) {
return;
}
gpioResult = gpioIF->pullLow(cookie->getChipSelectPin());
}
~ManualCsLockWrapper() {
if (gpioResult == RETURN_OK) {
gpioIF->pullHigh(cookie->getChipSelectPin());
}
cookie->setCsLockManual(false);
if (lockResult == RETURN_OK) {
lock->unlockMutex();
}
}
ReturnValue_t lockResult;
ReturnValue_t gpioResult;
private:
MutexIF* lock;
GpioIF* gpioIF;
SpiCookie* cookie;
MutexIF::TimeoutType type;
uint32_t timeoutMs = 0;
};

View File

@ -194,16 +194,22 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
bool fullDuplex = spiCookie->isFullDuplex(); bool fullDuplex = spiCookie->isFullDuplex();
gpioId_t gpioId = spiCookie->getChipSelectPin(); gpioId_t gpioId = spiCookie->getChipSelectPin();
bool csLockManual = spiCookie->getCsLockManual();
/* Pull SPI CS low. For now, no support for active high given */ MutexIF::TimeoutType csType;
if (gpioId != gpio::NO_GPIO) { dur_millis_t csTimeout = 0;
result = csMutex->lockMutex(timeoutType, timeoutMs); // Pull SPI CS low. For now, no support for active high given
if (gpioId != gpio::NO_GPIO and not csLockManual) {
spiCookie->getMutexParams(csType, csTimeout);
result = csMutex->lockMutex(csType, csTimeout);
if (result != RETURN_OK) { if (result != RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl; sif::error << "SpiComIF::sendMessage: Failed to lock mutex with code "
<< "0x" << std::hex << std::setfill('0') << std::setw(4) << result << std::dec
<< std::endl;
#else #else
sif::printError("SpiComIF::sendMessage: Failed to lock mutex\n"); sif::printError("SpiComIF::sendMessage: Failed to lock mutex with code %d\n", result);
#endif #endif
#endif #endif
return result; return result;
@ -249,7 +255,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
} }
} }
if (gpioId != gpio::NO_GPIO) { if (gpioId != gpio::NO_GPIO and not csLockManual) {
gpioComIF->pullHigh(gpioId); gpioComIF->pullHigh(gpioId);
result = csMutex->unlockMutex(); result = csMutex->unlockMutex();
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -292,12 +298,22 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
return result; return result;
} }
bool csLockManual = spiCookie->getCsLockManual();
gpioId_t gpioId = spiCookie->getChipSelectPin(); gpioId_t gpioId = spiCookie->getChipSelectPin();
if (gpioId != gpio::NO_GPIO) { MutexIF::TimeoutType csType;
result = csMutex->lockMutex(timeoutType, timeoutMs); dur_millis_t csTimeout = 0;
if (gpioId != gpio::NO_GPIO and not csLockManual) {
spiCookie->getMutexParams(csType, csTimeout);
result = csMutex->lockMutex(csType, csTimeout);
if (result != RETURN_OK) { if (result != RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SpiComIF::getSendSuccess: Failed to lock mutex" << std::endl; sif::error << "SpiComIF::sendMessage: Failed to lock mutex with code "
<< "0x" << std::hex << std::setfill('0') << std::setw(4) << result << std::dec
<< std::endl;
#else
sif::printError("SpiComIF::sendMessage: Failed to lock mutex with code %d\n", result);
#endif
#endif #endif
return result; return result;
} }
@ -315,7 +331,7 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
result = HALF_DUPLEX_TRANSFER_FAILED; result = HALF_DUPLEX_TRANSFER_FAILED;
} }
if (gpioId != gpio::NO_GPIO) { if (gpioId != gpio::NO_GPIO and not csLockManual) {
gpioComIF->pullHigh(gpioId); gpioComIF->pullHigh(gpioId);
result = csMutex->unlockMutex(); result = csMutex->unlockMutex();
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -346,15 +362,7 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
MutexIF* SpiComIF::getMutex(MutexIF::TimeoutType* timeoutType, uint32_t* timeoutMs) { MutexIF* SpiComIF::getCsMutex() { return csMutex; }
if (timeoutType != nullptr) {
*timeoutType = this->timeoutType;
}
if (timeoutMs != nullptr) {
*timeoutMs = this->timeoutMs;
}
return csMutex;
}
void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) { void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) {
if (spiCookie == nullptr) { if (spiCookie == nullptr) {

View File

@ -22,15 +22,15 @@ class SpiCookie;
*/ */
class SpiComIF : public DeviceCommunicationIF, public SystemObject { class SpiComIF : public DeviceCommunicationIF, public SystemObject {
public: public:
static constexpr uint8_t spiRetvalId = CLASS_ID::HAL_SPI; static constexpr uint8_t CLASS_ID = CLASS_ID::HAL_SPI;
static constexpr ReturnValue_t OPENING_FILE_FAILED = static constexpr ReturnValue_t OPENING_FILE_FAILED =
HasReturnvaluesIF::makeReturnCode(spiRetvalId, 0); HasReturnvaluesIF::makeReturnCode(CLASS_ID, 0);
/* Full duplex (ioctl) transfer failure */ /* Full duplex (ioctl) transfer failure */
static constexpr ReturnValue_t FULL_DUPLEX_TRANSFER_FAILED = static constexpr ReturnValue_t FULL_DUPLEX_TRANSFER_FAILED =
HasReturnvaluesIF::makeReturnCode(spiRetvalId, 1); HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
/* Half duplex (read/write) transfer failure */ /* Half duplex (read/write) transfer failure */
static constexpr ReturnValue_t HALF_DUPLEX_TRANSFER_FAILED = static constexpr ReturnValue_t HALF_DUPLEX_TRANSFER_FAILED =
HasReturnvaluesIF::makeReturnCode(spiRetvalId, 2); HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
SpiComIF(object_id_t objectId, std::string devname, GpioIF* gpioComIF); SpiComIF(object_id_t objectId, std::string devname, GpioIF* gpioComIF);
@ -44,7 +44,8 @@ class SpiComIF : public DeviceCommunicationIF, public SystemObject {
* @brief This function returns the mutex which can be used to protect the spi bus when * @brief This function returns the mutex which can be used to protect the spi bus when
* the chip select must be driven from outside of the com if. * the chip select must be driven from outside of the com if.
*/ */
MutexIF* getMutex(MutexIF::TimeoutType* timeoutType = nullptr, uint32_t* timeoutMs = nullptr); MutexIF* getCsMutex();
void setMutexParams(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs);
/** /**
* Perform a regular send operation using Linux iotcl. This is public so it can be used * Perform a regular send operation using Linux iotcl. This is public so it can be used
@ -59,6 +60,7 @@ class SpiComIF : public DeviceCommunicationIF, public SystemObject {
GpioIF* getGpioInterface(); GpioIF* getGpioInterface();
void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed); void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed);
void getSpiSpeedAndMode(int spiFd, spi::SpiModes& mode, uint32_t& speed) const;
/** /**
* This updates the SPI clock default polarity. Only setting the mode does not update * This updates the SPI clock default polarity. Only setting the mode does not update
@ -70,7 +72,6 @@ class SpiComIF : public DeviceCommunicationIF, public SystemObject {
* @param spiFd * @param spiFd
*/ */
void updateLinePolarity(int spiFd); void updateLinePolarity(int spiFd);
void getSpiSpeedAndMode(int spiFd, spi::SpiModes& mode, uint32_t& speed) const;
const std::string& getSpiDev() const; const std::string& getSpiDev() const;
void performSpiWiretapping(SpiCookie* spiCookie); void performSpiWiretapping(SpiCookie* spiCookie);
@ -90,8 +91,8 @@ class SpiComIF : public DeviceCommunicationIF, public SystemObject {
* pulled high * pulled high
*/ */
MutexIF* csMutex = nullptr; MutexIF* csMutex = nullptr;
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; // MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
uint32_t timeoutMs = 20; // uint32_t timeoutMs = DEFAULT_MUTEX_TIMEOUT;
spi_ioc_transfer clockUpdateTransfer = {}; spi_ioc_transfer clockUpdateTransfer = {};
using SpiDeviceMap = std::unordered_map<address_t, SpiInstance>; using SpiDeviceMap = std::unordered_map<address_t, SpiInstance>;

View File

@ -104,3 +104,17 @@ void SpiCookie::getCallback(spi::send_callback_function_t* callback, void** args
*callback = this->sendCallback; *callback = this->sendCallback;
*args = this->callbackArgs; *args = this->callbackArgs;
} }
void SpiCookie::setCsLockManual(bool enable) { manualCsLock = enable; }
bool SpiCookie::getCsLockManual() const { return manualCsLock; }
void SpiCookie::getMutexParams(MutexIF::TimeoutType& csTimeoutType, dur_millis_t& csTimeout) const {
csTimeoutType = this->csTimeoutType;
csTimeout = this->csTimeout;
}
void SpiCookie::setMutexParams(MutexIF::TimeoutType csTimeoutType, dur_millis_t csTimeout) {
this->csTimeoutType = csTimeoutType;
this->csTimeout = csTimeout;
}

View File

@ -2,6 +2,8 @@
#define LINUX_SPI_SPICOOKIE_H_ #define LINUX_SPI_SPICOOKIE_H_
#include <fsfw/devicehandlers/CookieIF.h> #include <fsfw/devicehandlers/CookieIF.h>
#include <fsfw/ipc/MutexIF.h>
#include <fsfw/timemanager/clockDefinitions.h>
#include <linux/spi/spidev.h> #include <linux/spi/spidev.h>
#include "../../common/gpio/gpioDefinitions.h" #include "../../common/gpio/gpioDefinitions.h"
@ -20,6 +22,8 @@
*/ */
class SpiCookie : public CookieIF { class SpiCookie : public CookieIF {
public: public:
static constexpr dur_millis_t DEFAULT_MUTEX_TIMEOUT = 20;
/** /**
* Each SPI device will have a corresponding cookie. The cookie is used by the communication * Each SPI device will have a corresponding cookie. The cookie is used by the communication
* interface and contains device specific information like the largest expected size to be * interface and contains device specific information like the largest expected size to be
@ -137,9 +141,42 @@ class SpiCookie : public CookieIF {
*/ */
void activateCsDeselect(bool deselectCs, uint16_t delayUsecs); void activateCsDeselect(bool deselectCs, uint16_t delayUsecs);
void getMutexParams(MutexIF::TimeoutType& csTimeoutType, dur_millis_t& csTimeout) const;
void setMutexParams(MutexIF::TimeoutType csTimeoutType, dur_millis_t csTimeout);
void setCsLockManual(bool enable);
bool getCsLockManual() const;
spi_ioc_transfer* getTransferStructHandle(); spi_ioc_transfer* getTransferStructHandle();
private: private:
address_t spiAddress;
gpioId_t chipSelectPin;
spi::SpiComIfModes comIfMode;
// Required for regular mode
const size_t maxSize;
spi::SpiModes spiMode;
/**
* If this is set to true, the SPI ComIF will not perform any mutex locking for the
* CS mechanism. The user is responsible to locking and unlocking the mutex for the
* whole duration of the transfers.
*/
bool manualCsLock = false;
uint32_t spiSpeed;
bool halfDuplex = false;
MutexIF::TimeoutType csTimeoutType = MutexIF::TimeoutType::WAITING;
dur_millis_t csTimeout = DEFAULT_MUTEX_TIMEOUT;
// Required for callback mode
spi::send_callback_function_t sendCallback = nullptr;
void* callbackArgs = nullptr;
struct spi_ioc_transfer spiTransferStruct = {};
UncommonParameters uncommonParameters;
/** /**
* Internal constructor which initializes every field * Internal constructor which initializes every field
* @param spiAddress * @param spiAddress
@ -154,24 +191,6 @@ class SpiCookie : public CookieIF {
SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect, SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect,
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
spi::send_callback_function_t callback, void* args); spi::send_callback_function_t callback, void* args);
address_t spiAddress;
gpioId_t chipSelectPin;
spi::SpiComIfModes comIfMode;
// Required for regular mode
const size_t maxSize;
spi::SpiModes spiMode;
uint32_t spiSpeed;
bool halfDuplex = false;
// Required for callback mode
spi::send_callback_function_t sendCallback = nullptr;
void* callbackArgs = nullptr;
struct spi_ioc_transfer spiTransferStruct = {};
UncommonParameters uncommonParameters;
}; };
#endif /* LINUX_SPI_SPICOOKIE_H_ */ #endif /* LINUX_SPI_SPICOOKIE_H_ */

View File

@ -3,6 +3,12 @@ if [[ ! -f README.md ]]; then
cd .. cd ..
fi fi
folder_list=(
"./src"
"./hal"
"./tests"
)
cmake_fmt="cmake-format" cmake_fmt="cmake-format"
file_selectors="-iname CMakeLists.txt" file_selectors="-iname CMakeLists.txt"
if command -v ${cmake_fmt} &> /dev/null; then if command -v ${cmake_fmt} &> /dev/null; then
@ -15,9 +21,10 @@ fi
cpp_format="clang-format" cpp_format="clang-format"
file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp" file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp"
if command -v ${cpp_format} &> /dev/null; then if command -v ${cpp_format} &> /dev/null; then
find ./src ${file_selectors} | xargs ${cpp_format} --style=file -i for dir in ${folder_list[@]}; do
find ./hal ${file_selectors} | xargs ${cpp_format} --style=file -i echo "Auto-formatting ${dir} recursively"
find ./tests ${file_selectors} | xargs ${cpp_format} --style=file -i find ${dir} ${file_selectors} | xargs clang-format --style=file -i
done
else else
echo "No ${cpp_format} tool found, not formatting C++/C files" echo "No ${cpp_format} tool found, not formatting C++/C files"
fi fi

View File

@ -577,6 +577,10 @@ ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(CommandMessage* me
CommandMessage reply; CommandMessage reply;
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
if (result == WRONG_HK_PACKET_TYPE) {
printWarningOrError(sif::OutputTypes::OUT_WARNING, "handleHousekeepingMessage",
WRONG_HK_PACKET_TYPE);
}
HousekeepingMessage::setHkRequestFailureReply(&reply, sid, result); HousekeepingMessage::setHkRequestFailureReply(&reply, sid, result);
} else { } else {
HousekeepingMessage::setHkRequestSuccessReply(&reply, sid); HousekeepingMessage::setHkRequestSuccessReply(&reply, sid);
@ -834,6 +838,8 @@ void LocalDataPoolManager::printWarningOrError(sif::OutputTypes outputType,
errorPrint = "Dataset not found"; errorPrint = "Dataset not found";
} else if (error == POOLOBJECT_NOT_FOUND) { } else if (error == POOLOBJECT_NOT_FOUND) {
errorPrint = "Pool Object not found"; errorPrint = "Pool Object not found";
} else if (error == WRONG_HK_PACKET_TYPE) {
errorPrint = "Wrong Packet Type";
} else if (error == HasReturnvaluesIF::RETURN_FAILED) { } else if (error == HasReturnvaluesIF::RETURN_FAILED) {
if (outputType == sif::OutputTypes::OUT_WARNING) { if (outputType == sif::OutputTypes::OUT_WARNING) {
errorPrint = "Generic Warning"; errorPrint = "Generic Warning";

View File

@ -572,6 +572,9 @@ void DeviceHandlerBase::setMode(Mode_t newMode, uint8_t newSubmode) {
mode = newMode; mode = newMode;
modeChanged(); modeChanged();
setNormalDatapoolEntriesInvalid(); setNormalDatapoolEntriesInvalid();
if (newMode == MODE_OFF) {
disableCommandsAndReplies();
}
if (!isTransitionalMode()) { if (!isTransitionalMode()) {
modeHelper.modeChanged(newMode, newSubmode); modeHelper.modeChanged(newMode, newSubmode);
announceMode(false); announceMode(false);
@ -1567,3 +1570,21 @@ void DeviceHandlerBase::setParent(object_id_t parent) { this->parent = parent; }
void DeviceHandlerBase::setPowerSwitcher(PowerSwitchIF* switcher) { void DeviceHandlerBase::setPowerSwitcher(PowerSwitchIF* switcher) {
this->powerSwitcher = switcher; this->powerSwitcher = switcher;
} }
void DeviceHandlerBase::disableCommandsAndReplies() {
for (auto& command : deviceCommandMap) {
if (command.second.isExecuting) {
command.second.isExecuting = false;
}
}
for (auto& reply : deviceReplyMap) {
if (!reply.second.periodic) {
if (reply.second.countdown != nullptr) {
reply.second.countdown->timeOut();
} else {
reply.second.delayCycles = 0;
}
reply.second.active = false;
}
}
}

View File

@ -1326,6 +1326,11 @@ class DeviceHandlerBase : public DeviceHandlerIF,
void printWarningOrError(sif::OutputTypes errorType, const char *functionName, void printWarningOrError(sif::OutputTypes errorType, const char *functionName,
ReturnValue_t errorCode = HasReturnvaluesIF::RETURN_FAILED, ReturnValue_t errorCode = HasReturnvaluesIF::RETURN_FAILED,
const char *errorPrint = nullptr); const char *errorPrint = nullptr);
/**
* @brief Disables all commands and replies when device is set to MODE_OFF
*/
void disableCommandsAndReplies();
}; };
#endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ */ #endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ */

View File

@ -1,6 +1,5 @@
#include "DleParser.h" #include "DleParser.h"
#include <fsfw/globalfunctions/DleEncoder.h>
#include <fsfw/serviceinterface/ServiceInterface.h> #include <fsfw/serviceinterface/ServiceInterface.h>
#include <cstdio> #include <cstdio>

View File

@ -1,5 +1,4 @@
#ifndef MISSION_DEVICES_DLEPARSER_H_ #pragma once
#define MISSION_DEVICES_DLEPARSER_H_
#include <fsfw/container/SimpleRingBuffer.h> #include <fsfw/container/SimpleRingBuffer.h>
#include <fsfw/globalfunctions/DleEncoder.h> #include <fsfw/globalfunctions/DleEncoder.h>
@ -123,5 +122,3 @@ class DleParser : public HasReturnvaluesIF {
Context ctx; Context ctx;
bool startFound = false; bool startFound = false;
}; };
#endif /* MISSION_DEVICES_DLEPARSER_H_ */

View File

@ -34,7 +34,7 @@ class CommandMessageIF {
static const Command_t CMD_NONE = MAKE_COMMAND_ID(0); static const Command_t CMD_NONE = MAKE_COMMAND_ID(0);
static const Command_t REPLY_COMMAND_OK = MAKE_COMMAND_ID(1); static const Command_t REPLY_COMMAND_OK = MAKE_COMMAND_ID(1);
//! Reply indicating that the current command was rejected, //! Reply indicating that the current command was rejected,
//! par1 should contain the error code //! Parameter 1 should contain the error code
static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID(2); static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID(2);
virtual ~CommandMessageIF(){}; virtual ~CommandMessageIF(){};

View File

@ -16,7 +16,9 @@ elseif(FSFW_OSAL MATCHES "host")
else() else()
message(WARNING "The OS_FSFW variable was not set. Assuming host OS..") message(
WARNING
"${MSG_PREFIX} The FSFW_OSAL variable was not set. Assuming host OS..")
# Not set. Assumuing this is a host build, try to determine host OS # Not set. Assumuing this is a host build, try to determine host OS
if(WIN32) if(WIN32)
add_subdirectory(host) add_subdirectory(host)

View File

@ -15,9 +15,7 @@ PowerSensor::PowerSensor(object_id_t objectId, sid_t setId, VariableIds ids, Def
limits.currentMin, limits.currentMax, events.currentLow, events.currentHigh), limits.currentMin, limits.currentMax, events.currentLow, events.currentHigh),
voltageLimit(objectId, MODULE_ID_VOLTAGE, ids.pidVoltage, confirmationCount, voltageLimit(objectId, MODULE_ID_VOLTAGE, ids.pidVoltage, confirmationCount,
limits.voltageMin, limits.voltageMax, events.voltageLow, events.voltageHigh) { limits.voltageMin, limits.voltageMax, events.voltageLow, events.voltageHigh) {
auto mqArgs = MqArgs(objectId, static_cast<void*>(this)); commandQueue = QueueFactory::instance()->createMessageQueue();
commandQueue = QueueFactory::instance()->createMessageQueue(
3, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
} }
PowerSensor::~PowerSensor() { QueueFactory::instance()->deleteMessageQueue(commandQueue); } PowerSensor::~PowerSensor() { QueueFactory::instance()->deleteMessageQueue(commandQueue); }

View File

@ -29,9 +29,9 @@ class PowerSwitchIF : public HasReturnvaluesIF {
static const ReturnValue_t FUSE_ON = MAKE_RETURN_CODE(3); static const ReturnValue_t FUSE_ON = MAKE_RETURN_CODE(3);
static const ReturnValue_t FUSE_OFF = MAKE_RETURN_CODE(4); static const ReturnValue_t FUSE_OFF = MAKE_RETURN_CODE(4);
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PCDU_2; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PCDU_2;
static const Event SWITCH_WENT_OFF = MAKE_EVENT( //!< Someone detected that a switch went off which shouldn't. Severity:
0, severity::LOW); //!< Someone detected that a switch went off which shouldn't. Severity: //!< Low, Parameter1: switchId1, Parameter2: switchId2
//!< Low, Parameter1: switchId1, Parameter2: switchId2 static const Event SWITCH_WENT_OFF = MAKE_EVENT(0, severity::LOW);
/** /**
* send a direct command to the Power Unit to enable/disable the specified switch. * send a direct command to the Power Unit to enable/disable the specified switch.
* *

View File

@ -78,7 +78,7 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::performService
// NOTE: The iterator is increased in the loop here. Increasing the iterator as for-loop arg // NOTE: The iterator is increased in the loop here. Increasing the iterator as for-loop arg
// does not work in this case as we are deleting the current element here. // does not work in this case as we are deleting the current element here.
for (auto it = telecommandMap.begin(); it != telecommandMap.end();) { for (auto it = telecommandMap.begin(); it != telecommandMap.end();) {
if (it->first <= tNow.tv_sec) { if (it->first <= static_cast<uint32_t>(tNow.tv_sec)) {
if (schedulingEnabled) { if (schedulingEnabled) {
// release tc // release tc
TmTcMessage releaseMsg(it->second.storeAddr); TmTcMessage releaseMsg(it->second.storeAddr);

View File

@ -208,7 +208,7 @@ ReturnValue_t Service3Housekeeping::handleReply(const CommandMessage* reply,
ReturnValue_t error = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t error = HasReturnvaluesIF::RETURN_FAILED;
HousekeepingMessage::getHkRequestFailureReply(reply, &error); HousekeepingMessage::getHkRequestFailureReply(reply, &error);
failureParameter2 = error; failureParameter2 = error;
return CommandingServiceBase::EXECUTION_COMPLETE; return RETURN_FAILED;
} }
default: default:
@ -248,19 +248,25 @@ void Service3Housekeeping::handleUnrequestedReply(CommandMessage* reply) {
case (HousekeepingMessage::HK_REQUEST_FAILURE): { case (HousekeepingMessage::HK_REQUEST_FAILURE): {
break; break;
} }
case (CommandMessage::REPLY_REJECTED): {
sif::warning << "Service3Housekeeping::handleUnrequestedReply: Unexpected reply "
"rejected with error code"
<< reply->getParameter() << std::endl;
break;
}
default: { default: {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Service3Housekeeping::handleUnrequestedReply: Invalid reply with reply " sif::warning << "Service3Housekeeping::handleUnrequestedReply: Invalid reply with reply "
"command " "command "
<< command << "!" << std::endl; << command << "" << std::endl;
#else #else
sif::printWarning( sif::printWarning(
"Service3Housekeeping::handleUnrequestedReply: Invalid reply with " "Service3Housekeeping::handleUnrequestedReply: Invalid reply with "
"reply command %hu!\n", "reply command %hu\n",
command); command);
#endif #endif
return; break;
} }
} }
@ -275,6 +281,7 @@ void Service3Housekeeping::handleUnrequestedReply(CommandMessage* reply) {
"Could not generate reply!\n"); "Could not generate reply!\n");
#endif #endif
} }
CommandingServiceBase::handleUnrequestedReply(reply);
} }
MessageQueueId_t Service3Housekeeping::getHkQueue() const { return commandQueue->getId(); } MessageQueueId_t Service3Housekeeping::getHkQueue() const { return commandQueue->getId(); }

View File

@ -13,9 +13,9 @@ class ThermalComponentIF : public HasParametersIF {
static const Event COMPONENT_TEMP_HIGH = MAKE_EVENT(2, severity::LOW); static const Event COMPONENT_TEMP_HIGH = MAKE_EVENT(2, severity::LOW);
static const Event COMPONENT_TEMP_OOL_LOW = MAKE_EVENT(3, severity::LOW); static const Event COMPONENT_TEMP_OOL_LOW = MAKE_EVENT(3, severity::LOW);
static const Event COMPONENT_TEMP_OOL_HIGH = MAKE_EVENT(4, severity::LOW); static const Event COMPONENT_TEMP_OOL_HIGH = MAKE_EVENT(4, severity::LOW);
static const Event TEMP_NOT_IN_OP_RANGE = MAKE_EVENT( //!< Is thrown when a device should start-up, but the temperature is out
5, severity::LOW); //!< Is thrown when a device should start-up, but the temperature is out //!< of OP range. P1: thermalState of the component, P2: 0
//!< of OP range. P1: thermalState of the component, P2: 0 static const Event TEMP_NOT_IN_OP_RANGE = MAKE_EVENT(5, severity::LOW);
static const uint8_t INTERFACE_ID = CLASS_ID::THERMAL_COMPONENT_IF; static const uint8_t INTERFACE_ID = CLASS_ID::THERMAL_COMPONENT_IF;
static const ReturnValue_t INVALID_TARGET_STATE = MAKE_RETURN_CODE(1); static const ReturnValue_t INVALID_TARGET_STATE = MAKE_RETURN_CODE(1);

View File

@ -36,7 +36,7 @@ ReturnValue_t TmTcBridge::setNumberOfSentPacketsPerCycle(uint8_t sentPacketsPerC
} }
} }
ReturnValue_t TmTcBridge::setMaxNumberOfPacketsStored(uint8_t maxNumberOfPacketsStored) { ReturnValue_t TmTcBridge::setMaxNumberOfPacketsStored(unsigned int maxNumberOfPacketsStored) {
if (maxNumberOfPacketsStored <= LIMIT_DOWNLINK_PACKETS_STORED) { if (maxNumberOfPacketsStored <= LIMIT_DOWNLINK_PACKETS_STORED) {
this->maxNumberOfPacketsStored = maxNumberOfPacketsStored; this->maxNumberOfPacketsStored = maxNumberOfPacketsStored;
return RETURN_OK; return RETURN_OK;

View File

@ -18,7 +18,7 @@ class TmTcBridge : public AcceptsTelemetryIF,
public: public:
static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20; static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20;
static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15; static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15;
static constexpr uint8_t LIMIT_DOWNLINK_PACKETS_STORED = 200; static constexpr unsigned int LIMIT_DOWNLINK_PACKETS_STORED = 1000;
static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5; static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5;
static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10; static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10;
@ -43,7 +43,7 @@ class TmTcBridge : public AcceptsTelemetryIF,
* @return -@c RETURN_OK if value was set successfully * @return -@c RETURN_OK if value was set successfully
* -@c RETURN_FAILED otherwise, stored value stays the same * -@c RETURN_FAILED otherwise, stored value stays the same
*/ */
ReturnValue_t setMaxNumberOfPacketsStored(uint8_t maxNumberOfPacketsStored); ReturnValue_t setMaxNumberOfPacketsStored(unsigned int maxNumberOfPacketsStored);
/** /**
* This will set up the bridge to overwrite old data in the FIFO. * This will set up the bridge to overwrite old data in the FIFO.
@ -152,7 +152,7 @@ class TmTcBridge : public AcceptsTelemetryIF,
*/ */
DynamicFIFO<store_address_t>* tmFifo = nullptr; DynamicFIFO<store_address_t>* tmFifo = nullptr;
uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE; uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE;
uint8_t maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED; unsigned int maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED;
}; };
#endif /* FSFW_TMTCSERVICES_TMTCBRIDGE_H_ */ #endif /* FSFW_TMTCSERVICES_TMTCBRIDGE_H_ */