syncSerialPort.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <boost/chrono.hpp>
9 #include <boost/asio/waitable_timer_service.hpp>
10 #include "serialPort.h"
11 
14 {
18  boost::asio::io_service mIo;
19 
23  explicit InputOutputObject() : mIo() {};
24 };
25 
26 typedef boost::asio::basic_waitable_timer<boost::chrono::steady_clock> steady_timer;
27 
37 {
38 public:
46  SyncSerialPort(const char* port, int baud_rate, boost::asio::serial_port_base::flow_control::type flow, TypeRec type = nocanonical);
47 
52 
56  virtual ~SyncSerialPort();
57 
58 #ifdef TESTING
59  virtual bool send(const char* buffer, int size);
60  virtual size_t readWithTimeout(char* buff, size_t max_length, int timeout_ms);
61 #else
62 
68  bool send(const char* buffer, int size);
69 
77  size_t readWithTimeout(char* buff, size_t max_length, int timeout_ms);
78 #endif
79 
80 private:
88  void read_callback(bool& data_available, std::size_t& bytes_read, const boost::system::error_code& error, std::size_t bytes_transferred);
89 
94  void wait_callback(const boost::system::error_code& error);
95 
96 private:
100  steady_timer m_timer;
101  std::mutex receiveLock;
102 
103 #ifdef TESTING
104 public:
105  FRIEND_TEST(SerialPort_test, Open_Close_Short_Sync_Serial_Port_Non_Canonical_OK);
106  FRIEND_TEST(SerialPort_test, Open_Close_Long_Sync_Serial_Port_Canonical_OK);
107  FRIEND_TEST(SerialPort_test, Open_Sync_Serial_Port_ERROR);
108  FRIEND_TEST(SerialPort_test, Receive_Sync_Serial_Port_OK);
109  FRIEND_TEST(SerialPort_test, Receive_Sync_Serial_Port_ERROR);
110  FRIEND_TEST(SerialPort_test, Send_Sync_Serial_Port_OK);
111  FRIEND_TEST(SerialPort_test, Send_Sync_Serial_Port_ERROR);
112 #endif
113 };
TypeRec
Enum to indicate how serial port must be configured.
Definition: serialPort.h:34
boost::asio::io_service mIo
I/O Service.
Definition: syncSerialPort.h:18
InputOutputObject()
Constructor of the class.
Definition: syncSerialPort.h:23
boost::asio::basic_waitable_timer< boost::chrono::steady_clock > steady_timer
Typedef to use a steady timer.
Definition: dpyMwClient.h:52
boost::asio::basic_waitable_timer< boost::chrono::steady_clock > steady_timer
Typedef to use a steady timer.
Definition: syncSerialPort.h:26
Struct which contains an io service object.
Definition: syncSerialPort.h:13
Class which manages the logic relative to send/receive messages from Synchronous Serial Port...
Definition: syncSerialPort.h:36
Class which manages the logic relative to send/receive messages from Serial Port. This class implemen...
Definition: serialPort.h:28