asyncSerialPort.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <list>
9 #include "serialPort.h"
10 
20 {
21 private:
25  typedef boost::function<void(const char* s, int n)> F_READ;
26 
27 public:
37  AsyncSerialPort(boost::asio::io_service& io, const char* port, int baud_rate, boost::asio::serial_port_base::flow_control::type flow, const F_READ& f = NULL, TypeRec type = nocanonical);
38 
43  explicit AsyncSerialPort(boost::asio::io_service& io);
44 
49 
55  bool open(boost::system::error_code& ec);
56 
61  void setReadCallback(const F_READ& f);
62 
69  bool send(const char* buffer, int size);
70 
71 public:
76  void handle_send_to(const boost::system::error_code& error);
77 
83  void handle_receive_from(const boost::system::error_code& error, size_t bytes_recvd);
84 
85 protected:
89  typedef std::list<VC_DATA> VC_PAQ;
90 
94  boost::asio::io_service::strand m_strand;
95 
99  F_READ m_fRead;
100 
101  enum
102  {
103  max_length = 1024
104  };
105 
109  char m_data[max_length];
110 
114  VC_PAQ m_vcDataSend;
115 
116 #ifdef TESTING
117 public:
118  FRIEND_TEST(SerialPort_test, Open_Close_Short_Async_Serial_Port_Non_Canonical_OK);
119  FRIEND_TEST(SerialPort_test, Open_Close_Long_Async_Serial_Port_Canonical_OK);
120  FRIEND_TEST(SerialPort_test, Open_Async_Serial_Port_ERROR);
121  FRIEND_TEST(SerialPort_test, Send_Async_Serial_Port_ERROR);
122  FRIEND_TEST(SerialPort_test, Receive_Async_Serial_Port_OK);
123 #endif
124 };
TypeRec
Enum to indicate how serial port must be configured.
Definition: serialPort.h:34
AsyncSerialPort(boost::asio::io_service &io, const char *port, int baud_rate, boost::asio::serial_port_base::flow_control::type flow, const F_READ &f=NULL, TypeRec type=nocanonical)
Constructor of the class.
void handle_receive_from(const boost::system::error_code &error, size_t bytes_recvd)
Function handler to be called when an async read took place.
void handle_send_to(const boost::system::error_code &error)
Function handler to be called when an async sent took place.
no-canonical
Definition: serialPort.h:37
F_READ m_fRead
Function handler to be called.
Definition: asyncSerialPort.h:99
std::list< VC_DATA > VC_PAQ
Definition: asyncSerialPort.h:89
bool open(boost::system::error_code &ec)
Method to open serial port.
char m_data[max_length]
Data buffer.
Definition: asyncSerialPort.h:109
VC_PAQ m_vcDataSend
Array with data buffer.
Definition: asyncSerialPort.h:114
boost::asio::io_service::strand m_strand
Definition: asyncSerialPort.h:94
Class which manages the logic relative to send/receive messages from Asynchronous Serial Port...
Definition: asyncSerialPort.h:19
bool send(const char *buffer, int size)
Method to send data to serial port asynchronously.
void setReadCallback(const F_READ &f)
Method to register the function that reads from the serial port.
~AsyncSerialPort()
Destructor of the class.
Class which manages the logic relative to send/receive messages from Serial Port. This class implemen...
Definition: serialPort.h:28