2018-07-25 00:32:20 +02:00
|
|
|
#ifndef BUZZERCONN_H
|
|
|
|
#define BUZZERCONN_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QtNetwork>
|
|
|
|
#include <QAuthenticator>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QDateTime>
|
2018-08-29 18:33:39 +02:00
|
|
|
#include <QtDebug>
|
2018-07-25 00:32:20 +02:00
|
|
|
|
|
|
|
typedef struct strReturnData{
|
|
|
|
int status_code;
|
|
|
|
QString text;
|
|
|
|
}ReturnData_t;
|
|
|
|
|
|
|
|
class BuzzerConn : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-08-30 16:44:04 +02:00
|
|
|
explicit BuzzerConn(QObject *parent = nullptr, QString ip = "http://192.168.4.1", int port = 80);
|
2018-07-26 20:51:46 +02:00
|
|
|
double offset;
|
2018-07-25 00:32:20 +02:00
|
|
|
QList<double> latest_offsets;
|
2018-07-26 14:54:11 +02:00
|
|
|
double latest_button_pressed;
|
|
|
|
double starttime;
|
2018-07-25 00:32:20 +02:00
|
|
|
bool connected;
|
2018-07-26 20:51:46 +02:00
|
|
|
int connection_progress;
|
2018-08-30 16:44:04 +02:00
|
|
|
QString ip;
|
|
|
|
int port;
|
2018-08-30 17:49:24 +02:00
|
|
|
int errors;
|
|
|
|
int errors_until_disconnect = 4;
|
2018-08-30 16:44:04 +02:00
|
|
|
|
|
|
|
|
2018-07-26 14:54:11 +02:00
|
|
|
|
2018-07-25 00:32:20 +02:00
|
|
|
private:
|
|
|
|
QNetworkAccessManager *networkManager;
|
2018-08-02 18:10:08 +02:00
|
|
|
QNetworkAccessManager *reloadNetworkManager;
|
2018-07-26 14:54:11 +02:00
|
|
|
QDateTime *date;
|
2018-08-30 16:44:04 +02:00
|
|
|
QTcpSocket *socket;
|
2018-07-25 00:32:20 +02:00
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
public slots:
|
2018-08-02 18:10:08 +02:00
|
|
|
ReturnData_t senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout);
|
|
|
|
//function to communicate with the buzzer
|
2018-08-30 17:49:24 +02:00
|
|
|
signed long sendCommand(QString command, int timeout);
|
|
|
|
//function to send commands to the sensor
|
|
|
|
//Can be:
|
|
|
|
//command - return
|
|
|
|
//GET_TIMESTAMP - timestamp of the sensor
|
|
|
|
//GET_LASTPRESSED - timestamp of the sensor when it was triggered the last time
|
|
|
|
//
|
|
|
|
//error codes:
|
|
|
|
//(-1) : timeout
|
|
|
|
//(-2) : invalid data was recieved
|
2018-08-02 12:50:55 +02:00
|
|
|
Q_INVOKABLE QList<double> gettimes(int timeout);
|
2018-08-02 18:10:08 +02:00
|
|
|
//function to get the times from the buzzer as a list with the normal network manager
|
2018-07-26 14:54:11 +02:00
|
|
|
Q_INVOKABLE bool connect();
|
2018-08-02 18:10:08 +02:00
|
|
|
//function to connect to buzzer
|
|
|
|
Q_INVOKABLE bool calcoffset(QList<double> times);
|
|
|
|
//function that calculates the average time offset between the buzzer and the device
|
2018-07-26 14:54:11 +02:00
|
|
|
Q_INVOKABLE bool buzzer_triggered();
|
2018-08-02 18:10:08 +02:00
|
|
|
//function that checks ih the buzzer has been pushed since the last call of this function
|
2018-07-26 14:54:11 +02:00
|
|
|
Q_INVOKABLE bool start();
|
2018-08-02 18:10:08 +02:00
|
|
|
//syncs the buzzer and the base to make a start possible
|
2018-07-26 14:54:11 +02:00
|
|
|
Q_INVOKABLE double get(QString key);
|
2018-08-02 18:10:08 +02:00
|
|
|
//can return some things (offset, lastpressed, currtime, connection_progress, connected)
|
2018-07-26 14:54:11 +02:00
|
|
|
Q_INVOKABLE QString test();
|
2018-08-02 18:10:08 +02:00
|
|
|
Q_INVOKABLE bool refresh();
|
|
|
|
//refreshed the connection to the buzzer
|
2018-08-30 16:44:04 +02:00
|
|
|
|
|
|
|
|
2018-07-25 00:32:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BUZZERCONN_H
|