diff --git a/src/fsfw/container/SharedRingBuffer.cpp b/src/fsfw/container/SharedRingBuffer.cpp index d226a829..bfc04ce1 100644 --- a/src/fsfw/container/SharedRingBuffer.cpp +++ b/src/fsfw/container/SharedRingBuffer.cpp @@ -18,8 +18,8 @@ SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t* buffer, const SharedRingBuffer::~SharedRingBuffer() { MutexFactory::instance()->deleteMutex(mutex); - if (receiveSizesFIFO != nullptr) { - delete (receiveSizesFIFO); + if (receiveSizesFifo != nullptr) { + delete (receiveSizesFifo); } } @@ -36,37 +36,29 @@ MutexIF* SharedRingBuffer::getMutexHandle() const { return mutex; } ReturnValue_t SharedRingBuffer::initialize() { if (fifoDepth > 0) { - receiveSizesFIFO = new DynamicFIFO(fifoDepth); + receiveSizesFifo = new DynamicFIFO(fifoDepth); } return SystemObject::initialize(); } -DynamicFIFO* SharedRingBuffer::getReceiveSizesFIFO() { - if (receiveSizesFIFO == nullptr) { +DynamicFIFO* SharedRingBuffer::getReceiveSizesFifo() { + if (receiveSizesFifo == nullptr) { // Configuration error. #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer" << " was not configured to have sizes FIFO, returning nullptr!" << std::endl; #endif } - return receiveSizesFIFO; + return receiveSizesFifo; } -ReturnValue_t SharedRingBuffer::lockedWrite(const uint8_t* data, size_t dataLen, - MutexIF::TimeoutType lockType, uint32_t waitTimeMs) { - MutexGuard mg(mutex, lockType, waitTimeMs); - if (availableWriteSpace() < dataLen || - (receiveSizesFIFO != nullptr && receiveSizesFIFO->full())) { - return returnvalue::FAILED; - } - // The following two operation should not fail.. - ReturnValue_t result = writeData(data, dataLen); - if (result != returnvalue::OK) { - return result; - } - if (receiveSizesFIFO != nullptr) { - result = receiveSizesFIFO->insert(dataLen); - if (result != returnvalue::OK) { - return result; + + ReturnValue_t SharedRingBuffer::fifoEmpty(bool& empty, MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { + if(receiveSizesFifo == nullptr) { + return returnvalue::FAILED; } - } -} + MutexGuard mg(mutex, timeoutType, timeoutMs); + if(mg.getLockResult() != returnvalue::OK) { + return mg.getLockResult(); + } + return receiveSizesFifo->empty(); + } \ No newline at end of file diff --git a/src/fsfw/container/SharedRingBuffer.h b/src/fsfw/container/SharedRingBuffer.h index 2ac7ee6e..828d58ad 100644 --- a/src/fsfw/container/SharedRingBuffer.h +++ b/src/fsfw/container/SharedRingBuffer.h @@ -78,16 +78,15 @@ class SharedRingBuffer : public SystemObject, public SimpleRingBuffer { * Do not forget to protect access with a lock if required! * @return */ - DynamicFIFO* getReceiveSizesFIFO(); + DynamicFIFO* getReceiveSizesFifo(); - ReturnValue_t lockedWrite(const uint8_t* data, size_t dataLen, MutexIF::TimeoutType lockType, - uint32_t waitTimeMs); + ReturnValue_t fifoEmpty(bool& empty, MutexIF::TimeoutType timeoutType, uint32_t timeoutMs); private: MutexIF* mutex = nullptr; size_t fifoDepth = 0; - DynamicFIFO* receiveSizesFIFO = nullptr; + DynamicFIFO* receiveSizesFifo = nullptr; }; -#endif /* FSFW_CONTAINER_SHAREDRINGBUFFER_H_ */ +#endif /* FSFW_CONTAINER_SHAREDRINGBUFFER_H_ */ \ No newline at end of file