#ifndef HOTCAMERAMODULE_H
#define HOTCAMERAMODULE_H

#include <QObject>
#include <QByteArray>
#include <QNetworkAccessManager>

struct HotCameraPara
{
    QString IP_Adress;
    int month;
    int week;
    int day;
    int start_hour;
    int start_minute;
    int end_hour;
    int end_minute;
    int reflectivetemperature ;
    float emissivity ;
    int distant ;
    int alert ;
    int alarm ;
    int alarm_time;
    uint32_t nominal_capacity;
    uint32_t calculated_capacity;
};

class MyNetManager;
class QTimer;
class HotCameraModule : public QObject
{
    Q_OBJECT

    typedef void (*ModuleNetProcess)();

public:
    explicit HotCameraModule(int id, QObject *parent = nullptr);
    virtual ~HotCameraModule();

signals:

    void sigRunTimeChanged();

public slots:

    /**
     * @brief 手动热成像抓图
     */
    void onSavePicture(QByteArray & d);

    /**
     * @brief 获取实时温度解析存储
     */
    void onSaveTemperature(QByteArray & d);

    /**
     * @brief 温度告警处理
     * @param temp
     */
    void onTempAlarm(float temp);

    /**
     * @brief 通信终端告警
     */
    void onConnectBrokeAlarm();


private slots:

    void appTimerProcess();

private:

    //热成像开启或关闭
    int id;
    bool module_enabled = false;
    bool TempAlarmFlag = false;

    MyNetManager * net;
    HotCameraPara para;
    //QString SaveTempPictureFileName;//最近存储的温度图片文件名

    //热成像参数初始化
    void moduleParaReadFromFile(HotCameraPara *p);
    //通知抓图完成
    void notifyCapPictureFinished(const QString &pic_name);

    QTimer *appTimer;

    bool eventParaChangedCheck();
    bool eventCapPictureCheck();
    bool eventGetTemperatureCheck();        //获取实时温度
    bool eventTimeChangeCheck();
    bool eventConnectTimeCheck();
    bool eventConnectBrokeAlarmCheck();
    bool eventConnectSwitch();

    void moduleConnect();
    void modleDisConnect();

    bool removeTempAlarmFile();
};

#endif // HOTCAMERAMODULE_H
