iodrivers_base
Public Member Functions | Protected Attributes | List of all members
iodrivers_base::Bus Class Reference

#include <Bus.hpp>

Inheritance diagram for iodrivers_base::Bus:
iodrivers_base::Driver

Public Member Functions

 Bus (int max_packet_size, bool extract_last=false)
 
int readPacket (uint8_t *buffer, int buffer_size, int packet_timeout, int first_byte_timeout=-1, Parser *parser=0)
 
void addParser (Parser *parser)
 
void removeParser (Parser *parser)
 
int extractPacket (uint8_t const *buffer, size_t buffer_size) const
 
bool writePacket (uint8_t const *buffer, int buffer_size, int timeout)
 
- Public Member Functions inherited from iodrivers_base::Driver
 Driver (int max_packet_size, bool extract_last=false)
 
virtual ~Driver ()
 
void setReadTimeout (base::Time const &t)
 
base::Time getReadTimeout () const
 
void setWriteTimeout (base::Time const &t)
 
base::Time getWriteTimeout () const
 
void clear ()
 
Status getStatus () const
 
void resetStatus ()
 
Status getStats () const
 
void resetStats ()
 
void setExtractLastPacket (bool flag)
 
bool getExtractLastPacket () const
 
virtual void openURI (std::string const &uri)
 
bool openInet (const char *hostname, int port)
 
void openTCP (std::string const &hostname, int port)
 
void openUDP (std::string const &hostname, int remote_port)
 
void openUDPBidirectional (std::string const &hostname, int out_port, int in_port)
 
bool openSerial (std::string const &port, int baudrate)
 
void openFile (std::string const &path)
 
void setFileDescriptor (int fd, bool auto_close=true)
 
int getFileDescriptor () const
 
bool isValid () const
 
bool setSerialBaudrate (int rate)
 
virtual void close ()
 
bool hasPacket () const
 
int readPacket (uint8_t *buffer, int bufsize)
 
int readPacket (uint8_t *buffer, int bufsize, base::Time const &packet_timeout)
 
int readPacket (uint8_t *buffer, int bufsize, int packet_timeout, int first_byte_timeout=-1)
 
int readPacket (uint8_t *buffer, int bufsize, base::Time const &packet_timeout, base::Time const &first_byte_timeout)
 
bool writePacket (uint8_t const *buffer, int bufsize)
 
bool writePacket (uint8_t const *buffer, int bufsize, int timeout)
 
bool writePacket (uint8_t const *buffer, int bufsize, base::Time const &timeout)
 
void setMainStream (IOStream *stream)
 
IOStreamgetMainStream () const
 
void openTestMode ()
 
void addListener (IOListener *stream)
 
void removeListener (IOListener *stream)
 

Protected Attributes

std::list< Parser * > parser
 
Parsercaller
 
boost::recursive_mutex mutex
 
- Protected Attributes inherited from iodrivers_base::Driver
IOStreamm_stream
 
std::set< IOListener * > m_listeners
 
bool m_auto_close
 
bool m_extract_last
 
base::Time m_read_timeout
 
base::Time m_write_timeout
 
Status m_stats
 

Additional Inherited Members

- Public Types inherited from iodrivers_base::Driver
enum  SERIAL_RATES {
  SERIAL_1200 = 1200, SERIAL_2400 = 2400, SERIAL_4800 = 4800, SERIAL_9600 = 9600,
  SERIAL_19200 = 19200, SERIAL_38400 = 38400, SERIAL_57600 = 57600, SERIAL_115200 = 115200,
  SERIAL_230400 = 230400, SERIAL_460800 = 460800, SERIAL_576000 = 576000, SERIAL_921600 = 921600,
  SERIAL_1152000 = 1152000
}
 
typedef iodrivers_base::Status Statistics
 
- Static Public Member Functions inherited from iodrivers_base::Driver
static int openSerialIO (std::string const &port, int baudrate)
 
static bool setNonBlockingFlag (int fd)
 
static bool setSerialBaudrate (int fd, int rate)
 
static std::string printable_com (std::string const &buffer)
 
static std::string printable_com (uint8_t const *buffer, size_t buffer_size)
 
static std::string printable_com (char const *buffer, size_t buffer_size)
 
static std::string binary_com (std::string const &str)
 
static std::string binary_com (uint8_t const *str, size_t str_size)
 
static std::string binary_com (char const *str, size_t str_size)
 
- Public Attributes inherited from iodrivers_base::Driver
int const MAX_PACKET_SIZE
 
- Static Public Attributes inherited from iodrivers_base::Driver
static const int INVALID_FD = -1
 
- Protected Member Functions inherited from iodrivers_base::Driver
std::pair< int, bool > readPacketInternal (uint8_t *buffer, int bufsize)
 
std::pair< uint8_t const *, int > findPacket (uint8_t const *buffer, int buffer_size) const
 
std::pair< int, bool > extractPacketFromInternalBuffer (uint8_t *buffer, int out_buffer_size)
 
int doPacketExtraction (uint8_t *buffer)
 
void openIPClient (std::string const &hostname, int port, addrinfo const &hints)
 

Detailed Description

Bus Version of the IODriver, to this class can "dock" IOBusHandler or Parser classes If you have Periodic devices you should use IOBusHandler, otherwise Parser, for more Details See the Classes.

Constructor & Destructor Documentation

Bus::Bus ( int  max_packet_size,
bool  extract_last = false 
)

Member Function Documentation

void Bus::addParser ( Parser parser)
int Bus::extractPacket ( uint8_t const *  buffer,
size_t  buffer_size 
) const
virtual

Find a packet into the currently accumulated data.

This method should be provided by subclasses. The buffer argument is the data that has been read until now, and buffer_size how many bytes there is in buffer.

There is four possible cases:

  • there is no packet in the buffer. In that case, return -buffer_size to discard all the data that has been gathered until now.
  • there is the beginning of a packet but it is not starting at the first byte of buffer. In that case, return -position_packet_start, where position_packet_start is the position of the packet in buffer.
  • a packet begins at the first byte of buffer, but the end of the packet is not in buffer yet. Return 0.
  • there is a full packet in buffer, starting at the first buffer byte. Return the packet size. That data will be copied back to the buffer given to readPacket.

Implements iodrivers_base::Driver.

int Bus::readPacket ( uint8_t *  buffer,
int  buffer_size,
int  packet_timeout,
int  first_byte_timeout = -1,
Parser parser = 0 
)
void Bus::removeParser ( Parser parser)
bool Bus::writePacket ( uint8_t const *  buffer,
int  buffer_size,
int  timeout 
)

Member Data Documentation

Parser* iodrivers_base::Bus::caller
protected
boost::recursive_mutex iodrivers_base::Bus::mutex
protected
std::list<Parser*> iodrivers_base::Bus::parser
protected

The documentation for this class was generated from the following files: