Public Member Functions | Private Types | Private Member Functions | Private Attributes
labust::comms::ASCIISerial Class Reference

#include <ascii_serial.h>

List of all members.

Public Member Functions

 ASCIISerial ()
bool connect (const std::string &port_name, int baud)
void registerCallback (const CallbackType &callback)
bool send (const std::string &msg)
 ~ASCIISerial ()

Private Types

typedef boost::function< void(const
std::string &)> 
CallbackType
 The callback type definition.

Private Member Functions

void onData (const boost::system::error_code &e, std::size_t size)
void startReceive ()
 Receive startup helper function.

Private Attributes

boost::asio::streambuf buffer
 The input buffer.
CallbackType callback
 The message callback.
boost::mutex callback_mux
 Muxer for the callback.
bool connected
 Connection flag.
boost::asio::io_service io
 Hardware i/o service.
boost::asio::serial_port port
 The serial input port.
boost::thread runner
 The main operation thread.

Detailed Description

The class implements a generic ASCII serial protocol.

Definition at line 51 of file ascii_serial.h.


Member Typedef Documentation

typedef boost::function<void(const std::string&)> labust::comms::ASCIISerial::CallbackType [private]

The callback type definition.

Definition at line 54 of file ascii_serial.h.


Constructor & Destructor Documentation

Main constructor

Definition at line 60 of file ascii_serial.h.

Generic destructor.

Definition at line 66 of file ascii_serial.h.


Member Function Documentation

bool labust::comms::ASCIISerial::connect ( const std::string &  port_name,
int  baud 
) [inline]

Internal function for setting up the serial port. NOTE: The function will re-throw an exception on connection errors.

Parameters:
portNameSerial port name.
baudSerial baud rate.
Returns:
True if connection is successful false otherwise

Definition at line 79 of file ascii_serial.h.

void labust::comms::ASCIISerial::onData ( const boost::system::error_code &  e,
std::size_t  size 
) [inline, private]

Handle the incoming serial data stream.

Parameters:
eSerial error indicator
sizeSize of the received message.

Definition at line 131 of file ascii_serial.h.

void labust::comms::ASCIISerial::registerCallback ( const CallbackType callback) [inline]

Register the message handler.

Parameters:
callbackThe callback function that will be called on new data.

Definition at line 109 of file ascii_serial.h.

bool labust::comms::ASCIISerial::send ( const std::string &  msg) [inline]

Send a message to the serial port. NOTE: The message will not be modified, append any delimiters.

Parameters:
msgThe string will be forwarded directly to the serial port with a blocking call.
Returns:
True if message was sent successfully.

Definition at line 119 of file ascii_serial.h.

void labust::comms::ASCIISerial::startReceive ( ) [inline, private]

Receive startup helper function.

Definition at line 144 of file ascii_serial.h.


Member Data Documentation

boost::asio::streambuf labust::comms::ASCIISerial::buffer [private]

The input buffer.

Definition at line 158 of file ascii_serial.h.

The message callback.

Definition at line 163 of file ascii_serial.h.

Muxer for the callback.

Definition at line 165 of file ascii_serial.h.

Connection flag.

Definition at line 160 of file ascii_serial.h.

boost::asio::io_service labust::comms::ASCIISerial::io [private]

Hardware i/o service.

Definition at line 152 of file ascii_serial.h.

boost::asio::serial_port labust::comms::ASCIISerial::port [private]

The serial input port.

Definition at line 154 of file ascii_serial.h.

boost::thread labust::comms::ASCIISerial::runner [private]

The main operation thread.

Definition at line 156 of file ascii_serial.h.


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


snippets
Author(s): Gyula Nagy
autogenerated on Fri Aug 28 2015 11:22:33