SynchroTime
rtc.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 RTC DS3231. 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 RTC_H
12 #define RTC_H
13 
14 //------------------------------------------------------------------------------
15 // Includes
16 //------------------------------------------------------------------------------
17 #include <QObject>
18 #include "serialportsettings.h"
19 
20 //------------------------------------------------------------------------------
21 // Preprocessor
22 //------------------------------------------------------------------------------
23 
24 //------------------------------------------------------------------------------
25 // Enums
26 //------------------------------------------------------------------------------
33 enum class Request : quint8
34 {
35  INFO = 'i',
36  ADJUST = 'a',
37  CALIBR = 'c',
38  RESET = 'r',
39  SETREG = 's',
40  STATUS = 't'
41 };
42 
48 enum class StatusMessages : quint8
49 {
50  STATUS_SUCCESS = 0x00,
51  STATUS_ERROR = 0x01,
54  STATUS_NOT_SUPPORTED = 0x04,
55  STATUS_UNKNOWN_ERROR = 0x05,
56  STATUS_DISCONNECTION = 0x06
57 };
58 
59 //------------------------------------------------------------------------------
60 // Types
61 //------------------------------------------------------------------------------
62 class QSerialPort;
63 class QTimer;
64 
70 class RTC : public QObject
71 {
72  Q_OBJECT
73 
74 public:
75  explicit RTC( const QString &portName, QObject *parent = 0 );
76  explicit RTC( const Settings_t &portSettings, QObject *parent = 0 );
77  ~RTC();
78 
79  // Connection check function.
80  bool isConnected() const;
81  bool isBusy() const;
82 
83 signals:
85  void getRate( const float rate );
86  void getData( const QString &data );
87  void portError( const QString &error );
88 
89 public slots:
90  // Information request slot.
91  void informationRequestSlot();
92  // Adjustment request slot.
93  void adjustmentRequestSlot();
94  // Calibration request slot.
95  void calibrationRequestSlot();
96  // Reset request slot.
97  void resetRequestSlot();
98  // Set register request slot.
99  void setRegisterRequestSlot( const float newValue );
100  // Status request slot.
101  void statusRequestSlot();
102 
103 private slots:
104  void handleError( QSerialPort::SerialPortError error );
105 
106 private:
107  // Open the serial port
108  bool openSerialPort() const;
109  // The connection function.
110  void connectToRTC();
111  // The function send a request to the RTC.
112  const QByteArray sendRequest( Request request, quint8 size = 0, const quint8 *const data = nullptr );
113  // Information request.
114  void informationRequest();
115  // Adjustment request.
116  void adjustmentRequest();
117  // Calibration request.
118  void calibrationRequest();
119  // Reset request.
120  void resetRequest();
121  // Set register request.
122  void setRegisterRequest( const float newValue );
123  // Status request.
124  bool statusRequest();
125 
126  QSerialPort *m_pSerialPort;
128  bool m_isBusy;
131 };
132 
133 #endif // RTC_H
Processing the data failed.
bool m_isBusy
Definition: rtc.h:128
Received parameter(s) are invalid.
Information request.
QSerialPort * m_pSerialPort
Definition: rtc.h:126
Calibration request.
Adjustment request.
Data processing has been successful.
The Settings class.
Definition: serialportsettings.h:43
Set register request.
Reset request.
No confirmation of connection received.
Status request.
float m_correctionFactor
Definition: rtc.h:130
QTimer * m_pTimerCheckConnection
Definition: rtc.h:129
The state of the device is undefined.
bool m_isConnected
Definition: rtc.h:127
StatusMessages
Definition: rtc.h:48
Request
Definition: rtc.h:33
The RTC class.
Definition: rtc.h:70