Ring buffer for data loggers and data transmitters.
More...
#include <RingBuf.h>
|
void | begin (F *file) |
|
void | beginISR () |
|
size_t | bytesFree () const |
|
size_t | bytesUsed () const |
|
void | endISR () |
|
size_t | printField (double value, char term, uint8_t prec=2) |
|
size_t | printField (float value, char term, uint8_t prec=2) |
|
template<typename Type > |
size_t | printField (Type value, char term) |
|
template<typename Type > |
bool | read (Type *data) |
|
size_t | read (void *buf, size_t count) |
|
int | readIn (size_t count) |
|
| RingBuf () |
|
bool | sync () |
|
size_t | write (const char *str) |
|
size_t | write (const uint8_t *buf, size_t count) override |
|
size_t | write (const void *buf, size_t count) |
|
template<typename Type > |
size_t | write (Type data) |
|
size_t | write (uint8_t data) final |
|
size_t | writeOut (size_t count) |
|
template<class
F, size_t Size>
class RingBuf< F, Size >
Ring buffer for data loggers and data transmitters.
This ring buffer may be used in ISRs. Use beginISR(), endISR(), write() and print() in the ISR and use writeOut() in non-interrupt code to write data to a file.
Use beginISR(), endISR() and read() in an ISR with readIn() in non-interrupt code to provide file data to an ISR.
◆ RingBuf()
template<class
F , size_t Size>
◆ begin()
template<class
F , size_t Size>
◆ beginISR()
template<class
F , size_t Size>
Disable protection of m_count by noInterrupts()/interrupts.
◆ bytesFree()
template<class
F , size_t Size>
size_t RingBuf< F, Size >::bytesFree |
( |
| ) |
const |
|
inline |
- Returns
- the RingBuf free space in bytes.
◆ bytesUsed()
template<class
F , size_t Size>
size_t RingBuf< F, Size >::bytesUsed |
( |
| ) |
const |
|
inline |
- Returns
- the RingBuf used space in bytes.
◆ endISR()
template<class
F , size_t Size>
Enable protection of m_count by noInterrupts()/interrupts.
◆ printField() [1/3]
template<class
F , size_t Size>
size_t RingBuf< F, Size >::printField |
( |
double |
value, |
|
|
char |
term, |
|
|
uint8_t |
prec = 2 |
|
) |
| |
|
inline |
Print a number followed by a field terminator.
- Parameters
-
[in] | value | The number to be printed. |
[in] | term | The field terminator. Use '\n' for CR LF. |
[in] | prec | Number of digits after decimal point. |
- Returns
- The number of bytes written.
◆ printField() [2/3]
template<class
F , size_t Size>
size_t RingBuf< F, Size >::printField |
( |
float |
value, |
|
|
char |
term, |
|
|
uint8_t |
prec = 2 |
|
) |
| |
|
inline |
Print a number followed by a field terminator.
- Parameters
-
[in] | value | The number to be printed. |
[in] | term | The field terminator. Use '\n' for CR LF. |
[in] | prec | Number of digits after decimal point. |
- Returns
- The number of bytes written or -1 if an error occurs.
◆ printField() [3/3]
template<class
F , size_t Size>
template<typename Type >
size_t RingBuf< F, Size >::printField |
( |
Type |
value, |
|
|
char |
term |
|
) |
| |
|
inline |
Print a number followed by a field terminator.
- Parameters
-
[in] | value | The number to be printed. |
[in] | term | The field terminator. Use '\n' for CR LF. |
- Returns
- The number of bytes written or -1 if an error occurs.
◆ read() [1/2]
template<class
F , size_t Size>
template<typename Type >
bool RingBuf< F, Size >::read |
( |
Type * |
data | ) |
|
|
inline |
Efficient read for small types.
- Parameters
-
[in] | data | location for data item. |
- Returns
- true for success else false.
◆ read() [2/2]
template<class
F , size_t Size>
size_t RingBuf< F, Size >::read |
( |
void * |
buf, |
|
|
size_t |
count |
|
) |
| |
|
inline |
Read data from RingBuf.
- Parameters
-
[out] | buf | destination for data. |
[in] | count | number of bytes to read. |
- Returns
- Actual count of bytes read.
◆ readIn()
template<class
F , size_t Size>
int RingBuf< F, Size >::readIn |
( |
size_t |
count | ) |
|
|
inline |
Read data into the RingBuf from the underlying file. the number of bytes read may be less than count if bytesFree is less than count.
This function must not be used in an ISR.
- Parameters
-
[in] | count | number of bytes to be read. |
- Returns
- Number of bytes actually read or negative for read error.
◆ sync()
template<class
F , size_t Size>
Write all data in the RingBuf to the underlying file.
- Returns
- true for success.
◆ write() [1/5]
template<class
F , size_t Size>
size_t RingBuf< F, Size >::write |
( |
const char * |
str | ) |
|
|
inline |
Copy str to RingBuf.
- Parameters
-
[in] | str | Location of data to be written. |
- Returns
- Number of bytes actually written.
◆ write() [2/5]
template<class
F , size_t Size>
size_t RingBuf< F, Size >::write |
( |
const uint8_t * |
buf, |
|
|
size_t |
count |
|
) |
| |
|
inlineoverride |
Override virtual function in Print for efficiency.
- Parameters
-
[in] | buf | Location of data to be written. |
[in] | count | number of bytes to be written. |
- Returns
- Number of bytes actually written.
◆ write() [3/5]
template<class
F , size_t Size>
size_t RingBuf< F, Size >::write |
( |
const void * |
buf, |
|
|
size_t |
count |
|
) |
| |
|
inline |
Copy data to the RingBuf from buf.
No data will be copied if count is greater than bytesFree. Use getWriteError() to check for print errors and clearWriteError() to clear the error.
- Parameters
-
[in] | buf | Location of data to be written. |
[in] | count | number of bytes to be written. |
- Returns
- Number of bytes actually written.
◆ write() [4/5]
template<class
F , size_t Size>
template<typename Type >
size_t RingBuf< F, Size >::write |
( |
Type |
data | ) |
|
|
inline |
Efficient write for small types.
- Parameters
-
[in] | data | Item to be written. |
- Returns
- Number of bytes actually written.
◆ write() [5/5]
template<class
F , size_t Size>
size_t RingBuf< F, Size >::write |
( |
uint8_t |
data | ) |
|
|
inlinefinal |
Required function for Print.
- Parameters
-
[in] | data | Byte to be written. |
- Returns
- Number of bytes actually written.
Try to force devirtualization by using final and always_inline.
◆ writeOut()
template<class
F , size_t Size>
size_t RingBuf< F, Size >::writeOut |
( |
size_t |
count | ) |
|
|
inline |
Write data to file from RingBuf buffer.
- Parameters
-
[in] | count | number of bytes to be written. |
The number of bytes written may be less than count if bytesUsed is less than count or if an error occurs.
This function must only be used in non-interrupt code.
- Returns
- Number of bytes actually written.
The documentation for this class was generated from the following file: