Dev pour retour du LoRa au chalet

This commit is contained in:
2021-10-12 11:28:53 -04:00
parent 512bc280e7
commit 75b487a862
9 changed files with 335 additions and 18 deletions
+97
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;
}
+3
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:
+21 -1
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());
}
+4
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
+114 -11
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/>
@@ -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);
+1
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();
}
+34
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,