2018-09-23 17:54:20 +02:00
|
|
|
#ifndef BASECONN_H
|
|
|
|
#define BASECONN_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QTcpSocket>
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QEventLoop>
|
2018-10-04 18:35:29 +02:00
|
|
|
#include <QSemaphore>
|
2018-10-14 18:39:39 +02:00
|
|
|
#include <QThread>
|
|
|
|
#include <QFuture>
|
|
|
|
#include <QtConcurrent/QtConcurrent>
|
|
|
|
#include <string.h>
|
2018-10-04 18:35:29 +02:00
|
|
|
|
|
|
|
#include "headers/appsettings.h"
|
|
|
|
#include "headers/speedtimer.h"
|
2018-09-23 17:54:20 +02:00
|
|
|
|
|
|
|
class BaseConn : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(QString ipAdress WRITE setIP READ getIP)
|
|
|
|
Q_PROPERTY(QString state READ getState NOTIFY stateChanged)
|
|
|
|
Q_PROPERTY(int progress READ getProgress NOTIFY progressChanged)
|
2018-10-04 18:35:29 +02:00
|
|
|
Q_PROPERTY(QStringList connections READ getConnections NOTIFY connectionsChanged)
|
2018-10-14 18:39:39 +02:00
|
|
|
Q_PROPERTY(QString nextRemoteAction READ getNextRemoteAction NOTIFY nextRemoteActionChanged)
|
|
|
|
Q_PROPERTY(float nextRemoteActionDelayProg READ getNextRemoteActionDelayProg NOTIFY nextRemoteActionDelayProgChanged)
|
2018-09-23 17:54:20 +02:00
|
|
|
public:
|
|
|
|
explicit BaseConn(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
// values for the socket connection
|
|
|
|
int connection_progress;
|
|
|
|
QString ip;
|
|
|
|
qint16 port = 3563;
|
|
|
|
int errors;
|
|
|
|
int errors_until_disconnect = 4;
|
|
|
|
|
|
|
|
// the current state
|
|
|
|
QString state;
|
|
|
|
// can be:
|
|
|
|
// - 'disconnected'
|
|
|
|
// - 'connecting'
|
|
|
|
// - 'connected'
|
|
|
|
|
2018-10-04 18:35:29 +02:00
|
|
|
QStringList connections;
|
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
QString latestReadReply;
|
2018-10-04 18:35:29 +02:00
|
|
|
|
|
|
|
//---general status values---//
|
|
|
|
|
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
private:
|
|
|
|
QDateTime *date;
|
|
|
|
//to get the current time
|
|
|
|
|
|
|
|
QTcpSocket *socket;
|
|
|
|
//socket for communication with the extention
|
|
|
|
|
2018-10-04 18:35:29 +02:00
|
|
|
QList<SpeedTimer*> speedTimers;
|
2018-09-23 17:54:20 +02:00
|
|
|
|
2018-10-14 18:39:39 +02:00
|
|
|
QTimer *refreshTimer;
|
|
|
|
QSemaphore remoteSessions;
|
|
|
|
|
|
|
|
int nextConnectionId;
|
|
|
|
|
|
|
|
struct waitingRequest {
|
|
|
|
int id;
|
|
|
|
QEventLoop * loop;
|
|
|
|
QString reply;
|
|
|
|
};
|
|
|
|
|
|
|
|
QList<waitingRequest> waitingRequests;
|
|
|
|
|
|
|
|
QString nextRemoteAction;
|
|
|
|
|
|
|
|
float nextRemoteActionDelayProg;
|
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
signals:
|
|
|
|
void stateChanged();
|
|
|
|
//is emitted, when the connection state changes
|
|
|
|
|
|
|
|
void progressChanged();
|
|
|
|
//is emmited during the connection process when the progress changes
|
|
|
|
|
2018-10-14 18:39:39 +02:00
|
|
|
void gotUnexpectedReply(QString reply);
|
2018-09-23 17:54:20 +02:00
|
|
|
|
2018-10-04 18:35:29 +02:00
|
|
|
void connectionsChanged();
|
|
|
|
|
2018-10-14 18:39:39 +02:00
|
|
|
void connectionSlotReleased();
|
|
|
|
|
|
|
|
void nextRemoteActionChanged();
|
|
|
|
|
|
|
|
void nextRemoteActionDelayProgChanged();
|
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
public slots:
|
|
|
|
|
|
|
|
Q_INVOKABLE bool connectToHost();
|
|
|
|
//function to connect to the base station
|
|
|
|
|
|
|
|
Q_INVOKABLE QString sendCommand(QString command);
|
|
|
|
|
2018-10-04 18:35:29 +02:00
|
|
|
Q_INVOKABLE bool refreshConnections();
|
|
|
|
|
|
|
|
void refreshTimers();
|
|
|
|
|
|
|
|
bool startTimers();
|
|
|
|
|
2018-10-14 18:39:39 +02:00
|
|
|
bool stopTimers(QString type);
|
2018-10-04 18:35:29 +02:00
|
|
|
|
|
|
|
bool resetTimers();
|
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
// functions for the qml adapter
|
|
|
|
QString getIP() const;
|
|
|
|
void setIP(const QString &ipAdress);
|
|
|
|
|
|
|
|
QString getState() const;
|
|
|
|
void setState(QString newState);
|
|
|
|
|
|
|
|
int getProgress() const;
|
|
|
|
|
2018-10-04 18:35:29 +02:00
|
|
|
QStringList getConnections();
|
|
|
|
|
2018-10-14 18:39:39 +02:00
|
|
|
QString getNextRemoteAction();
|
|
|
|
|
|
|
|
float getNextRemoteActionDelayProg();
|
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
private slots:
|
|
|
|
void readyRead();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BASECONN_H
|