19 #ifndef FF_SERIAL_SERIAL_H_
20 #define FF_SERIAL_SERIAL_H_
23 #include <boost/asio.hpp>
24 #include <boost/bind.hpp>
25 #include <boost/thread.hpp>
26 #include <boost/utility.hpp>
27 #include <boost/function.hpp>
35 #define MAX_BUFFER_SIZE 512
36 #define MAX_READ_ERRORS 10
37 #define READ_TIMEOUT_MS 1000
52 class Serial :
private boost::noncopyable {
67 bool Open(
const std::string& port_name,
unsigned int baud_rate,
68 boost::asio::serial_port_base::parity option_parity =
69 boost::asio::serial_port_base::parity(
70 boost::asio::serial_port_base::parity::none),
71 boost::asio::serial_port_base::character_size option_csize =
72 boost::asio::serial_port_base::character_size(8),
73 boost::asio::serial_port_base::flow_control option_flow =
74 boost::asio::serial_port_base::flow_control(
75 boost::asio::serial_port_base::flow_control::none),
76 boost::asio::serial_port_base::stop_bits option_stop =
77 boost::asio::serial_port_base::stop_bits(
78 boost::asio::serial_port_base::stop_bits::one));
87 size_t Write(
const uint8_t *data,
size_t size);
97 void ReadStop(
const boost::system::error_code&
error,
size_t bytes);
103 boost::asio::io_service asio_;
104 boost::asio::serial_port port_;
105 boost::asio::deadline_timer timer_;
106 boost::thread thread_;
111 uint32_t timeout_ms_;
117 #endif // FF_SERIAL_SERIAL_H_