From aebd4817b8318cde3412314cc839a6d805eda578 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Feb 2022 11:33:41 +0100 Subject: [PATCH 1/9] periodic printouts are runtime configurable now --- .../devicehandlers/GyroL3GD20Handler.cpp | 35 +++++++------ .../devicehandlers/GyroL3GD20Handler.h | 8 +-- .../devicehandlers/MgmLIS3MDLHandler.cpp | 52 +++++++++++-------- .../devicehandlers/MgmLIS3MDLHandler.h | 8 +-- .../devicehandlers/MgmRM3100Handler.cpp | 37 ++++++------- .../devicehandlers/MgmRM3100Handler.h | 11 ++-- src/fsfw/FSFW.h.in | 12 ----- 7 files changed, 78 insertions(+), 85 deletions(-) diff --git a/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp b/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp index be4c9aa97..94e1331c6 100644 --- a/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp +++ b/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp @@ -8,11 +8,7 @@ GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceC CookieIF *comCookie, uint32_t transitionDelayMs) : DeviceHandlerBase(objectId, deviceCommunication, comCookie), transitionDelayMs(transitionDelayMs), - dataset(this) { -#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1 - debugDivider = new PeriodicOperationDivider(3); -#endif -} + dataset(this) {} GyroHandlerL3GD20H::~GyroHandlerL3GD20H() {} @@ -193,22 +189,22 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id, int8_t temperaturOffset = (-1) * packet[L3GD20H::TEMPERATURE_IDX]; float temperature = 25.0 + temperaturOffset; -#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1 - if (debugDivider->checkAndIncrement()) { - /* Set terminal to utf-8 if there is an issue with micro printout. */ + if (periodicPrintout) { + if (debugDivider.checkAndIncrement()) { + /* Set terminal to utf-8 if there is an issue with micro printout. */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "GyroHandlerL3GD20H: Angular velocities (deg/s):" << std::endl; - sif::info << "X: " << angVelocX << std::endl; - sif::info << "Y: " << angVelocY << std::endl; - sif::info << "Z: " << angVelocZ << std::endl; + sif::info << "GyroHandlerL3GD20H: Angular velocities (deg/s):" << std::endl; + sif::info << "X: " << angVelocX << std::endl; + sif::info << "Y: " << angVelocY << std::endl; + sif::info << "Z: " << angVelocZ << std::endl; #else - sif::printInfo("GyroHandlerL3GD20H: Angular velocities (deg/s):\n"); - sif::printInfo("X: %f\n", angVelocX); - sif::printInfo("Y: %f\n", angVelocY); - sif::printInfo("Z: %f\n", angVelocZ); + sif::printInfo("GyroHandlerL3GD20H: Angular velocities (deg/s):\n"); + sif::printInfo("X: %f\n", angVelocX); + sif::printInfo("Y: %f\n", angVelocY); + sif::printInfo("Z: %f\n", angVelocZ); #endif + } } -#endif PoolReadGuard readSet(&dataset); if (readSet.getReadResult() == HasReturnvaluesIF::RETURN_OK) { @@ -272,3 +268,8 @@ void GyroHandlerL3GD20H::setAbsoluteLimits(float limitX, float limitY, float lim this->absLimitY = limitY; this->absLimitZ = limitZ; } + +void GyroHandlerL3GD20H::enablePeriodicPrintouts(bool enable, uint8_t divider) { + periodicPrintout = enable; + debugDivider.setDivider(divider); +} diff --git a/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.h b/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.h index 784dcf4cd..7c1ebdac1 100644 --- a/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.h +++ b/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.h @@ -5,7 +5,6 @@ #include #include "devicedefinitions/GyroL3GD20Definitions.h" -#include "fsfw/FSFW.h" /** * @brief Device Handler for the L3GD20H gyroscope sensor @@ -22,6 +21,8 @@ class GyroHandlerL3GD20H : public DeviceHandlerBase { uint32_t transitionDelayMs); virtual ~GyroHandlerL3GD20H(); + void enablePeriodicPrintouts(bool enable, uint8_t divider); + /** * Set the absolute limit for the values on the axis in degrees per second. * The dataset values will be marked as invalid if that limit is exceeded @@ -80,9 +81,8 @@ class GyroHandlerL3GD20H : public DeviceHandlerBase { // Set default value float sensitivity = L3GD20H::SENSITIVITY_00; -#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1 - PeriodicOperationDivider *debugDivider = nullptr; -#endif + bool periodicPrintout = false; + PeriodicOperationDivider debugDivider = PeriodicOperationDivider(3); }; #endif /* MISSION_DEVICES_GYROL3GD20HANDLER_H_ */ diff --git a/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp index f3ea99428..69f6311e3 100644 --- a/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp +++ b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp @@ -12,9 +12,6 @@ MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCom : DeviceHandlerBase(objectId, deviceCommunication, comCookie), dataset(this), transitionDelay(transitionDelay) { -#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 - debugDivider = new PeriodicOperationDivider(3); -#endif // Set to default values right away registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; @@ -264,7 +261,7 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, cons int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::Z_LOWBYTE_IDX]; - /* Target value in microtesla */ + // Target value in microtesla float mgmX = static_cast(mgmMeasurementRawX) * sensitivityFactor * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; float mgmY = static_cast(mgmMeasurementRawY) * sensitivityFactor * @@ -272,23 +269,24 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, cons float mgmZ = static_cast(mgmMeasurementRawZ) * sensitivityFactor * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; -#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 - if (debugDivider->checkAndIncrement()) { + if (periodicPrintout) { + if (debugDivider.checkAndIncrement()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "MGMHandlerLIS3: Magnetic field strength in" - " microtesla:" - << std::endl; - sif::info << "X: " << mgmX << " uT" << std::endl; - sif::info << "Y: " << mgmY << " uT" << std::endl; - sif::info << "Z: " << mgmZ << " uT" << std::endl; + sif::info << "MGMHandlerLIS3: Magnetic field strength in" + " microtesla:" + << std::endl; + sif::info << "X: " << mgmX << " uT" << std::endl; + sif::info << "Y: " << mgmY << " uT" << std::endl; + sif::info << "Z: " << mgmZ << " uT" << std::endl; #else - sif::printInfo("MGMHandlerLIS3: Magnetic field strength in microtesla:\n"); - sif::printInfo("X: %f uT\n", mgmX); - sif::printInfo("Y: %f uT\n", mgmY); - sif::printInfo("Z: %f uT\n", mgmZ); + sif::printInfo("MGMHandlerLIS3: Magnetic field strength in microtesla:\n"); + sif::printInfo("X: %f uT\n", mgmX); + sif::printInfo("Y: %f uT\n", mgmY); + sif::printInfo("Z: %f uT\n", mgmZ); #endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */ + } } -#endif /* OBSW_VERBOSE_LEVEL >= 1 */ + PoolReadGuard readHelper(&dataset); if (readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) { if (std::abs(mgmX) < absLimitX) { @@ -318,15 +316,16 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, cons case MGMLIS3MDL::READ_TEMPERATURE: { int16_t tempValueRaw = packet[2] << 8 | packet[1]; float tempValue = 25.0 + ((static_cast(tempValueRaw)) / 8.0); -#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 - if (debugDivider->check()) { + if (periodicPrintout) { + if (debugDivider.check()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" << std::endl; + sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" << std::endl; #else - sif::printInfo("MGMHandlerLIS3: Temperature: %f C\n"); + sif::printInfo("MGMHandlerLIS3: Temperature: %f C\n"); #endif + } } -#endif + ReturnValue_t result = dataset.read(); if (result == HasReturnvaluesIF::RETURN_OK) { dataset.temperature = tempValue; @@ -462,7 +461,9 @@ ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() { return RETURN_OK; } -void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {} +void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { + DeviceHandlerBase::doTransition(modeFrom, subModeFrom); +} uint32_t MgmLIS3MDLHandler::getTransitionDelayMs(Mode_t from, Mode_t to) { return transitionDelay; } @@ -482,3 +483,8 @@ void MgmLIS3MDLHandler::setAbsoluteLimits(float xLimit, float yLimit, float zLim this->absLimitY = yLimit; this->absLimitZ = zLimit; } + +void MgmLIS3MDLHandler::enablePeriodicPrintouts(bool enable, uint8_t divider) { + periodicPrintout = enable; + debugDivider.setDivider(divider); +} diff --git a/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h index b7cfc3783..42bd5d4ce 100644 --- a/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h +++ b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h @@ -3,8 +3,8 @@ #include "devicedefinitions/MgmLIS3HandlerDefs.h" #include "events/subsystemIdRanges.h" -#include "fsfw/FSFW.h" #include "fsfw/devicehandlers/DeviceHandlerBase.h" +#include "fsfw/globalfunctions/PeriodicOperationDivider.h" class PeriodicOperationDivider; @@ -30,6 +30,7 @@ class MgmLIS3MDLHandler : public DeviceHandlerBase { uint32_t transitionDelay); virtual ~MgmLIS3MDLHandler(); + void enablePeriodicPrintouts(bool enable, uint8_t divider); /** * Set the absolute limit for the values on the axis in microtesla. The dataset values will * be marked as invalid if that limit is exceeded @@ -167,9 +168,8 @@ class MgmLIS3MDLHandler : public DeviceHandlerBase { */ ReturnValue_t prepareCtrlRegisterWrite(); -#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 - PeriodicOperationDivider *debugDivider; -#endif + bool periodicPrintout = false; + PeriodicOperationDivider debugDivider = PeriodicOperationDivider(3); }; #endif /* MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ */ diff --git a/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp b/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp index 4c6e09b12..f9929d638 100644 --- a/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp +++ b/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp @@ -10,11 +10,7 @@ MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommu CookieIF *comCookie, uint32_t transitionDelay) : DeviceHandlerBase(objectId, deviceCommunication, comCookie), primaryDataset(this), - transitionDelay(transitionDelay) { -#if FSFW_HAL_RM3100_MGM_DEBUG == 1 - debugDivider = new PeriodicOperationDivider(3); -#endif -} + transitionDelay(transitionDelay) {} MgmRM3100Handler::~MgmRM3100Handler() {} @@ -337,23 +333,23 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) { float fieldStrengthY = fieldStrengthRawY * scaleFactorX; float fieldStrengthZ = fieldStrengthRawZ * scaleFactorX; -#if FSFW_HAL_RM3100_MGM_DEBUG == 1 - if (debugDivider->checkAndIncrement()) { + if (periodicPrintout) { + if (debugDivider.checkAndIncrement()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "MgmRM3100Handler: Magnetic field strength in" - " microtesla:" - << std::endl; - sif::info << "X: " << fieldStrengthX << " uT" << std::endl; - sif::info << "Y: " << fieldStrengthY << " uT" << std::endl; - sif::info << "Z: " << fieldStrengthZ << " uT" << std::endl; + sif::info << "MgmRM3100Handler: Magnetic field strength in" + " microtesla:" + << std::endl; + sif::info << "X: " << fieldStrengthX << " uT" << std::endl; + sif::info << "Y: " << fieldStrengthY << " uT" << std::endl; + sif::info << "Z: " << fieldStrengthZ << " uT" << std::endl; #else - sif::printInfo("MgmRM3100Handler: Magnetic field strength in microtesla:\n"); - sif::printInfo("X: %f uT\n", fieldStrengthX); - sif::printInfo("Y: %f uT\n", fieldStrengthY); - sif::printInfo("Z: %f uT\n", fieldStrengthZ); + sif::printInfo("MgmRM3100Handler: Magnetic field strength in microtesla:\n"); + sif::printInfo("X: %f uT\n", fieldStrengthX); + sif::printInfo("Y: %f uT\n", fieldStrengthY); + sif::printInfo("Z: %f uT\n", fieldStrengthZ); #endif + } } -#endif // TODO: Sanity check on values? PoolReadGuard readGuard(&primaryDataset); @@ -365,3 +361,8 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) { } return RETURN_OK; } + +void MgmRM3100Handler::enablePeriodicPrintouts(bool enable, uint8_t divider) { + periodicPrintout = enable; + debugDivider.setDivider(divider); +} diff --git a/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h b/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h index 67362f591..d1048cb6e 100644 --- a/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h +++ b/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h @@ -2,12 +2,8 @@ #define MISSION_DEVICES_MGMRM3100HANDLER_H_ #include "devicedefinitions/MgmRM3100HandlerDefs.h" -#include "fsfw/FSFW.h" #include "fsfw/devicehandlers/DeviceHandlerBase.h" - -#if FSFW_HAL_RM3100_MGM_DEBUG == 1 #include "fsfw/globalfunctions/PeriodicOperationDivider.h" -#endif /** * @brief Device Handler for the RM3100 geomagnetic magnetometer sensor @@ -33,6 +29,7 @@ class MgmRM3100Handler : public DeviceHandlerBase { uint32_t transitionDelay); virtual ~MgmRM3100Handler(); + void enablePeriodicPrintouts(bool enable, uint8_t divider); /** * Configure device handler to go to normal mode after startup immediately * @param enable @@ -98,9 +95,9 @@ class MgmRM3100Handler : public DeviceHandlerBase { size_t commandDataLen); ReturnValue_t handleDataReadout(const uint8_t *packet); -#if FSFW_HAL_RM3100_MGM_DEBUG == 1 - PeriodicOperationDivider *debugDivider; -#endif + + bool periodicPrintout = false; + PeriodicOperationDivider debugDivider = PeriodicOperationDivider(3); }; #endif /* MISSION_DEVICEHANDLING_MGMRM3100HANDLER_H_ */ diff --git a/src/fsfw/FSFW.h.in b/src/fsfw/FSFW.h.in index 88ad10cf3..563f30948 100644 --- a/src/fsfw/FSFW.h.in +++ b/src/fsfw/FSFW.h.in @@ -57,16 +57,4 @@ #define FSFW_HAL_SPI_WIRETAPPING 0 #endif -#ifndef FSFW_HAL_L3GD20_GYRO_DEBUG -#define FSFW_HAL_L3GD20_GYRO_DEBUG 0 -#endif /* FSFW_HAL_L3GD20_GYRO_DEBUG */ - -#ifndef FSFW_HAL_RM3100_MGM_DEBUG -#define FSFW_HAL_RM3100_MGM_DEBUG 0 -#endif /* FSFW_HAL_RM3100_MGM_DEBUG */ - -#ifndef FSFW_HAL_LIS3MDL_MGM_DEBUG -#define FSFW_HAL_LIS3MDL_MGM_DEBUG 0 -#endif /* FSFW_HAL_LIS3MDL_MGM_DEBUG */ - #endif /* FSFW_FSFW_H_ */ From 0c4835bfb52b79cd6cdd56ae73480cbf37293f45 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Feb 2022 11:37:38 +0100 Subject: [PATCH 2/9] update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 335c0f7bb..8da336b72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). # [unreleased] +# [v5.0.0] + +## Changes + +- HAL Devicehandlers: Periodic printout is run-time configurable now + # [v4.0.0] ## Additions From f6357b45315a2cfbf744855d7c4676cc89d6f137 Mon Sep 17 00:00:00 2001 From: Steffen Gaisser Date: Wed, 23 Feb 2022 18:23:22 +0100 Subject: [PATCH 3/9] WIP compiler Flags and new unit tests for fixes --- CMakeLists.txt | 18 ++++ hal/src/fsfw_hal/linux/uart/UartComIF.cpp | 2 +- src/fsfw/cfdp/tlv/FilestoreTlvBase.h | 1 + src/fsfw/globalfunctions/CRC.cpp | 86 +---------------- src/fsfw/osal/linux/BinarySemaphore.cpp | 2 + src/fsfw/rmap/RMAP.h | 8 +- src/fsfw/rmap/RMAPChannelIF.h | 14 +-- .../ServiceInterfacePrinter.h | 2 + src/fsfw/storagemanager/LocalPool.cpp | 10 +- src/fsfw/storagemanager/PoolManager.cpp | 2 +- src/fsfw/timemanager/CCSDSTime.cpp | 31 ++++--- .../unit/globalfunctions/CMakeLists.txt | 1 + .../unit/globalfunctions/testCRC.cpp | 14 +++ .../fsfw_tests/unit/testcfg/FSFWConfig.h.in | 4 +- .../unit/timemanager/CMakeLists.txt | 1 + .../unit/timemanager/TestCCSDSTime.cpp | 92 +++++++++++++++++++ 16 files changed, 171 insertions(+), 117 deletions(-) create mode 100644 tests/src/fsfw_tests/unit/globalfunctions/testCRC.cpp create mode 100644 tests/src/fsfw_tests/unit/timemanager/TestCCSDSTime.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 79258db2d..9786d5728 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -281,6 +281,24 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") -Wimplicit-fallthrough=1 -Wno-unused-parameter -Wno-psabi + -Wduplicated-cond # check for duplicate conditions + -Wduplicated-branches # check for duplicate branches + -Wlogical-op # Search for bitwise operations instead of logical + -Wnull-dereference # Search for NULL dereference + -Wundef # Warn if undefind marcos are used + -Wformat=2 # Format string problem detection + -Wformat-overflow=2 # Formatting issues in printf + -Wformat-truncation=2 # Formatting issues in printf + -Wformat-security # Search for dangerous printf operations + -Wstrict-overflow=3 # Warn if integer overflows might happen + -Warray-bounds=2 # Some array bounds violations will be found + -Wshift-overflow=2 # Search for bit left shift overflows (second.replyBuffer.data(); // Size check to prevent buffer overflow if (requestLen > uartCookie.getMaxReplyLen()) { -#if OBSW_VERBOSE_LEVEL >= 1 +#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!" << std::endl; diff --git a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h index bb9f10bba..c123f94c2 100644 --- a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h +++ b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include diff --git a/src/fsfw/globalfunctions/CRC.cpp b/src/fsfw/globalfunctions/CRC.cpp index 033920d0f..03945612a 100644 --- a/src/fsfw/globalfunctions/CRC.cpp +++ b/src/fsfw/globalfunctions/CRC.cpp @@ -28,7 +28,7 @@ const uint16_t CRC::crc16ccitt_table[256] = { // CRC implementation uint16_t CRC::crc16ccitt(uint8_t const input[], uint32_t length, uint16_t startingCrc) { - uint8_t *data = (uint8_t *)input; + const uint8_t *data = static_cast(input); unsigned int tbl_idx; while (length--) { @@ -39,88 +39,4 @@ uint16_t CRC::crc16ccitt(uint8_t const input[], uint32_t length, uint16_t starti } return startingCrc & 0xffff; - // The part below is not used! - // bool temr[16]; - // bool xor_out[16]; - // bool r[16]; - // bool d[8]; - // uint16_t crc_value = 0; - // - // - // for (int i=0; i<16 ;i++) { - // temr[i] = false; - // xor_out[i] = false; - // } - // - // - // for (int i=0; i<16 ;i++) - // r[i] = true; // initialize with 0xFFFF - // - // - // - // for (int j=0; j + BinarySemaphore::BinarySemaphore() { // Using unnamed semaphores for now initSemaphore(); diff --git a/src/fsfw/rmap/RMAP.h b/src/fsfw/rmap/RMAP.h index 7c6542629..d274fb159 100644 --- a/src/fsfw/rmap/RMAP.h +++ b/src/fsfw/rmap/RMAP.h @@ -169,8 +169,8 @@ class RMAP : public HasReturnvaluesIF { * @param buffer the data to write * @param length length of data * @return - * - @c COMMAND_NULLPOINTER datalen was != 0 but data was == NULL - * in write command + * - @c COMMAND_NULLPOINTER datalen was != 0 but data was == + * NULL in write command * - return codes of RMAPChannelIF::sendCommand() */ static ReturnValue_t sendWriteCommand(RMAPCookie *cookie, const uint8_t *buffer, size_t length); @@ -205,8 +205,8 @@ class RMAP : public HasReturnvaluesIF { * @param cookie to cookie to read from * @param expLength the expected maximum length of the reply * @return - * - @c COMMAND_NULLPOINTER datalen was != 0 but data was == NULL - * in write command, or nullpointer in read command + * - @c COMMAND_NULLPOINTER datalen was != 0 but data was == + * NULL in write command, or nullpointer in read command * - return codes of RMAPChannelIF::sendCommand() */ static ReturnValue_t sendReadCommand(RMAPCookie *cookie, uint32_t expLength); diff --git a/src/fsfw/rmap/RMAPChannelIF.h b/src/fsfw/rmap/RMAPChannelIF.h index 7dab07c11..56ede1e2b 100644 --- a/src/fsfw/rmap/RMAPChannelIF.h +++ b/src/fsfw/rmap/RMAPChannelIF.h @@ -75,11 +75,11 @@ class RMAPChannelIF { * - @c RETURN_OK * - @c COMMAND_NO_DESCRIPTORS_AVAILABLE no descriptors available for sending * command; command was not sent - * - @c COMMAND_BUFFER_FULL no receiver buffer available for expected - * len; command was not sent - * - @c COMMAND_TOO_BIG the data that was to be sent was too long for the - * hw to handle (write command) or the expected len was bigger than maximal expected len (read - * command) command was not sent + * - @c COMMAND_BUFFER_FULL no receiver buffer available for + * expected len; command was not sent + * - @c COMMAND_TOO_BIG the data that was to be sent was too long + * for the hw to handle (write command) or the expected len was bigger than maximal expected len + * (read command) command was not sent * - @c COMMAND_CHANNEL_DEACTIVATED the channel has no port set * - @c NOT_SUPPORTED if you dont feel like * implementing something... @@ -97,8 +97,8 @@ class RMAPChannelIF { * - @c REPLY_NO_REPLY no reply was received * - @c REPLY_NOT_SENT command was not sent, implies no reply * - @c REPLY_NOT_YET_SENT command is still waiting to be sent - * - @c WRITE_REPLY_INTERFACE_BUSY Interface is busy (transmission buffer - * still being processed) + * - @c WRITE_REPLY_INTERFACE_BUSY Interface is busy (transmission + * buffer still being processed) * - @c WRITE_REPLY_TRANSMISSION_ERROR Interface encountered errors during last * operation, data could not be processed. (transmission error) * - @c WRITE_REPLY_INVALID_DATA Invalid data (amount / value) diff --git a/src/fsfw/serviceinterface/ServiceInterfacePrinter.h b/src/fsfw/serviceinterface/ServiceInterfacePrinter.h index 89d793c35..2f3dfed5a 100644 --- a/src/fsfw/serviceinterface/ServiceInterfacePrinter.h +++ b/src/fsfw/serviceinterface/ServiceInterfacePrinter.h @@ -1,6 +1,8 @@ #ifndef FSFW_SERVICEINTERFACE_SERVICEINTERFACEPRINTER #define FSFW_SERVICEINTERFACE_SERVICEINTERFACEPRINTER +#include + #if FSFW_DISABLE_PRINTOUT == 0 #include #endif diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index 075de4b82..9bd12b4d3 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -2,6 +2,8 @@ #include +#include + #include "fsfw/FSFW.h" #include "fsfw/objectmanager/ObjectManager.h" @@ -110,7 +112,7 @@ ReturnValue_t LocalPool::modifyData(store_address_t storeId, uint8_t** packetPtr } ReturnValue_t LocalPool::deleteData(store_address_t storeId) { -#if FSFW_VERBOSE_PRINTOUT == 2 +#if FSFW_VERBOSE_LEVEL >= 2 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "Delete: Pool: " << std::dec << storeId.poolIndex << " Index: " << storeId.packetIndex << std::endl; @@ -148,7 +150,7 @@ ReturnValue_t LocalPool::deleteData(uint8_t* ptr, size_t size, store_address_t* // element of an object. localId.packetIndex = deltaAddress / elementSizes[n]; result = deleteData(localId); -#if FSFW_VERBOSE_PRINTOUT == 2 +#if FSFW_VERBOSE_LEVEL >= 2 if (deltaAddress % elementSizes[n] != 0) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "LocalPool::deleteData: Address not aligned!" << std::endl; @@ -219,7 +221,7 @@ ReturnValue_t LocalPool::reserveSpace(const size_t size, store_address_t* storeI status = findEmpty(storeId->poolIndex, &storeId->packetIndex); } if (status == RETURN_OK) { -#if FSFW_VERBOSE_PRINTOUT == 2 +#if FSFW_VERBOSE_LEVEL >= 2 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "Reserve: Pool: " << std::dec << storeId->poolIndex << " Index: " << storeId->packetIndex << std::endl; @@ -257,7 +259,7 @@ void LocalPool::setToSpillToHigherPools(bool enable) { this->spillsToHigherPools ReturnValue_t LocalPool::getSubPoolIndex(size_t packetSize, uint16_t* subpoolIndex, uint16_t startAtIndex) { for (uint16_t n = startAtIndex; n < NUMBER_OF_SUBPOOLS; n++) { -#if FSFW_VERBOSE_PRINTOUT == 2 +#if FSFW_VERBOSE_LEVEL >= 2 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "LocalPool " << getObjectId() << "::getPoolIndex: Pool: " << n << ", Element Size: " << elementSizes[n] << std::endl; diff --git a/src/fsfw/storagemanager/PoolManager.cpp b/src/fsfw/storagemanager/PoolManager.cpp index 6ff003609..92de1dfe0 100644 --- a/src/fsfw/storagemanager/PoolManager.cpp +++ b/src/fsfw/storagemanager/PoolManager.cpp @@ -17,7 +17,7 @@ ReturnValue_t PoolManager::reserveSpace(const size_t size, store_address_t* addr } ReturnValue_t PoolManager::deleteData(store_address_t storeId) { -#if FSFW_VERBOSE_PRINTOUT == 2 +#if FSFW_VERBOSE_LEVEL >= 2 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "PoolManager( " << translateObject(getObjectId()) << " )::deleteData from store " << storeId.poolIndex << ". id is " << storeId.packetIndex << std::endl; diff --git a/src/fsfw/timemanager/CCSDSTime.cpp b/src/fsfw/timemanager/CCSDSTime.cpp index 4445fd244..9a92c21e6 100644 --- a/src/fsfw/timemanager/CCSDSTime.cpp +++ b/src/fsfw/timemanager/CCSDSTime.cpp @@ -109,8 +109,8 @@ ReturnValue_t CCSDSTime::convertFromCCS(Clock::TimeOfDay_t* to, const uint8_t* f if (result != RETURN_OK) { return result; } - - Ccs_mseconds* temp = (Ccs_mseconds*)from; + // At this point we made sure that this is a valid ccs time + const Ccs_mseconds* temp = reinterpret_cast(from); to->year = (temp->yearMSB << 8) + temp->yearLSB; to->hour = temp->hour; @@ -118,16 +118,19 @@ ReturnValue_t CCSDSTime::convertFromCCS(Clock::TimeOfDay_t* to, const uint8_t* f to->second = temp->second; if (temp->pField & (1 << 3)) { // day of year variation - uint16_t tempDay = (temp->month << 8) + temp->day; - result = convertDaysOfYear(tempDay, to->year, &(temp->month), &(temp->day)); + uint16_t tempDayOfYear = (temp->month << 8) + temp->day; + uint8_t tempDay = 0; + uint8_t tempMonth = 0; + result = convertDaysOfYear(tempDayOfYear, to->year, &tempMonth, &tempDay); if (result != RETURN_OK) { return result; } + to->month = tempMonth; + to->day = tempDay; + }else{ + to->month = temp->month; + to->day = temp->day; } - - to->month = temp->month; - to->day = temp->day; - to->usecond = 0; if (subsecondsLength > 0) { *foundLength += 1; @@ -162,7 +165,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* uint16_t hour; uint16_t minute; float second; - int count = sscanf((char*)from, + int count = sscanf((const char*)from, "%4" SCNu16 "-%2" SCNu16 "-%2" SCNu16 "T%" "2" SCNu16 ":%2" SCNu16 ":%fZ", @@ -179,7 +182,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* } // try Code B (yyyy-ddd) - count = sscanf((char*)from, + count = sscanf((const char*)from, "%4" SCNu16 "-%3" SCNu16 "T%2" SCNu16 ":%" "2" SCNu16 ":%fZ", @@ -211,7 +214,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* float second; // try Code A (yyyy-mm-dd) int count = - sscanf((char*)from, "%4" SCNu16 "-%2" SCNu8 "-%2" SCNu16 "T%2" SCNu8 ":%2" SCNu8 ":%fZ", + sscanf((const char*)from, "%4" SCNu16 "-%2" SCNu8 "-%2" SCNu16 "T%2" SCNu8 ":%2" SCNu8 ":%fZ", &year, &month, &day, &hour, &minute, &second); if (count == 6) { to->year = year; @@ -225,7 +228,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* } // try Code B (yyyy-ddd) - count = sscanf((char*)from, "%4" SCNu16 "-%3" SCNu16 "T%2" SCNu8 ":%2" SCNu8 ":%fZ", &year, &day, + count = sscanf((const char*)from, "%4" SCNu16 "-%3" SCNu16 "T%2" SCNu8 ":%2" SCNu8 ":%fZ", &year, &day, &hour, &minute, &second); if (count == 5) { uint8_t tempDay; @@ -248,7 +251,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* } ReturnValue_t CCSDSTime::checkCcs(const uint8_t* time, uint8_t length) { - Ccs_mseconds* time_struct = (Ccs_mseconds*)time; + const Ccs_mseconds* time_struct = reinterpret_cast(time); uint8_t additionalBytes = time_struct->pField & 0b111; if ((additionalBytes == 0b111) || (length < (additionalBytes + 8))) { @@ -278,7 +281,7 @@ ReturnValue_t CCSDSTime::checkCcs(const uint8_t* time, uint8_t length) { return INVALID_TIME_FORMAT; } - uint8_t* additionalByte = &time_struct->secondEminus2; + const uint8_t* additionalByte = &time_struct->secondEminus2; for (; additionalBytes != 0; additionalBytes--) { if (*additionalByte++ > 99) { diff --git a/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt b/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt index 3b29f23fc..79f847bff 100644 --- a/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt @@ -2,4 +2,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testDleEncoder.cpp testOpDivider.cpp testBitutil.cpp + testCRC.cpp ) diff --git a/tests/src/fsfw_tests/unit/globalfunctions/testCRC.cpp b/tests/src/fsfw_tests/unit/globalfunctions/testCRC.cpp new file mode 100644 index 000000000..b163ea1fc --- /dev/null +++ b/tests/src/fsfw_tests/unit/globalfunctions/testCRC.cpp @@ -0,0 +1,14 @@ +#include + +#include "catch2/catch_test_macros.hpp" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw_tests/unit/CatchDefinitions.h" + +TEST_CASE("CRC", "[CRC]") { + std::array testData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + uint16_t crc = CRC::crc16ccitt(testData.data(), 10); + REQUIRE(crc == 49729); + for (uint8_t index = 0; index < testData.size(); index++) { + REQUIRE(testData[index] == index); + } +} \ No newline at end of file diff --git a/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in b/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in index f05ef40bd..ef58f4cd0 100644 --- a/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in +++ b/tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in @@ -11,10 +11,12 @@ //! More FSFW related printouts depending on level. Useful for development. #define FSFW_VERBOSE_LEVEL 0 - + //! Can be used to completely disable printouts, even the C stdio ones. #if FSFW_CPP_OSTREAM_ENABLED == 0 && FSFW_VERBOSE_LEVEL == 0 #define FSFW_DISABLE_PRINTOUT 1 +#else + #define FSFW_DISABLE_PRINTOUT 0 #endif #define FSFW_USE_PUS_C_TELEMETRY 1 diff --git a/tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt b/tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt index 6ce1c6c6c..4b1693a93 100644 --- a/tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt @@ -1,3 +1,4 @@ target_sources(${FSFW_TEST_TGT} PRIVATE TestCountdown.cpp + TestCCSDSTime.cpp ) diff --git a/tests/src/fsfw_tests/unit/timemanager/TestCCSDSTime.cpp b/tests/src/fsfw_tests/unit/timemanager/TestCCSDSTime.cpp new file mode 100644 index 000000000..783517a6a --- /dev/null +++ b/tests/src/fsfw_tests/unit/timemanager/TestCCSDSTime.cpp @@ -0,0 +1,92 @@ +#include + +#include + +#include +#include + +#include "fsfw_tests/unit/CatchDefinitions.h" + +TEST_CASE("CCSDSTime Tests", "[TestCCSDSTime]") { + INFO("CCSDSTime Tests"); + CCSDSTime::Ccs_mseconds cssMilliSecconds; + Clock::TimeOfDay_t time; + time.year = 2020; + time.month = 2; + time.day = 29; + time.hour = 13; + time.minute = 24; + time.second = 45; + time.usecond = 123456; + SECTION("Test CCS Time") { + auto result = CCSDSTime::convertToCcsds(&cssMilliSecconds, &time); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(cssMilliSecconds.pField == 0x52); // 0b01010010 + REQUIRE(cssMilliSecconds.yearMSB == 0x07); + REQUIRE(cssMilliSecconds.yearLSB == 0xe4); + REQUIRE(cssMilliSecconds.month == 2); + REQUIRE(cssMilliSecconds.day == 29); + REQUIRE(cssMilliSecconds.hour == 13); + REQUIRE(cssMilliSecconds.minute == 24); + REQUIRE(cssMilliSecconds.second == 45); + uint16_t secondsMinus4 = (static_cast(cssMilliSecconds.secondEminus2) * 100) + + cssMilliSecconds.secondEminus4; + REQUIRE(secondsMinus4 == 1234); + Clock::TimeOfDay_t timeTo; + const uint8_t* dataPtr = reinterpret_cast(&cssMilliSecconds); + size_t length = sizeof(CCSDSTime::Ccs_mseconds); + result = CCSDSTime::convertFromCCS(&timeTo, dataPtr, &length, sizeof(CCSDSTime::Ccs_mseconds)); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(cssMilliSecconds.pField == 0x52); // 0b01010010 + REQUIRE(cssMilliSecconds.yearMSB == 0x07); + REQUIRE(cssMilliSecconds.yearLSB == 0xe4); + REQUIRE(cssMilliSecconds.month == 2); + REQUIRE(cssMilliSecconds.day == 29); + REQUIRE(cssMilliSecconds.hour == 13); + REQUIRE(cssMilliSecconds.minute == 24); + REQUIRE(cssMilliSecconds.second == 45); + REQUIRE(timeTo.year == 2020); + REQUIRE(timeTo.month == 2); + REQUIRE(timeTo.day == 29); + REQUIRE(timeTo.hour == 13); + REQUIRE(timeTo.minute == 24); + REQUIRE(timeTo.second == 45); + REQUIRE(timeTo.usecond == 123400); + } + SECTION("CCS_Day of Year"){ + Clock::TimeOfDay_t timeTo; + std::array ccsDayOfYear = {0b01011000, 0x07, 0xe4, 0, 60, 13, 24, 45}; + size_t length = ccsDayOfYear.size(); + auto result = CCSDSTime::convertFromCCS(&timeTo, ccsDayOfYear.data(), &length, ccsDayOfYear.size()); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + // Check constness + REQUIRE(ccsDayOfYear[0] == 0b01011000); + REQUIRE(ccsDayOfYear[1] == 0x07); + REQUIRE(ccsDayOfYear[2] == 0xe4); + REQUIRE(ccsDayOfYear[3] == 0x0); + REQUIRE(ccsDayOfYear[4] == 60); + REQUIRE(ccsDayOfYear[5] == 13); + REQUIRE(ccsDayOfYear[6] == 24); + REQUIRE(ccsDayOfYear[7] == 45); + REQUIRE(timeTo.year == 2020); + REQUIRE(timeTo.month == 2); + REQUIRE(timeTo.day == 29); + REQUIRE(timeTo.hour == 13); + REQUIRE(timeTo.minute == 24); + REQUIRE(timeTo.second == 45); + REQUIRE(timeTo.usecond == 0); + } + SECTION("Test convertFromASCII"){ + std::string timeAscii = "2022-12-31T23:59:59.123Z"; + Clock::TimeOfDay_t timeTo; + const uint8_t* timeChar = reinterpret_cast(timeAscii.c_str()); + CCSDSTime::convertFromASCII(&timeTo, timeChar, timeAscii.length()); + REQUIRE(timeTo.year == 2022); + REQUIRE(timeTo.month == 12); + REQUIRE(timeTo.day == 31); + REQUIRE(timeTo.hour == 23); + REQUIRE(timeTo.minute == 59); + REQUIRE(timeTo.second == 59); + REQUIRE(timeTo.usecond == Catch::Approx(123000)); + } +} \ No newline at end of file From 09815f5cce17deefb9435ffc9c9b55b5b8d6f3ce Mon Sep 17 00:00:00 2001 From: Steffen Gaisser Date: Wed, 23 Feb 2022 18:24:07 +0100 Subject: [PATCH 4/9] Clang format --- src/fsfw/cfdp/tlv/FilestoreTlvBase.h | 2 +- src/fsfw/osal/linux/BinarySemaphore.cpp | 3 +-- src/fsfw/rmap/RMAPChannelIF.h | 6 ++--- src/fsfw/storagemanager/LocalPool.cpp | 4 ++-- src/fsfw/timemanager/CCSDSTime.cpp | 6 ++--- .../unit/timemanager/TestCCSDSTime.cpp | 22 +++++++++---------- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h index c123f94c2..9a02c2132 100644 --- a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h +++ b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h @@ -1,12 +1,12 @@ #ifndef FSFW_SRC_FSFW_CFDP_FILESTOREREQUESTBASE_H_ #define FSFW_SRC_FSFW_CFDP_FILESTOREREQUESTBASE_H_ +#include #include #include #include #include #include -#include #include #include diff --git a/src/fsfw/osal/linux/BinarySemaphore.cpp b/src/fsfw/osal/linux/BinarySemaphore.cpp index 536681a6d..4fb67f15d 100644 --- a/src/fsfw/osal/linux/BinarySemaphore.cpp +++ b/src/fsfw/osal/linux/BinarySemaphore.cpp @@ -1,6 +1,7 @@ #include "fsfw/osal/linux/BinarySemaphore.h" #include +#include #include #include @@ -9,8 +10,6 @@ #include "fsfw/serviceinterface/ServiceInterfacePrinter.h" #include "fsfw/serviceinterface/ServiceInterfaceStream.h" -#include - BinarySemaphore::BinarySemaphore() { // Using unnamed semaphores for now initSemaphore(); diff --git a/src/fsfw/rmap/RMAPChannelIF.h b/src/fsfw/rmap/RMAPChannelIF.h index 56ede1e2b..9e666dfb6 100644 --- a/src/fsfw/rmap/RMAPChannelIF.h +++ b/src/fsfw/rmap/RMAPChannelIF.h @@ -77,9 +77,9 @@ class RMAPChannelIF { * command; command was not sent * - @c COMMAND_BUFFER_FULL no receiver buffer available for * expected len; command was not sent - * - @c COMMAND_TOO_BIG the data that was to be sent was too long - * for the hw to handle (write command) or the expected len was bigger than maximal expected len - * (read command) command was not sent + * - @c COMMAND_TOO_BIG the data that was to be sent was too + * long for the hw to handle (write command) or the expected len was bigger than maximal expected + * len (read command) command was not sent * - @c COMMAND_CHANNEL_DEACTIVATED the channel has no port set * - @c NOT_SUPPORTED if you dont feel like * implementing something... diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index 9bd12b4d3..6acedacab 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -1,9 +1,9 @@ #include "fsfw/storagemanager/LocalPool.h" -#include - #include +#include + #include "fsfw/FSFW.h" #include "fsfw/objectmanager/ObjectManager.h" diff --git a/src/fsfw/timemanager/CCSDSTime.cpp b/src/fsfw/timemanager/CCSDSTime.cpp index 9a92c21e6..290d58dce 100644 --- a/src/fsfw/timemanager/CCSDSTime.cpp +++ b/src/fsfw/timemanager/CCSDSTime.cpp @@ -127,7 +127,7 @@ ReturnValue_t CCSDSTime::convertFromCCS(Clock::TimeOfDay_t* to, const uint8_t* f } to->month = tempMonth; to->day = tempDay; - }else{ + } else { to->month = temp->month; to->day = temp->day; } @@ -228,8 +228,8 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* } // try Code B (yyyy-ddd) - count = sscanf((const char*)from, "%4" SCNu16 "-%3" SCNu16 "T%2" SCNu8 ":%2" SCNu8 ":%fZ", &year, &day, - &hour, &minute, &second); + count = sscanf((const char*)from, "%4" SCNu16 "-%3" SCNu16 "T%2" SCNu8 ":%2" SCNu8 ":%fZ", &year, + &day, &hour, &minute, &second); if (count == 5) { uint8_t tempDay; ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year, &month, &tempDay); diff --git a/tests/src/fsfw_tests/unit/timemanager/TestCCSDSTime.cpp b/tests/src/fsfw_tests/unit/timemanager/TestCCSDSTime.cpp index 783517a6a..89713488b 100644 --- a/tests/src/fsfw_tests/unit/timemanager/TestCCSDSTime.cpp +++ b/tests/src/fsfw_tests/unit/timemanager/TestCCSDSTime.cpp @@ -1,9 +1,8 @@ -#include - #include -#include +#include #include +#include #include "fsfw_tests/unit/CatchDefinitions.h" @@ -53,11 +52,12 @@ TEST_CASE("CCSDSTime Tests", "[TestCCSDSTime]") { REQUIRE(timeTo.second == 45); REQUIRE(timeTo.usecond == 123400); } - SECTION("CCS_Day of Year"){ + SECTION("CCS_Day of Year") { Clock::TimeOfDay_t timeTo; - std::array ccsDayOfYear = {0b01011000, 0x07, 0xe4, 0, 60, 13, 24, 45}; + std::array ccsDayOfYear = {0b01011000, 0x07, 0xe4, 0, 60, 13, 24, 45}; size_t length = ccsDayOfYear.size(); - auto result = CCSDSTime::convertFromCCS(&timeTo, ccsDayOfYear.data(), &length, ccsDayOfYear.size()); + auto result = + CCSDSTime::convertFromCCS(&timeTo, ccsDayOfYear.data(), &length, ccsDayOfYear.size()); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); // Check constness REQUIRE(ccsDayOfYear[0] == 0b01011000); @@ -76,11 +76,11 @@ TEST_CASE("CCSDSTime Tests", "[TestCCSDSTime]") { REQUIRE(timeTo.second == 45); REQUIRE(timeTo.usecond == 0); } - SECTION("Test convertFromASCII"){ - std::string timeAscii = "2022-12-31T23:59:59.123Z"; - Clock::TimeOfDay_t timeTo; - const uint8_t* timeChar = reinterpret_cast(timeAscii.c_str()); - CCSDSTime::convertFromASCII(&timeTo, timeChar, timeAscii.length()); + SECTION("Test convertFromASCII") { + std::string timeAscii = "2022-12-31T23:59:59.123Z"; + Clock::TimeOfDay_t timeTo; + const uint8_t* timeChar = reinterpret_cast(timeAscii.c_str()); + CCSDSTime::convertFromASCII(&timeTo, timeChar, timeAscii.length()); REQUIRE(timeTo.year == 2022); REQUIRE(timeTo.month == 12); REQUIRE(timeTo.day == 31); From 32381a78725f393b8304c4308bbbeaf0ef65f3cf Mon Sep 17 00:00:00 2001 From: Steffen Gaisser Date: Wed, 23 Feb 2022 21:20:22 +0100 Subject: [PATCH 5/9] Fixed an issue with wrong buffer size --- src/fsfw/globalfunctions/arrayprinter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/globalfunctions/arrayprinter.cpp b/src/fsfw/globalfunctions/arrayprinter.cpp index e0899d94a..325bf2477 100644 --- a/src/fsfw/globalfunctions/arrayprinter.cpp +++ b/src/fsfw/globalfunctions/arrayprinter.cpp @@ -107,7 +107,7 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, size_t maxCharPerL break; } - currentPos += snprintf(printBuffer + currentPos, 3, "%d", data[i]); + currentPos += snprintf(printBuffer + currentPos, 4, "%d", data[i]); if (i < size - 1) { currentPos += sprintf(printBuffer + currentPos, ","); if (i > 0 and (i + 1) % maxCharPerLine == 0) { From 1ef3dae72e44498c7fcfab986032cabe605af319 Mon Sep 17 00:00:00 2001 From: Steffen Gaisser Date: Wed, 23 Feb 2022 22:36:29 +0100 Subject: [PATCH 6/9] Fixed an missing include --- src/fsfw/cfdp/tlv/FilestoreTlvBase.h | 1 + src/fsfw/globalfunctions/arrayprinter.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h index 9a02c2132..18eb515a7 100644 --- a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h +++ b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/src/fsfw/globalfunctions/arrayprinter.cpp b/src/fsfw/globalfunctions/arrayprinter.cpp index 325bf2477..40dc09f56 100644 --- a/src/fsfw/globalfunctions/arrayprinter.cpp +++ b/src/fsfw/globalfunctions/arrayprinter.cpp @@ -1,6 +1,7 @@ #include "fsfw/globalfunctions/arrayprinter.h" #include +#include #include "fsfw/serviceinterface/ServiceInterface.h" @@ -68,7 +69,7 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, size_t maxCharPerL currentPos += snprintf(printBuffer + currentPos, 6, "%02x", data[i]); if (i < size - 1) { currentPos += sprintf(printBuffer + currentPos, ","); - if (i > 0 and (i + 1) % maxCharPerLine == 0) { + if ((i + 1) % maxCharPerLine == 0) { currentPos += sprintf(printBuffer + currentPos, "\n"); } } @@ -97,20 +98,21 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, size_t maxCharPerL } std::cout << "]" << std::endl; #else - // General format: 32, 243, -12 so it is number of chars times 5 + // General format: 32,243,-12 so it is number of chars times 4 // plus line break plus small safety margin. - char printBuffer[(size + 1) * 5 + 1] = {}; + uint16_t expectedLines = ceil((double)size / maxCharPerLine); + char printBuffer[size * 4 + 1 + expectedLines] = {}; size_t currentPos = 0; for (size_t i = 0; i < size; i++) { // To avoid buffer overflows. - if (sizeof(printBuffer) - currentPos <= 5) { + if (sizeof(printBuffer) - currentPos <= 4) { break; } currentPos += snprintf(printBuffer + currentPos, 4, "%d", data[i]); if (i < size - 1) { currentPos += sprintf(printBuffer + currentPos, ","); - if (i > 0 and (i + 1) % maxCharPerLine == 0) { + if ((i + 1) % maxCharPerLine == 0) { currentPos += sprintf(printBuffer + currentPos, "\n"); } } From 0e8328fca30a0f8e7b5e94e3362b1ade400567cf Mon Sep 17 00:00:00 2001 From: Steffen Gaisser Date: Thu, 24 Feb 2022 11:22:51 +0100 Subject: [PATCH 7/9] Fixed include based on Feedback --- src/fsfw/cfdp/tlv/FilestoreTlvBase.h | 3 ++- src/fsfw/serviceinterface/ServiceInterfacePrinter.h | 2 +- src/fsfw/storagemanager/LocalPool.cpp | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h index 18eb515a7..04012cda2 100644 --- a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h +++ b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h @@ -1,7 +1,6 @@ #ifndef FSFW_SRC_FSFW_CFDP_FILESTOREREQUESTBASE_H_ #define FSFW_SRC_FSFW_CFDP_FILESTOREREQUESTBASE_H_ -#include #include #include #include @@ -12,6 +11,8 @@ #include #include +#include "fsfw/FSFW.h" + namespace cfdp { enum FilestoreActionCode { diff --git a/src/fsfw/serviceinterface/ServiceInterfacePrinter.h b/src/fsfw/serviceinterface/ServiceInterfacePrinter.h index 2f3dfed5a..65f7250ab 100644 --- a/src/fsfw/serviceinterface/ServiceInterfacePrinter.h +++ b/src/fsfw/serviceinterface/ServiceInterfacePrinter.h @@ -1,7 +1,7 @@ #ifndef FSFW_SERVICEINTERFACE_SERVICEINTERFACEPRINTER #define FSFW_SERVICEINTERFACE_SERVICEINTERFACEPRINTER -#include +#include "fsfw/FSFW.h" #if FSFW_DISABLE_PRINTOUT == 0 #include diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index 6acedacab..cee1d4070 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -1,7 +1,5 @@ #include "fsfw/storagemanager/LocalPool.h" -#include - #include #include "fsfw/FSFW.h" From f659f137599515995785bf768b6297eec4a1f91b Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Thu, 3 Mar 2022 16:03:06 +0100 Subject: [PATCH 8/9] Changing build to -j4 from -j to lessen load on build server --- automation/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index 3424f986c..d1459e52f 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -21,14 +21,14 @@ pipeline { stage('Build') { steps { dir(BUILDDIR) { - sh 'cmake --build . -j' + sh 'cmake --build . -j4' } } } stage('Unittests') { steps { dir(BUILDDIR) { - sh 'cmake --build . -- fsfw-tests_coverage -j' + sh 'cmake --build . -- fsfw-tests_coverage -j4' } } } From 117747970d1d1e417393044e98ea404ca26676cb Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Sat, 5 Mar 2022 22:03:25 +0100 Subject: [PATCH 9/9] some forgotten size_t --- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 2 +- src/fsfw/devicehandlers/DeviceHandlerBase.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index ea1fcdf1d..08a15d5ff 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -824,7 +824,7 @@ void DeviceHandlerBase::handleReply(const uint8_t* receivedData, DeviceCommandId } ReturnValue_t DeviceHandlerBase::getStorageData(store_address_t storageAddress, uint8_t** data, - uint32_t* len) { + size_t* len) { size_t lenTmp; if (IPCStore == nullptr) { diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index 037f4bd75..c8b8b86d7 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -673,7 +673,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, //! Pointer to the raw packet that will be sent. uint8_t *rawPacket = nullptr; //! Size of the #rawPacket. - uint32_t rawPacketLen = 0; + size_t rawPacketLen = 0; /** * The mode the device handler is currently in. @@ -1250,7 +1250,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, * - @c RETURN_FAILED IPCStore is nullptr * - the return value from the IPCStore if it was not @c RETURN_OK */ - ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data, uint32_t *len); + ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data, size_t *len); /** * @param modeTo either @c MODE_ON, MODE_NORMAL or MODE_RAW, nothing else!