-
Notifications
You must be signed in to change notification settings - Fork 0
/
commobject.h
63 lines (46 loc) · 1.4 KB
/
commobject.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
#ifndef COMMOBJECT_H
#define COMMOBJECT_H
#include <QObject>
#include <QTimer>
#include <QMutex>
#include <QAtomicInteger>
#include "esp01.h"
enum commState {
COMM_UNINIT,
COMM_IDLE,
COMM_COMMAND_PENDING,
};
class CommObject : public QObject
{
Q_OBJECT
public:
explicit CommObject(QObject *parent = nullptr);
virtual ~CommObject();
bool isOpen() const;
bool isPending() const;
bool open(QString portName = QString());
void close();
int atCommand(QString command, QStringList * response = nullptr, int timeout = 5000);
QString getSerialPort() const;
void getVersion(QString & atVersion,
QString & sdkVersion,
QString & compileTime);
int getMode();
void setMode();
signals:
public slots:
void onCommandResponse(bool status, QStringList response);
void onTimeout();
protected:
ESP01 * esp01 = nullptr;
QTimer timer1;
enum commState state = COMM_UNINIT;
QMutex commMutex;
QString serialPort;
QString defaultPort;
bool bCmdResult = false;
QStringList responseArray;
QAtomicInteger<bool> bResponseReceived = false;
QAtomicInteger<bool> bReqTimedOut = false;
};
#endif // COMMOBJECT_H