From 8610e48b1922d6f62d2a2c03b5dd81b760e8f1b5 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 27 Apr 2022 16:08:17 +0200 Subject: [PATCH] countdown based timeout --- README.md | 10 +++++++++- bsp_q7s/core/InitMission.cpp | 2 +- fsfw | 2 +- .../PlocSupervisorDefinitions.h | 4 ++-- linux/devices/ploc/PlocSupervisorHandler.cpp | 20 +++++++++++++++++-- linux/devices/ploc/PlocSupervisorHandler.h | 12 +++++++++++ mission/tmtc/CCSDSHandler.cpp | 4 ++-- mission/tmtc/CCSDSHandler.h | 6 +++--- 8 files changed, 48 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7f9e9d72..3200dab1 100644 --- a/README.md +++ b/README.md @@ -1197,7 +1197,7 @@ in the same way. # Coding Style * the formatting is based on the clang-format tools -## Setting up eclipse auto-fromatter with clang-format +## Setting auto-fromatter with clang-format in Xilinx SDK 1. Help → Install New Software → Add 2. In location insert the link http://www.cppstyle.com/luna 3. The software package CppStyle should now be available for installation @@ -1206,3 +1206,11 @@ in the same way. 6. Insert the path to the clang-format executable 7. Under C/C++ → Code Style → Formatter, change the formatter to CppStyle (clang-format) 8. Code can now be formatted with the clang tool by using the key combination Ctrl + Shift + f + +## Setting up auto-fromatter with clang-format in eclipse +1. Help → Eclipse market place → Search for "Cppstyle" and install +2. On windows download the clang-formatting tools from https://llvm.org/builds/. On linux clang-format can be installed with the package manager. +3. Navigate to Preferences → C/C++ → CppStyle +4. Insert the path to the clang-format executable +5. Under C/C++ → Code Style → Formatter, change the formatter to CppStyle (clang-format) +6. Code can now be formatted with the clang tool by using the key combination Ctrl + Shift + f diff --git a/bsp_q7s/core/InitMission.cpp b/bsp_q7s/core/InitMission.cpp index 919e9fbd..2cd6486e 100644 --- a/bsp_q7s/core/InitMission.cpp +++ b/bsp_q7s/core/InitMission.cpp @@ -173,7 +173,7 @@ void initmission::initTasks() { #if OBSW_ADD_PLOC_SUPERVISOR == 1 PeriodicTaskIF* supvHelperTask = factory->createPeriodicTask( - "PLOC_SUPV_HELPER", 10, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 1.0, missedDeadlineFunc); + "PLOC_SUPV_HELPER", 10, PeriodicTaskIF::MINIMUM_STACK_SIZE * 8, 1.0, missedDeadlineFunc); result = supvHelperTask->addComponent(objects::PLOC_SUPERVISOR_HELPER); if (result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("PLOC_SUPV_HELPER", objects::PLOC_SUPERVISOR_HELPER); diff --git a/fsfw b/fsfw index 9f7b9be8..900ef5b9 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 9f7b9be800402215e97759eb35d4c40a484d1f68 +Subproject commit 900ef5b9124063b5eec88de19d851006b2e1e601 diff --git a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h index 11af022b..a0592ce3 100644 --- a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -268,7 +268,7 @@ static const uint32_t ADC_REPORT_SET_ID = REQUEST_ADC_REPORT; namespace recv_timeout { // Erase memory can require up to 60 seconds for execution static const uint32_t ERASE_MEMORY = 60000; -static const uint32_t UPDATE_STATUS_REPORT = 60000; +static const uint32_t UPDATE_STATUS_REPORT = 70000; } // namespace recv_timeout /** @@ -1163,7 +1163,7 @@ class WriteMemory : public SupvTcSpacePacket { SerializeIF::Endianness::BIG); std::memcpy(dataFieldPtr, updateData, length); if (length % 2 != 0) { - this->setPacketDataLength(this->getFullSize() + 1); + this->setPacketDataLength(length + sizeof(CCSDSPrimaryHeader) + CRC_SIZE - 1); // The data field must be two bytes aligned. Thus, in case the number of bytes to write is odd // a value of zero is added here *(dataFieldPtr + length + 1) = 0; diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index 3668a6cd..35a11124 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -402,7 +402,7 @@ void PlocSupervisorHandler::fillCommandAndReplyMap() { this->insertInCommandAndReplyMap(FIRST_MRAM_DUMP, 3); this->insertInCommandAndReplyMap(CONSECUTIVE_MRAM_DUMP, 3); this->insertInReplyMap(ACK_REPORT, 3, nullptr, SIZE_ACK_REPORT); - this->insertInReplyMap(EXE_REPORT, 50, nullptr, SIZE_EXE_REPORT); + this->insertInReplyMap(EXE_REPORT, 0, nullptr, SIZE_EXE_REPORT, false, &executionTimeout); this->insertInReplyMap(HK_REPORT, 3, &hkset, SIZE_HK_REPORT); this->insertInReplyMap(BOOT_STATUS_REPORT, 3, &bootStatusReport, SIZE_BOOT_STATUS_REPORT); this->insertInReplyMap(LATCHUP_REPORT, 3, &latchupStatusReport, SIZE_LATCHUP_STATUS_REPORT); @@ -546,6 +546,8 @@ ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::ite << " not in replyMap" << std::endl; } + setExecutionTimeout(command->first); + return RETURN_OK; } @@ -795,6 +797,19 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) { } } +void PlocSupervisorHandler::setExecutionTimeout(DeviceCommandId_t command) { + using namespace supv; + switch(command) { + case FIRST_MRAM_DUMP: + case CONSECUTIVE_MRAM_DUMP: + executionTimeout.setTimeout(MRAM_DUMP_EXECUTION_TIMEOUT); + break; + default: + executionTimeout.setTimeout(EXECUTION_DEFAULT_TIMEOUT); + break; + } +} + ReturnValue_t PlocSupervisorHandler::verifyPacket(const uint8_t* start, size_t foundLen) { uint16_t receivedCrc = *(start + foundLen - 2) << 8 | *(start + foundLen - 1); uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2); @@ -1237,7 +1252,8 @@ size_t PlocSupervisorHandler::getNextReplyLength(DeviceCommandId_t commandId) { DeviceReplyIter iter = deviceReplyMap.find(nextReplyId); if (iter != deviceReplyMap.end()) { - if (iter->second.delayCycles == 0) { + if ((iter->second.delayCycles == 0 && iter->second.countdown == nullptr) || + (not iter->second.active && iter->second.countdown != nullptr)) { /* Reply inactive */ return replyLen; } diff --git a/linux/devices/ploc/PlocSupervisorHandler.h b/linux/devices/ploc/PlocSupervisorHandler.h index b2d0352a..19ccfa63 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.h +++ b/linux/devices/ploc/PlocSupervisorHandler.h @@ -8,6 +8,7 @@ #include "fsfw_hal/linux/gpio/Gpio.h" #include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h" #include "fsfw_hal/linux/uart/UartComIF.h" +#include "fsfw/timemanager/Countdown.h" #include "linux/devices/devicedefinitions/PlocSupervisorDefinitions.h" #include "linux/devices/devicedefinitions/SupvReturnValuesIF.h" #include "PlocSupvHelper.h" @@ -78,6 +79,10 @@ class PlocSupervisorHandler : public DeviceHandlerBase { static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF; static const uint8_t EXE_STATUS_OFFSET = 10; static const uint8_t SIZE_NULL_TERMINATOR = 1; + // 5 s + static const uint32_t EXECUTION_DEFAULT_TIMEOUT = 5000; + // 30 s + static const uint32_t MRAM_DUMP_EXECUTION_TIMEOUT = 30000; uint8_t commandBuffer[supv::MAX_COMMAND_SIZE]; @@ -128,6 +133,13 @@ class PlocSupervisorHandler : public DeviceHandlerBase { // Supervisor helper class currently executing a command bool plocSupvHelperExecuting = false; + Countdown executionTimeout = Countdown(EXECUTION_DEFAULT_TIMEOUT, false); + + /** + * @brief Adjusts the timeout of the execution report dependent on command + */ + void setExecutionTimeout(DeviceCommandId_t command); + /** * @brief Handles event messages received from the supervisor helper */ diff --git a/mission/tmtc/CCSDSHandler.cpp b/mission/tmtc/CCSDSHandler.cpp index a42a798a..0c49f6af 100644 --- a/mission/tmtc/CCSDSHandler.cpp +++ b/mission/tmtc/CCSDSHandler.cpp @@ -22,7 +22,7 @@ CCSDSHandler::CCSDSHandler(object_id_t objectId, object_id_t ptmeId, object_id_t gpioIF(gpioIF), enTxClock(enTxClock), enTxData(enTxData), - TRANSMITTER_TIMEOUT(transmitterTimeout) { + transmitterTimeout(transmitterTimeout) { commandQueue = QueueFactory::instance()->createMessageQueue(QUEUE_SIZE); auto mqArgs = MqArgs(objectId, static_cast(this)); eventQueue = @@ -312,7 +312,7 @@ void CCSDSHandler::enableTransmit() { // Transmitter already enabled return; } - transmitterCountdown.setTimeout(TRANSMITTER_TIMEOUT); + transmitterCountdown.setTimeout(transmitterTimeout); #ifndef TE0720_1CFA gpioIF->pullHigh(enTxClock); gpioIF->pullHigh(enTxData); diff --git a/mission/tmtc/CCSDSHandler.h b/mission/tmtc/CCSDSHandler.h index 1c4fde09..d4cf1da4 100644 --- a/mission/tmtc/CCSDSHandler.h +++ b/mission/tmtc/CCSDSHandler.h @@ -133,9 +133,9 @@ class CCSDSHandler : public SystemObject, gpioId_t enTxClock = gpio::NO_GPIO; gpioId_t enTxData = gpio::NO_GPIO; - // syrlinks must not be transmitting more than 15 minutes (according to datasheet) - // Value can be configured via CTOR argument to allow test setups - const uint32_t TRANSMITTER_TIMEOUT = 900000; // 900000 ms = 15 min + // Syrlinks must not be transmitting more than 15 minutes (according to datasheet) + // Value initialized by constructor argument + const uint32_t transmitterTimeout = 0; // Countdown to disable transmitter after 15 minutes Countdown transmitterCountdown;