|
|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
#include "GlobalDefine.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CChaletLoraDevice::CChaletLoraDevice(int Address, CAbstractNetworkCommIF *NetworkInterface):
|
|
|
|
|
CNetworkDevice(ID_CHALET_DEVICE,Address,NetworkInterface)
|
|
|
|
|
{
|
|
|
|
@@ -40,10 +41,15 @@ int CChaletLoraDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, i
|
|
|
|
|
case CHALET_GENERAL_STATUS_RESPONSE:
|
|
|
|
|
{
|
|
|
|
|
float temp;
|
|
|
|
|
qint16 temp2;
|
|
|
|
|
qDebug("Chalet Status RX");
|
|
|
|
|
char VoltageArray[4];
|
|
|
|
|
char SolarPanelCurrentArray[2];
|
|
|
|
|
char BatterySOCArray[2];
|
|
|
|
|
|
|
|
|
|
mChaletMainStatus.mInverterRelayStatus = ((Data[0] & LORA_CHALET_STATUS_POWER_RELAY_MASK) != 0);
|
|
|
|
|
mChaletMainStatus.mCurrentSensorStatus = ((Data[0] & LORA_CHALET_STATUS_CUR_SENSOR_MASK) != 0);
|
|
|
|
|
|
|
|
|
|
mChaletMainStatus.mInverterRelayStatus = Data[0];
|
|
|
|
|
mChaletMainStatus.mWiFiModuleStatus = Data[1];
|
|
|
|
|
VoltageArray[0] = Data[2];
|
|
|
|
|
VoltageArray[1] = Data[3];
|
|
|
|
@@ -51,8 +57,30 @@ int CChaletLoraDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, i
|
|
|
|
|
VoltageArray[3] = Data[5];
|
|
|
|
|
memcpy(&temp,VoltageArray,4);
|
|
|
|
|
mChaletMainStatus.mBatteryVoltage = temp;
|
|
|
|
|
|
|
|
|
|
SolarPanelCurrentArray[0] = Data[6];
|
|
|
|
|
SolarPanelCurrentArray[1] = Data[7];
|
|
|
|
|
memcpy(&temp2,SolarPanelCurrentArray,2);
|
|
|
|
|
mChaletMainStatus.mBatteryCurrent = temp2;
|
|
|
|
|
|
|
|
|
|
BatterySOCArray[0] = Data[8];
|
|
|
|
|
BatterySOCArray[1] = Data[9];
|
|
|
|
|
memcpy(&temp2,BatterySOCArray,2);
|
|
|
|
|
mChaletMainStatus.mBatterySOC = temp2;
|
|
|
|
|
|
|
|
|
|
mChaletMainStatus.mStatusToggleBit = !mChaletMainStatus.mStatusToggleBit;
|
|
|
|
|
|
|
|
|
|
CmdResponseReceived(CHALET_GENERAL_STATUS_REQUEST);
|
|
|
|
|
qDebug("voltage: %f",mChaletMainStatus.mBatteryVoltage);
|
|
|
|
|
qDebug("Current: %d",mChaletMainStatus.mBatteryCurrent);
|
|
|
|
|
qDebug("SOC: %d",mChaletMainStatus.mBatterySOC);
|
|
|
|
|
|
|
|
|
|
mBlynkInterface.UpdateChaletCurrent(mChaletMainStatus.mBatteryCurrent);
|
|
|
|
|
mBlynkInterface.UpdateChaletVoltage(mChaletMainStatus.mBatteryVoltage);
|
|
|
|
|
// mBlynkInterface.UpdateChaletWifiStatus((int)mChaletMainStatus.mInverterRelayStatus);
|
|
|
|
|
mBlynkInterface.UpdateChaletInverterStatus((int)mChaletMainStatus.mInverterRelayStatus);
|
|
|
|
|
mBlynkInterface.UpdateChaletStatusLed(((int)mChaletMainStatus.mStatusToggleBit)*255);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CHALET_AC_POWER_STATE_STATUS_RESPONSE:
|
|
|
|
@@ -134,21 +162,27 @@ void CChaletLoraDevice::CommTimerExpired()
|
|
|
|
|
{
|
|
|
|
|
qDebug("Empty command list in comm timer ");
|
|
|
|
|
ScheduleChaletStatusRequest();
|
|
|
|
|
mChaletStatusTimer->start(1000);
|
|
|
|
|
mChaletStatusTimer->start(LORA_NORMAL_REQUEST_TIMEOUT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(mPendingNetworkMsgList.first().PendingResponse == true)
|
|
|
|
|
{
|
|
|
|
|
//The current command is still waiting for a response. Check how many times we tried to send it
|
|
|
|
|
qDebug("Cmd 0x%x timetout... retrying",mPendingNetworkMsgList.first().mMessageID);
|
|
|
|
|
if(mPendingNetworkMsgList.first().ResendCounter >= 5)
|
|
|
|
|
if(mPendingNetworkMsgList.first().ResendCounter >= 2)
|
|
|
|
|
{
|
|
|
|
|
//TODO: manage this. Module offline?
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mPendingNetworkMsgList[0].ResendCounter++;
|
|
|
|
|
//After 2 retries, declare module offline, clear the send buffer and start sending status requests...
|
|
|
|
|
if(mChaletMainStatus.mIsOnline == true)
|
|
|
|
|
{
|
|
|
|
|
mChaletMainStatus.mIsOnline = false;
|
|
|
|
|
qDebug("Chalet LORA interface Offline. Switching to status requests...");
|
|
|
|
|
|
|
|
|
|
mPendingNetworkMsgList.clear();
|
|
|
|
|
ScheduleChaletStatusRequest();
|
|
|
|
|
mPendingNetworkMsgList.first().ResendCounter = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mPendingNetworkMsgList[0].ResendCounter++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qDebug("Sending chalet request 0x%x",mPendingNetworkMsgList.at(0).mMessageID);
|
|
|
|
@@ -164,7 +198,7 @@ void CChaletLoraDevice::CommTimerExpired()
|
|
|
|
|
ScheduleChaletStatusRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mChaletStatusTimer->start(5000); //we should get an answer within 5 seconds.
|
|
|
|
|
mChaletStatusTimer->start(LORA_RESPONSE_TIME_TIMEOUT); //we should get an answer within 5 seconds.
|
|
|
|
|
// SendChaletCommand(CHALET_GENERAL_STATUS_REQUEST,0,QByteArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -181,8 +215,7 @@ int CChaletLoraDevice::SendWiFiModuleSetState(bool State)
|
|
|
|
|
Data[0] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScheduleChaletCommand(CHALET_WIFI_SET_STATE_REQUEST,1,Data);
|
|
|
|
|
return RET_OK;
|
|
|
|
|
return ScheduleChaletCommand(CHALET_WIFI_SET_STATE_REQUEST,1,Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CChaletLoraDevice::SendInverterPowerRelayState(bool State)
|
|
|
|
@@ -198,9 +231,7 @@ int CChaletLoraDevice::SendInverterPowerRelayState(bool State)
|
|
|
|
|
Data[0] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScheduleChaletCommand(CHALET_AC_POWER_SET_STATE_REQUEST,Data);
|
|
|
|
|
// SendChaletCommand(CHALET_AC_POWER_SET_STATE_REQUEST,1,Data);
|
|
|
|
|
return RET_OK;
|
|
|
|
|
return ScheduleChaletCommand(CHALET_AC_POWER_SET_STATE_REQUEST,Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CChaletLoraDevice::SendDOHarakiri()
|
|
|
|
@@ -212,7 +243,7 @@ int CChaletLoraDevice::SendDOHarakiri()
|
|
|
|
|
Data.append(0xBE);
|
|
|
|
|
Data.append(0xEF);
|
|
|
|
|
|
|
|
|
|
ScheduleChaletCommand(CHALET_DO_HARAKIRI_REQUEST,Data);
|
|
|
|
|
return ScheduleChaletCommand(CHALET_DO_HARAKIRI_REQUEST,Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CChaletLoraDevice::SendRebootCmd()
|
|
|
|
@@ -224,7 +255,7 @@ int CChaletLoraDevice::SendRebootCmd()
|
|
|
|
|
Data.append(0xCA);
|
|
|
|
|
Data.append(0xFE);
|
|
|
|
|
|
|
|
|
|
ScheduleChaletCommand(CHALET_REBOOT_CPU_REQUEST,Data);
|
|
|
|
|
return ScheduleChaletCommand(CHALET_REBOOT_CPU_REQUEST,Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CChaletLoraDevice::SendChaletCommand(int CmdID, int DataSize, QByteArray Data)
|
|
|
|
@@ -237,6 +268,12 @@ int CChaletLoraDevice::CmdResponseReceived(int CmdID)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(CmdID)
|
|
|
|
|
|
|
|
|
|
if(mChaletMainStatus.mIsOnline == false)
|
|
|
|
|
{
|
|
|
|
|
mChaletMainStatus.mIsOnline = true;
|
|
|
|
|
qDebug("Chalet is ONLINE!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qDebug("Chalet response received from cmd: 0x%x",CmdID);
|
|
|
|
|
if(mPendingNetworkMsgList.size() == 0)
|
|
|
|
|
{
|
|
|
|
@@ -266,20 +303,46 @@ int CChaletLoraDevice::CmdResponseReceived(int CmdID)
|
|
|
|
|
|
|
|
|
|
int CChaletLoraDevice::ScheduleChaletStatusRequest()
|
|
|
|
|
{
|
|
|
|
|
ScheduleChaletCommand(CHALET_GENERAL_STATUS_REQUEST,0,QByteArray());
|
|
|
|
|
return ScheduleChaletCommand(CHALET_GENERAL_STATUS_REQUEST,0,QByteArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CChaletLoraDevice::ScheduleChaletCommand(int CmdID, int DataSize, QByteArray Data)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(DataSize)
|
|
|
|
|
CChaletNetworkMessage Command(CmdID,Data);
|
|
|
|
|
mPendingNetworkMsgList.append(Command);
|
|
|
|
|
|
|
|
|
|
// if(mChaletMainStatus.mIsOnline == false)
|
|
|
|
|
// {
|
|
|
|
|
// return RET_ERROR;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// CChaletNetworkMessage Command(CmdID,Data);
|
|
|
|
|
// mPendingNetworkMsgList.append(Command);
|
|
|
|
|
|
|
|
|
|
ScheduleChaletCommand(CmdID,Data);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CChaletLoraDevice::ScheduleChaletCommand(int CmdID, QByteArray Data)
|
|
|
|
|
{
|
|
|
|
|
// if(mChaletMainStatus.mIsOnline == false)
|
|
|
|
|
// {
|
|
|
|
|
// return RET_ERROR;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if(mChaletMainStatus.mIsOnline == true && CmdID != CHALET_GENERAL_STATUS_REQUEST) //When chalet is online, send command right away if we are not waiting for an answer.
|
|
|
|
|
{
|
|
|
|
|
//if we are in nominal conditions (waiting to send a status request). Cancel the status request and send the command right away.
|
|
|
|
|
if((mPendingNetworkMsgList.size() == 1) &&
|
|
|
|
|
(mPendingNetworkMsgList.at(0).mMessageID == CHALET_GENERAL_STATUS_REQUEST) &&
|
|
|
|
|
mPendingNetworkMsgList.at(0).PendingResponse == false)
|
|
|
|
|
{
|
|
|
|
|
mPendingNetworkMsgList.clear();
|
|
|
|
|
mChaletStatusTimer->start(10); //Allow some time to breathe
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CChaletNetworkMessage Command(CmdID,Data);
|
|
|
|
|
mPendingNetworkMsgList.append(Command);
|
|
|
|
|
|
|
|
|
|