forked from dihonglongxi/FactoryTestApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portmanager.h
72 lines (49 loc) · 1.8 KB
/
portmanager.h
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
#ifndef PORTMANAGER_H
#define PORTMANAGER_H
#include <QSerialPort>
#include <QSharedPointer>
#include "SlipProtocol.h"
#include "Logger.h"
class PortManager : public QObject
{
Q_OBJECT
public:
enum Mode {idleMode, railMode, slipMode};
explicit PortManager(QObject *parent = nullptr);
void setPort(const QString &name,
qint32 baudRate = QSerialPort::Baud115200,
QSerialPort::DataBits dataBits = QSerialPort::Data8,
QSerialPort::Parity parity = QSerialPort::NoParity,
QSerialPort::StopBits stopBits = QSerialPort::OneStop,
QSerialPort::FlowControl flowControl = QSerialPort::NoFlowControl);
void setLogger(const QSharedPointer<Logger>& logger) {_logger = logger;}
public slots:
void open();
void close();
QStringList slipCommand(int channel, const QByteArray &frame);
QStringList railtestCommand(int channel, const QByteArray &cmd);
void setTimeout(int value) {_timeout = value;}
signals:
void responseRecieved(QStringList response);
private slots:
void onSerialPortReadyRead();
void onSerialPortErrorOccurred(QSerialPort::SerialPortError errorCode);
void sendFrame(int channel, const QByteArray &frame) Q_DECL_NOTHROW;
void processResponsePacket();
void decodeFrame() Q_DECL_NOTHROW;
void onSlipPacketReceived(quint8 channel, QByteArray frame) Q_DECL_NOTHROW;
void decodeRailtestReply(const QByteArray &reply);
void waitCommandFinished();
private:
QSharedPointer<Logger> _logger;
QSerialPort _serial;
Mode _mode = idleMode;
bool _frameStarted;
QByteArray _recvBuffer;
QByteArray _syncCommand;
QVariantList _syncReplies;
QStringList _response;
int _timeout = 10000;
QByteArray _railReply[4];
};
#endif // PORTMANAGER_H