Thunderbots Project
Loading...
Searching...
No Matches
boost_uart_communication.h
1#pragma once
2
3#include <boost/asio.hpp>
4#include <boost/function.hpp>
5
6#include "uart_communication.h"
7
8/*
9 * A boost::asio wrapper class that is used to synchronously communicate with a serial
10 * device via UART
11 */
12
14{
15 using IoService = boost::asio::io_service;
16 using SerialPortPtr = std::shared_ptr<boost::asio::serial_port>;
17
18 public:
27 BoostUartCommunication(int baud_rate, std::string device_serial_port);
28
30
31 BoostUartCommunication &operator=(const BoostUartCommunication &) = delete;
32
33 ~BoostUartCommunication() override;
34
35
42 bool operator<<(const std::vector<unsigned char> &write_val);
43
44
52 bool serialWrite(const std::vector<unsigned char> &write_val) override;
53
62 std::vector<unsigned char> serialRead(size_t num_read_bytes) override;
63
69 bool flushSerialPort(FlushType flush_type) override;
70
71 private:
80 void openPort(IoService &io_service, int baud_rate, std::string device_serial_port);
81
85 void closePort();
86
87 SerialPortPtr serial_port;
88 IoService io_service_;
89};
Definition boost_uart_communication.h:14
std::vector< unsigned char > serialRead(size_t num_read_bytes) override
Definition boost_uart_communication.cpp:14
bool operator<<(const std::vector< unsigned char > &write_val)
Definition boost_uart_communication.cpp:62
bool serialWrite(const std::vector< unsigned char > &write_val) override
Definition boost_uart_communication.cpp:23
bool flushSerialPort(FlushType flush_type) override
Definition boost_uart_communication.cpp:30
Definition uart_communication.h:10