You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
3.1 KiB
C

1 year ago
#ifndef MYNETMANAGER_H
#define MYNETMANAGER_H
#include <QString>
#include <QAuthenticator>
#include <QNetworkAccessManager>
#include <QTimer>
#include <atomic>
#include <QNetworkReply>
typedef enum
{
NET_DISCONNECT,
NET_CONNECTING = 1,
NET_CONNECTED,
}NetState;
class QNetworkReply;
class MyNetManager : public QObject
{
Q_OBJECT
public:
explicit MyNetManager(QObject *parent = nullptr);
~MyNetManager();
/**
* @brief IP
* @param ip
*/
void SetIp(QString ip);
/**
* @brief
* @param reflectiveTemperature
* @param emissivity
* @param distance
* @return
*/
bool SetTempraturePara(uint16_t reflectiveTemperature,float emissivity,uint16_t distance) ;
/**
* @brief
* @param alert
* @param alarm
* @param alarm_time
* @return
*/
bool SetAlarmPara(uint16_t alert,uint16_t alarm,uint16_t alarm_time);
/**
* @brief
* @return
*/
bool GetPicture();
/**
* @brief
* @return
*/
bool GetRealTimeTemperature();
/**
* @brief
* @return
*/
bool KeepConnect();
/**
* @brief
* @return
*/
bool KeepDisconnect();
/**
* @brief
* @return
*/
bool KeepReconnect();
/**
* @brief
* @return
*/
NetState KeepState();
signals:
/**
* @brief
* @param temp
*/
void sigTempAlarm(float temp);
/**
* @brief
* @param d
*/
void sigCapPicture(QByteArray & d);
/**
* @brief
* @param d
*/
void sigGetTemperature(QByteArray & d);
/**
* @brief
*/
void sigKeepBrokeAlarm();
private slots:
/**
* @brief
*/
void onKeepRelyfinished();
/**
* @brief
*/
void onCapPicRelyfinished();
/**
* @brief
*/
void onGetTemperatureRelyfinished();
/**
* @brief
*/
void onKeepTimerOverProcess();
/**
* @brief
*/
void onKeepConnectTimeOut();
void onKeepConnectFinished(QNetworkReply *reply);
private:
/**
* @brief put
* @param url
* @param bytes
* @return
*/
bool putWait(QString url, QByteArray& bytes);
QNetworkAccessManager *m_pManager;
QNetworkReply *keep;
QTimer *keepTimer; //长连接短线检测定时器默认11秒超时
uint32_t connect_over_time_seconds = 15000;
private:
QString ip;
QByteArray capPicData;
QByteArray responseData;
std::atomic<NetState> keepNetState;
/**
* @brief
*/
void keepRelayOkProcess(QNetworkReply *reply);
/**
* @brief
*/
void keepRelayErrProcess(QNetworkReply *reply);
};
#endif // MYNETMANAGER_H