Byggern
|
This class is an interface for implementing a duplex FIFO stream. More...
#include <stream.h>
Public Member Functions | |
Stream (uint16_t input_stream_size, uint16_t output_stream_size) | |
virtual void | Write (uint8_t *string, uint16_t size) |
virtual uint16_t | Read (uint8_t *string, uint16_t size) |
virtual bool | ReadByte (uint8_t &byte) |
virtual void | WriteByte (uint8_t byte) |
virtual uint8_t | GetAvailableWriteBytes () |
virtual uint8_t | GetAvailableReadBytes () |
virtual bool | CheckInputOverflowFlag () |
virtual bool | CheckOutputOverflowFlag () |
virtual uint16_t | GetInputBufferLength () |
virtual uint16_t | GetOutputBufferLength () |
virtual void | FlushInputBuffer () |
virtual void | FlushOutputBuffer () |
Protected Member Functions | |
virtual uint16_t | ReadFromBuffer (uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty, uint8_t *string, uint16_t &string_size) |
virtual void | WriteToBuffer (uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty, bool &overflow_flag, uint8_t *string, uint16_t &string_size, void(*cb)(Stream *stream)) |
virtual bool | ReadByteFromBuffer (uint8_t &byte, uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty) |
virtual void | WriteByteToBuffer (uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty, bool &overflow_flag, uint8_t &byte, void(*cb)(Stream *stream)) |
virtual void | WriteByteToInputStream (uint8_t &byte) |
virtual bool | ReadByteFromOutputStream (uint8_t &byte) |
virtual void | WriteToInputStream (uint8_t *string, uint16_t size) |
virtual uint16_t | ReadFromOutputStream (uint8_t *string, uint16_t size) |
virtual uint16_t | CalculateLength (uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty) |
virtual void | FlushStream (uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty) |
Protected Attributes | |
uint8_t * | input_buffer |
uint8_t * | output_buffer |
uint16_t | input_buffer_start_index = 0 |
uint16_t | output_buffer_start_index = 0 |
uint16_t | input_buffer_stop_index |
uint16_t | output_buffer_stop_index |
uint16_t | input_buffer_size |
uint16_t | output_buffer_size |
void(* | event_input_buffer_not_empty )(Stream *stream) = nullptr |
void(* | event_output_buffer_not_empty )(Stream *stream) = nullptr |
bool | input_buffer_empty = true |
bool | output_buffer_empty = true |
bool | input_buffer_overflowed = false |
bool | output_buffer_overflowed = false |
This class is an interface for implementing a duplex FIFO stream.
This class implements a duplex FIFO stream using two circular buffers. For instance both an RS232 driver and a CAN driver would need to implement a stream. Inheriting from this interface makes the communication interface for RS232, CAN and other stream based classes/drivers the same, meaning the end user does not need to know whether the data being sent is being sent over a UART or a CAN bus.
As an example you can set up a CAN bus using a CAN driver inheriting from this interface. Then it can be passed to a function expecting to send data to an RS232 class also inheriting from this interface, and it will just work. This interface is in other words written to make it easier to write consistent and driver independent code.
Stream::Stream | ( | uint16_t | input_stream_size, |
uint16_t | output_stream_size | ||
) |
Used to initialize the stream sizes and other data members.
input_stream_size | The maximum size of the input stream. |
output_stream_size | The maximum size of the output stream. |
|
protectedvirtual |
Calculates the length of the valid part of the buffer.
start_index | The start index of the buffer. |
stop_index | The stop index of the buffer. |
|
virtual |
Checks whether or not the input overflow flag has been set. This also clears the flag.
|
virtual |
Checks whether or not the output overflow flag has been set. This also clears the flag.
|
virtual |
Flushes the input buffer
|
virtual |
Flushes the output buffer
|
protectedvirtual |
Flushes the given buffer
buffer | Reference to the buffer which is to be flushed |
start_index | Start index of the buffer which is to be flushed |
stop_index | Stop index of the buffer which is to be flushed |
buffer_size | The size of the given buffer |
empty | Reference to the empty flag of the given buffer |
|
virtual |
Returns the number of bytes available for reading.
|
virtual |
Returns number of bytes not being used in the output buffer (size - length)
|
virtual |
Calculates the length of the readable part of the buffer.
|
virtual |
Calculates the length of the readable part of the buffer.
|
virtual |
Reads data from the input stream into the specified string.
string | String to store read data in. |
size | Size of the string. |
|
virtual |
Reads one byte from the input stream.
|
protectedvirtual |
Reads a byte from the given buffer.
buffer | The buffer to read from. |
start_index | The first valid bit of the buffer. |
stop_index | The last valid bit of the buffer. |
buffer_size | The size of the buffer. |
empty | Flag indicating whether the buffer is empty or completely full. |
|
protectedvirtual |
Reads a byte from the output stream.
|
protectedvirtual |
Reads a string from the given buffer.
buffer | Buffer to read from. |
start_index | The first valid byte of the buffer. |
stop_index | The last valid byte of the buffer. |
buffer_size | The size of the buffer. |
empty | Flag indicating whether the buffer is empty or completely full. |
string | The string to read into. |
string_size | The size of the string. |
|
protectedvirtual |
Reads data from the input stream into the specified string.
string | String to store the read data in. |
size | Size of the string. |
|
virtual |
|
virtual |
Writes one byte to the output stream.
byte | The byte to be written. |
Reimplemented in Socket.
|
protectedvirtual |
Writes a byte to the buffer.
buffer | The buffer to write to. |
start_index | The first valid bit of the buffer. |
stop_index | The last valid bit of the buffer. |
buffer_size | The size of the buffer. |
empty | Flag indicating whether the buffer is empty or completely full. |
overflow_flag | A flag indicating whether or not the buffer has overflowed. |
byte | The byte to be written. |
cb_flag | A flag indicating wether or not the cb function should be called |
cb | Callback function to be called if cb_flag is true |
|
protectedvirtual |
Writes a byte to the input stream.
byte | The byte to be written. |
|
protectedvirtual |
Writes a string to the given buffer.
buffer | Buffer to write to. |
start_index | The first valid byte of the buffer. |
stop_index | The last valid byte of the buffer. |
buffer_size | The size of the buffer. |
empty | Flag indicating whether the buffer is empty or completely full. |
overflow_flag | A flag indicating whether or not the buffer has overflowed. |
string | The string to read from. |
string_size | The size of the string. |
cb_flag | A flag indicating wether or not the cb function should be called |
cb | Callback function to be called if cb_flag is true |
|
protectedvirtual |
Writes the specified data to the output stream.
string | Input data. |
size | Size of the input data. |
|
protected |
Buffer that stores the input stream data.
|
protected |
Flag indicating whether the buffer is empty or full.
|
protected |
Flag indicating whether the input buffer has overflowed or not. This is reset when read by CheckInputOverflowFlag().
|
protected |
The size of the input buffer.
|
protected |
Indicates the first valid data byte in the buffer.
|
protected |
Indicates the last valid data byte in the buffer.
|
protected |
Buffer that stores the output stream data.
|
protected |
Flag indicating whether the buffer is empty or full.
|
protected |
Flag indicating whether the output buffer has overflowed or not. This is reset when read by CheckOutputOverflowFlag().
|
protected |
The size of the output buffer.
|
protected |
Indicates the first valid data byte in the buffer.
|
protected |
Indicates the last valid data byte in the buffer.