WIP: somethings wrong.. #19
@ -2,12 +2,14 @@
|
|||||||
#define FRAMEWORK_CONTAINER_RINGBUFFERBASE_H_
|
#define FRAMEWORK_CONTAINER_RINGBUFFERBASE_H_
|
||||||
|
|
||||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
template<uint8_t N_READ_PTRS = 1>
|
template<uint8_t N_READ_PTRS = 1>
|
||||||
class RingBufferBase {
|
class RingBufferBase {
|
||||||
public:
|
public:
|
||||||
RingBufferBase(uint32_t startAddress, uint32_t size, bool overwriteOld) :
|
RingBufferBase(uint32_t startAddress, const size_t size, bool overwriteOld) :
|
||||||
start(startAddress), write(startAddress), size(size), overwriteOld(overwriteOld) {
|
start(startAddress), write(startAddress), size(size),
|
||||||
|
overwriteOld(overwriteOld) {
|
||||||
for (uint8_t count = 0; count < N_READ_PTRS; count++) {
|
for (uint8_t count = 0; count < N_READ_PTRS; count++) {
|
||||||
read[count] = startAddress;
|
read[count] = startAddress;
|
||||||
}
|
}
|
||||||
@ -83,7 +85,7 @@ protected:
|
|||||||
const uint32_t start;
|
const uint32_t start;
|
||||||
uint32_t write;
|
uint32_t write;
|
||||||
uint32_t read[N_READ_PTRS];
|
uint32_t read[N_READ_PTRS];
|
||||||
const uint32_t size;
|
const size_t size;
|
||||||
const bool overwriteOld;
|
const bool overwriteOld;
|
||||||
void incrementWrite(uint32_t amount) {
|
void incrementWrite(uint32_t amount) {
|
||||||
write = ((write + amount - start) % size) + start;
|
write = ((write + amount - start) % size) + start;
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
#include <framework/container/SimpleRingBuffer.h>
|
#include <framework/container/SimpleRingBuffer.h>
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
|
|
||||||
SimpleRingBuffer::SimpleRingBuffer(uint32_t size, bool overwriteOld) :
|
SimpleRingBuffer::SimpleRingBuffer(const size_t size, bool overwriteOld) :
|
||||||
RingBufferBase<>(0, size, overwriteOld), buffer(NULL) {
|
RingBufferBase<>(0, size, overwriteOld) {
|
||||||
buffer = new uint8_t[size];
|
buffer = new uint8_t[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SimpleRingBuffer::SimpleRingBuffer(uint8_t *buffer, const size_t size,
|
||||||
|
bool overwriteOld):
|
||||||
|
RingBufferBase<>(0, size, overwriteOld), buffer(buffer) {}
|
||||||
|
|
||||||
|
|
||||||
SimpleRingBuffer::~SimpleRingBuffer() {
|
SimpleRingBuffer::~SimpleRingBuffer() {
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
}
|
}
|
||||||
@ -66,3 +71,4 @@ ReturnValue_t SimpleRingBuffer::deleteData(uint32_t amount,
|
|||||||
incrementRead(amount, READ_PTR);
|
incrementRead(amount, READ_PTR);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,13 +5,29 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Circular buffer implementation, useful for buffering into data streams.
|
* @brief Circular buffer implementation, useful for buffering
|
||||||
* @details Note that the deleteData() has to be called to increment the read pointer
|
* into data streams.
|
||||||
|
* @details
|
||||||
|
* Note that the deleteData() has to be called to increment the read pointer.
|
||||||
|
* This class allocated dynamically, so
|
||||||
* @ingroup containers
|
* @ingroup containers
|
||||||
*/
|
*/
|
||||||
class SimpleRingBuffer: public RingBufferBase<> {
|
class SimpleRingBuffer: public RingBufferBase<> {
|
||||||
public:
|
public:
|
||||||
SimpleRingBuffer(uint32_t size, bool overwriteOld);
|
/**
|
||||||
|
* This constructor allocates a new internal buffer with the supplied size.
|
||||||
|
* @param size
|
||||||
|
* @param overwriteOld
|
||||||
|
*/
|
||||||
|
SimpleRingBuffer(const size_t size, bool overwriteOld);
|
||||||
|
/**
|
||||||
|
* This constructor takes an external buffer with the specified size.
|
||||||
|
* @param buffer
|
||||||
|
* @param size
|
||||||
|
* @param overwriteOld
|
||||||
|
*/
|
||||||
|
SimpleRingBuffer(uint8_t* buffer, const size_t size, bool overwriteOld);
|
||||||
|
|
||||||
virtual ~SimpleRingBuffer();
|
virtual ~SimpleRingBuffer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,7 +46,8 @@ public:
|
|||||||
* @param trueAmount
|
* @param trueAmount
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ReturnValue_t readData(uint8_t* data, uint32_t amount, bool readRemaining = false, uint32_t* trueAmount = NULL);
|
ReturnValue_t readData(uint8_t* data, uint32_t amount,
|
||||||
|
bool readRemaining = false, uint32_t* trueAmount = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete data starting by incrementing read pointer
|
* Delete data starting by incrementing read pointer
|
||||||
@ -39,11 +56,12 @@ public:
|
|||||||
* @param trueAmount
|
* @param trueAmount
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ReturnValue_t deleteData(uint32_t amount, bool deleteRemaining = false, uint32_t* trueAmount = NULL);
|
ReturnValue_t deleteData(uint32_t amount, bool deleteRemaining = false,
|
||||||
|
uint32_t* trueAmount = nullptr);
|
||||||
private:
|
private:
|
||||||
// static const uint8_t TEMP_READ_PTR = 1;
|
// static const uint8_t TEMP_READ_PTR = 1;
|
||||||
static const uint8_t READ_PTR = 0;
|
static const uint8_t READ_PTR = 0;
|
||||||
uint8_t* buffer;
|
uint8_t* buffer = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_ */
|
#endif /* FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user