2#include "TinyRobotics/utils/Config.h"
3#include "TinyRobotics/utils/Buffers.h"
4#include "TinyRobotics/utils/LoggerClass.h"
8 namespace tinyrobotics {
11
12
13
14
15
16
17
18
26 is_sync_available = syncAvailable;
30 bool read(T &result)
override {
32 return p_buffer->read(result);
39 return p_buffer->readArray(data, lenResult);
44 return p_buffer->writeArray(data, len);
48 bool peek(T &result)
override {
50 return p_buffer->peek(result);
54 bool isFull()
override {
return p_buffer->isFull(); }
59 bool write(T data)
override {
61 return p_buffer->write(data);
65 void reset()
override {
72 if (is_sync_available)
LockGuard guard(p_mutex);
73 return p_buffer->available();
78 if (is_sync_available)
LockGuard guard(p_mutex);
79 return p_buffer->availableForWrite();
84 return p_buffer->address();
88 return p_buffer->size();
94 bool is_sync_available =
false;
Shared functionality of all buffers.
Definition: Buffers.h:26
RAII implementaion using a Mutex: Only a few microcontrollers provide lock guards,...
Definition: LockGuard.h:18
Empty Mutex implementation which does nothing.
Definition: Mutex.h:18
Wrapper class that can turn any Buffer into a thread save implementation.
Definition: SynchronizedBuffer.h:21
bool peek(T &result) override
peeks the actual entry from the buffer
Definition: SynchronizedBuffer.h:48
bool read(T &result) override
reads a single value
Definition: SynchronizedBuffer.h:30
bool write(T data) override
write add an entry to the buffer
Definition: SynchronizedBuffer.h:59
int available() override
provides the number of entries that are available to read
Definition: SynchronizedBuffer.h:71
int availableForWrite() override
provides the number of entries that are available to write
Definition: SynchronizedBuffer.h:77
T * address() override
returns the address of the start of the physical read buffer
Definition: SynchronizedBuffer.h:83
bool isFull() override
checks if the buffer is full
Definition: SynchronizedBuffer.h:54
int writeArray(const T data[], int len)
Fills the buffer data.
Definition: SynchronizedBuffer.h:42
void reset() override
clears the buffer
Definition: SynchronizedBuffer.h:65
int readArray(T data[], int len)
reads multiple values
Definition: SynchronizedBuffer.h:36