127 lines
2.7 KiB
C++
127 lines
2.7 KiB
C++
#include "CChalet.h"
|
|
#include "ChaletMasterCtrlInterface.h"
|
|
|
|
CChalet::CChalet(CChaletGui *ChaletGuiPtr)
|
|
{
|
|
mChaletGui = ChaletGuiPtr;
|
|
mChaletGui->mProgramHandle = this;
|
|
mNetworkInterface = new CChaletMasterCtrlInterface(this);
|
|
|
|
|
|
mChaletPollTimer = new QTimer();
|
|
mChaletPollTimer->setInterval(1000);
|
|
mChaletPollTimer->setSingleShot(false);
|
|
connect(mChaletPollTimer,SIGNAL(timeout()),this,SLOT(ChaletPollTimerExpired()));
|
|
|
|
|
|
}
|
|
|
|
CChalet::~CChalet()
|
|
{
|
|
delete mNetworkInterface;
|
|
delete mChaletPollTimer;
|
|
}
|
|
|
|
int CChalet::Start()
|
|
{
|
|
mNetworkInterface->ConnectToMasterCtrl();
|
|
mChaletPollTimer->start();
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
void CChalet::ChaletPollTimerExpired()
|
|
{
|
|
mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_GENERAL_STATUS_REQUEST,QByteArray());
|
|
}
|
|
|
|
int CChalet::ChaletStatusReceived(CChaletMainStatus Status)
|
|
{
|
|
mChaletGui->UpdateChaletStatus(Status);
|
|
|
|
return RET_OK;
|
|
}
|
|
int CChalet::ChaletLogReceived(QByteArray *Log)
|
|
{
|
|
mChaletGui->UpdateChaletLogPlot(Log);
|
|
return RET_OK;
|
|
}
|
|
|
|
int CChalet::ChaletCommActivity()
|
|
{
|
|
return mChaletGui->ChaletCommActivity();
|
|
}
|
|
|
|
int CChalet::WiFiToggleButtonPressed(bool RequestedState)
|
|
{
|
|
|
|
QByteArray WiFiState;
|
|
WiFiState.clear();
|
|
|
|
if(RequestedState)
|
|
{
|
|
WiFiState.append((char)0x01);
|
|
}
|
|
else
|
|
{
|
|
WiFiState.append((char)0x00);
|
|
}
|
|
return mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_WIFI_SET_STATE_REQUEST,WiFiState);
|
|
}
|
|
|
|
int CChalet::InverterToggleButtonPressed(bool RequestedState)
|
|
{
|
|
QByteArray InverterState;
|
|
InverterState.clear();
|
|
|
|
if(RequestedState)
|
|
{
|
|
InverterState.append((char)0x01);
|
|
}
|
|
else
|
|
{
|
|
InverterState.append((char)0x00);
|
|
}
|
|
return mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_AC_POWER_SET_STATE_REQUEST,InverterState);
|
|
}
|
|
|
|
int CChalet::DoHarakiriButtonClicked(bool Verified)
|
|
{
|
|
if(Verified)
|
|
{
|
|
return mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_DO_HARAKIRI_REQUEST,QByteArray());
|
|
}
|
|
|
|
return RET_ERROR;
|
|
}
|
|
|
|
int CChalet::RebootCPUButtonPressed()
|
|
{
|
|
return mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_REBOOT_CPU_REQUEST,QByteArray());
|
|
}
|
|
|
|
int CChalet::ConnectedToMaster(bool connected)
|
|
{
|
|
if(connected)
|
|
{
|
|
mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_GET_TODAYS_DATA_LOG_REQUEST,QByteArray());
|
|
}
|
|
return RET_OK;
|
|
}
|
|
|
|
int CChalet::RequestChaletLogs(QDate StartDate)
|
|
{
|
|
if(StartDate > QDate::currentDate())
|
|
{
|
|
return false;
|
|
}
|
|
QByteArray StartDateData;
|
|
QDataStream Strm(&StartDateData,QIODevice::WriteOnly);
|
|
Strm.device()->seek(0);
|
|
|
|
Strm << StartDate;
|
|
|
|
return mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_GET_DATA_LOG_REQUEST,StartDateData);
|
|
|
|
}
|