SynchroTime
interface.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Home Office
3 // Nürnberg, Germany
4 // E-Mail: sergej1@email.ua
5 //
6 // Copyright (C) 2020 free Project SynchroTime. All rights reserved.
7 //------------------------------------------------------------------------------
8 // Project SynchroTime: Command-line client for adjust the exact time and
9 // calibrating the RTC DS3231 module via the serial interface (UART).
10 //------------------------------------------------------------------------------
11 #ifndef INTERFACE_H
12 #define INTERFACE_H
13 
14 //------------------------------------------------------------------------------
15 // Includes
16 //------------------------------------------------------------------------------
17 #include <QtSerialPort/QSerialPort>
18 #include <QtSerialPort/QSerialPortInfo>
19 #include <QTimer>
20 #include <QByteArray>
21 #include "base.h"
22 
23 //------------------------------------------------------------------------------
24 // Preprocessor
25 //------------------------------------------------------------------------------
26 
27 //------------------------------------------------------------------------------
28 // Enums
29 //------------------------------------------------------------------------------
30 
31 //------------------------------------------------------------------------------
32 // Types
33 //------------------------------------------------------------------------------
34 // Interval for a time-out in milliseconds
35 #define REBOOT_WAIT 2500
36 
47 class Interface : public Base
48 {
49  Q_OBJECT
50  Q_CLASSINFO("className", "Interface")
51 
52 public:
53  explicit Interface(QObject *parent = 0);
54 
55  // Virtual communicate Methods
56  virtual qint64 writeTheData( const QByteArray & ) = 0;
57  virtual bool readTheData( const quint32, const quint32 bytes = 0U ) = 0;
58  virtual QIODevice *getSocket( void ) = 0;
59  virtual void initSocket( void ) = 0;
60  virtual bool openSocket( void ) = 0;
61  virtual void closeSocket( void ) = 0;
62 
63  void setBlockSize( const quint16 size);
64  quint16 getBlockSize( void ) const;
65  quint32 getReceivedBytes( void ) const;
66  void setTimer( QTimer *timer );
67  QTimer *getTimer( void );
68  void setTimeout( quint32 time );
69  quint32 getTimeout( void ) const;
70  QByteArray& getReceivedData( void );
71 
72 signals:
73  void infoMessage( const QVariant & message ) const;
74  void debugMessage( const QVariant & message ) const;
75  void errorMessage( const QVariant & message ) const;
76 
77 private:
78 
80  QTimer *timer;
81 
83  quint32 timeout;
84 
86  quint16 blockSize;
87 
89  QByteArray receivedData;
90 };
91 
108 class InterfaceSP : public Interface
109 {
110  Q_OBJECT
111  Q_CLASSINFO("className", "InterfaceSP")
112 
113 public:
114  InterfaceSP(QObject *parent = 0);
115  InterfaceSP(QObject *parent, const QString & portName );
116  InterfaceSP(QObject *parent, QSerialPort * port );
117  ~InterfaceSP();
118 
119  // Init Method
120  void init( void );
121 
122  // Init a Serial Port
123  void initSerialPort( void );
124  void searchAllSerialPort( void );
125  bool searchSerialPort( const QString & portName );
126  QStringList availableSerialPorts( void );
127 
128  // Virtual communicate Methods
129  qint64 writeTheData( const QByteArray & data );
130  bool readTheData( const quint32 timewait, const quint32 bytes = 0U );
131  QSerialPort* getSocket( void );
132  void initSocket( void );
133  bool openSocket( void );
134  void closeSocket( void );
135 
136  // Get methods
137  QString getPortName( void ) const;
138  qint32 getPortBaudRate( void ) const;
139  QString getDescription( void ) const;
140  QString getManufacturer( void ) const;
141  QString getSerialNumber( void ) const;
142  quint16 getProductIdentifier( void ) const;
143  QSerialPortInfo getSerialPortInfo( void ) const;
144  QSerialPort* getSerialPort( void );
145 
146 private slots:
147  void handleReadyRead();
148  void handleTimeout();
149  void handleError( QSerialPort::SerialPortError error );
150 
151 private:
152 
154  QSerialPort *serialPort;
155 
164  QSerialPortInfo serialPortInfo;
165 
170 
173 
174 };
175 
176 #endif // INTERFACE_H
virtual bool openSocket(void)=0
Definition: base.h:48
qint64 bytesAvailable
The number of bytes that are in the buffer for reading.
Definition: interface.h:172
void setBlockSize(const quint16 size)
Interface::setBlockSize.
Definition: interface.cpp:64
QTimer * timer
Timer for Time-out method.
Definition: interface.h:80
void debugMessage(const QVariant &message) const
quint16 blockSize
Size of the data block for the communication protocol.
Definition: interface.h:86
qint64 readBufferSize
Definition: interface.h:169
virtual qint64 writeTheData(const QByteArray &)=0
virtual void initSocket(void)=0
QSerialPortInfo serialPortInfo
Definition: interface.h:164
void errorMessage(const QVariant &message) const
quint32 timeout
The timeout interval in milliseconds.
Definition: interface.h:83
void setTimer(QTimer *timer)
Interface::setTimer.
Definition: interface.cpp:104
virtual QIODevice * getSocket(void)=0
Interface The base class Interface provides for the communication between Bootloader Client and Host ...
Definition: interface.h:47
QByteArray & getReceivedData(void)
Interface::getReceivedData.
Definition: interface.cpp:153
QSerialPort * serialPort
Serial Port.
Definition: interface.h:154
quint32 getTimeout(void) const
Interface::getTimeout.
Definition: interface.cpp:141
The class InterfaceSP provides methods to access serial ports.
Definition: interface.h:108
QTimer * getTimer(void)
Interface::getTimer.
Definition: interface.cpp:116
QByteArray receivedData
The received data.
Definition: interface.h:89
virtual void closeSocket(void)=0
void setTimeout(quint32 time)
Interface::setTimeout.
Definition: interface.cpp:129
quint16 getBlockSize(void) const
Interface::getBlockSize.
Definition: interface.cpp:76
void infoMessage(const QVariant &message) const
virtual bool readTheData(const quint32, const quint32 bytes=0U)=0
quint32 getReceivedBytes(void) const
Interface::getReceivedBytes.
Definition: interface.cpp:88
Interface(QObject *parent=0)
Interface::Interface Constructor of the class Interface for creating objects with default values...
Definition: interface.cpp:50