35 #ifndef CREATE_SERIAL_H 36 #define CREATE_SERIAL_H 38 #include <condition_variable> 44 #include <boost/asio.hpp> 51 class Serial :
public std::enable_shared_from_this<Serial> {
54 boost::asio::io_service
io;
56 boost::asio::serial_port
port;
68 void onData(
const boost::system::error_code& e,
const std::size_t& size);
76 std::shared_ptr<Data>
data;
84 void signalHandler(
const boost::system::error_code& error,
int signal_number);
89 Serial(std::shared_ptr<Data> data,
bool install_signal_handler);
91 bool connect(
const std::string& port,
const int& baud = 115200, std::function<
void()> cb = 0);
93 inline bool connected()
const {
return port.is_open(); };
94 bool send(
const uint8_t* bytes,
const uint32_t numBytes);
101 #endif // CREATE_SERIAL_H std::function< void()> callback
uint64_t getTotalPackets() const
boost::asio::serial_port port
virtual void processByte(uint8_t byteRead)=0
bool sendOpcode(const Opcode &code)
std::condition_variable dataReadyCond
std::shared_ptr< Data > data
boost::asio::signal_set signals
Serial(std::shared_ptr< Data > data, bool install_signal_handler)
bool send(const uint8_t *bytes, const uint32_t numBytes)
virtual bool startSensorStream()=0
void signalHandler(const boost::system::error_code &error, int signal_number)
bool connect(const std::string &port, const int &baud=115200, std::function< void()> cb=0)
void onData(const boost::system::error_code &e, const std::size_t &size)
boost::asio::io_service io
uint64_t getNumCorruptPackets() const