#include "ChaletData.h"
#include <QDataStream>

CChaletMainStatus::CChaletMainStatus()
{
    mInverterRelayStatus = UNKNOWN_STATE;
    mWiFiModuleStatus = UNKNOWN_STATE;
    mCurrentSensorStatus = UNKNOWN_STATE;
    mBatteryCurrent = 0;
    mBatteryVoltage = 0;
    mIsOnline = false;
    mHarakiriDone = false;
    mStatusToggleBit = 0;
    mLostRequestPercentage = 0;
    mChaletTemperature = -100;
    mTotalNbChaletRxCmds = 0;
    mTotalNbMasterTxCmds = 0;
    mMasterLostRequestCount = 0;

}

//int CChaletMainStatus::FromByteArray(QByteArray Data)
//{
////    QDataStream Strm(Data);
////    Strm.device()->seek(0);

////    mInverterRelayStatus >> Data;
////    mWiFiModuleStatus = Data[1];




////    ChaletStatus[0] = GetChaletPowerRelayState();    //Inverter relay status
////                ChaletStatus[1] = GetWiFiSate();    //Wifi Module state
////                ChaletStatus[2] = 3;    //Battery Voltage 1
////                ChaletStatus[3] = 4;    //Battery voltage 2
////                ChaletStatus[4] = 5;    //Battery current 1
////                ChaletStatus[5] = 6;    //Batgtery current 2
////                ChaletStatus[6] = 7;    //Battery SOC
////                ChaletStatus[7] = 8;    //Snatch
////                ChaletStatus[8] = 9;
////                ChaletStatus[9] = 10;

//    return RET_OK;
//}

QByteArray CChaletMainStatus::ToByteArray()
{
    QByteArray Data;
    Data.clear();
    QDataStream Strm(&Data,QIODevice::WriteOnly);

    Strm << mInverterRelayStatus;
    Strm << mWiFiModuleStatus;
    Strm << mBatteryVoltage;
    Strm << mBatteryCurrent;
    Strm << mBatterySOC;
    Strm << mIsOnline;
    Strm << mCurrentSensorStatus;
    Strm << mLostRequestPercentage;
    Strm << mThisStatusDateTime;
    Strm << mLastLoraStatus;
    Strm << mStatusToggleBit;
    Strm << mChaletTemperature;
    Strm << mTotalNbChaletRxCmds;
    Strm << mTotalNbMasterTxCmds;
    Strm << mMasterLostRequestCount;

    return Data;
}
