79 lines
2.4 KiB
C++
79 lines
2.4 KiB
C++
#ifndef BUZZERCONN_H
|
|
#define BUZZERCONN_H
|
|
|
|
#include <QObject>
|
|
#include <QObject>
|
|
#include <QDir>
|
|
#include <QUrl>
|
|
#include <QtNetwork>
|
|
#include <QAuthenticator>
|
|
#include <QDesktopServices>
|
|
#include <QDateTime>
|
|
#include <QtDebug>
|
|
|
|
typedef struct strReturnData{
|
|
int status_code;
|
|
QString text;
|
|
}ReturnData_t;
|
|
|
|
class BuzzerConn : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit BuzzerConn(QObject *parent = nullptr, QString ip = "http://192.168.4.1", int port = 80);
|
|
double offset;
|
|
QList<double> latest_offsets;
|
|
double latest_button_pressed;
|
|
double starttime;
|
|
bool connected;
|
|
int connection_progress;
|
|
QString ip;
|
|
int port;
|
|
int errors;
|
|
int errors_until_disconnect = 4;
|
|
|
|
|
|
|
|
private:
|
|
QNetworkAccessManager *networkManager;
|
|
QNetworkAccessManager *reloadNetworkManager;
|
|
QDateTime *date;
|
|
QTcpSocket *socket;
|
|
QStringList pending_commands;
|
|
//QSemaphore dataPipe(1);
|
|
signals:
|
|
|
|
public slots:
|
|
ReturnData_t senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout);
|
|
//function to communicate with the buzzer
|
|
Q_INVOKABLE 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
|
|
Q_INVOKABLE QList<double> gettimes(int timeout);
|
|
//function to get the times from the buzzer as a list with the normal network manager
|
|
Q_INVOKABLE bool connect();
|
|
//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
|
|
Q_INVOKABLE bool buzzer_triggered();
|
|
//function that checks ih the buzzer has been pushed since the last call of this function
|
|
Q_INVOKABLE bool start();
|
|
//syncs the buzzer and the base to make a start possible
|
|
Q_INVOKABLE double get(QString key);
|
|
//can return some things (offset, lastpressed, currtime, connection_progress, connected)
|
|
Q_INVOKABLE QString test();
|
|
Q_INVOKABLE bool refresh();
|
|
//refreshed the connection to the buzzer
|
|
Q_INVOKABLE void appendCommand(QString command);
|
|
|
|
|
|
};
|
|
|
|
#endif // BUZZERCONN_H
|