Chalet LORA

This commit is contained in:
2020-09-13 13:50:05 -04:00
parent 5d4ef09df6
commit 940287a97e
19 changed files with 3801 additions and 73 deletions
+91
View File
@@ -0,0 +1,91 @@
#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::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());
}
+39
View File
@@ -0,0 +1,39 @@
#ifndef CCHALET_H
#define CCHALET_H
#include "ChaletGui.h"
#include <QObject>
#include <QTimer>
#include "ChaletData.h"
class CChaletMasterCtrlInterface;
class CChalet : public QObject
{
Q_OBJECT
public:
explicit CChalet(CChaletGui *ChaletGuiPtr);
~CChalet();
CChaletGui *mChaletGui;
CChaletMasterCtrlInterface *mNetworkInterface;
QTimer *mChaletPollTimer;
int Start();
int ChaletStatusReceived(CChaletMainStatus Status);
int WiFiToggleButtonPressed(bool RequestedState);
int InverterToggleButtonPressed(bool RequestedState);
int DoHarakiriButtonClicked(bool Verified);
int RebootCPUButtonPressed();
signals:
public slots:
void ChaletPollTimerExpired();
};
#endif // CCHALET_H
-14
View File
@@ -1,14 +0,0 @@
#include "Chalet.h"
#include "ChaletMasterCtrlInterface.h"
CChalet::CChalet(CChaletGui *ChaletGui)
{
mChaletGui = ChaletGui;
mChaletGui->mProgramHandle = this;
mNetworkInterface = new CChaletMasterCtrlInterface(this);
}
CChalet::~CChalet()
{
delete mNetworkInterface;
}
-22
View File
@@ -1,22 +0,0 @@
#ifndef CCHALET_H
#define CCHALET_H
#include <QObject>
#include "ChaletGui.h"
class CChaletMasterCtrlInterface;
class CChalet : public QObject
{
Q_OBJECT
public:
explicit CChalet(CChaletGui *ChaletGui);
~CChalet();
CChaletMasterCtrlInterface *mNetworkInterface;
CChaletGui *mChaletGui;
signals:
};
#endif // CCHALET_H
+49
View File
@@ -0,0 +1,49 @@
#include "ChaletData.h"
#include <QDataStream>
CChaletMainStatus::CChaletMainStatus()
{
mInverterRelayStatus = CHALET_POWER_RELAY_UNKNOWN_STATE;
mWiFiModuleStatus = WIFI_UNKNOWN_STATE;
mBatteryCurrent = 0;
mBatteryVoltage = 0;
}
int CChaletMainStatus::FromByteArray(QByteArray Data)
{
QDataStream Strm(Data);
Strm.device()->seek(0);
Strm >> mInverterRelayStatus;
Strm >> mWiFiModuleStatus;
Strm >> mBatteryVoltage;
Strm >> mBatteryCurrent;
Strm >> mBatterySOC;
// 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.resize(10);
// Data.append(mInverterRelayStatus);
// Data.append(mWiFiModuleStatus);
// return Data;
//}
+49
View File
@@ -0,0 +1,49 @@
#ifndef CHALETDATA_H
#define CHALETDATA_H
#include <QString>
#include "GlobalDefine.h"
#include <QDateTime>
#include <QByteArray>
enum eWiFiState
{
WIFI_MODULE_OFF_STATE = 0,
WIFI_CONNECTED_STATE,
WIFI_DISCONNECTED_STATE,
WIFI_INIT_ERROR_STATE,
WIFI_UNKNOWN_STATE
};
enum eChaletPowerRelayState
{
CHALET_POWER_RELAY_OFF_STATE = 0,
CHALET_POWER_RELAY_ON_STATE,
CHALET_POWER_RELAY_UNKNOWN_STATE
};
class CChaletMainStatus
{
public:
// QByteArray ToByteArray();
int FromByteArray(QByteArray Data);
CChaletMainStatus();
quint8 mInverterRelayStatus;
quint8 mWiFiModuleStatus;
float mBatteryVoltage;
float mBatteryCurrent;
float mBatterySOC;
bool mHarakiriDone;
bool mIsOnline;
QDateTime mLastLoraStatus;
};
#endif // CHALETDATA_H
+112 -1
View File
@@ -1,15 +1,126 @@
#include "ChaletGui.h"
#include "ui_ChaletGui.h"
#include "Chalet.h"
#include "CChalet.h"
CChaletGui::CChaletGui(QWidget *parent) :
QWidget(parent),
ui(new Ui::CChaletGui)
{
ui->setupUi(this);
ui->mDoHarakiriButton->setEnabled(false);
connect(ui->mWiFiModuleONBtn,SIGNAL(clicked()),this,SLOT(WiFiONButtonClicked()));
connect(ui->mWiFiModuleOFFBtn,SIGNAL(clicked(bool)),this,SLOT(WiFiOFFButtonClicked()));
connect(ui->mInverterRelayOFFBtn,SIGNAL(clicked()),this,SLOT(InverterPowerOFFButtonClicked()));
connect(ui->mInverterRelayONBtn,SIGNAL(clicked(bool)),this,SLOT(InverterPowerONButtonClicked()));
connect(ui->mRebootCPUBtn,SIGNAL(clicked(bool)),this,SLOT(RebootCPUButtonClicked()));
connect(ui->mDoHarakiriButton,SIGNAL(clicked(bool)),this,SLOT(DoHarakiriButtonClicked()));
connect(ui->mEnableHarakiriChkBx,SIGNAL(clicked(bool)),this,SLOT(EnableHarakiriClicked(bool)));
}
CChaletGui::~CChaletGui()
{
delete ui;
}
int CChaletGui::UpdateChaletStatus(CChaletMainStatus Status)
{
QString text;
switch(Status.mWiFiModuleStatus)
{
case WIFI_CONNECTED_STATE:
{
text = "Connected";
break;
}
case WIFI_MODULE_OFF_STATE:
{
text = "Module OFF";
break;
}
case WIFI_DISCONNECTED_STATE:
{
text = "Disconnected";
break;
}
case WIFI_INIT_ERROR_STATE:
{
text = "Init. Error";
break;
}
case WIFI_UNKNOWN_STATE:
default:
{
text = "WiFi: Unknown state";
break;
}
}
ui->mWiFiModuleStatusLabel->setText(text);
switch(Status.mInverterRelayStatus)
{
case CHALET_POWER_RELAY_OFF_STATE:
{
text = "OFF";
break;
}
case CHALET_POWER_RELAY_ON_STATE:
{
text = "ON";
break;
}
case CHALET_POWER_RELAY_UNKNOWN_STATE:
default:
{
text = "Unknown";
break;
}
}
ui->mInverterRlyStatusLabel->setText(text);
QString Voltage = QString("Battery Voltage: %1").arg(Status.mBatteryVoltage);
ui->mBatteryVoltageLabel->setText(Voltage);
return RET_OK;
}
void CChaletGui::WiFiONButtonClicked()
{
mProgramHandle->WiFiToggleButtonPressed(true);
}
void CChaletGui::WiFiOFFButtonClicked()
{
mProgramHandle->WiFiToggleButtonPressed(false);
}
void CChaletGui::InverterPowerONButtonClicked()
{
mProgramHandle->InverterToggleButtonPressed(true);
}
void CChaletGui::InverterPowerOFFButtonClicked()
{
mProgramHandle->InverterToggleButtonPressed(false);
}
void CChaletGui::DoHarakiriButtonClicked()
{
mProgramHandle->DoHarakiriButtonClicked(true);
}
void CChaletGui::RebootCPUButtonClicked()
{
mProgramHandle->RebootCPUButtonPressed();
}
void CChaletGui::EnableHarakiriClicked(bool checked)
{
if(checked)
{
ui->mDoHarakiriButton->setEnabled(true);
}
else
{
ui->mDoHarakiriButton->setEnabled(false);
}
}
+12
View File
@@ -2,6 +2,7 @@
#define CHALETGUI_H
#include <QWidget>
#include "ChaletData.h"
class CChalet;
@@ -19,8 +20,19 @@ public:
CChalet *mProgramHandle;
int UpdateChaletStatus(CChaletMainStatus Status);
private:
Ui::CChaletGui *ui;
public slots:
void WiFiONButtonClicked();
void WiFiOFFButtonClicked();
void InverterPowerONButtonClicked();
void InverterPowerOFFButtonClicked();
void RebootCPUButtonClicked();
void DoHarakiriButtonClicked();
void EnableHarakiriClicked(bool);
};
#endif // CHALETGUI_H
+187 -5
View File
@@ -6,18 +6,18 @@
<rect>
<x>0</x>
<y>0</y>
<width>615</width>
<height>521</height>
<width>849</width>
<height>598</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="label">
<widget class="QLabel" name="MainPageLabel">
<property name="geometry">
<rect>
<x>220</x>
<y>40</y>
<x>370</x>
<y>20</y>
<width>201</width>
<height>31</height>
</rect>
@@ -33,6 +33,188 @@
<string>Chalet</string>
</property>
</widget>
<widget class="QLabel" name="mInverterRlyStatusLabel">
<property name="geometry">
<rect>
<x>350</x>
<y>90</y>
<width>211</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Inverter Relay : OFF</string>
</property>
</widget>
<widget class="QLabel" name="mWiFiModuleStatusLabel">
<property name="geometry">
<rect>
<x>360</x>
<y>130</y>
<width>131</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>ON</string>
</property>
</widget>
<widget class="QLabel" name="mWiFiSectionLabel">
<property name="geometry">
<rect>
<x>180</x>
<y>130</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>WiFi :</string>
</property>
</widget>
<widget class="QPushButton" name="mInverterRelayOFFBtn">
<property name="geometry">
<rect>
<x>280</x>
<y>90</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Turn OFF</string>
</property>
</widget>
<widget class="QPushButton" name="mWiFiModuleOFFBtn">
<property name="geometry">
<rect>
<x>280</x>
<y>130</y>
<width>61</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Turn OFF</string>
</property>
</widget>
<widget class="QPushButton" name="mInverterRelayONBtn">
<property name="geometry">
<rect>
<x>224</x>
<y>90</y>
<width>51</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Turn ON</string>
</property>
</widget>
<widget class="QPushButton" name="mWiFiModuleONBtn">
<property name="geometry">
<rect>
<x>224</x>
<y>130</y>
<width>51</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Turn ON</string>
</property>
</widget>
<widget class="QLabel" name="mWiFiSectionLabel_2">
<property name="geometry">
<rect>
<x>170</x>
<y>90</y>
<width>51</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Inverter:</string>
</property>
</widget>
<widget class="QPushButton" name="mRebootCPUBtn">
<property name="geometry">
<rect>
<x>220</x>
<y>170</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Reboot CPU</string>
</property>
</widget>
<widget class="QCheckBox" name="mEnableHarakiriChkBx">
<property name="geometry">
<rect>
<x>640</x>
<y>80</y>
<width>111</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Enable HARAKIRI</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>620</x>
<y>50</y>
<width>151</width>
<height>81</height>
</rect>
</property>
<property name="title">
<string>HARAKIRI!!!</string>
</property>
<widget class="QPushButton" name="mDoHarakiriButton">
<property name="geometry">
<rect>
<x>20</x>
<y>50</y>
<width>101</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>DO HARAKIRI !!!</string>
</property>
</widget>
</widget>
<widget class="QLabel" name="mBatteryVoltageLabel">
<property name="geometry">
<rect>
<x>170</x>
<y>210</y>
<width>241</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Battery Voltage</string>
</property>
</widget>
<zorder>groupBox</zorder>
<zorder>MainPageLabel</zorder>
<zorder>mInverterRlyStatusLabel</zorder>
<zorder>mWiFiModuleStatusLabel</zorder>
<zorder>mWiFiSectionLabel</zorder>
<zorder>mInverterRelayOFFBtn</zorder>
<zorder>mWiFiModuleOFFBtn</zorder>
<zorder>mInverterRelayONBtn</zorder>
<zorder>mWiFiModuleONBtn</zorder>
<zorder>mWiFiSectionLabel_2</zorder>
<zorder>mRebootCPUBtn</zorder>
<zorder>mEnableHarakiriChkBx</zorder>
<zorder>mBatteryVoltageLabel</zorder>
</widget>
<resources/>
<connections/>
+12 -1
View File
@@ -1,7 +1,15 @@
#include "ChaletMasterCtrlInterface.h"
#include "ChaletData.h"
#include "CChalet.h"
CChaletMasterCtrlInterface::CChaletMasterCtrlInterface(CChalet *ProgramHandle)
{
mMyDeviceID = ID_CHALET_INTERFACE;
mNetworkPort = 2182;
mMasterCtrlIPAddress = "127.0.0.1";
mNetworkCommSocket = 0;
mDeviceAddress = 1;
mProgramHandle = ProgramHandle;
}
@@ -37,7 +45,10 @@ int CChaletMasterCtrlInterface::DeviceFrameReceived(int TargetDeviceID, int Targ
case CHALET_INTERFACE_GENERAL_STATUS_RESPONSE:
{
qDebug("Chalet General Status received :)");
// qDebug("Chalet General Status received :)");
CChaletMainStatus Status;
Status.FromByteArray(Data);
mProgramHandle->ChaletStatusReceived(Status);
break;
}
+1 -1
View File
@@ -2,7 +2,7 @@
CMasterCtrlInterface::CMasterCtrlInterface()
{
mNetworkCommSocket = 0;
}
int CMasterCtrlInterface::ConnectToMasterCtrl()
+7
View File
@@ -258,6 +258,13 @@ enum CHALET_INTERFACE_CMDS
CHALET_INTERFACE_AC_POWER_SET_STATE_RESPONSE,
CHALET_INTERFACE_BATTERY_VOLTAGE_REQUEST,
CHALET_INTERFACE_BATTERY_VOLTAGE_RESPONSE,
CHALET_INTERFACE_WIFI_SET_STATE_REQUEST,
CHALET_INTERFACE_WIFI_SET_STATE_RESPONSE,
CHALET_INTERFACE_DO_HARAKIRI_REQUEST,
CHALET_INTERFACE_DO_HARAKIRI_RESPONSE,
CHALET_INTERFACE_REBOOT_CPU_REQUEST,
CHALET_INTERFACE_REBOOT_CPU_RESPONSE,
MAX_CHALET_INTERFACE_CMD
};
+3
View File
@@ -8,6 +8,7 @@ CSystemGui::CSystemGui(QObject *parent) : QObject(parent)
mSMSClient = new CSMSClient(mGui->mSMSGui,&mSettings.mVoipMSSettings);
mSprinklers = new CSprinkler(mGui->mSprinklerGui);
mAvReceiver = new CAvReceiver(mGui->mAvReceiverGui);
mChalet = new CChalet(mGui->mChaletGui);
mSysTrayMgr = new CSystemTrayManager();
mSysTrayMgr->mProgramHandle=this;
@@ -22,6 +23,7 @@ CSystemGui::~CSystemGui()
delete mProgramSettings;
delete mSysTrayMgr;
delete mAvReceiver;
delete mChalet;
}
@@ -31,6 +33,7 @@ void CSystemGui::Start()
mGui->show();
mSMSClient->Start();
mAvReceiver->Start();
mChalet->Start();
}
+2
View File
@@ -9,6 +9,7 @@
#include "Sprinkler.h"
#include "AvReceiverGui.h"
#include "AvReceiver.h"
#include "CChalet.h"
class CSystemGui : public QObject
@@ -33,6 +34,7 @@ private:
CSystemTrayManager *mSysTrayMgr;
CSprinkler *mSprinklers;
CAvReceiver *mAvReceiver;
CChalet *mChalet;
signals: