16#include <boost/asio.hpp>
17#include <boost/utility.hpp>
18#include <boost/date_time/posix_time/posix_time.hpp>
19#include <boost/circular_buffer.hpp>
20#include <boost/thread/shared_mutex.hpp>
21#include <condition_variable>
144 void setBaudrate(
unsigned int rate);
145 unsigned int getBaudrate();
147 void setFlowControl(
const boost::asio::serial_port_base::flow_control::type &type);
148 boost::asio::serial_port_base::flow_control::type getFlowControl();
150 void setParity(
const boost::asio::serial_port_base::parity::type &parity);
151 boost::asio::serial_port_base::parity::type getParity();
153 void setStopBits(
const boost::asio::serial_port_base::stop_bits::type &stop_bits);
154 boost::asio::serial_port_base::stop_bits::type getStopBits();
156 void setCharacterSize(
unsigned int character_size);
157 unsigned int getCharacterSize();
161 m_circular_buffer_parser.reset(circular_buffer_parser);
165 return m_circular_buffer_parser;
170 return m_circular_read_buffer;
179 template <
typename T>
180 void waitMoreData(
const std::chrono::steady_clock::time_point &until, T &&callback)
182 std::unique_lock<std::mutex> ul(cond_var_mutex_);
183 cond_var_.wait_until(ul, until, [&]() {
return data_flag_; });
193 template <
typename T>
196 std::unique_lock<std::mutex> ul(cond_var_mutex_);
207 void do_read(
const boost::system::error_code &e,
size_t bytes_transferred);
209 void do_close(
const boost::system::error_code &error);
213 void write_complete(
const boost::system::error_code &error,
214 const size_t bytes_transferred);
A CircularBufferParser class.
Definition: circularbufferparser.hpp:18
A class that represents a serial (COM) port.
Definition: serialport.hpp:40
ByteVector m_read_buffer
Definition: serialport.hpp:227
boost::asio::io_service m_io
Definition: serialport.hpp:221
void waitMoreData(const std::chrono::steady_clock::time_point &until, T &&callback)
Definition: serialport.hpp:180
SerialPort(const SerialPort &other)=delete
Remove copy.
virtual ~SerialPort()
Destructor.
Definition: serialport.hpp:66
void lockedExecute(T &&callback)
Definition: serialport.hpp:194
std::string m_dev
The internal device name.
Definition: serialport.hpp:219
std::shared_ptr< CircularBufferParser > m_circular_buffer_parser
Definition: serialport.hpp:233
ByteVector m_write_buffer
Definition: serialport.hpp:229
std::shared_ptr< std::thread > m_thread_reader
Definition: serialport.hpp:231
void setCircularBufferParser(CircularBufferParser *circular_buffer_parser)
Definition: serialport.hpp:159
std::mutex cond_var_mutex_
Definition: serialport.hpp:241
std::condition_variable cond_var_
Definition: serialport.hpp:239
boost::asio::serial_port m_serial_port
Definition: serialport.hpp:223
std::shared_ptr< CircularBufferParser > getCircularBufferParser() const
Definition: serialport.hpp:163
boost::circular_buffer< unsigned char > & getCircularReadBuffer()
Definition: serialport.hpp:168
const std::string & deviceName() const
Get the device name.
Definition: serialport.hpp:113
boost::circular_buffer< unsigned char > m_circular_read_buffer
Definition: serialport.hpp:225
bool data_flag_
Definition: serialport.hpp:240
SerialPort & operator=(const SerialPort &)=delete
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80