some bugfixes and improvements
This commit is contained in:
parent
adbf39166f
commit
9385f90241
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user