From e3cbc4dfd5a854204130df4e0dd3434438b8d795 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 22 Sep 2020 02:12:02 +0200 Subject: [PATCH 1/4] shared ring buffer extended --- container/SharedRingBuffer.cpp | 25 +++++++++++++++++++++++++ container/SharedRingBuffer.h | 16 ++++++++++++++++ timemanager/Countdown.cpp | 13 +++---------- timemanager/Countdown.h | 26 +++++++++++++------------- 4 files changed, 57 insertions(+), 23 deletions(-) diff --git a/container/SharedRingBuffer.cpp b/container/SharedRingBuffer.cpp index 800e75d3..48bdb9df 100644 --- a/container/SharedRingBuffer.cpp +++ b/container/SharedRingBuffer.cpp @@ -9,6 +9,7 @@ SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size, mutex = MutexFactory::instance()->createMutex(); } + SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer, const size_t size, bool overwriteOld, size_t maxExcessBytes): SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld, @@ -16,6 +17,11 @@ SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer, mutex = MutexFactory::instance()->createMutex(); } + +void SharedRingBuffer::setToUseReceiveSizeFIFO(uint32_t fifoDepth) { + this->fifoDepth = fifoDepth; +} + ReturnValue_t SharedRingBuffer::lockRingBufferMutex( MutexIF::TimeoutType timeoutType, dur_millis_t timeout) { return mutex->lockMutex(timeoutType, timeout); @@ -25,6 +31,25 @@ ReturnValue_t SharedRingBuffer::unlockRingBufferMutex() { return mutex->unlockMutex(); } + + MutexIF* SharedRingBuffer::getMutexHandle() const { return mutex; } + +ReturnValue_t SharedRingBuffer::initialize() { + if(fifoDepth > 0) { + receiveSizesFIFO = new DynamicFIFO(fifoDepth); + } + return SystemObject::initialize(); +} + +DynamicFIFO* SharedRingBuffer::getReceiveSizesFIFO() { + if(receiveSizesFIFO == nullptr) { + // Configuration error. + sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer" + << " was not configured to have sizes FIFO, returning nullptr!" + << std::endl; + } + return receiveSizesFIFO; +} diff --git a/container/SharedRingBuffer.h b/container/SharedRingBuffer.h index 80c068b3..c9e0ae3f 100644 --- a/container/SharedRingBuffer.h +++ b/container/SharedRingBuffer.h @@ -1,6 +1,7 @@ #ifndef FSFW_CONTAINER_SHAREDRINGBUFFER_H_ #define FSFW_CONTAINER_SHAREDRINGBUFFER_H_ +#include #include "SimpleRingBuffer.h" #include "../ipc/MutexIF.h" #include "../objectmanager/SystemObject.h" @@ -26,6 +27,8 @@ public: SharedRingBuffer(object_id_t objectId, const size_t size, bool overwriteOld, size_t maxExcessBytes); + void setToUseReceiveSizeFIFO(uint32_t fifoDepth); + /** * This constructor takes an external buffer with the specified size. * @param buffer @@ -59,8 +62,21 @@ public: * @return */ MutexIF* getMutexHandle() const; + + ReturnValue_t initialize() override; + + /** + * If the shared ring buffer was configured to have a sizes FIFO, a handle + * to that FIFO can be retrieved with this function. + * Do not forget to protect access with a lock if required! + * @return + */ + DynamicFIFO* getReceiveSizesFIFO(); private: MutexIF* mutex = nullptr; + + size_t fifoDepth = 0; + DynamicFIFO* receiveSizesFIFO = nullptr; }; diff --git a/timemanager/Countdown.cpp b/timemanager/Countdown.cpp index 95cce029..dfe0e1ec 100644 --- a/timemanager/Countdown.cpp +++ b/timemanager/Countdown.cpp @@ -1,14 +1,7 @@ -/** - * @file Countdown.cpp - * @brief This file defines the Countdown class. - * @date 21.03.2013 - * @author baetz - */ +#include "Countdown.h" - -#include "../timemanager/Countdown.h" - -Countdown::Countdown(uint32_t initialTimeout) : startTime(0), timeout(initialTimeout) { +Countdown::Countdown(uint32_t initialTimeout): startTime(0), + timeout(initialTimeout) { } Countdown::~Countdown() { diff --git a/timemanager/Countdown.h b/timemanager/Countdown.h index 20380e71..f6a41e73 100644 --- a/timemanager/Countdown.h +++ b/timemanager/Countdown.h @@ -1,18 +1,13 @@ +#ifndef FSFW_TIMEMANAGER_COUNTDOWN_H_ +#define FSFW_TIMEMANAGER_COUNTDOWN_H_ + +#include "Clock.h" + /** - * @file Countdown.h * @brief This file defines the Countdown class. - * @date 21.03.2013 * @author baetz */ - -#ifndef COUNTDOWN_H_ -#define COUNTDOWN_H_ - -#include "../timemanager/Clock.h" - class Countdown { -private: - uint32_t startTime; public: uint32_t timeout; Countdown(uint32_t initialTimeout = 0); @@ -23,9 +18,14 @@ public: bool isBusy() const; - ReturnValue_t resetTimer(); //!< Use last set timeout value and restart timer. + //!< Use last set timeout value and restart timer. + ReturnValue_t resetTimer(); - void timeOut(); //!< Make hasTimedOut() return true + //!< Make hasTimedOut() return true + void timeOut(); + +private: + uint32_t startTime = 0; }; -#endif /* COUNTDOWN_H_ */ +#endif /* FSFW_TIMEMANAGER_COUNTDOWN_H_ */ From 5072c09bc030e381df054b5b28ff979804030cff Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 22 Sep 2020 13:59:25 +0200 Subject: [PATCH 2/4] csb hotfix --- tmtcservices/CommandingServiceBase.cpp | 9 ++------- tmtcservices/CommandingServiceBase.h | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/tmtcservices/CommandingServiceBase.cpp b/tmtcservices/CommandingServiceBase.cpp index 3a124f5d..0ebc3944 100644 --- a/tmtcservices/CommandingServiceBase.cpp +++ b/tmtcservices/CommandingServiceBase.cpp @@ -384,10 +384,10 @@ void CommandingServiceBase::acceptPacket(uint8_t reportId, } -void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter iter) { +void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter& iter) { store_address_t address; if (iter->second.fifo.retrieve(&address) != RETURN_OK) { - commandMap.erase(iter->first); + commandMap.erase(&iter); } else { TcPacketStored newPacket(address); startExecution(&newPacket, iter); @@ -411,12 +411,7 @@ void CommandingServiceBase::checkTimeout() { uint32_t uptime; Clock::getUptime(&uptime); CommandMapIter iter; - // TODO: BUG HERE! Problems with comparison operator of iterator. for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) { - if(commandMap.empty()) { - // intermediate solution! - break; - } if ((iter->second.uptimeOfStart + (timeoutSeconds * 1000)) < uptime) { verificationReporter.sendFailureReport( TC_VERIFY::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, diff --git a/tmtcservices/CommandingServiceBase.h b/tmtcservices/CommandingServiceBase.h index 8237415a..252b6943 100644 --- a/tmtcservices/CommandingServiceBase.h +++ b/tmtcservices/CommandingServiceBase.h @@ -316,7 +316,7 @@ protected: ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content, SerializeIF* header = nullptr); - void checkAndExecuteFifo(CommandMapIter iter); + void checkAndExecuteFifo(CommandMapIter& iter); private: /** From 4074ca1b8970e3c3c115f77df15dc87e60f64f59 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 22 Sep 2020 14:22:14 +0200 Subject: [PATCH 3/4] error code improved --- tmtcservices/TmTcBridge.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index 8c2f15e5..8abe37a2 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -95,8 +95,9 @@ ReturnValue_t TmTcBridge::handleTm() { ReturnValue_t status = HasReturnvaluesIF::RETURN_OK; ReturnValue_t result = handleTmQueue(); if(result != RETURN_OK) { - sif::error << "TmTcBridge::handleTm: Error handling TM queue!" - << std::endl; + sif::error << "TmTcBridge::handleTm: Error handling TM queue with " + << "error code 0x" << std::hex << result << std::dec + << "!" << std::endl; status = result; } From c7a6711eecddf89a5bad9ab193f166dfd8e93452 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 22 Sep 2020 16:25:10 +0200 Subject: [PATCH 4/4] include fix --- container/SharedRingBuffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container/SharedRingBuffer.h b/container/SharedRingBuffer.h index c9e0ae3f..fdc9d626 100644 --- a/container/SharedRingBuffer.h +++ b/container/SharedRingBuffer.h @@ -1,8 +1,8 @@ #ifndef FSFW_CONTAINER_SHAREDRINGBUFFER_H_ #define FSFW_CONTAINER_SHAREDRINGBUFFER_H_ -#include #include "SimpleRingBuffer.h" +#include "DynamicFIFO.h" #include "../ipc/MutexIF.h" #include "../objectmanager/SystemObject.h" #include "../timemanager/Clock.h"