-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserialserver.h
74 lines (52 loc) · 1.62 KB
/
serialserver.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
73
74
#ifndef SERIALSERVER_H
#define SERIALSERVER_H
#include <QObject>
#include <QList>
#include <QHash>
#include "qtwebsocket/QtWebSocket/QWsServer.h"
#include "qtwebsocket/QtWebSocket/QWsSocket.h"
#include "qextserialenumerator.h"
#include "qextserialport.h"
#include "qt-json/json.h"
using namespace QtJson;
typedef struct {
QString serial;
int baudrate;
StopBitsType stopbits;
ParityType parity;
FlowType flowcontrol;
int databits;
} SerialSettings;
class SerialServer : public QObject
{
Q_OBJECT
public:
SerialServer(int port);
~SerialServer();
signals:
public slots:
void onClientConnection();
void onDataReceived(QString data);
void onPong(quint64 elapsedTime);
void onClientDisconnection();
void onReadyRead();
private:
QVariantMap serialSettingToMap(SerialSettings *settings);
void sendSerialportList(QWsSocket *sock);
void sendSupportedConfigs(QWsSocket *sock);
void sendConfig(QWsSocket *sock, QString serialport);
int connectSerial(QString serial,
int baudrate,
StopBitsType stopbits,
ParityType parity,
FlowType flow,
int databits);
int connectSerial(SerialSettings *settings);
int connectSerial(QMap<QString, QVariant> *settings);
QWsServer *server;
QList<QWsSocket*> clients;
QList<QSet<QString>*> clientPorts;
QHash<QString, QextSerialPort*> serialPorts;
QHash<QString, SerialSettings> serialSettings;
};
#endif // SERIALSERVER_H