|
@@ -0,0 +1,74 @@
|
|
|
|
+#ifndef WSSSERVER_H
|
|
|
|
+#define WSSSERVER_H
|
|
|
|
+#include <QObject>
|
|
|
|
+#include <QList>
|
|
|
|
+#include <QByteArray>
|
|
|
|
+#include <QDateTime>
|
|
|
|
+#include <QString>
|
|
|
|
+#include <QTimer>
|
|
|
|
+#include <QFile>
|
|
|
|
+#include <QtNetwork/QSslError>
|
|
|
|
+#include <QJsonDocument>
|
|
|
|
+#include <QJsonObject>
|
|
|
|
+#include <QJsonValue>
|
|
|
|
+#include <QJsonParseError>
|
|
|
|
+#include <QUuid>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
|
|
|
|
+QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
|
|
|
+
|
|
|
|
+class WssClient {
|
|
|
|
+public:
|
|
|
|
+ explicit WssClient(QWebSocket *so=nullptr){
|
|
|
|
+ DeviceId = "";
|
|
|
|
+ m_client = so;
|
|
|
|
+ LoginFlag = false;
|
|
|
|
+ Dir=0;
|
|
|
|
+ NeedComm=1;
|
|
|
|
+ NeedSQL=0;
|
|
|
|
+ NeedErr=0;
|
|
|
|
+ }
|
|
|
|
+ bool LoginFlag ;
|
|
|
|
+ QString DeviceId;
|
|
|
|
+ int Dir;
|
|
|
|
+ int NeedComm;
|
|
|
|
+ int NeedSQL;
|
|
|
|
+ int NeedErr;
|
|
|
|
+ QWebSocket *m_client;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+class WssServer : public QObject
|
|
|
|
+{
|
|
|
|
+ Q_OBJECT
|
|
|
|
+public:
|
|
|
|
+ explicit WssServer(QObject *parent = nullptr);
|
|
|
|
+ ~WssServer();
|
|
|
|
+ void start();
|
|
|
|
+ void subReport(QString DeviceCode, int Dir, bool isSql, bool isErr, QString data);
|
|
|
|
+ QString getPassword(QString psd);
|
|
|
|
+
|
|
|
|
+signals:
|
|
|
|
+ void closed();
|
|
|
|
+ void resetRequest(QString deviceID, int commandType, int parameterType, int pseq);
|
|
|
|
+ void requestRealTimeData(QString deviceID, int commandType, int parameterType, int pn, int queryNumber, int startPoint);
|
|
|
|
+ void requestSetParameters(QString deviceID, int commandType, int parameterType, QString tmp);
|
|
|
|
+ void CommData(QString deviceID, int dir, QString data);
|
|
|
|
+
|
|
|
|
+public slots:
|
|
|
|
+ void onNewConnection();
|
|
|
|
+ void processTextMessage(QString message);
|
|
|
|
+ void socketDisconnected();
|
|
|
|
+ void timeout();
|
|
|
|
+ void onSslErrors(const QList<QSslError> &errors);
|
|
|
|
+
|
|
|
|
+private:
|
|
|
|
+ QWebSocketServer *m_pWebSocketServer;
|
|
|
|
+ QList<WssClient *> clientList;
|
|
|
|
+ QTimer *timer;
|
|
|
|
+ int count;
|
|
|
|
+ int pseq;
|
|
|
|
+ quint16 WssPort;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+#endif // WSSSERVER_H
|