#include "LoraModuleInterface.h"
#include "LoraModuleIFMasterCtrlInterface.h"

CLoraModuleInterface::CLoraModuleInterface(CChaletGui *ChaletGuiPtr)
{
    mChaletGui = ChaletGuiPtr;
    mChaletGui->mLoraModuleIFProgramHandle = this;
    mNetworkInterface = new CLoraModuleIFMasterCtrlInterface(this);


    mLoraModulePollTimer = new QTimer();
    mLoraModulePollTimer->setInterval(1000);
    mLoraModulePollTimer->setSingleShot(false);
    connect(mLoraModulePollTimer,&QTimer::timeout,this,&CLoraModuleInterface::LoraModulePollTimerExpired);
}

int CLoraModuleInterface::ConnectedToMaster(bool connected)
{
    if(connected)
    {
        mLoraModulePollTimer->start();
    }
    else
    {
        mLoraModulePollTimer->stop();
    }
    return RET_OK;
}

int CLoraModuleInterface::Start()
{
    mNetworkInterface->ConnectToMasterCtrl();
    return RET_OK;
}

void CLoraModuleInterface::LoraModulePollTimerExpired()
{
    mNetworkInterface->SendMasterCtrlCommand(LORA_MODULE_IF_INTERFACE_GENERAL_STATUS_REQUEST,QByteArray());
}

int CLoraModuleInterface::NewLoraModuleStatusData(CLoraModuleInterfaceStatus Data)
{
    mChaletGui->UpdateLoraModuleStatus(Data);
}
