41 using boost::asio::serial_port_base;
45 write_in_progress_(
false),
46 serial_port_(io_service_),
64 serial_port_.set_option(serial_port_base::character_size(8));
65 serial_port_.set_option(serial_port_base::parity(serial_port_base::parity::none));
66 serial_port_.set_option(serial_port_base::stop_bits(serial_port_base::stop_bits::one));
67 serial_port_.set_option(serial_port_base::flow_control(serial_port_base::flow_control::none));
69 catch (boost::system::system_error e)
109 boost::asio::placeholders::error,
110 boost::asio::placeholders::bytes_transferred));
134 for (
int i = 0; i < len; i++)
136 buffer->
data[i] = bytes[i];
159 boost::asio::buffer(buffer->
dpos(), buffer->
nbytes()),
163 boost::asio::placeholders::error,
164 boost::asio::placeholders::bytes_transferred));
172 std::cerr << error.message() << std::endl;
185 buffer->
pos += bytes_transferred;
186 if (buffer->
nbytes() == 0)
boost::asio::serial_port serial_port_
boost serial port object
void async_read_end(const boost::system::error_code &error, size_t bytes_transferred)
Handler for end of asynchronous read operation.
boost::asio::io_service io_service_
boost io service provider
void async_write(bool check_write_state)
Initialize an asynchronous write operation.
void close()
Stops communication and closes the port.
bool write_in_progress_
flag for whether async_write is already running
void write(const uint8_t *buffer, uint8_t len)
write data
void async_read()
Initiate an asynchronous read operation.
Struct for buffering the contents of a mavlink message.
NMI_API sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
virtual void handle_bytes(const uint8_t *bytes, uint8_t len)=0
void register_listener(SerialListener *const listener)
Register a listener for received bytes.
boost::recursive_mutex mutex_
mutex for threadsafe operation
boost::lock_guard< boost::recursive_mutex > mutex_lock
Convenience typedef for mutex lock.
uint8_t read_buf_raw_[BUFFER_SIZE]
std::list< WriteBuffer * > write_queue_
queue of buffers to be written to the serial port
uint8_t data[BUFFER_SIZE]
Serial(std::__cxx11::string port, int baud_rate)
Instantiates the class and begins communication on the specified serial port.
void open()
Opens the port and begins communication.
const uint8_t * dpos() const
void async_write_end(const boost::system::error_code &error, size_t bytes_transferred)
Handler for end of asynchronous write operation.
SerialListener * listener_
Pointer to byte listener.
boost::thread io_thread_
thread on which the io service runs
~Serial()
Stops communication and closes the serial port before the object is destroyed.