-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqs_serialthread.h
More file actions
112 lines (90 loc) · 2.37 KB
/
qs_serialthread.h
File metadata and controls
112 lines (90 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* @file qs_serialthread.h
* @author Fernando Morani
* @date 30 Mar 2022
* @brief Header file for the serial thread class
*
*/
#ifndef QS_SerialThread_H
#define QS_SerialThread_H
#include <QMutex>
#include <QThread>
#include <QWaitCondition>
#include <QSerialPort>
#include <QTime>
#include <QDebug>
#include "qs_serialdefine.h"
class QS_SerialThread : public QThread
{
Q_OBJECT
public:
explicit QS_SerialThread(QObject *parent = nullptr);
~QS_SerialThread() override;
/*!
* \brief getBaudRate: Get Baud rate from the array
* \param _index
* \return
*/
uint32_t getBaudRate(int _index);
/*!
* \brief setBaudRate: Set the baudRate for the seril port
* \param _baudRate
* \return: false if setting is wrong
*/
bool setBaudRate(uint32_t _baudRate);
/*!
* \brief setPort: Set the reference port for the serial connection
* \param _comPort
* \return: false if setting is wrong
*/
bool setPort(QString _comPort);
/*!
* \brief openSerial: Open serial connection
* \return: true if the port is open
*/
bool openSerial();
/*!
* \brief closeSerial: Close serial connection
* \return
*/
bool closeSerial();
/*!
* \brief writeToSerial
* \return: true if write to serial send the packet
*/
bool writeToSerial();
/*!
* \brief getReadTimeout
* \return Return read timeout for any commands
*/
int getReadTimeout(){return m_waitTimeout;}
/*!
* \brief setReadTimeout
* \param _timeout
*/
void setReadTimeout(int _timeout){m_waitTimeout = _timeout;}
QByteArray m_responseData;
QByteArray m_requestData;
uint8_t m_SerialBuffer[QS_SERIAL_MAX_BUF_LEN ];
uint16_t m_BytesToWrite;
signals:
void response(const QString &s);
void error(const QString &s);
void timeout(const QString &s);
private:
void run() override;
QString m_portName;
QString m_request;
int m_waitTimeout = 0;
int m_waitWriteTimeout = 0;
bool m_quit = false;
bool m_enableRead = false;
QSerialPort m_serial;
uint32_t m_BaudeRatesAvail[QS_SERIAL_BAUD_END] = {
QS_SERIAL_BAUD_2400,QS_SERIAL_BAUD_4800,
QS_SERIAL_BAUD_9600,QS_SERIAL_BAUD_19200,
QS_SERIAL_BAUD_38400,QS_SERIAL_BAUD_57600,
QS_SERIAL_BAUD_115200
};
};
#endif // QS_SerialThread_H