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..fdc9d626 100644 --- a/container/SharedRingBuffer.h +++ b/container/SharedRingBuffer.h @@ -2,6 +2,7 @@ #define FSFW_CONTAINER_SHAREDRINGBUFFER_H_ #include "SimpleRingBuffer.h" +#include "DynamicFIFO.h" #include "../ipc/MutexIF.h" #include "../objectmanager/SystemObject.h" #include "../timemanager/Clock.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_ */ 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: /** 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; }