Abstract base class for an asynchronous communication port.
More...
#include <comm.h>
|
virtual bool | is_open ()=0 |
|
virtual bool | do_init ()=0 |
|
virtual void | do_close ()=0 |
|
virtual void | do_async_read (const boost::asio::mutable_buffers_1 &buffer, boost::function< void(const boost::system::error_code &, size_t)> handler)=0 |
|
virtual void | do_async_write (const boost::asio::const_buffers_1 &buffer, boost::function< void(const boost::system::error_code &, size_t)> handler)=0 |
|
|
static constexpr size_t | READ_BUFFER_SIZE = 1024 |
|
static constexpr size_t | WRITE_BUFFER_SIZE = 1024 |
|
static DefaultMessageHandler | default_message_handler_ |
|
Abstract base class for an asynchronous communication port.
Definition at line 81 of file comm.h.
◆ Comm()
async_comm::Comm::Comm |
( |
MessageHandler & |
message_handler = default_message_handler_ | ) |
|
Set up asynchronous communication base class.
- Parameters
-
message_handler | Custom message handler, or omit for default handler |
Definition at line 48 of file comm.cpp.
◆ init()
bool async_comm::Comm::init |
( |
| ) |
|
Initializes and opens the port.
- Returns
- True if the port was succesfully initialized
Definition at line 61 of file comm.cpp.
◆ register_listener()
void async_comm::Comm::register_listener |
( |
CommListener & |
listener | ) |
|
Register a listener for when bytes are received on the port.
The listener must inherit from CommListener and implement the receive_callback
function. This is another mechanism for receiving data from the Comm interface without needing to create function pointers. Multiple listeners can be added and all will get the callback
- Parameters
-
listener | Reference to listener |
Definition at line 115 of file comm.cpp.
◆ register_receive_callback()
void async_comm::Comm::register_receive_callback |
( |
std::function< void(const uint8_t *, size_t)> |
fun | ) |
|
Register a callback function for when bytes are received on the port.
The callback function needs to accept two parameters. The first is of type const uint8_t*
, and is a constant pointer to the data buffer. The second is of type size_t
, and specifies the number of bytes available in the buffer.
- Warning
- The data buffer passed to the callback function will be invalid after the callback function exits. If you want to store the data for later processing, you must copy the data to a new buffer rather than storing the pointer to the buffer.
- Parameters
-
fun | Function to call when bytes are received |
Definition at line 110 of file comm.cpp.
◆ send_byte()
void async_comm::Comm::send_byte |
( |
uint8_t |
data | ) |
|
|
inline |
Send a single byte over the port.
- Parameters
-
Definition at line 113 of file comm.h.
◆ send_bytes()
void async_comm::Comm::send_bytes |
( |
const uint8_t * |
src, |
|
|
size_t |
len |
|
) |
| |
Send bytes from a buffer over the port.
- Parameters
-
src | Address of the buffer |
len | Number of bytes to send |
Definition at line 97 of file comm.cpp.
The documentation for this class was generated from the following files: