#include "ChaletInterface.h"

CChaletInterface::CChaletInterface(int Address, CAbstractNetworkCommIF *NetworkInterface, CChaletLoraDevice *DevicePtr):
    CNetworkDevice(ID_CHALET_INTERFACE,Address,NetworkInterface)
{
    mChaletLoraDevice = DevicePtr;
}


int CChaletInterface::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data)
{

    Q_UNUSED(DeviceID)
    Q_UNUSED(DeviceAddress)
    Q_UNUSED(DataSize)
    Q_UNUSED(Data)

    switch(MessageID)
    {
        case CHALET_INTERFACE_ACK:
        {
            break;
        }
        case CHALET_INTERFACE_GENERAL_STATUS_REQUEST:
        {
            QByteArray data = mChaletLoraDevice->GetChaletMainStatus().ToByteArray();
            mNetworkInterfacePtr->SendNetworkMessage(ID_CHALET_INTERFACE,mDeviceAddress,CHALET_INTERFACE_GENERAL_STATUS_RESPONSE,data.size(),data);

            break;
        }
        case CHALET_INTERFACE_AC_POWER_STATE_STATUS_REQUEST:
        {

            break;
        }
        case CHALET_INTERFACE_AC_POWER_SET_STATE_REQUEST:
        {
            qDebug("AC power state set request received from interface");
            if(Data[0] == (char)1)
            {
               mChaletLoraDevice->SendInverterPowerRelayState(true);
            }
            else if(Data[0] == (char)0)
            {
               mChaletLoraDevice->SendInverterPowerRelayState(false);
            }

            break;
        }
        case CHALET_INTERFACE_BATTERY_VOLTAGE_REQUEST:
        {
            break;
        }
        case CHALET_INTERFACE_WIFI_SET_STATE_REQUEST:
        {
            qDebug("WiFi state set request received from interface");
            if(Data[0] == (char)1)
            {
               mChaletLoraDevice->SendWiFiModuleSetState(true);
            }
            else if(Data[0] == (char)0)
            {
               mChaletLoraDevice->SendWiFiModuleSetState(false);
            }
            break;
        }
        case CHALET_INTERFACE_DO_HARAKIRI_REQUEST:
        {
            mChaletLoraDevice->SendDOHarakiri();
            break;
        }
        case CHALET_INTERFACE_REBOOT_CPU_REQUEST:
        {
            mChaletLoraDevice->SendRebootCmd();
            break;
        }
        case CHALET_INTERFACE_GENERAL_STATUS_RESPONSE:
        case CHALET_INTERFACE_AC_POWER_STATE_STATUS_RESPONSE:
        case CHALET_INTERFACE_AC_POWER_SET_STATE_RESPONSE:
        case CHALET_INTERFACE_BATTERY_VOLTAGE_RESPONSE:
        case CHALET_INTERFACE_WIFI_SET_STATE_RESPONSE:
        {
            break;

        }






    }

    return RET_OK;
}
