serialPort.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <iostream>
9 #include <stdio.h>
10 #include <vector>
11 #include <boost/asio.hpp>
12 #include <boost/function.hpp>
13 #include <boost/enable_shared_from_this.hpp>
14 #include <boost/filesystem.hpp>
15 
16 #ifdef TESTING
17 #include "gtest/gtest.h"
18 #endif
19 
28 class SerialPort: public boost::enable_shared_from_this<SerialPort>
29 {
30 public:
34  enum TypeRec
35  {
36  canonical = 0,
38  };
39 
48  SerialPort(boost::asio::io_service& io, const char* port, int baud_rate, boost::asio::serial_port_base::flow_control::type flow, TypeRec type = nocanonical);
49 
54  explicit SerialPort(boost::asio::io_service& io);
55 
59  virtual ~SerialPort();
60 
61 #ifdef TESTING
62  virtual bool setPort(const char* port, int baud_rate, boost::asio::serial_port_base::flow_control::type flow);
63  virtual const char* getPort() const;
64  virtual bool open(boost::system::error_code& ec);
65  virtual bool isOpened() const;
66  virtual bool isBusy() const;
67  virtual bool isBusyOp() const;
68  virtual void close();
69  virtual bool flush();
70 #else
71 
78  bool setPort(const char* port, int baud_rate, boost::asio::serial_port_base::flow_control::type flow);
79 
84  const char* getPort() const;
85 
92  bool open(boost::system::error_code& ec);
93 
99  bool isOpened() const;
100 
105  bool isBusy() const;
106 
111  bool isBusyOp() const;
112 
116  void close();
117 
122  bool flush();
123 #endif
124 
131  virtual bool send(const char* buffer, int size) = 0;
132 
133 protected:
137  typedef std::vector<char> VC_DATA;
138 
142  boost::asio::serial_port m_serial_port;
143 
147  std::string m_port;
148 
153 
157  boost::asio::serial_port_base::flow_control::type m_flow_control;
158 
163 };
TypeRec
Enum to indicate how serial port must be configured.
Definition: serialPort.h:34
TypeRec m_TypeR
Canonical or non-canonical.
Definition: serialPort.h:162
bool isOpened() const
Method to query if serial port is opened by the current app.
SerialPort(boost::asio::io_service &io, const char *port, int baud_rate, boost::asio::serial_port_base::flow_control::type flow, TypeRec type=nocanonical)
Constructor of the class.
no-canonical
Definition: serialPort.h:37
void close()
Method to close serial port.
virtual bool send(const char *buffer, int size)=0
Method to send data to serial port synchronously.
bool open(boost::system::error_code &ec)
Method to open serial port.
boost::asio::serial_port_base::flow_control::type m_flow_control
UART flow control.
Definition: serialPort.h:157
std::string m_port
Port Path name.
Definition: serialPort.h:147
virtual ~SerialPort()
Destructor of the class.
bool isBusy() const
Method to query if serial port is opened by any app.
std::vector< char > VC_DATA
vector of characters
Definition: serialPort.h:137
bool setPort(const char *port, int baud_rate, boost::asio::serial_port_base::flow_control::type flow)
Method to establish serial port when it is not established in constructor.
bool isBusyOp() const
Method to query if serial port is opened by any app.
const char * getPort() const
Method to take the serial port path.
bool flush()
Method to clear the serial port buffer.
boost::asio::serial_port m_serial_port
Serial Port Object.
Definition: serialPort.h:142
canonical
Definition: serialPort.h:36
Class which manages the logic relative to send/receive messages from Serial Port. This class implemen...
Definition: serialPort.h:28
int m_baud_rate
Baud Rate to communicate.
Definition: serialPort.h:152