From 9385f9024132a5f5edb23284ee70911e7a302110 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 20 Aug 2020 20:36:49 +0200 Subject: [PATCH] some bugfixes and improvements --- container/SimpleRingBuffer.cpp | 10 +++++++++- container/SimpleRingBuffer.h | 11 ++++++++++- globalfunctions/arrayprinter.cpp | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/container/SimpleRingBuffer.cpp b/container/SimpleRingBuffer.cpp index 0b7a175f9..7ed019b25 100644 --- a/container/SimpleRingBuffer.cpp +++ b/container/SimpleRingBuffer.cpp @@ -42,7 +42,6 @@ ReturnValue_t SimpleRingBuffer::getFreeElement(uint8_t **writePointer, excessBytes = amount - amountTillWrap; } *writePointer = &buffer[write]; - incrementWrite(amount); return HasReturnvaluesIF::RETURN_OK; } else { @@ -50,6 +49,14 @@ ReturnValue_t SimpleRingBuffer::getFreeElement(uint8_t **writePointer, } } +void SimpleRingBuffer::confirmBytesWritten(size_t amount) { + if(getExcessBytes() > 0) { + moveExcessBytesToStart(); + } + incrementWrite(amount); + +} + ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data, size_t amount) { if (availableWriteSpace() >= amount or overwriteOld) { @@ -125,3 +132,4 @@ ReturnValue_t SimpleRingBuffer::deleteData(size_t amount, return HasReturnvaluesIF::RETURN_OK; } + diff --git a/container/SimpleRingBuffer.h b/container/SimpleRingBuffer.h index a2cb96ab0..b13e9f2aa 100644 --- a/container/SimpleRingBuffer.h +++ b/container/SimpleRingBuffer.h @@ -56,7 +56,8 @@ public: /** * Returns a pointer to a free element. If the remaining buffer is * not large enough, the data will be written past the actual size - * and the amount of excess bytes will be cached. + * and the amount of excess bytes will be cached. This function + * does not increment the write pointer! * @param writePointer Pointer to a pointer which can be used to write * contiguous blocks into the ring buffer * @param amount @@ -64,6 +65,14 @@ public: */ ReturnValue_t getFreeElement(uint8_t** writePointer, size_t amount); + /** + * This increments the write pointer and also copies the excess bytes + * to the beginning. It should be called if the write operation + * conducted after calling getFreeElement() was performed. + * @return + */ + void confirmBytesWritten(size_t amount); + virtual size_t getExcessBytes() const; /** * Helper functions which moves any excess bytes to the start diff --git a/globalfunctions/arrayprinter.cpp b/globalfunctions/arrayprinter.cpp index 3f02c882e..ca080cc5f 100644 --- a/globalfunctions/arrayprinter.cpp +++ b/globalfunctions/arrayprinter.cpp @@ -27,7 +27,7 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, if(i < size - 1){ sif::info << " , "; if(i > 0 and i % maxCharPerLine == 0) { - sif::info << std::endl; + printf("\n"); } }