#ifndef CCHALETLORADEVICE_H
#define CCHALETLORADEVICE_H
#include <QByteArray>
#include <QObject>
#include <QSerialPort>
#include "LoraNetworkCommIF.h"
#include "NetworkDevice.h"
#include <QTimer>
#include "ChaletData.h"
#include "ChaletNetworkMessage.h"
#include <QList>
#include "BlynkCloudClient.h"

#define LORA_MAGIC_WORD 0xBAADCAFE
#define LORA_NORMAL_REQUEST_TIMEOUT 1000
#define LORA_IMMEDIATE_REQUEST_TIMEOUT 300
#define LORA_RETRY_REQUEST_TIMEOUT 1000
#define LORA_RESPONSE_TIME_TIMEOUT 5000

#define LORA_CHALET_STATUS_POWER_RELAY_MASK 0x01
#define LORA_CHALET_STATUS_CUR_SENSOR_MASK 0x02


class CChaletLoraDevice : public QObject, public CNetworkDevice
{
    Q_OBJECT

public:
    CChaletLoraDevice(int Address,CAbstractNetworkCommIF *NetworkInterface);
    ~CChaletLoraDevice();

    virtual int NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);

    QTimer *mChaletStatusTimer;
    int Start();

    CChaletMainStatus GetChaletMainStatus() {return mChaletMainStatus;}
    CBlynkCloudClient mBlynkInterface;

    CChaletMainStatus mChaletMainStatus;
    QList<CChaletNetworkMessage> mPendingNetworkMsgList;

    int SendWiFiModuleSetState(bool State);
    int SendInverterPowerRelayState(bool State);
    int SendDOHarakiri();
    int SendRebootCmd();
    int SendChaletCommand(int CmdID,int DataSize, QByteArray Data);

    int CmdResponseReceived(int CmdID);
    int ScheduleChaletStatusRequest();
    int ScheduleChaletCommand(int CmdID, int DataSize, QByteArray Data);
    int ScheduleChaletCommand(int CmdID,QByteArray Data);

public slots:
    void CommTimerExpired();

};

#endif // CCHALETLORADEVICE_H
