-
Notifications
You must be signed in to change notification settings - Fork 7
/
serialocd.h
67 lines (59 loc) · 1.47 KB
/
serialocd.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
#ifndef SERIALOCD_H
#define SERIALOCD_H
#define DEBUG_FRAME_HEADER 0xDB
#include <QObject>
#include <qtcpserver.h>
#include <qtcpsocket.h>
#include <QRegExp>
#include <qserialport.h>
#include <qserialportinfo.h>
#include <qthread.h>
#include <QTime>
#include <qtimer.h>
struct SerialParam {
QString name;
int baudRate;
QSerialPort::DataBits dataBits;
QSerialPort::StopBits stopBits;
QSerialPort::Parity parity;
};
class SerialOCD : public QThread
{
Q_OBJECT
public:
explicit SerialOCD(QObject *parent = nullptr);
QStringList getSerialList();
void startConnect(const SerialParam ¶m,int port);
void stopConnect();
signals:
void onErrorOccur(const QString &info);
void onStopConnect();
private slots:
void slotSerialReadyRead();
void slotSocketReadyRead();
private:
enum SerialCMD{
SerialCMD_ReadMem,
SerialCMD_WriteMem,
SerialCMD_Reset
};
QTcpServer *server;
QTcpSocket *socket;
QSerialPort *port;
QString serialName;
SerialParam serialParam;
int listenPort;
QByteArray serialBuf;
QTimer *waitReadMemTimer;
void run();
bool startServer(int port);
void stopServer();
void sendToClient(const QString &data);
bool startSerial(const SerialParam ¶m);
void stopSerial();
void parseSerial();
void sendSerialReadMem(int addr,int len);
void sendSerialWriteMem(int addr,const QByteArray &data);
void sendSerialReset();
};
#endif // SERIALOCD_H