WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

buffer.h

Defines a 'first in first out circular' buffer which can be written to and read from by different tasks.
The 'front' of the buffer is where you normally read data from, whereas the 'back' is where you write data to. If the front is equal to the end then there is no data in the buffer.

 

Function

 


bufferInit(cBuffer* buffer, void *start, size_t size)

Before the buffer can be used it must be initialised by this function.
Parameters:
buffer - The cBuffer being initialised
start - The byte array to be used for the buffer
size - The number of bytes in the buffer
For example you could initialise a 30 byte buffer as follows:-
cBuffer myBuffer; // create the buffer
char data[30]; // create the array to be used by the buffer
// Initialise myBuffer to use the data array
bufferInit(&myBuffer,data,sizeof(data));

boolean bufferGet(cBuffer* buffer,uint8_t *rtn)

Gets the next byte from the buffer.
If the buffer is empty this will return FALSE otherwise it will return TRUE and store the next available byte at the address specified.

bufferDump(cBuffer* buffer, size_t numbytes)

Deletes numbytes from the front of the buffer. This is like calling bufferGet(cBuffer* buffer,uint8_t *rtn) numbytes times.

uint8_t bufferGetAtIndex(const cBuffer* buffer, size_t index)

This allows you to look ahead in the buffer and will return the byte at index from the buffer but will leave the byte in the buffer.
If the value of index exceeds the current length of the buffer then the behaviour is undefined.

boolean bufferPut(cBuffer* buffer, uint8_t data)

Writes the byte into the buffer. If this returns FALSE then the buffer was full and the byte was not written.

bufferFlush(cBuffer* buffer)

Removes all data from the buffer

boolean bufferIsFull(const cBuffer* buffer)

Returns TRUE if the buffer is full or FALSE if not.

size_t bufferFreeSpace(const cBuffer* buffer)

Returns the number of bytes available in the buffer.
Note that if the buffer is being read from, or written to, by an interrupt service routine then this number may become out of date almost immediately.

size_t bufferBytesUsed(const cBuffer* buffer)

Return the number of bytes currently stored in the buffer.

boolean bufferQueue(cBuffer* buffer, const void* src, size_t len)

Write a block of bytes to the buffer it has enough capacity to support the whole block.
This will return TRUE if all of the data has been written to the queue or FALSE if the buffer is unchanged because it did not enough space to copy the whole block.

Valid XHTML 1.0 Transitional