app/headers/buzzerconn.h

80 lines
2.4 KiB
C
Raw Normal View History

#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>
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;
2018-07-26 14:54:11 +02:00
double latest_button_pressed;
double starttime;
bool connected;
int connection_progress;
QString ip;
int port;
int errors;
int errors_until_disconnect = 4;
2018-07-26 14:54:11 +02:00
private:
QNetworkAccessManager *networkManager;
QNetworkAccessManager *reloadNetworkManager;
2018-07-26 14:54:11 +02:00
QDateTime *date;
QTcpSocket *socket;
2018-09-09 20:18:00 +02:00
QStringList pending_commands;
//QSemaphore dataPipe(1);
signals:
public slots:
ReturnData_t senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout);
//function to communicate with the buzzer
2018-09-09 20:18:00 +02:00
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
2018-08-02 12:50:55 +02:00
Q_INVOKABLE QList<double> gettimes(int timeout);
//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();
//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();
//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();
//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);
//can return some things (offset, lastpressed, currtime, connection_progress, connected)
2018-07-26 14:54:11 +02:00
Q_INVOKABLE QString test();
Q_INVOKABLE bool refresh();
//refreshed the connection to the buzzer
2018-09-09 20:18:00 +02:00
Q_INVOKABLE void appendCommand(QString command);
};
#endif // BUZZERCONN_H