This repository has been archived on 2024-06-03. You can view files and clone it, but cannot push or open issues or pull requests.
app/headers/baseconn.h

75 lines
1.6 KiB
C++

#ifndef BASECONN_H
#define BASECONN_H
#include <QObject>
#include <QTcpSocket>
#include <QDataStream>
#include <QDateTime>
#include <QTimer>
#include <QEventLoop>
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)
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'
QString latestReadReply;
private:
QDateTime *date;
//to get the current time
QTcpSocket *socket;
//socket for communication with the extention
signals:
void stateChanged();
//is emitted, when the connection state changes
void progressChanged();
//is emmited during the connection process when the progress changes
void gotReply();
public slots:
Q_INVOKABLE bool connectToHost();
//function to connect to the base station
Q_INVOKABLE QString sendCommand(QString command);
// functions for the qml adapter
QString getIP() const;
void setIP(const QString &ipAdress);
QString getState() const;
void setState(QString newState);
int getProgress() const;
private slots:
void readyRead();
};
#endif // BASECONN_H