-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial.h
68 lines (50 loc) · 1.37 KB
/
serial.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
#ifndef SERIAL_H
#define SERIAL_H
#include <QQueue>
#include <QDebug>
#include <QObject>
#include <QThread>
#include <QByteArray>
#include <QSerialPort>
#include <QSerialPortInfo>
#define delete_obj(x) {delete x; x = nullptr;}
#define delete_arr(x) {delete[] x; x = nullptr;}
#define value_in_range(a, x, b) ((a <= x) && (x <= b))
extern "C" {
#include "../porter/Source/porter.h"
#include "../sheller/Source/sheller.h"
}
class Serial: public QObject
{
Q_OBJECT
bool loopEnabled = true;
QSerialPort serial;
QQueue<QByteArray> receiveQueue;
QQueue<QByteArray> transmitQueue;
uint8_t serialDataLength = 8;
sheller_t *shell = nullptr;
uint8_t shellerStartByte = 0x23;
uint16_t shellerReceiveBuffSize = 128;
uint8_t *receivedMessage = nullptr;
uint8_t *wrapperedDataBuff = nullptr;
porter_t *porter = nullptr;
public:
explicit Serial(QObject *parent = nullptr);
~Serial();
void setName (const QString &name);
void setSpeed(const quint32 &speed);
void setStartByte(const quint8 &startByte);
void setDataLength(const quint32 dataLength);
void setReceiveBufferSize(const quint32 size);
void loop();
bool open();
void close();
QByteArray read();
bool write(const QByteArray &data);
bool isOpen();
bool isEmpty();
signals:
public slots:
void disableLoop();
};
#endif // SERIAL_H