#include <ascii_serial.h>
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. |
The class implements a generic ASCII serial protocol.
Definition at line 51 of file ascii_serial.h.
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.
labust::comms::ASCIISerial::ASCIISerial | ( | ) | [inline] |
Main constructor
Definition at line 60 of file ascii_serial.h.
labust::comms::ASCIISerial::~ASCIISerial | ( | ) | [inline] |
Generic destructor.
Definition at line 66 of file ascii_serial.h.
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.
portName | Serial port name. |
baud | Serial baud rate. |
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.
e | Serial error indicator |
size | Size 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.
callback | The 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.
msg | The string will be forwarded directly to the serial port with a blocking call. |
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.
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.
boost::mutex labust::comms::ASCIISerial::callback_mux [private] |
Muxer for the callback.
Definition at line 165 of file ascii_serial.h.
bool labust::comms::ASCIISerial::connected [private] |
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.