diff --git a/Sources/Chalet/CChalet.cpp b/Sources/Chalet/CChalet.cpp index efb814a..e9e062b 100644 --- a/Sources/Chalet/CChalet.cpp +++ b/Sources/Chalet/CChalet.cpp @@ -134,6 +134,11 @@ int CChalet::RequestDeviceWifiParams() } +int CChalet::RequestFirmwareVersion() +{ + mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_GET_FIRMWARE_VERSION_REQUEST,QByteArray()); +} + int CChalet::DeviceWiFiParamsReceived(QByteArray *Data) { quint32 Add = 0; @@ -169,6 +174,11 @@ int CChalet::DeviceWiFiParamsReceived(QByteArray *Data) return RET_OK; } +int CChalet::DeviceFirmwareVersionReceived(QByteArray Data) +{ + mChaletGui->UpdateFirmwareVersion(Data); +} + int CChalet::SetDeviceWifiParams(QString IP, QString Gateway) { QHostAddress DeviceIP; diff --git a/Sources/Chalet/CChalet.h b/Sources/Chalet/CChalet.h index 819c341..475a598 100644 --- a/Sources/Chalet/CChalet.h +++ b/Sources/Chalet/CChalet.h @@ -35,6 +35,8 @@ public: int RequestDeviceWifiParams(); int DeviceWiFiParamsReceived(QByteArray *Data); int SetDeviceWifiParams(QString IP, QString Gateway); + int RequestFirmwareVersion(); + int DeviceFirmwareVersionReceived(QByteArray Data); signals: diff --git a/Sources/Chalet/ChaletGui.cpp b/Sources/Chalet/ChaletGui.cpp index 34fd0de..fc34a06 100644 --- a/Sources/Chalet/ChaletGui.cpp +++ b/Sources/Chalet/ChaletGui.cpp @@ -15,6 +15,15 @@ CChaletGui::CChaletGui(QWidget *parent) : ui->mDoHarakiriButton->setEnabled(false); ui->mLogStartDateEdit->setDate(QDate::currentDate()); + mGetFimwVersionButtonColorTimer = new QTimer; + mGetFimwVersionButtonColorTimer->setSingleShot(true); + mGetFimwVersionButtonColorTimer->setInterval(500); + + mGetWifiParamsButtonColorTimer = new QTimer; + mGetWifiParamsButtonColorTimer->setSingleShot(true); + mGetWifiParamsButtonColorTimer->setInterval(500); + + 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())); @@ -25,6 +34,11 @@ CChaletGui::CChaletGui(QWidget *parent) : 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))); + connect(ui->mGetFirmwareVersionBtn,SIGNAL(clicked(bool)),this,SLOT(GetFirmwareVersionBtnClicked())); + connect(ui->mStartSyslogShellBtn,SIGNAL(clicked(bool)),this,SLOT(StartSyslogShellBtnClicked())); + connect(ui->mStartTerminalShellBtn,SIGNAL(clicked(bool)),this,SLOT(StartTerminalShellBtnClicked())); + connect(mGetFimwVersionButtonColorTimer,SIGNAL(timeout()),this,SLOT(GetFirmwVersionBtnColorTimerExpired())); + connect(mGetWifiParamsButtonColorTimer,SIGNAL(timeout()),this,SLOT(GetWifiParamsBtnColorTimerExpired())); mBatteryPlotWidget = new QCustomPlot(ui->mPlotWidget); mBatteryPlotWidget->resize(ui->mPlotWidget->size()); @@ -59,12 +73,18 @@ CChaletGui::CChaletGui(QWidget *parent) : mBatteryPlotWidget->graph(0)->addData(now,13.5); mBatteryPlotWidget->replot(); + + mFirmVersionDefaultBtnPal = ui->mGetFirmwareVersionBtn->palette(); + mWifiDefaultBtnPal = ui->mGetFirmwareVersionBtn->palette(); + } CChaletGui::~CChaletGui() { delete ui; delete mBatteryPlotWidget; + delete mGetFimwVersionButtonColorTimer; + delete mGetWifiParamsButtonColorTimer; } int CChaletGui::UpdateChaletStatus(CChaletMainStatus Status) @@ -87,7 +107,8 @@ int CChaletGui::UpdateChaletStatus(CChaletMainStatus Status) 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->mSolarPanelCurrentLabel->setText("Raw Solar Panel Current: Unknown"); + ui->mSolarPanelCurrentCnvLbl->setText("Solar Panel Current (A): Unknown"); ui->mLostReqPercentLbl->setText("N/A"); ui->mChaletTemperatureLbl->setText("Temperature: -100)"); @@ -186,9 +207,17 @@ int CChaletGui::UpdateChaletStatus(CChaletMainStatus Status) QString Voltage = QString("Battery Voltage: %1").arg(Status.mBatteryVoltage); ui->mBatteryVoltageLabel->setText(Voltage); - QString Current = QString("Solar Panel Current: %1").arg(Status.mBatteryCurrent); + QString Current = QString("Raw Solar Panel Current: %1").arg(Status.mBatteryCurrent); ui->mSolarPanelCurrentLabel->setText(Current); + float ConvertedCurrent = (float)Status.mBatteryCurrent * (3.3/1023); //*0.080645; // 3.3/(1023*0.04) = 0.080645; + ConvertedCurrent -= (3.3/2); + ConvertedCurrent *= 25; + QString CnvCurrent = QString("Solar Panel Current (A): %1").arg(ConvertedCurrent); + ui->mSolarPanelCurrentCnvLbl->setText(CnvCurrent); + + + QString SOC = QString("Battery SOC: %1").arg(Status.mBatterySOC); ui->mBatterySOCLabel->setText(SOC); @@ -331,4 +360,60 @@ void CChaletGui::RebootCPUButtonClicked() { ui->mWiFiIPAddressEditBx->setText(IP.toString()); ui->mWiFiGatewayAddressEditBx->setText(Gateway.toString()); + + QPalette pal = ui->mWiFiGetRemoteSettingsBtn->palette(); + pal.setColor(QPalette::Button, QColor(Qt::green)); + ui->mWiFiGetRemoteSettingsBtn->setAutoFillBackground(true); + ui->mWiFiGetRemoteSettingsBtn->setPalette(pal); + ui->mWiFiGetRemoteSettingsBtn->update(); + + mGetWifiParamsButtonColorTimer->start(); + } + + void CChaletGui::GetFirmwareVersionBtnClicked() + { + mProgramHandle->RequestFirmwareVersion(); + } + + void CChaletGui::UpdateFirmwareVersion(QByteArray Version) + { + QString VersionString(Version); + VersionString.prepend("Firmware version: "); + ui->mFirmwareVersionLabel->setText(VersionString); + + QPalette pal = ui->mGetFirmwareVersionBtn->palette(); + pal.setColor(QPalette::Button, QColor(Qt::green)); + ui->mGetFirmwareVersionBtn->setAutoFillBackground(true); + ui->mGetFirmwareVersionBtn->setPalette(pal); + ui->mGetFirmwareVersionBtn->update(); + + mGetFimwVersionButtonColorTimer->start(); + + } + + void CChaletGui::StartSyslogShellBtnClicked() + { + //system("c:\\progra~1\\putty\\putty.exe -load \"0-ChaletDuino_Syslog\""); +// QProcess Putty; + QProcess::startDetached("c:\\progra~1\\putty\\putty.exe -load \"0-ChaletDuino_Syslog\""); + } + + void CChaletGui::StartTerminalShellBtnClicked() + { +// system("c:\\program files\\putty\\putty.exe -load \"0-ChaletDuino_Terminal\""); + QProcess::startDetached("c:\\progra~1\\putty\\putty.exe -load \"0-ChaletDuino_Terminal\""); + } + + void CChaletGui::GetFirmwVersionBtnColorTimerExpired() + { + ui->mGetFirmwareVersionBtn->setAutoFillBackground(true); + ui->mGetFirmwareVersionBtn->setPalette(mFirmVersionDefaultBtnPal); + ui->mGetFirmwareVersionBtn->update(); + } + + void CChaletGui::GetWifiParamsBtnColorTimerExpired() + { + ui->mWiFiGetRemoteSettingsBtn->setAutoFillBackground(true); + ui->mWiFiGetRemoteSettingsBtn->setPalette(mFirmVersionDefaultBtnPal); + ui->mWiFiGetRemoteSettingsBtn->update(); } diff --git a/Sources/Chalet/ChaletGui.h b/Sources/Chalet/ChaletGui.h index bf7972a..c864f09 100644 --- a/Sources/Chalet/ChaletGui.h +++ b/Sources/Chalet/ChaletGui.h @@ -26,6 +26,8 @@ public: int UpdateChaletStatus(CChaletMainStatus Status); int UpdateChaletLogPlot(QByteArray* Log); int ChaletCommActivity(); + QTimer *mGetWifiParamsButtonColorTimer, *mGetFimwVersionButtonColorTimer; + QPalette mFirmVersionDefaultBtnPal, mWifiDefaultBtnPal; private: Ui::CChaletGui *ui; @@ -42,6 +44,14 @@ public slots: void GetDeviceWiFiParamsButtonClicked(bool); void SetDeviceWiFiParamsButtonClicked(bool); void UpdateDeviceWiFiParameters(QHostAddress IP,QHostAddress Gateway); + void GetFirmwareVersionBtnClicked(); + void UpdateFirmwareVersion(QByteArray Version); + void StartSyslogShellBtnClicked(); + void StartTerminalShellBtnClicked(); + void GetWifiParamsBtnColorTimerExpired(); + void GetFirmwVersionBtnColorTimerExpired(); + + }; #endif // CHALETGUI_H diff --git a/Sources/Chalet/ChaletGui.ui b/Sources/Chalet/ChaletGui.ui index d3312df..1a8ace1 100644 --- a/Sources/Chalet/ChaletGui.ui +++ b/Sources/Chalet/ChaletGui.ui @@ -6,8 +6,8 @@ 0 0 - 1024 - 598 + 1443 + 662 @@ -236,14 +236,14 @@ - Solar Panel Current: + Raw Solar Panel Current: - 187 - 280 + 190 + 300 241 16 @@ -255,8 +255,8 @@ - 187 - 300 + 190 + 320 241 16 @@ -283,7 +283,7 @@ 420 240 - 571 + 1021 321 @@ -341,7 +341,7 @@ 190 - 320 + 340 241 16 @@ -457,6 +457,76 @@ WiFi parameters (stored in flash) + + + + 190 + 280 + 201 + 16 + + + + Solar Panel Current (A): + + + + + + 180 + 520 + 231 + 20 + + + + + 10 + + + + Firmware Version: ? + + + + + + 90 + 520 + 75 + 23 + + + + GET + + + + + + 60 + 590 + 75 + 23 + + + + Terminal + + + + + + 150 + 590 + 75 + 23 + + + + Syslog + + groupBox_2 groupBox MainPageLabel @@ -488,6 +558,11 @@ label mWiFiGatewayAddressEditBx label_2 + mSolarPanelCurrentCnvLbl + mFirmwareVersionLabel + mGetFirmwareVersionBtn + mStartTerminalShellBtn + mStartSyslogShellBtn diff --git a/Sources/Chalet/ChaletMasterCtrlInterface.cpp b/Sources/Chalet/ChaletMasterCtrlInterface.cpp index 13c2044..243e7b5 100644 --- a/Sources/Chalet/ChaletMasterCtrlInterface.cpp +++ b/Sources/Chalet/ChaletMasterCtrlInterface.cpp @@ -94,6 +94,11 @@ int CChaletMasterCtrlInterface::DeviceFrameReceived(int TargetDeviceID, int Targ { break; } + case CHALET_INTERFACE_GET_FIRMWARE_VERSION_RESPONSE: + { + mProgramHandle->DeviceFirmwareVersionReceived(Data); + break; + } case CHALET_INTERFACE_GENERAL_STATUS_REQUEST: case CHALET_INTERFACE_AC_POWER_STATE_STATUS_REQUEST: case CHALET_INTERFACE_AC_POWER_SET_STATE_REQUEST: diff --git a/Sources/GuiMain.cpp b/Sources/GuiMain.cpp index db107f7..4ad8f0c 100644 --- a/Sources/GuiMain.cpp +++ b/Sources/GuiMain.cpp @@ -9,6 +9,7 @@ CGuiMain::CGuiMain(QWidget *parent) mAvReceiverGui = new CAvReceiverGui(this); mMainTabWidget = new QTabWidget(this); mChaletGui = new CChaletGui(this); + mIspindelGui = new CIspindelGUI(this); mTowerLightShowGui = new CTowerLightShowGui; mPICUploaderGui = new CPICUploaderGui; setCentralWidget(mMainTabWidget); @@ -18,8 +19,9 @@ CGuiMain::CGuiMain(QWidget *parent) mMainTabWidget->addTab(mChaletGui,"Chalet"); mMainTabWidget->addTab(mTowerLightShowGui,"Lightshow"); mMainTabWidget->addTab(mPICUploaderGui,"Firmware Upload"); + mMainTabWidget->addTab(mIspindelGui,"ISpindel"); - resize(1024,768); + resize(1700,768); } CGuiMain::~CGuiMain() diff --git a/Sources/GuiMain.h b/Sources/GuiMain.h index ad137bf..56b73f8 100644 --- a/Sources/GuiMain.h +++ b/Sources/GuiMain.h @@ -10,6 +10,7 @@ #include "ChaletGui.h" #include "TowerLightShowGui.h" #include "PICUploaderGui.h" +#include "IspindelGUI.h" class CGuiMain : public QMainWindow { @@ -26,6 +27,7 @@ public: QTabWidget *mMainTabWidget; CTowerLightShowGui *mTowerLightShowGui; CPICUploaderGui *mPICUploaderGui; + CIspindelGUI *mIspindelGui; int RespawnMainWindow(); int HideMainWindow(); diff --git a/Sources/Ispindel/Ispindel.cpp b/Sources/Ispindel/Ispindel.cpp new file mode 100644 index 0000000..eb7e9e8 --- /dev/null +++ b/Sources/Ispindel/Ispindel.cpp @@ -0,0 +1,123 @@ +#include "Ispindel.h" +#include +#include "IspindelInterface.h" + +CIspindel::CIspindel(CIspindelGUI *IspindelGui) +{ + mIspindelGui = IspindelGui; + IspindelGui->mProgramHandle = this; + mNetworkInterface = new CIspindelInterface(this); + +} + +CIspindel::~CIspindel() +{ + delete mNetworkInterface; +} + +void CIspindel::Start() +{ + mNetworkInterface->ConnectToMasterCtrl(); +} + +void CIspindel::IspindelFullBufferReceived(QByteArray *Data) +{ + int NbItems; + QDataStream Strm(Data,QIODevice::ReadOnly | QIODevice::Unbuffered); + + Strm >> NbItems; + + if(NbItems == 0) + { + qDebug("Received empty Ispindel buffer..."); + return; + } + + ClearIspindleDataList(); + + for(int i = 0; i < NbItems; i++) + { + CIspindelData *NewFrame = new CIspindelData; + Strm >> *NewFrame; + + mIspindelDataList.append(NewFrame); + } + + SetLasFrameTextInGUI(*mIspindelDataList.last()); + mIspindelGui->UpdateIspindelPlot(&mIspindelDataList); + +} + +void CIspindel::IspindelLastFrameReceived(QByteArray Data) +{ + int DataSize; + QDataStream Strm(&Data,QIODevice::ReadOnly | QIODevice::Unbuffered); + + if(Data.size() == 0) + return; + + CIspindelData *NewData = new CIspindelData(); + Strm >> *NewData; + + mIspindelDataList.append(NewData); + SetLasFrameTextInGUI(*NewData); + mIspindelGui->NewIspindelFrameReceived(NewData); + + // qDebug("Latest Ispindel data received"); + +} + +void CIspindel::ClearIspindleDataList() +{ + for(int i = 0; i < mIspindelDataList.size(); i++) + { + delete mIspindelDataList[i]; + } + + mIspindelDataList.clear(); +} + +void CIspindel::ConnectedToMaster(bool connected) +{ + if(connected) + { + mNetworkInterface->SendMasterCtrlCommand(ISPINDEL_GET_FULL_DATA_BUFFER_REQUEST,QByteArray()); + } +} + +void CIspindel::SetLasFrameTextInGUI(CIspindelData Frame) +{ + QString FrameText; + + FrameText = QString("\nLast Frame:\n------------------------------\nAngle: %1\nBattery Voltage: %2\nGravity: %3\nSample Interval: %4\nIspindel ID: %5\nIspindel Name: %6\nRSSI: %7\nTemperature: %8%9\nSample date time: %10\n------------------------------")\ + .arg(Frame.mAngle)\ + .arg(Frame.mBattery)\ + .arg(Frame.mGravity)\ + .arg(Frame.mInterval)\ + .arg(Frame.mIspindelID)\ + .arg(Frame.mIspindelName)\ + .arg(Frame.mRSSI)\ + .arg(Frame.mTemperature).arg(Frame.mTemperatureUnits)\ + .arg(Frame.mSampleDateTime.toString("yyyy-MM-dd - hh:mm:ss")); +// FrameText = QString("\nLast Frame\n\ +// Angle: %1\n\ +// Battery Voltage: %2\n\ +// Gravity: %3\n\ +// Sample Interval: %4\n\ +// Ispindel ID: %5\n\ +// Ispindel Name: %6\n\ +// RSSI: %7\n\ +// Temperature: %8%9\n\ +// Sample date time: %10")\ +// .arg(Frame.mAngle)\ +// .arg(Frame.mBattery)\ +// .arg(Frame.mGravity)\ +// .arg(Frame.mInterval)\ +// .arg(Frame.mIspindelID)\ +// .arg(Frame.mIspindelName)\ +// .arg(Frame.mRSSI)\ +// .arg(Frame.mTemperature).arg(Frame.mTemperatureUnits)\ +// .arg(Frame.mSampleDateTime.toString("yyyy-MM-dd - hh:mm:ss")); + + mIspindelGui->SetLastIspindelFrameData(FrameText); +} diff --git a/Sources/Ispindel/Ispindel.h b/Sources/Ispindel/Ispindel.h new file mode 100644 index 0000000..a5f6956 --- /dev/null +++ b/Sources/Ispindel/Ispindel.h @@ -0,0 +1,39 @@ +#ifndef ISPINDEL_H +#define ISPINDEL_H + +#include +#include "IspindelGUI.h" +#include "IspindelData.h" +#include +#include "QCustomPlot/qcustomplot.h" + +class CIspindelInterface; + +class CIspindel : public QObject +{ + Q_OBJECT +public: + explicit CIspindel(CIspindelGUI *IspindelGui); + ~CIspindel(); + + CIspindelGUI *mIspindelGui; + + + void Start(); + void IspindelFullBufferReceived(QByteArray *Data); + void IspindelLastFrameReceived(QByteArray Data); + void ClearIspindleDataList(); + void ConnectedToMaster(bool connected); + void SetLasFrameTextInGUI(CIspindelData Frame); + + QList mIspindelDataList; + CIspindelInterface *mNetworkInterface; + + + +signals: + +public slots: +}; + +#endif // ISPINDEL_H diff --git a/Sources/Ispindel/IspindelData.cpp b/Sources/Ispindel/IspindelData.cpp new file mode 100644 index 0000000..3edd24b --- /dev/null +++ b/Sources/Ispindel/IspindelData.cpp @@ -0,0 +1,54 @@ +#include "IspindelData.h" + + +CIspindelData::CIspindelData() +{ + mIspindelID = mRSSI = mInterval = 0; + mIspindelName = mTemperatureUnits = ""; + mAngle = mBattery = mGravity = mTemperature = 0.0; + mSampleDateTime = QDateTime::currentDateTime(); +} + +QDataStream &operator<<(QDataStream &out, const CIspindelData &source) +{ + out << source.mAngle + << source.mBattery + << source.mGravity + << source.mInterval + << source.mIspindelID + << source.mIspindelName + << source.mRSSI + << source.mTemperature + << source.mTemperatureUnits + << source.mSampleDateTime; + + return out; +} + +QDataStream &operator>>(QDataStream &in, CIspindelData &dest) +{ + in >> dest.mAngle + >> dest.mBattery + >> dest.mGravity + >> dest.mInterval + >> dest.mIspindelID + >> dest.mIspindelName + >> dest.mRSSI + >> dest.mTemperature + >> dest.mTemperatureUnits + >> dest.mSampleDateTime; + + return in; +} + +QByteArray CIspindelData::ToByteArray() +{ + QByteArray Array; + QDataStream Strm(&Array,QIODevice::WriteOnly | QIODevice::Unbuffered); + + Strm << *this; + + return Array; +} + + diff --git a/Sources/Ispindel/IspindelData.h b/Sources/Ispindel/IspindelData.h new file mode 100644 index 0000000..6a4a897 --- /dev/null +++ b/Sources/Ispindel/IspindelData.h @@ -0,0 +1,25 @@ +#ifndef CISPINDELDATA_H +#define CISPINDELDATA_H + +#include +#include +#include + +class CIspindelData +{ +public: + CIspindelData(); + + int mIspindelID, mRSSI, mInterval; + QString mIspindelName, mTemperatureUnits; + double mAngle, mBattery, mGravity, mTemperature; + QDateTime mSampleDateTime; + + QByteArray ToByteArray(); + +}; + + +QDataStream &operator<<(QDataStream &out, const CIspindelData &source); +QDataStream &operator>>(QDataStream &in, CIspindelData &dest); +#endif // CISPINDELDATA_H diff --git a/Sources/Ispindel/IspindelGUI.cpp b/Sources/Ispindel/IspindelGUI.cpp new file mode 100644 index 0000000..3b78368 --- /dev/null +++ b/Sources/Ispindel/IspindelGUI.cpp @@ -0,0 +1,110 @@ +#include "IspindelGUI.h" +#include "ui_IspindelGUI.h" +#include "Ispindel.h" +#include "IspindelData.h" +#include "GlobalDefine.h" + +CIspindelGUI::CIspindelGUI(QWidget *parent) : + QDialog(parent), + ui(new Ui::CIspindelGUI) +{ + ui->setupUi(this); + + + mIspindelPlot = new QCustomPlot(ui->mIspindelPlot); + mIspindelPlot->resize(ui->mIspindelPlot->size()); + + // create graph and assign data to it: + mIspindelPlot->addGraph(); + mIspindelPlot->addGraph(mIspindelPlot->xAxis,mIspindelPlot->yAxis2); + + + // give the axes some labels: + mIspindelPlot->xAxis->setLabel("Time"); + mIspindelPlot->yAxis->setLabel("Gravity"); + mIspindelPlot->yAxis2->setLabel("Temprature (C)"); + mIspindelPlot->yAxis2->setVisible(true); + + double now = QDateTime::currentDateTime().toSecsSinceEpoch(); + QSharedPointer dateTicker(new QCPAxisTickerDateTime); + dateTicker->setDateTimeFormat("hh:mm:ss\ndd MMM"); + mIspindelPlot->xAxis->setTicker(dateTicker); + mIspindelPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); + QList xAxis, yAxis; + xAxis.append(mIspindelPlot->xAxis); + yAxis.append(mIspindelPlot->yAxis); + yAxis.append(mIspindelPlot->yAxis2); + mIspindelPlot->axisRect()->setRangeDragAxes(xAxis,yAxis); + mIspindelPlot->axisRect()->setRangeZoomAxes(xAxis,yAxis); +// mIspindelPlot->yAxis2->axisRect()->setRangeZoomAxes(0,mIspindelPlot->yAxis2); + + + QDateTime Now = QDateTime::currentDateTime().toLocalTime(); + + QDateTime midnight = Now; + midnight.setTime(QTime(0,0,0)); + QDateTime eod = Now; + eod.setTime(QTime(23,59,0)); + + //mIspindelPlot->xAxis->setRange(0/*QCPAxisTickerDateTime::dateTimeToKey(midnight)*/,QCPAxisTickerDateTime::dateTimeToKey(eod)); +// mIspindelPlot->xAxis->setRange(now, now+(2*3600)); + mIspindelPlot->xAxis->setRange(midnight.toSecsSinceEpoch(), eod.toSecsSinceEpoch()); + + mIspindelPlot->yAxis->setRange(1.000,1.01); + mIspindelPlot->yAxis2->setRange(15,25); + +// mIspindelPlot->graph(0)->addData(now,1.005); +// mIspindelPlot->graph(1)->addData(now,20); + + mIspindelPlot->replot(); +} + +CIspindelGUI::~CIspindelGUI() +{ + delete ui; +} + +void CIspindelGUI::SetLastIspindelFrameData(QString Data) +{ + ui->mLastFrameDataLbl->setText(Data); +} + +int CIspindelGUI::UpdateIspindelPlot(QList *Data) +{ + if(Data->size() == 0) + return RET_ERROR; + + QVector x,y,ty; + for(int i = 0; i < Data->size(); i++) + { + x.append(Data->at(i)->mSampleDateTime.toSecsSinceEpoch()); + y.append(Data->at(i)->mGravity); + ty.append(Data->at(i)->mTemperature); + } + + if(x.size() == 0 || y.size() == 0) + return RET_ERROR; + + mIspindelPlot->graph(0)->data().clear(); + mIspindelPlot->graph(0)->setData(x,y); + mIspindelPlot->xAxis->setRange(x.first(),x.last()); + mIspindelPlot->yAxis->setRange(y.first(),y.last()); + + + mIspindelPlot->graph(1)->setPen(QColor(Qt::red)); + mIspindelPlot->graph(1)->setName("Température"); + mIspindelPlot->graph(1)->setData(x,ty); + mIspindelPlot->yAxis2->setRange(10,30); + + mIspindelPlot->replot(); + + return RET_OK; +} + +int CIspindelGUI::NewIspindelFrameReceived(CIspindelData *Data) +{ + mIspindelPlot->graph(0)->addData(Data->mSampleDateTime.toSecsSinceEpoch(),Data->mGravity); + mIspindelPlot->graph(1)->addData(Data->mSampleDateTime.toSecsSinceEpoch(),Data->mTemperature); + + mIspindelPlot->replot(); +} diff --git a/Sources/Ispindel/IspindelGUI.h b/Sources/Ispindel/IspindelGUI.h new file mode 100644 index 0000000..33c78a5 --- /dev/null +++ b/Sources/Ispindel/IspindelGUI.h @@ -0,0 +1,34 @@ +#ifndef ISPINDELGUI_H +#define ISPINDELGUI_H + +#include +#include "QCustomPlot/qcustomplot.h" +#include + +namespace Ui { +class CIspindelGUI; +} + +class CIspindel; +class CIspindelData; + +class CIspindelGUI : public QDialog +{ + Q_OBJECT + +public: + explicit CIspindelGUI(QWidget *parent = 0); + ~CIspindelGUI(); + CIspindel *mProgramHandle; + + void SetLastIspindelFrameData(QString Data); + int UpdateIspindelPlot(QList *Data); + int NewIspindelFrameReceived(CIspindelData *Data); + + QCustomPlot *mIspindelPlot; + +private: + Ui::CIspindelGUI *ui; +}; + +#endif // ISPINDELGUI_H diff --git a/Sources/Ispindel/IspindelGUI.ui b/Sources/Ispindel/IspindelGUI.ui new file mode 100644 index 0000000..1ffd27e --- /dev/null +++ b/Sources/Ispindel/IspindelGUI.ui @@ -0,0 +1,81 @@ + + + CIspindelGUI + + + + 0 + 0 + 1123 + 629 + + + + Dialog + + + + + 510 + 20 + 91 + 41 + + + + + 12 + + + + ISpindel + + + + + + 520 + 100 + 661 + 461 + + + + + + + 60 + 50 + 381 + 211 + + + + + Tahoma + 11 + 75 + true + + + + No data... + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + 10 + 290 + 461 + 331 + + + + + + + diff --git a/Sources/Ispindel/IspindelInterface.cpp b/Sources/Ispindel/IspindelInterface.cpp new file mode 100644 index 0000000..d0129f0 --- /dev/null +++ b/Sources/Ispindel/IspindelInterface.cpp @@ -0,0 +1,64 @@ +#include "IspindelInterface.h" +#include "IspindelData.h" +#include "Ispindel.h" +#include "ProtocolDefs.h" + +CIspindelInterface::CIspindelInterface(CIspindel *ProgramHandle) +{ + mMyDeviceID = ID_ISPINDEL_INTERFACE; + mNetworkPort = 2182; + mMasterCtrlIPAddress = "127.0.0.1"; + mNetworkCommSocket = 0; + mDeviceAddress = 1; + + mProgramHandle = ProgramHandle; +} + +int CIspindelInterface::DeviceConnectedToMaster(bool Connected) +{ + if(Connected) + { + qDebug("Ispindel Interface connected to Master."); + mProgramHandle->ConnectedToMaster(Connected); + + } + else + return RET_ERROR; + + return RET_OK; +} + +int CIspindelInterface::DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data) +{ + Q_UNUSED(DataSize) + Q_UNUSED(SenderID) + Q_UNUSED(SenderAddress) + + if(TargetDeviceID == mMyDeviceID && (TargetDeviceAddress == BROADCAST_VALUE || TargetDeviceAddress == mDeviceAddress)) + { + switch(MessageID) + { + case ISPINDEL_GET_FULL_DATA_BUFFER_RESPONSE: + { + mProgramHandle->IspindelFullBufferReceived(&Data); + break; + } + case ISPINDLE_LATEST_DATA_RESPONSE: + { + mProgramHandle->IspindelLastFrameReceived(Data); + break; + } + case ISPINDEL_GET_FULL_DATA_BUFFER_REQUEST: + case ISPINDLE_LATEST_DATA_REQUEST: + default: + { + qDebug("Ispindel: Invalid Ethernet Msg received from MasterCtrl: %d",MessageID); + break; + } + } + + } + + return RET_OK; + +} diff --git a/Sources/Ispindel/IspindelInterface.h b/Sources/Ispindel/IspindelInterface.h new file mode 100644 index 0000000..c254b45 --- /dev/null +++ b/Sources/Ispindel/IspindelInterface.h @@ -0,0 +1,20 @@ +#ifndef ISPINDELINTERFACE_H +#define ISPINDELINTERFACE_H + +#include "MasterCtrlInterface.h" + +class CIspindel; + +class CIspindelInterface : public CMasterCtrlInterface +{ +public: + CIspindelInterface(CIspindel *ProgramHandle); + + int DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data); + int DeviceConnectedToMaster(bool Connected); + +private: + CIspindel *mProgramHandle; +}; + +#endif // ISPINDELINTERFACE_H diff --git a/Sources/PICUploader/PICUploaderGui.ui b/Sources/PICUploader/PICUploaderGui.ui index 7033284..dd86329 100644 --- a/Sources/PICUploader/PICUploaderGui.ui +++ b/Sources/PICUploader/PICUploaderGui.ui @@ -56,7 +56,7 @@ - 192.168.50.126 + 192.168.30.125 diff --git a/Sources/ProtocolDefs.h b/Sources/ProtocolDefs.h index 9d089eb..a687378 100644 --- a/Sources/ProtocolDefs.h +++ b/Sources/ProtocolDefs.h @@ -59,10 +59,11 @@ enum DEVICES_IDS ID_DEADBOLT_INTERFACE, ID_AVRECEIVER_INTERFACE, ID_CHALET_INTERFACE, + ID_CHALET_DEVICE, + ID_ISPINDEL_INTERFACE, ID_NB_DEVICE_ID }; - // Commands definitions enum MASTER_CMD @@ -273,6 +274,8 @@ enum CHALET_INTERFACE_CMDS CHALET_INTERFACE_WIFI_GET_DEVICE_PARAMS_RESPONSE, CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_REQUEST, CHALET_INTERFACE_WIFI_SET_DEVICE_PARAMS_RESPONSE, + CHALET_INTERFACE_GET_FIRMWARE_VERSION_REQUEST, + CHALET_INTERFACE_GET_FIRMWARE_VERSION_RESPONSE, MAX_CHALET_INTERFACE_CMD @@ -342,4 +345,15 @@ enum BOOTLOADER_CMDS MAX_BOOTLOADER_CMD }; +enum ISPINDLE_CMDS +{ + ISPINDLE_ACK = 1, + ISPINDLE_LATEST_DATA_REQUEST, + ISPINDLE_LATEST_DATA_RESPONSE, + ISPINDEL_GET_FULL_DATA_BUFFER_REQUEST, + ISPINDEL_GET_FULL_DATA_BUFFER_RESPONSE, + + MAX_ISPINDLE_CMDS +}; + #endif diff --git a/Sources/SystemGui.cpp b/Sources/SystemGui.cpp index a566e1f..c6a897c 100644 --- a/Sources/SystemGui.cpp +++ b/Sources/SystemGui.cpp @@ -10,6 +10,7 @@ CSystemGui::CSystemGui(QObject *parent) : QObject(parent) mAvReceiver = new CAvReceiver(mGui->mAvReceiverGui); mChalet = new CChalet(mGui->mChaletGui); mPICUploader = new CPICUploader(mGui->mPICUploaderGui); + mIspindel = new CIspindel(mGui->mIspindelGui); mSysTrayMgr = new CSystemTrayManager(); mSysTrayMgr->mProgramHandle=this; @@ -26,6 +27,7 @@ CSystemGui::~CSystemGui() delete mAvReceiver; delete mChalet; delete mPICUploader; + delete mIspindel; } @@ -37,6 +39,7 @@ void CSystemGui::Start() mAvReceiver->Start(); mChalet->Start(); mPICUploader->Start(); + mIspindel->Start(); } diff --git a/Sources/SystemGui.h b/Sources/SystemGui.h index 67a23e5..49427c8 100644 --- a/Sources/SystemGui.h +++ b/Sources/SystemGui.h @@ -11,6 +11,7 @@ #include "AvReceiver.h" #include "CChalet.h" #include "PICUploader.h" +#include "Ispindel.h" class CSystemGui : public QObject @@ -37,6 +38,7 @@ private: CAvReceiver *mAvReceiver; CChalet *mChalet; CPICUploader *mPICUploader; + CIspindel *mIspindel; signals: diff --git a/SystemGui.pro b/SystemGui.pro index 80d868e..8ab0a59 100644 --- a/SystemGui.pro +++ b/SystemGui.pro @@ -29,6 +29,7 @@ INCLUDEPATH += Sources\ Sources/Chalet\ Sources/Tower\ Sources/PICUploader\ + Sources/Ispindel \ SOURCES += \ Sources/Chalet/CChalet.cpp \ @@ -71,7 +72,11 @@ SOURCES += \ Sources/PICUploader/HexFile.cpp \ Sources/PICUploader/HexRecord.cpp \ Sources/PICUploader/BootloaderProtocol.cpp \ - Sources/CRC32.cpp + Sources/CRC32.cpp \ + Sources/Ispindel/IspindelGUI.cpp \ + Sources/Ispindel/Ispindel.cpp \ + Sources/Ispindel/IspindelInterface.cpp \ + Sources/Ispindel/IspindelData.cpp HEADERS += Sources/AbstractNetworkInterface.h \ Sources/Chalet/CChalet.h \ @@ -115,7 +120,11 @@ HEADERS += Sources/AbstractNetworkInterface.h \ Sources/PICUploader/HexFile.h \ Sources/PICUploader/HexRecord.h \ Sources/PICUploader/BootloaderProtocol.h \ - Sources/CRC32.h + Sources/CRC32.h \ + Sources/Ispindel/IspindelGUI.h \ + Sources/Ispindel/Ispindel.h \ + Sources/Ispindel/IspindelInterface.h \ + Sources/Ispindel/IspindelData.h FORMS += \ SMSGui.ui \ @@ -124,4 +133,5 @@ FORMS += \ Sources/Sprinkler/SprinklerGui.ui \ Sources/Sprinkler/SprinklerDeviceGuiItem.ui \ Sources/AvReceiver/AvReceiverGui.ui \ - Sources/Tower/TowerLightShowGui.ui + Sources/Tower/TowerLightShowGui.ui \ + Sources/Ispindel/IspindelGUI.ui diff --git a/ui_ChaletGui.h b/ui_ChaletGui.h index c17f04f..9e3c70d 100644 --- a/ui_ChaletGui.h +++ b/ui_ChaletGui.h @@ -56,12 +56,17 @@ public: QLineEdit *mWiFiGatewayAddressEditBx; QLabel *label_2; QGroupBox *groupBox_2; + QLabel *mSolarPanelCurrentCnvLbl; + QLabel *mFirmwareVersionLabel; + QPushButton *mGetFirmwareVersionBtn; + QPushButton *mStartTerminalShellBtn; + QPushButton *mStartSyslogShellBtn; void setupUi(QWidget *CChaletGui) { if (CChaletGui->objectName().isEmpty()) CChaletGui->setObjectName(QString::fromUtf8("CChaletGui")); - CChaletGui->resize(1024, 598); + CChaletGui->resize(1443, 662); MainPageLabel = new QLabel(CChaletGui); MainPageLabel->setObjectName(QString::fromUtf8("MainPageLabel")); MainPageLabel->setGeometry(QRect(460, 10, 71, 31)); @@ -124,16 +129,16 @@ public: mSolarPanelCurrentLabel->setGeometry(QRect(187, 260, 241, 16)); mBatterySOCLabel = new QLabel(CChaletGui); mBatterySOCLabel->setObjectName(QString::fromUtf8("mBatterySOCLabel")); - mBatterySOCLabel->setGeometry(QRect(187, 280, 241, 16)); + mBatterySOCLabel->setGeometry(QRect(190, 300, 241, 16)); mCurrentSensorStateLbl = new QLabel(CChaletGui); mCurrentSensorStateLbl->setObjectName(QString::fromUtf8("mCurrentSensorStateLbl")); - mCurrentSensorStateLbl->setGeometry(QRect(187, 300, 241, 16)); + mCurrentSensorStateLbl->setGeometry(QRect(190, 320, 241, 16)); mLostReqPercentLbl = new QLabel(CChaletGui); mLostReqPercentLbl->setObjectName(QString::fromUtf8("mLostReqPercentLbl")); mLostReqPercentLbl->setGeometry(QRect(600, 190, 241, 16)); mPlotWidget = new QWidget(CChaletGui); mPlotWidget->setObjectName(QString::fromUtf8("mPlotWidget")); - mPlotWidget->setGeometry(QRect(420, 240, 571, 321)); + mPlotWidget->setGeometry(QRect(420, 240, 1021, 321)); mChaletCommActivityLbl = new QLabel(CChaletGui); mChaletCommActivityLbl->setObjectName(QString::fromUtf8("mChaletCommActivityLbl")); mChaletCommActivityLbl->setGeometry(QRect(600, 170, 47, 16)); @@ -148,7 +153,7 @@ public: mGetChaletLogButton->setGeometry(QRect(900, 210, 75, 23)); mChaletTemperatureLbl = new QLabel(CChaletGui); mChaletTemperatureLbl->setObjectName(QString::fromUtf8("mChaletTemperatureLbl")); - mChaletTemperatureLbl->setGeometry(QRect(190, 320, 241, 16)); + mChaletTemperatureLbl->setGeometry(QRect(190, 340, 241, 16)); mWiFiIPAddressEditBx = new QLineEdit(CChaletGui); mWiFiIPAddressEditBx->setObjectName(QString::fromUtf8("mWiFiIPAddressEditBx")); mWiFiIPAddressEditBx->setGeometry(QRect(160, 430, 221, 20)); @@ -176,6 +181,22 @@ public: groupBox_2 = new QGroupBox(CChaletGui); groupBox_2->setObjectName(QString::fromUtf8("groupBox_2")); groupBox_2->setGeometry(QRect(80, 370, 321, 131)); + mSolarPanelCurrentCnvLbl = new QLabel(CChaletGui); + mSolarPanelCurrentCnvLbl->setObjectName(QString::fromUtf8("mSolarPanelCurrentCnvLbl")); + mSolarPanelCurrentCnvLbl->setGeometry(QRect(190, 280, 201, 16)); + mFirmwareVersionLabel = new QLabel(CChaletGui); + mFirmwareVersionLabel->setObjectName(QString::fromUtf8("mFirmwareVersionLabel")); + mFirmwareVersionLabel->setGeometry(QRect(180, 520, 231, 20)); + mFirmwareVersionLabel->setFont(font2); + mGetFirmwareVersionBtn = new QPushButton(CChaletGui); + mGetFirmwareVersionBtn->setObjectName(QString::fromUtf8("mGetFirmwareVersionBtn")); + mGetFirmwareVersionBtn->setGeometry(QRect(90, 520, 75, 23)); + mStartTerminalShellBtn = new QPushButton(CChaletGui); + mStartTerminalShellBtn->setObjectName(QString::fromUtf8("mStartTerminalShellBtn")); + mStartTerminalShellBtn->setGeometry(QRect(60, 590, 75, 23)); + mStartSyslogShellBtn = new QPushButton(CChaletGui); + mStartSyslogShellBtn->setObjectName(QString::fromUtf8("mStartSyslogShellBtn")); + mStartSyslogShellBtn->setGeometry(QRect(150, 590, 75, 23)); groupBox_2->raise(); groupBox->raise(); MainPageLabel->raise(); @@ -207,6 +228,11 @@ public: label->raise(); mWiFiGatewayAddressEditBx->raise(); label_2->raise(); + mSolarPanelCurrentCnvLbl->raise(); + mFirmwareVersionLabel->raise(); + mGetFirmwareVersionBtn->raise(); + mStartTerminalShellBtn->raise(); + mStartSyslogShellBtn->raise(); retranslateUi(CChaletGui); @@ -231,7 +257,7 @@ public: mDoHarakiriButton->setText(QCoreApplication::translate("CChaletGui", "DO HARAKIRI !!!", nullptr)); mBatteryVoltageLabel->setText(QCoreApplication::translate("CChaletGui", "Battery Voltage", nullptr)); mChaletOnlineStatusLbl->setText(QCoreApplication::translate("CChaletGui", "OFFLINE", nullptr)); - mSolarPanelCurrentLabel->setText(QCoreApplication::translate("CChaletGui", "Solar Panel Current: ", nullptr)); + mSolarPanelCurrentLabel->setText(QCoreApplication::translate("CChaletGui", "Raw Solar Panel Current: ", nullptr)); mBatterySOCLabel->setText(QCoreApplication::translate("CChaletGui", "Battery SOC: ", nullptr)); mCurrentSensorStateLbl->setText(QCoreApplication::translate("CChaletGui", "Current Sensor:", nullptr)); mLostReqPercentLbl->setText(QCoreApplication::translate("CChaletGui", "Lost requests: ", nullptr)); @@ -246,6 +272,11 @@ public: 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)); + mSolarPanelCurrentCnvLbl->setText(QCoreApplication::translate("CChaletGui", "Solar Panel Current (A):", nullptr)); + mFirmwareVersionLabel->setText(QCoreApplication::translate("CChaletGui", "Firmware Version: ?", nullptr)); + mGetFirmwareVersionBtn->setText(QCoreApplication::translate("CChaletGui", "GET", nullptr)); + mStartTerminalShellBtn->setText(QCoreApplication::translate("CChaletGui", "Terminal", nullptr)); + mStartSyslogShellBtn->setText(QCoreApplication::translate("CChaletGui", "Syslog", nullptr)); } // retranslateUi }; diff --git a/ui_IspindelGUI.h b/ui_IspindelGUI.h new file mode 100644 index 0000000..86fa5ca --- /dev/null +++ b/ui_IspindelGUI.h @@ -0,0 +1,78 @@ +/******************************************************************************** +** Form generated from reading UI file 'IspindelGUI.ui' +** +** Created by: Qt User Interface Compiler version 5.14.2 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_ISPINDELGUI_H +#define UI_ISPINDELGUI_H + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Ui_CIspindelGUI +{ +public: + QLabel *label; + QWidget *mIspindelPlot; + QLabel *mLastFrameDataLbl; + QTableWidget *tableWidget; + + void setupUi(QDialog *CIspindelGUI) + { + if (CIspindelGUI->objectName().isEmpty()) + CIspindelGUI->setObjectName(QString::fromUtf8("CIspindelGUI")); + CIspindelGUI->resize(1123, 629); + label = new QLabel(CIspindelGUI); + label->setObjectName(QString::fromUtf8("label")); + label->setGeometry(QRect(510, 20, 91, 41)); + QFont font; + font.setPointSize(12); + label->setFont(font); + mIspindelPlot = new QWidget(CIspindelGUI); + mIspindelPlot->setObjectName(QString::fromUtf8("mIspindelPlot")); + mIspindelPlot->setGeometry(QRect(520, 100, 661, 461)); + mLastFrameDataLbl = new QLabel(CIspindelGUI); + mLastFrameDataLbl->setObjectName(QString::fromUtf8("mLastFrameDataLbl")); + mLastFrameDataLbl->setGeometry(QRect(60, 50, 381, 211)); + QFont font1; + font1.setFamily(QString::fromUtf8("Tahoma")); + font1.setPointSize(11); + font1.setBold(true); + font1.setWeight(75); + mLastFrameDataLbl->setFont(font1); + mLastFrameDataLbl->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter); + tableWidget = new QTableWidget(CIspindelGUI); + tableWidget->setObjectName(QString::fromUtf8("tableWidget")); + tableWidget->setGeometry(QRect(10, 290, 461, 331)); + + retranslateUi(CIspindelGUI); + + QMetaObject::connectSlotsByName(CIspindelGUI); + } // setupUi + + void retranslateUi(QDialog *CIspindelGUI) + { + CIspindelGUI->setWindowTitle(QCoreApplication::translate("CIspindelGUI", "Dialog", nullptr)); + label->setText(QCoreApplication::translate("CIspindelGUI", "ISpindel", nullptr)); + mLastFrameDataLbl->setText(QCoreApplication::translate("CIspindelGUI", "No data...", nullptr)); + } // retranslateUi + +}; + +namespace Ui { + class CIspindelGUI: public Ui_CIspindelGUI {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_ISPINDELGUI_H diff --git a/ui_PICUploaderGui.h b/ui_PICUploaderGui.h index 3e8f586..2df9296 100644 --- a/ui_PICUploaderGui.h +++ b/ui_PICUploaderGui.h @@ -137,7 +137,7 @@ public: CPICUploaderGui->setWindowTitle(QCoreApplication::translate("CPICUploaderGui", "Dialog", nullptr)); label->setText(QCoreApplication::translate("CPICUploaderGui", "Firmware Uploader", nullptr)); mHexFileSelectBtn->setText(QCoreApplication::translate("CPICUploaderGui", "Open Hex File", nullptr)); - mIPAddressEdit->setText(QCoreApplication::translate("CPICUploaderGui", "192.168.50.126", nullptr)); + mIPAddressEdit->setText(QCoreApplication::translate("CPICUploaderGui", "192.168.30.125", nullptr)); mOpenedHexFilePathLbl->setText(QCoreApplication::translate("CPICUploaderGui", "No File Opened", nullptr)); mHexFileStatsLbl->setText(QString()); mConnectBtn->setText(QCoreApplication::translate("CPICUploaderGui", "Connect", nullptr));