Dev pour retour du LoRa au chalet

This commit is contained in:
jfmartel 2021-10-12 11:28:53 -04:00
parent 512bc280e7
commit 75b487a862
9 changed files with 335 additions and 18 deletions

View File

@ -124,3 +124,100 @@ int CChalet::RequestChaletLogs(QDate StartDate)
return mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_GET_DATA_LOG_REQUEST,StartDateData);
}
int CChalet::RequestDeviceWifiParams()
{
mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_REQUEST,QByteArray());
return RET_OK;
}
int CChalet::DeviceWiFiParamsReceived(QByteArray *Data)
{
quint32 Add = 0;
char byte;
byte = Data->at(0);
Add += (quint32)(byte & 0x000000FF);
Add <<= 8;
byte = Data->at(1);
Add += (quint32)(byte & 0x000000FF);
Add <<= 8;
byte = Data->at(2);
Add += (quint32)(byte & 0x000000FF);
Add <<= 8;
byte = Data->at(3);
Add += (quint32)(byte & 0x000000FF);
QHostAddress IP = QHostAddress(Add);
Add = 0;
byte = Data->at(4);
Add += (quint32)(byte & 0x000000FF);
Add <<= 8;
byte = Data->at(5);
Add += (quint32)(byte & 0x000000FF);
Add <<= 8;
byte = Data->at(6);
Add += (quint32)(byte & 0x000000FF);
Add <<= 8;
byte = Data->at(7);
Add += (quint32)(byte & 0x000000FF);
QHostAddress Gateway = QHostAddress(Add);
mChaletGui->UpdateDeviceWiFiParameters(IP, Gateway);
return RET_OK;
}
int CChalet::SetDeviceWifiParams(QString IP, QString Gateway)
{
QHostAddress DeviceIP;
QHostAddress DeviceGateway;
if(DeviceIP.setAddress(IP) == false)
{
return RET_ERROR;
}
if(DeviceGateway.setAddress(Gateway) == false)
{
return RET_ERROR;
}
QByteArray Buffer;
Buffer.resize(8);
quint32 Address = DeviceIP.toIPv4Address();
char byte = (char)(Address & 0x000000FF);
Buffer[3] = byte;
Address >>= 8;
byte = (char)(Address & 0x000000FF);
Buffer[2] = byte;
Address >>= 8;
byte = (char)(Address & 0x000000FF);
Buffer[1] = byte;
Address >>= 8;
byte = (char)(Address & 0x000000FF);
Buffer[0] = byte;
Address >>= 8;
Address = DeviceGateway.toIPv4Address();
byte = (char)(Address & 0x000000FF);
Buffer[7] = byte;
Address >>= 8;
byte = (char)(Address & 0x000000FF);
Buffer[6] = byte;
Address >>= 8;
byte = (char)(Address & 0x000000FF);
Buffer[5] = byte;
Address >>= 8;
byte = (char)(Address & 0x000000FF);
Buffer[4] = byte;
Address >>= 8;
mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_REQUEST,Buffer);
return RET_OK;
}

View File

@ -32,6 +32,9 @@ public:
int DoHarakiriButtonClicked(bool Verified);
int RebootCPUButtonPressed();
int RequestChaletLogs(QDate StartDate);
int RequestDeviceWifiParams();
int DeviceWiFiParamsReceived(QByteArray *Data);
int SetDeviceWifiParams(QString IP, QString Gateway);
signals:

View File

@ -23,6 +23,8 @@ CChaletGui::CChaletGui(QWidget *parent) :
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()));
connect(ui->mWiFiGetRemoteSettingsBtn,SIGNAL(clicked(bool)),this,SLOT(GetDeviceWiFiParamsButtonClicked(bool)));
connect(ui->mWiFiSetRemoteSettingsBtn,SIGNAL(clicked(bool)),this,SLOT(SetDeviceWiFiParamsButtonClicked(bool)));
mBatteryPlotWidget = new QCustomPlot(ui->mPlotWidget);
mBatteryPlotWidget->resize(ui->mPlotWidget->size());
@ -183,7 +185,6 @@ int CChaletGui::UpdateChaletStatus(CChaletMainStatus Status)
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);
@ -312,3 +313,22 @@ void CChaletGui::RebootCPUButtonClicked()
}
mProgramHandle->RequestChaletLogs(StartDate);
}
void CChaletGui::GetDeviceWiFiParamsButtonClicked(bool state)
{
mProgramHandle->RequestDeviceWifiParams();
}
void CChaletGui::SetDeviceWiFiParamsButtonClicked(bool state)
{
if(mProgramHandle->SetDeviceWifiParams(ui->mWiFiIPAddressEditBx->text(),ui->mWiFiGatewayAddressEditBx->text()) == RET_ERROR)
{
QMessageBox::critical(this,"IP error","Invalid IP address");
}
}
void CChaletGui::UpdateDeviceWiFiParameters(QHostAddress IP, QHostAddress Gateway)
{
ui->mWiFiIPAddressEditBx->setText(IP.toString());
ui->mWiFiGatewayAddressEditBx->setText(Gateway.toString());
}

View File

@ -4,6 +4,7 @@
#include <QWidget>
#include "ChaletData.h"
#include "QCustomPlot/qcustomplot.h"
#include <QHostAddress>
class CChalet;
@ -38,6 +39,9 @@ public slots:
void DoHarakiriButtonClicked();
void EnableHarakiriClicked(bool);
void GetChaletLogsBtnClicked();
void GetDeviceWiFiParamsButtonClicked(bool);
void SetDeviceWiFiParamsButtonClicked(bool);
void UpdateDeviceWiFiParameters(QHostAddress IP,QHostAddress Gateway);
};
#endif // CHALETGUI_H

View File

@ -288,16 +288,6 @@
</rect>
</property>
</widget>
<widget class="QLCDNumber" name="mVoltageLCD">
<property name="geometry">
<rect>
<x>70</x>
<y>240</y>
<width>111</width>
<height>23</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="mChaletCommActivityLbl">
<property name="geometry">
<rect>
@ -360,6 +350,114 @@
<string>Temperature:</string>
</property>
</widget>
<widget class="QLineEdit" name="mWiFiIPAddressEditBx">
<property name="geometry">
<rect>
<x>160</x>
<y>430</y>
<width>221</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>?</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="mWiFiGetRemoteSettingsBtn">
<property name="geometry">
<rect>
<x>160</x>
<y>400</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>GET</string>
</property>
</widget>
<widget class="QPushButton" name="mWiFiSetRemoteSettingsBtn">
<property name="geometry">
<rect>
<x>250</x>
<y>400</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>SET</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>90</x>
<y>430</y>
<width>71</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>IP Address:</string>
</property>
</widget>
<widget class="QLineEdit" name="mWiFiGatewayAddressEditBx">
<property name="geometry">
<rect>
<x>160</x>
<y>460</y>
<width>221</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>?</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>90</x>
<y>460</y>
<width>71</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Gatweway:</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>80</x>
<y>370</y>
<width>321</width>
<height>131</height>
</rect>
</property>
<property name="title">
<string>WiFi parameters (stored in flash)</string>
</property>
</widget>
<zorder>groupBox_2</zorder>
<zorder>groupBox</zorder>
<zorder>MainPageLabel</zorder>
<zorder>mInverterRlyStatusLabel</zorder>
@ -379,12 +477,17 @@
<zorder>mCurrentSensorStateLbl</zorder>
<zorder>mLostReqPercentLbl</zorder>
<zorder>mPlotWidget</zorder>
<zorder>mVoltageLCD</zorder>
<zorder>mChaletCommActivityLbl</zorder>
<zorder>mLasCommRequestReceivedLbl</zorder>
<zorder>mLogStartDateEdit</zorder>
<zorder>mGetChaletLogButton</zorder>
<zorder>mChaletTemperatureLbl</zorder>
<zorder>mWiFiIPAddressEditBx</zorder>
<zorder>mWiFiGetRemoteSettingsBtn</zorder>
<zorder>mWiFiSetRemoteSettingsBtn</zorder>
<zorder>label</zorder>
<zorder>mWiFiGatewayAddressEditBx</zorder>
<zorder>label_2</zorder>
</widget>
<resources/>
<connections/>

View File

@ -84,11 +84,23 @@ int CChaletMasterCtrlInterface::DeviceFrameReceived(int TargetDeviceID, int Targ
mProgramHandle->ChaletLogReceived(&Data);
break;
}
case CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_RESPONSE:
{
mProgramHandle->DeviceWiFiParamsReceived(&Data);
break;
}
case CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_RESPONSE:
{
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:
case CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_REQUEST:
case CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_REQUEST:
default:
{
qDebug("Chalet: Invalid Ethernet Msg received from MasterCtrl: %d",MessageID);

View File

@ -15,6 +15,7 @@ CPICUploaderGui::CPICUploaderGui(QWidget *parent) :
connect(ui->mSendCmdBtn,SIGNAL(clicked(bool)),this,SLOT(SendSingleCmdCliked(bool)));
connect(ui->mClearLogginWndwBtn,SIGNAL(clicked(bool)),SLOT(ClearLogScreen(bool)));
connect(ui->mShowHexFileInfoBtn,SIGNAL(clicked(bool)),this,SLOT(ShowHexFileInfoClicked(bool)));
ui->mUploadProgressBar->reset();
}

View File

@ -269,11 +269,45 @@ enum CHALET_INTERFACE_CMDS
CHALET_INTERFACE_CHALET_ACTIVITY_RESPONSE,
CHALET_INTERFACE_GET_DATA_LOG_REQUEST,
CHALET_INTERFACE_GET_DATA_LOG_RESPONSE,
CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_REQUEST,
CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_RESPONSE,
CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_REQUEST,
CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_RESPONSE,
MAX_CHALET_INTERFACE_CMD
};
enum CHALET_CMDS
{
CHALET_ACK = 1,
CHALET_GENERAL_STATUS_REQUEST, //2
CHALET_GENERAL_STATUS_RESPONSE, //3
CHALET_AC_POWER_STATE_STATUS_REQUEST,
CHALET_AC_POWER_STATE_STATUS_RESPONSE,
CHALET_AC_POWER_SET_STATE_REQUEST,
CHALET_AC_POWER_SET_STATE_RESPONSE,
CHALET_BATTERY_VOLTAGE_REQUEST,
CHALET_BATTERY_VOLTAGE_RESPONSE, //9
CHALET_BATTERY_CURRENT_REQUEST,
CHALET_BATTERY_CURRENT_RESPONSE,
CHALET_WIFI_STATUS_REQUEST,
CHALET_WIFI_STATUS_RESPONSE, //D
CHALET_WIFI_SET_STATE_REQUEST,
CHALET_WIFI_SET_STATE_RESPONSE, //F
CHALET_DO_HARAKIRI_REQUEST,
CHALET_DO_HARAKIRI_CONFIRMATION,
CHALET_REBOOT_CPU_REQUEST, //12
CHALET_REBOOT_CPU_RESPONSE,
CHALET_GET_STORED_WIFI_SETTINGS_REQUEST, //14
CHALET_GET_STORED_WIFI_SETTINGS_RESPONSE,
CHALET_SET_STORED_WIFI_SETTINGS_REQUEST,
CHALET_SET_STORED_WIFI_SETTINGS_RESPONSE,
MAX_CHALET_CMD
};
enum BOOTLOADER_CMDS
{
BOOTLOADER_ACK = 1,

View File

@ -14,8 +14,8 @@
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QDateEdit>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QLCDNumber>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>
@ -44,12 +44,18 @@ public:
QLabel *mCurrentSensorStateLbl;
QLabel *mLostReqPercentLbl;
QWidget *mPlotWidget;
QLCDNumber *mVoltageLCD;
QLabel *mChaletCommActivityLbl;
QLabel *mLasCommRequestReceivedLbl;
QDateEdit *mLogStartDateEdit;
QPushButton *mGetChaletLogButton;
QLabel *mChaletTemperatureLbl;
QLineEdit *mWiFiIPAddressEditBx;
QPushButton *mWiFiGetRemoteSettingsBtn;
QPushButton *mWiFiSetRemoteSettingsBtn;
QLabel *label;
QLineEdit *mWiFiGatewayAddressEditBx;
QLabel *label_2;
QGroupBox *groupBox_2;
void setupUi(QWidget *CChaletGui)
{
@ -128,9 +134,6 @@ public:
mPlotWidget = new QWidget(CChaletGui);
mPlotWidget->setObjectName(QString::fromUtf8("mPlotWidget"));
mPlotWidget->setGeometry(QRect(420, 240, 571, 321));
mVoltageLCD = new QLCDNumber(CChaletGui);
mVoltageLCD->setObjectName(QString::fromUtf8("mVoltageLCD"));
mVoltageLCD->setGeometry(QRect(70, 240, 111, 23));
mChaletCommActivityLbl = new QLabel(CChaletGui);
mChaletCommActivityLbl->setObjectName(QString::fromUtf8("mChaletCommActivityLbl"));
mChaletCommActivityLbl->setGeometry(QRect(600, 170, 47, 16));
@ -146,6 +149,34 @@ public:
mChaletTemperatureLbl = new QLabel(CChaletGui);
mChaletTemperatureLbl->setObjectName(QString::fromUtf8("mChaletTemperatureLbl"));
mChaletTemperatureLbl->setGeometry(QRect(190, 320, 241, 16));
mWiFiIPAddressEditBx = new QLineEdit(CChaletGui);
mWiFiIPAddressEditBx->setObjectName(QString::fromUtf8("mWiFiIPAddressEditBx"));
mWiFiIPAddressEditBx->setGeometry(QRect(160, 430, 221, 20));
mWiFiIPAddressEditBx->setAlignment(Qt::AlignCenter);
mWiFiGetRemoteSettingsBtn = new QPushButton(CChaletGui);
mWiFiGetRemoteSettingsBtn->setObjectName(QString::fromUtf8("mWiFiGetRemoteSettingsBtn"));
mWiFiGetRemoteSettingsBtn->setGeometry(QRect(160, 400, 75, 23));
mWiFiSetRemoteSettingsBtn = new QPushButton(CChaletGui);
mWiFiSetRemoteSettingsBtn->setObjectName(QString::fromUtf8("mWiFiSetRemoteSettingsBtn"));
mWiFiSetRemoteSettingsBtn->setGeometry(QRect(250, 400, 75, 23));
label = new QLabel(CChaletGui);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(90, 430, 71, 20));
QFont font2;
font2.setPointSize(10);
label->setFont(font2);
mWiFiGatewayAddressEditBx = new QLineEdit(CChaletGui);
mWiFiGatewayAddressEditBx->setObjectName(QString::fromUtf8("mWiFiGatewayAddressEditBx"));
mWiFiGatewayAddressEditBx->setGeometry(QRect(160, 460, 221, 20));
mWiFiGatewayAddressEditBx->setAlignment(Qt::AlignCenter);
label_2 = new QLabel(CChaletGui);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(90, 460, 71, 20));
label_2->setFont(font2);
groupBox_2 = new QGroupBox(CChaletGui);
groupBox_2->setObjectName(QString::fromUtf8("groupBox_2"));
groupBox_2->setGeometry(QRect(80, 370, 321, 131));
groupBox_2->raise();
groupBox->raise();
MainPageLabel->raise();
mInverterRlyStatusLabel->raise();
@ -165,12 +196,17 @@ public:
mCurrentSensorStateLbl->raise();
mLostReqPercentLbl->raise();
mPlotWidget->raise();
mVoltageLCD->raise();
mChaletCommActivityLbl->raise();
mLasCommRequestReceivedLbl->raise();
mLogStartDateEdit->raise();
mGetChaletLogButton->raise();
mChaletTemperatureLbl->raise();
mWiFiIPAddressEditBx->raise();
mWiFiGetRemoteSettingsBtn->raise();
mWiFiSetRemoteSettingsBtn->raise();
label->raise();
mWiFiGatewayAddressEditBx->raise();
label_2->raise();
retranslateUi(CChaletGui);
@ -203,6 +239,13 @@ public:
mLasCommRequestReceivedLbl->setText(QCoreApplication::translate("CChaletGui", "Last Request: ", nullptr));
mGetChaletLogButton->setText(QCoreApplication::translate("CChaletGui", "PushButton", nullptr));
mChaletTemperatureLbl->setText(QCoreApplication::translate("CChaletGui", "Temperature:", nullptr));
mWiFiIPAddressEditBx->setText(QCoreApplication::translate("CChaletGui", "?", nullptr));
mWiFiGetRemoteSettingsBtn->setText(QCoreApplication::translate("CChaletGui", "GET", nullptr));
mWiFiSetRemoteSettingsBtn->setText(QCoreApplication::translate("CChaletGui", "SET", nullptr));
label->setText(QCoreApplication::translate("CChaletGui", "IP Address:", nullptr));
mWiFiGatewayAddressEditBx->setText(QCoreApplication::translate("CChaletGui", "?", nullptr));
label_2->setText(QCoreApplication::translate("CChaletGui", "Gatweway:", nullptr));
groupBox_2->setTitle(QCoreApplication::translate("CChaletGui", "WiFi parameters (stored in flash)", nullptr));
} // retranslateUi
};