Roomba App  1.0
communication.hh
Go to the documentation of this file.
1 
16 #ifndef COMMUNICATION_HH
17 #define COMMUNICATION_HH
18 
19 #include <QSerialPort>
20 
21 #include "frameBuffer.hh"
22 
30 {
31  QSerialPort* _device = nullptr;
33  std::string _deviceName;
34  bool _continue = true;
35  bool _opened = false;
36 
37  public:
43  Communication() = default;
44 
50  ~Communication() = default;
51 
57  void setDeviceName(const std::string& name) { _deviceName = name; }
58 
64  const std::string& getDeviceName() const { return _deviceName; }
65 
71  void setDevice(QSerialPort* device) { _device = device; }
72 
83  bool openSerialPort(const char* serialPort);
84 
89  bool openSerialPort() { return openSerialPort(_deviceName.c_str()); }
90 
97  bool closeSerialPort();
98 
105  bool isOpen() const { return _opened; }
106 
112 
117  const FrameBuffer& getFrameBuffer() const { return _frame; }
118 
125  bool toContinue() const { return _continue; }
126 
130  void endCommunication() { _continue = false; }
131 
135  void receiveData();
136 };
137 
138 #endif /* COMMUNICATION_HH */
The class connecting main application and serial port.
const FrameBuffer & getFrameBuffer() const
Get a unmodifiable frame from the circular buffer.
void receiveData()
Receive line one by one from the serial device in loop until end of communication.
std::string _deviceName
Serial device name.
FrameBuffer & useFrameBuffer()
Get a modifiable frame from the circular buffer.
bool closeSerialPort()
Close the serial port.
QSerialPort * _device
Serial device handle.
bool _continue
Identifier whether to continue communication with serial device.
const std::string & getDeviceName() const
Get the serial device name.
void setDevice(QSerialPort *device)
Set a new handle to the serial device.
void setDeviceName(const std::string &name)
Set the serial device name.
bool openSerialPort()
Wrapper function for opening a serial port.
void endCommunication()
Set the end of communication flag to end communication.
bool isOpen() const
Check if the serial port is open.
~Communication()=default
Destroy the Communication object.
bool toContinue() const
Check wether to continue communication with the serial device.
Communication()=default
Construct a new Communication object.
FrameBuffer _frame
Circular buffer for frames.
bool _opened
Identifier whether serial device is open.
Class implementing circular buffer.
Definition: frameBuffer.hh:29
FrameBuffer class declaration.