Ben des affaires...

This commit is contained in:
2021-04-11 13:18:40 -04:00
parent 940287a97e
commit 50d091c68c
33 changed files with 38430 additions and 67 deletions
+35
View File
@@ -41,6 +41,16 @@ int CChalet::ChaletStatusReceived(CChaletMainStatus 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)
{
@@ -89,3 +99,28 @@ 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);
}
+4
View File
@@ -23,11 +23,15 @@ public:
int Start();
int ChaletStatusReceived(CChaletMainStatus Status);
int ChaletLogReceived(QByteArray *Log);
int ConnectedToMaster(bool connected);
int ChaletCommActivity();
int WiFiToggleButtonPressed(bool RequestedState);
int InverterToggleButtonPressed(bool RequestedState);
int DoHarakiriButtonClicked(bool Verified);
int RebootCPUButtonPressed();
int RequestChaletLogs(QDate StartDate);
signals:
+24 -11
View File
@@ -7,8 +7,11 @@ CChaletMainStatus::CChaletMainStatus()
{
mInverterRelayStatus = CHALET_POWER_RELAY_UNKNOWN_STATE;
mWiFiModuleStatus = WIFI_UNKNOWN_STATE;
mCurrentSensorStatus = CHALET_CURRENT_SENSOR_UNKNOWN_STATE;
mBatteryCurrent = 0;
mBatteryVoltage = 0;
mIsOnline = false;
mLostRequestPercentage = 0;
}
@@ -17,26 +20,36 @@ int CChaletMainStatus::FromByteArray(QByteArray Data)
QDataStream Strm(Data);
Strm.device()->seek(0);
Strm >> *this;
/*
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;
Strm >> mIsOnline;
Strm >> mCurrentSensorStatus;
Strm >> mLostRequestPercentage;*/
return RET_OK;
}
QDataStream &operator>>(QDataStream &in, CChaletMainStatus &dest)
{
in >> dest.mInverterRelayStatus
>> dest.mWiFiModuleStatus
>> dest.mBatteryVoltage
>> dest.mBatteryCurrent
>> dest.mBatterySOC
>> dest.mIsOnline
>> dest.mCurrentSensorStatus
>> dest.mLostRequestPercentage
>> dest.mThisStatusDateTime
>> dest.mLastLoraStatus
>> dest.mStatusToggleBit;
return in;
}
//QByteArray CChaletMainStatus::ToByteArray()
//{
// QByteArray Data;
+18 -3
View File
@@ -21,6 +21,13 @@ enum eChaletPowerRelayState
CHALET_POWER_RELAY_UNKNOWN_STATE
};
enum eChaletCurrentSensorState
{
CHALET_CURRENT_SENSOR_DEFECT_STATE = 0,
CHALET_CURRENT_SENSOR_OK_STATE,
CHALET_CURRENT_SENSOR_UNKNOWN_STATE
};
class CChaletMainStatus
{
@@ -33,17 +40,25 @@ public:
quint8 mInverterRelayStatus;
quint8 mWiFiModuleStatus;
qint8 mCurrentSensorStatus;
float mBatteryVoltage;
float mBatteryCurrent;
float mBatterySOC;
qint16 mBatteryCurrent;
qint16 mBatterySOC;
bool mHarakiriDone;
bool mIsOnline;
bool mStatusToggleBit;
QDateTime mLastLoraStatus;
QDateTime mThisStatusDateTime;
float mLostRequestPercentage;
};
QDataStream &operator>>(QDataStream &in, CChaletMainStatus &dest);
#endif // CHALETDATA_H
+180
View File
@@ -1,14 +1,19 @@
#include "ChaletGui.h"
#include "ui_ChaletGui.h"
#include "CChalet.h"
#include <QWidget>
#include <QDate>
CChaletGui::CChaletGui(QWidget *parent) :
QWidget(parent),
ui(new Ui::CChaletGui)
{
ui->setupUi(this);
ui->mDoHarakiriButton->setEnabled(false);
ui->mLogStartDateEdit->setDate(QDate::currentDate());
connect(ui->mWiFiModuleONBtn,SIGNAL(clicked()),this,SLOT(WiFiONButtonClicked()));
connect(ui->mWiFiModuleOFFBtn,SIGNAL(clicked(bool)),this,SLOT(WiFiOFFButtonClicked()));
@@ -17,16 +22,84 @@ CChaletGui::CChaletGui(QWidget *parent) :
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)));
connect(ui->mGetChaletLogButton,SIGNAL(clicked(bool)),this,SLOT(GetChaletLogsBtnClicked()));
mBatteryPlotWidget = new QCustomPlot(ui->mPlotWidget);
mBatteryPlotWidget->resize(ui->mPlotWidget->size());
// create graph and assign data to it:
mBatteryPlotWidget->addGraph();
// give the axes some labels:
mBatteryPlotWidget->xAxis->setLabel("time");
mBatteryPlotWidget->yAxis->setLabel("Volts");
double now = QDateTime::currentDateTime().toSecsSinceEpoch();
QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime);
dateTicker->setDateTimeFormat("hh:mm:ss\ndd MMM");
mBatteryPlotWidget->xAxis->setTicker(dateTicker);
mBatteryPlotWidget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
QDateTime Now = QDateTime::currentDateTime().toLocalTime();
QDateTime midnight = Now;
midnight.setTime(QTime(0,0,0));
QDateTime eod = Now;
eod.setTime(QTime(23,59,0));
//mBatteryPlotWidget->xAxis->setRange(0/*QCPAxisTickerDateTime::dateTimeToKey(midnight)*/,QCPAxisTickerDateTime::dateTimeToKey(eod));
// mBatteryPlotWidget->xAxis->setRange(now, now+(2*3600));
mBatteryPlotWidget->xAxis->setRange(midnight.toSecsSinceEpoch(), eod.toSecsSinceEpoch());
mBatteryPlotWidget->yAxis->setRange(12,15);
mBatteryPlotWidget->graph(0)->addData(now,13.5);
mBatteryPlotWidget->replot();
}
CChaletGui::~CChaletGui()
{
delete ui;
delete mBatteryPlotWidget;
}
int CChaletGui::UpdateChaletStatus(CChaletMainStatus Status)
{
static bool LastToggle = false;
QString text;
int Delta = QDateTime::currentDateTime().toSecsSinceEpoch() - Status.mLastLoraStatus.toSecsSinceEpoch();
ui->mLasCommRequestReceivedLbl->setText(QString("Last response: %1 | %2 seconds ago...").arg(Status.mLastLoraStatus.toString("yyyy-MM-dd-hh:mm:ss")).arg(Delta));
if(Status.mIsOnline == false)
{
ui->mChaletOnlineStatusLbl->setText("OFFLINE");
QPalette pal = QPalette(ui->mChaletOnlineStatusLbl->palette());
pal.setColor(QPalette::WindowText,QColor(Qt::red));
ui->mChaletOnlineStatusLbl->setPalette(pal);
ui->mWiFiModuleStatusLabel->setText("Unknown");
ui->mInverterRlyStatusLabel->setText("Unknown");
ui->mCurrentSensorStateLbl->setText("Current Sensor: Unknown state");
ui->mBatteryVoltageLabel->setText("Battery Voltage: Unknown");
ui->mBatterySOCLabel->setText("Battery SOC: Unknown");
ui->mSolarPanelCurrentLabel->setText("Solar Panel Current: Unknown");
ui->mLostReqPercentLbl->setText("N/A");
return RET_OK;
}
else if(ui->mChaletOnlineStatusLbl->text() == "OFFLINE")
{
ui->mChaletOnlineStatusLbl->setText("ONLINE");
QPalette pal = QPalette(ui->mChaletOnlineStatusLbl->palette());
pal.setColor(QPalette::WindowText,QColor(Qt::darkGreen));
ui->mChaletOnlineStatusLbl->setPalette(pal);
}
switch(Status.mWiFiModuleStatus)
{
case WIFI_CONNECTED_STATE:
@@ -82,8 +155,91 @@ int CChaletGui::UpdateChaletStatus(CChaletMainStatus Status)
}
ui->mInverterRlyStatusLabel->setText(text);
switch(Status.mCurrentSensorStatus)
{
case CHALET_CURRENT_SENSOR_DEFECT_STATE:
{
text = "Current Sensor: DEFECTIVE";
break;
}
case CHALET_CURRENT_SENSOR_OK_STATE:
{
text = "Current Sensor: OK";
break;
}
case CHALET_CURRENT_SENSOR_UNKNOWN_STATE:
default:
{
text = "Current Sensor: Unknown state";
break;
}
}
ui->mCurrentSensorStateLbl->setText(text);
QString Voltage = QString("Battery Voltage: %1").arg(Status.mBatteryVoltage);
ui->mBatteryVoltageLabel->setText(Voltage);
ui->mVoltageLCD->display(Voltage);
QString Current = QString("Solar Panel Current: %1").arg(Status.mBatteryCurrent);
ui->mSolarPanelCurrentLabel->setText(Current);
QString SOC = QString("Battery SOC: %1").arg(Status.mBatterySOC);
ui->mBatterySOCLabel->setText(SOC);
QString Percent = QString("Lost Requests: %1%").arg(Status.mLostRequestPercentage,0,'f',2);
ui->mLostReqPercentLbl->setText(Percent);
if(Status.mStatusToggleBit != LastToggle)
{
LastToggle = Status.mStatusToggleBit;
if(ui->mChaletCommActivityLbl->isEnabled())
{
ui->mChaletCommActivityLbl->setEnabled(false);
}
else
{
ui->mChaletCommActivityLbl->setEnabled(true);
}
double CurTime = QDateTime::currentDateTime().toSecsSinceEpoch();
mBatteryPlotWidget->graph(0)->addData(CurTime,Status.mBatteryVoltage);
mBatteryPlotWidget->replot();
}
return RET_OK;
}
int CChaletGui::UpdateChaletLogPlot(QByteArray *Log)
{
int NbRecords;
CChaletMainStatus CurData;
QVector<double> x,y;
QDataStream Strm(Log,QIODevice::ReadOnly);
Strm.device()->seek(0);
Strm >> NbRecords;
if(NbRecords > 0)
{
for(int i = 0; i < NbRecords; i++)
{
Strm >> CurData;
x.append(CurData.mThisStatusDateTime.toSecsSinceEpoch());
y.append(CurData.mBatteryVoltage);
}
}
mBatteryPlotWidget->graph(0)->data().clear();
mBatteryPlotWidget->graph(0)->setData(x,y);
mBatteryPlotWidget->xAxis->setRange(x.first(),x.last());
mBatteryPlotWidget->replot();
return RET_OK;
}
@@ -124,3 +280,27 @@ void CChaletGui::RebootCPUButtonClicked()
ui->mDoHarakiriButton->setEnabled(false);
}
}
int CChaletGui::ChaletCommActivity()
{
if(ui->mChaletCommActivityLbl->isEnabled())
{
ui->mChaletCommActivityLbl->setEnabled(false);
}
else
{
ui->mChaletCommActivityLbl->setEnabled(true);
}
return RET_OK;
}
void CChaletGui::GetChaletLogsBtnClicked()
{
QDate StartDate = ui->mLogStartDateEdit->date();
if(StartDate > QDate::currentDate())
{
QMessageBox::critical(this,"Error","Date is in the future!");
return;
}
mProgramHandle->RequestChaletLogs(StartDate);
}
+5
View File
@@ -3,6 +3,7 @@
#include <QWidget>
#include "ChaletData.h"
#include "QCustomPlot/qcustomplot.h"
class CChalet;
@@ -19,8 +20,11 @@ public:
~CChaletGui();
CChalet *mProgramHandle;
QCustomPlot *mBatteryPlotWidget;
int UpdateChaletStatus(CChaletMainStatus Status);
int UpdateChaletLogPlot(QByteArray* Log);
int ChaletCommActivity();
private:
Ui::CChaletGui *ui;
@@ -33,6 +37,7 @@ public slots:
void RebootCPUButtonClicked();
void DoHarakiriButtonClicked();
void EnableHarakiriClicked(bool);
void GetChaletLogsBtnClicked();
};
#endif // CHALETGUI_H
+184 -28
View File
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>849</width>
<width>1205</width>
<height>598</height>
</rect>
</property>
@@ -16,9 +16,9 @@
<widget class="QLabel" name="MainPageLabel">
<property name="geometry">
<rect>
<x>370</x>
<y>20</y>
<width>201</width>
<x>460</x>
<y>10</y>
<width>71</width>
<height>31</height>
</rect>
</property>
@@ -36,9 +36,9 @@
<widget class="QLabel" name="mInverterRlyStatusLabel">
<property name="geometry">
<rect>
<x>350</x>
<y>90</y>
<width>211</width>
<x>198</x>
<y>50</y>
<width>210</width>
<height>16</height>
</rect>
</property>
@@ -49,9 +49,9 @@
<widget class="QLabel" name="mWiFiModuleStatusLabel">
<property name="geometry">
<rect>
<x>360</x>
<y>130</y>
<width>131</width>
<x>198</x>
<y>90</y>
<width>130</width>
<height>16</height>
</rect>
</property>
@@ -62,8 +62,8 @@
<widget class="QLabel" name="mWiFiSectionLabel">
<property name="geometry">
<rect>
<x>180</x>
<y>130</y>
<x>26</x>
<y>90</y>
<width>31</width>
<height>16</height>
</rect>
@@ -75,8 +75,8 @@
<widget class="QPushButton" name="mInverterRelayOFFBtn">
<property name="geometry">
<rect>
<x>280</x>
<y>90</y>
<x>126</x>
<y>50</y>
<width>61</width>
<height>22</height>
</rect>
@@ -88,8 +88,8 @@
<widget class="QPushButton" name="mWiFiModuleOFFBtn">
<property name="geometry">
<rect>
<x>280</x>
<y>130</y>
<x>126</x>
<y>90</y>
<width>61</width>
<height>23</height>
</rect>
@@ -101,8 +101,8 @@
<widget class="QPushButton" name="mInverterRelayONBtn">
<property name="geometry">
<rect>
<x>224</x>
<y>90</y>
<x>70</x>
<y>50</y>
<width>51</width>
<height>23</height>
</rect>
@@ -114,8 +114,8 @@
<widget class="QPushButton" name="mWiFiModuleONBtn">
<property name="geometry">
<rect>
<x>224</x>
<y>130</y>
<x>70</x>
<y>90</y>
<width>51</width>
<height>23</height>
</rect>
@@ -127,8 +127,8 @@
<widget class="QLabel" name="mWiFiSectionLabel_2">
<property name="geometry">
<rect>
<x>170</x>
<y>90</y>
<x>16</x>
<y>50</y>
<width>51</width>
<height>20</height>
</rect>
@@ -140,8 +140,8 @@
<widget class="QPushButton" name="mRebootCPUBtn">
<property name="geometry">
<rect>
<x>220</x>
<y>170</y>
<x>66</x>
<y>130</y>
<width>75</width>
<height>23</height>
</rect>
@@ -151,9 +151,12 @@
</property>
</widget>
<widget class="QCheckBox" name="mEnableHarakiriChkBx">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>640</x>
<x>850</x>
<y>80</y>
<width>111</width>
<height>17</height>
@@ -166,7 +169,7 @@
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>620</x>
<x>830</x>
<y>50</y>
<width>151</width>
<height>81</height>
@@ -192,8 +195,8 @@
<widget class="QLabel" name="mBatteryVoltageLabel">
<property name="geometry">
<rect>
<x>170</x>
<y>210</y>
<x>147</x>
<y>170</y>
<width>241</width>
<height>16</height>
</rect>
@@ -202,6 +205,148 @@
<string>Battery Voltage</string>
</property>
</widget>
<widget class="QLabel" name="mChaletOnlineStatusLbl">
<property name="geometry">
<rect>
<x>450</x>
<y>50</y>
<width>91</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>Terminal</family>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>OFFLINE</string>
</property>
</widget>
<widget class="QLabel" name="mSolarPanelCurrentLabel">
<property name="geometry">
<rect>
<x>147</x>
<y>190</y>
<width>241</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Solar Panel Current: </string>
</property>
</widget>
<widget class="QLabel" name="mBatterySOCLabel">
<property name="geometry">
<rect>
<x>147</x>
<y>210</y>
<width>241</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Battery SOC: </string>
</property>
</widget>
<widget class="QLabel" name="mCurrentSensorStateLbl">
<property name="geometry">
<rect>
<x>147</x>
<y>230</y>
<width>241</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Current Sensor:</string>
</property>
</widget>
<widget class="QLabel" name="mLostReqPercentLbl">
<property name="geometry">
<rect>
<x>770</x>
<y>200</y>
<width>241</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Lost requests: </string>
</property>
</widget>
<widget class="QWidget" name="mPlotWidget" native="true">
<property name="geometry">
<rect>
<x>590</x>
<y>250</y>
<width>571</width>
<height>321</height>
</rect>
</property>
</widget>
<widget class="QLCDNumber" name="mVoltageLCD">
<property name="geometry">
<rect>
<x>30</x>
<y>170</y>
<width>111</width>
<height>23</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="mChaletCommActivityLbl">
<property name="geometry">
<rect>
<x>770</x>
<y>180</y>
<width>47</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Activity!!!</string>
</property>
</widget>
<widget class="QLabel" name="mLasCommRequestReceivedLbl">
<property name="geometry">
<rect>
<x>770</x>
<y>160</y>
<width>301</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Last Request: </string>
</property>
</widget>
<widget class="QDateEdit" name="mLogStartDateEdit">
<property name="geometry">
<rect>
<x>950</x>
<y>220</y>
<width>110</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="mGetChaletLogButton">
<property name="geometry">
<rect>
<x>1070</x>
<y>220</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<zorder>groupBox</zorder>
<zorder>MainPageLabel</zorder>
<zorder>mInverterRlyStatusLabel</zorder>
@@ -215,6 +360,17 @@
<zorder>mRebootCPUBtn</zorder>
<zorder>mEnableHarakiriChkBx</zorder>
<zorder>mBatteryVoltageLabel</zorder>
<zorder>mChaletOnlineStatusLbl</zorder>
<zorder>mSolarPanelCurrentLabel</zorder>
<zorder>mBatterySOCLabel</zorder>
<zorder>mCurrentSensorStateLbl</zorder>
<zorder>mLostReqPercentLbl</zorder>
<zorder>mPlotWidget</zorder>
<zorder>mVoltageLCD</zorder>
<zorder>mChaletCommActivityLbl</zorder>
<zorder>mLasCommRequestReceivedLbl</zorder>
<zorder>mLogStartDateEdit</zorder>
<zorder>mGetChaletLogButton</zorder>
</widget>
<resources/>
<connections/>
@@ -19,6 +19,8 @@ int CChaletMasterCtrlInterface::DeviceConnectedToMaster(bool Connected)
if(Connected)
{
qDebug("Chalet Interface connected to Master.");
mProgramHandle->ConnectedToMaster(Connected);
}
else
return RET_ERROR;
@@ -66,10 +68,27 @@ int CChaletMasterCtrlInterface::DeviceFrameReceived(int TargetDeviceID, int Targ
{
break;
}
case CHALET_INTERFACE_GET_TODAYS_DATA_LOG_RESPONSE:
{
mProgramHandle->ChaletLogReceived(&Data);
break;
}
case CHALET_INTERFACE_CHALET_ACTIVITY_RESPONSE:
{
mProgramHandle->ChaletCommActivity();
break;
}
case CHALET_INTERFACE_GET_DATA_LOG_RESPONSE:
{
mProgramHandle->ChaletLogReceived(&Data);
break;
}
case CHALET_INTERFACE_GENERAL_STATUS_REQUEST:
case CHALET_INTERFACE_AC_POWER_STATE_STATUS_REQUEST:
case CHALET_INTERFACE_AC_POWER_SET_STATE_REQUEST:
case CHALET_INTERFACE_BATTERY_VOLTAGE_REQUEST:
case CHALET_INTERFACE_GET_TODAYS_DATA_LOG_REQUEST:
default:
{
qDebug("Chalet: Invalid Ethernet Msg received from MasterCtrl: %d",MessageID);