-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerialPort.h
57 lines (42 loc) · 1.3 KB
/
SerialPort.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <boost/asio.hpp>
#include <boost/asio/serial_port.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <string>
typedef boost::shared_ptr<boost::asio::serial_port> serial_port_ptr;
#define SERIAL_PORT_READ_BUF_SIZE 256
class SerialPort
{
protected:
boost::asio::io_service io_service_;
serial_port_ptr port_;
boost::mutex mutex_;
char read_buf_raw_[SERIAL_PORT_READ_BUF_SIZE];
std::string read_buf_str_;
char end_of_line_char_;
private:
SerialPort(const SerialPort &p);
SerialPort &operator=(const SerialPort &p);
volatile double angle; // radians
volatile double x; // decimeters
volatile double y; // decimeters
public:
SerialPort(void);
virtual ~SerialPort(void);
char end_of_line_char() const;
void end_of_line_char(const char &c);
virtual bool start(const char *com_port_name, int baud_rate=9600);
virtual void stop();
int write_some(const std::string &buf);
int write_some(const char *buf, const int &size);
boost::mutex angle_mutex_;
double get_angle();
double get_x();
double get_y();
protected:
virtual void async_read_some_();
virtual void on_receive_(const boost::system::error_code& ec, size_t bytes_transferred);
virtual void on_receive_(const std::string &data);
};