BufferedSerial Class Reference

#include <Robots/Scorbot/Controller/firmware/mbed/buffered_serial.h>

Inheritance diagram for BufferedSerial:
Inheritance graph
[legend]
Collaboration diagram for BufferedSerial:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 BufferedSerial (PinName tx, PinName rx, uint8_t bufferSize)
bool readable ()
uint8_t availableBytes ()
uint8_t peek ()
uint8_t getc ()
long readLong ()
void readBytes (uint8_t *bytes, size_t requested)
void flushBuffer ()
void writeLong (long data)
template<typename T >
void setFullCallback (T *object, void(T::*member)(void))

Detailed Description

Serial wrapper providing a variable sized RX buffer

Used to store serial data received in a circular buffer in cases where the data stream is larger than the hardware buffer (16 bytes) and the data is not immediately processed. On RXIRQ interrupt (i.e., on receipt of data), new data is retreived from the hardware serial buffer and stored in a circular buffer. If the circular buffer becomes full, no additional data will be added until some of the current data has been removed.

Definition at line 26 of file buffered_serial.h.


Constructor & Destructor Documentation

BufferedSerial::BufferedSerial ( PinName  tx,
PinName  rx,
uint8_t  buffer_size 
)

Constructs a BufferedSerial object

Creates a BufferedSerial with default settings of 9600 8N1. Valid (TX/RX) pairs are {(USBTX/USBRX), (9/10), (13/14), (28/27)}. Valid baud rates are {110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 230400, 460800, 921600}. Maximum buffer size is 256 bytes.

Parameters:
PinName tx The transmit out (TXO) pin for this serial port
PinName rx The receive in (RXI) pin for this serial port
uint8_t buffer_size The desired size of the circular buffer

Definition at line 30 of file buffered_serial.cpp.


Member Function Documentation

uint8_t BufferedSerial::availableBytes (  ) 

Checks how many bytes are ready to be read

Returns:
uint8_t The number of bytes ready to be read

Definition at line 72 of file buffered_serial.cpp.

void BufferedSerial::flushBuffer (  ) 

Flushes the receive buffer

Definition at line 160 of file buffered_serial.cpp.

uint8_t BufferedSerial::getc (  ) 

Reads the next available received byte

Removes a single byte from the front of the circular buffer and returns its value. This method will block until a single byte is available.

Returns:
uint8_t The frontmost byte in the circular receive buffer

Definition at line 105 of file buffered_serial.cpp.

Referenced by readBytes(), and readLong().

uint8_t BufferedSerial::peek (  ) 

Reads the next available byte without removing it from the buffer

Reads a single byte from the front of the circular buffer (without removing it from the buffer and returns its value. This method will block until a single byte is available.

Returns:
uint8_t The frontmost byte in the circular receive buffer

Definition at line 87 of file buffered_serial.cpp.

bool BufferedSerial::readable (  ) 

Checks if there are bytes ready to be read

Returns:
bool true if there are bytes ready to be read false otherwise

Definition at line 61 of file buffered_serial.cpp.

void BufferedSerial::readBytes ( uint8_t *  bytes,
size_t  requested_bytes 
)

Reads requested_bytes bytes into a provided buffer

Reads a specified number of bytes into a caller-supplied buffer. This method will block until requested_bytes bytes are available. The reads are performed byte-wise and will remove the byte from the circular buffer as it is added to the destination buffer.

Parameters:
uint8_t* bytes The pre-allocated destination buffer
size_t requested_bytes The number of bytes to move into the buffer

Definition at line 151 of file buffered_serial.cpp.

References getc().

long BufferedSerial::readLong (  ) 

Reads the next four bytes into a long data type

Reads the next four bytes and stores them into a signed long data type. This method will block until four bytes are available. The first byte is considered to be the MSB, and the last byte is considered to be the LSB.

Returns:
long The front most four bytes in the buffer as a long

Definition at line 129 of file buffered_serial.cpp.

References getc().

template<typename T >
void BufferedSerial::setFullCallback ( T *  object,
void(T::*)(void)  member 
) [inline]

Set a callback function when buffer fills

Set a member function on a particular object to be called once the buffer becomes full. While this this callback function is running, no additional data will be received (even if the callback function immediately empties the buffer). If this becomes an issue, we can add a Timeout to call the callback 1us later, which would allow us to receive data again.

Parameters:
T* object The object on whom the callback should be made
void (T::*member)(void) The member which should be called back

Definition at line 57 of file buffered_serial.h.


The documentation for this class was generated from the following files:
Generated on Sun May 8 08:43:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3