From da697ff567f597a31c7a83fa62bcf45850cddd87 Mon Sep 17 00:00:00 2001 From: zonetest Date: Thu, 20 Jul 2017 10:23:10 -0400 Subject: [PATCH] Modification de l'interface pour la synchro de la date & heure Modbus. --- Configuration/ZTSettings.ztc | Bin 29 -> 30 bytes sources/GuiElements/GeneralSettingsPage.cpp | 45 ++++++++------------ sources/GuiElements/GeneralSettingsPage.h | 2 + sources/ZTData.h | 1 + sources/ZTSettings.cpp | 11 ++++- sources/Zonetest.cpp | 16 ++++++- sources/Zonetest.h | 1 + 7 files changed, 45 insertions(+), 31 deletions(-) diff --git a/Configuration/ZTSettings.ztc b/Configuration/ZTSettings.ztc index 8a86c076bd1b6c8daabdacc802fd799b626acc7d..c64b1cd203e6cee44817ff0723a018c56f1fbe83 100644 GIT binary patch literal 30 VcmdnB_A~<{5?}ysetChecked(Qt::Checked); + mApplyDateTimeBtn->hide(); + } + else + { + mUseNetworkTimeChkBx->setChecked(Qt::Unchecked); + mApplyDateTimeBtn->show(); + } +} + void CGeneralSettingsPage::resizeEvent(QGraphicsSceneResizeEvent *event) { Q_UNUSED(event) @@ -141,38 +155,11 @@ void CGeneralSettingsPage::ButtonClicked(CTextButtonWidget *BtnPtr) } else if(BtnPtr == mApplyDateTimeBtn) { - QDateTime DateTime; DateTime.setTime(mTimeEdit->time()); DateTime.setDate(mCalendarWidget->selectedDate()); + CZTLog::instance()->AddLogString("Changement manuel de la date et l'heure",true); mProgramHandle->SetSystemDateTime(&DateTime); - - -// time_t time_data = time(0); -// struct tm* tm_ptr = localtime(&time_data); - -// tm_ptr->tm_min = mTimeEdit->time().minute(); -// tm_ptr->tm_hour = mTimeEdit->time().hour(); -// tm_ptr->tm_mday = mCalendarWidget->selectedDate().day(); -// tm_ptr->tm_mon = mCalendarWidget->selectedDate().month()-1; -// tm_ptr->tm_year = mCalendarWidget->selectedDate().year()-1900; - -// const struct timeval tv = {mktime(tm_ptr),0}; -// if(settimeofday(&tv,0) < 0) -// { -// qDebug("Settimeofday failed"); -// CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure",true); -// } -// else -// { -// if ( system("/sbin/hwclock --systohc") < 0 ) -// { -// //qDebug("hwclock sync failed"); -// CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure (hwsync failure)",true); -// } -// else -// CZTLog::instance()->AddLogString(QString().sprintf("Changement de date & heure: %s %s",mCalendarWidget->selectedDate().toString("yyyy/MM/dd").toUtf8().data(),mTimeEdit->time().toString("hh:mm").toUtf8().data()),true); -// } } else if(BtnPtr == mPGValueSetBtn) { @@ -195,10 +182,12 @@ void CGeneralSettingsPage::NetworkTimeChkBxClicked(int state) if(state == Qt::Checked) { mApplyDateTimeBtn->hide(); + mProgramHandle->UseNetworkTime(true); } else { mApplyDateTimeBtn->show(); + mProgramHandle->UseNetworkTime(false); } } diff --git a/sources/GuiElements/GeneralSettingsPage.h b/sources/GuiElements/GeneralSettingsPage.h index 9ad9405..7592713 100644 --- a/sources/GuiElements/GeneralSettingsPage.h +++ b/sources/GuiElements/GeneralSettingsPage.h @@ -52,6 +52,7 @@ public: CZoneTest *mProgramHandle; + void UseNetworkTime(bool UseNetworkTime); virtual void resizeEvent(QGraphicsSceneResizeEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); @@ -67,6 +68,7 @@ private: QTimeEdit *mTimeEdit; + QSpinBox *mPGTresholdValueSpinBox; CTextButtonWidget *mPGValueSetBtn; QGraphicsTextItem *mActualPGTresholdValueText; diff --git a/sources/ZTData.h b/sources/ZTData.h index eacb0d1..dfff449 100644 --- a/sources/ZTData.h +++ b/sources/ZTData.h @@ -327,6 +327,7 @@ class CZTSettingsData bool mKeepMPM10Logs; bool mKeepAllZT1Logs; bool mKeepAllZT2Logs; + bool mUseNetworkTime; }; diff --git a/sources/ZTSettings.cpp b/sources/ZTSettings.cpp index 792b9e7..1529e91 100644 --- a/sources/ZTSettings.cpp +++ b/sources/ZTSettings.cpp @@ -65,7 +65,7 @@ unsigned int CZTSettingsFileMgr::LoadSettings(CZTSettingsData *SettingsData) *InputStream >> MagicNbr; - if(MagicNbr != 0xBAADCAFE + 1) + if(MagicNbr != 0xBAADCAFE + 2) { CEngLog::instance()->AddLogString("Fichier de settings invalide (mauvais magic number). Chargement des paramètres par défaut"); LoadDefaultSettings(SettingsData); @@ -80,6 +80,7 @@ unsigned int CZTSettingsFileMgr::LoadSettings(CZTSettingsData *SettingsData) *InputStream >> SettingsData->mKeepMPM10Logs; *InputStream >> SettingsData->mKeepAllZT1Logs; *InputStream >> SettingsData->mKeepAllZT2Logs; + *InputStream >> SettingsData->mUseNetworkTime; SettingsFile->close(); @@ -110,7 +111,7 @@ unsigned int CZTSettingsFileMgr::SaveSettings(CZTSettingsData *SettingsData) QDataStream * OutputStream = new QDataStream(SettingsFile); - quint32 MagicNbr = 0xBAADCAFE + 1; + quint32 MagicNbr = 0xBAADCAFE + 2; *OutputStream << MagicNbr; @@ -123,6 +124,7 @@ unsigned int CZTSettingsFileMgr::SaveSettings(CZTSettingsData *SettingsData) *OutputStream << SettingsData->mKeepMPM10Logs; *OutputStream << SettingsData->mKeepAllZT1Logs; *OutputStream << SettingsData->mKeepAllZT2Logs; + *OutputStream << SettingsData->mUseNetworkTime; SettingsFile->flush(); SettingsFile->close(); @@ -161,6 +163,8 @@ void CZTSettingsFileMgr::LoadDefaultSettings(CZTSettingsData *SettingsData) SettingsData->mKeepAllZT1Logs = false; SettingsData->mKeepAllZT2Logs = false; + SettingsData->mUseNetworkTime = false; + } void CZTSettingsFileMgr::SetStationName(QString StationName) { @@ -225,6 +229,9 @@ void CZTSettingsFileMgr::LogSettings(CZTSettingsData *SettingsData, bool LogStat stream << " Conserver LOGS ZT2 = " << SettingsData->mKeepAllZT2Logs; CZTLog::instance()->AddLogString(temp,true); temp.clear(); + stream << QString().fromUtf8(" Utilisation de l'heure réseau = ") << SettingsData->mUseNetworkTime; + CZTLog::instance()->AddLogString(temp,true); + temp.clear(); } diff --git a/sources/Zonetest.cpp b/sources/Zonetest.cpp index 70ebbca..83776a4 100644 --- a/sources/Zonetest.cpp +++ b/sources/Zonetest.cpp @@ -507,6 +507,7 @@ unsigned int CZoneTest::InitZT() // connect(mModbusCCMgr,SIGNAL(RepoHasChanged()),mZTStateMachine,SLOT(ModbusCCANUpdate())); connect(mModbusCCMgr,SIGNAL(ModbusCCConnected()),panel.mZTMainPage,SLOT(ModbusCCConnected())); connect(mModbusCCMgr,SIGNAL(ModbusCCDisconnected()),panel.mZTMainPage,SLOT(ModbusCCDisconnected())); + connect(mModbusCCMgr,SIGNAL(ModbusDateTimeReceived(QDateTime*)),this,SLOT(ModbusDateTimeUpdate(QDateTime*))); panel.mZTMainPage->ModbusCCDisconnected(); } else @@ -585,6 +586,7 @@ unsigned int CZoneTest::InitZT() mWelcomePagePtr->InsertTextBoxString(QString("Chargement des fichiers de passage de trains: OK")); mZTStateMachine->SetAutoExportZT1CSV(mZTSettings->mAutoExportZT1CSV); mZTStateMachine->SetAutoExportZT2CSV(mZTSettings->mAutoExportZT2CSV); + panel.mGeneralSettingsPage->UseNetworkTime(mZTSettings->mUseNetworkTime); panel.mLogsListPage->BindPointers(mUSBDriveInterface); mUSBDriveInterface->Start(); // if(mDI710Module != 0) @@ -1020,6 +1022,11 @@ void CZoneTest::CloseGeneralSettingsPage() panel.mGeneralSettingsPage->hide(); } +void CZoneTest::UseNetworkTime(bool UseNetworkTime) +{ + mZTSettings->mUseNetworkTime = UseNetworkTime; + mZTSettingsFileMgr.SaveSettings(mZTSettings); +} ///Messages from ZTLog viewer page void CZoneTest::ShowZTLogViewerPage() @@ -1273,7 +1280,14 @@ void CZoneTest::ACPISocketEvent() void CZoneTest::ModbusDateTimeUpdate(QDateTime *NewDateTime) { - + if(mZTSettings->mUseNetworkTime == true) + { + if(*NewDateTime != QDateTime::currentDateTime()) + { + CZTLog::instance()->AddLogString("Synchronisation de l'heure avec le SACL"); + SetSystemDateTime(NewDateTime); + } + } } int CZoneTest::SetSystemDateTime(QDateTime *DateTime) diff --git a/sources/Zonetest.h b/sources/Zonetest.h index 3f006b7..5f5b072 100644 --- a/sources/Zonetest.h +++ b/sources/Zonetest.h @@ -115,6 +115,7 @@ public: void OpenGeneralSettingsPage(); void CloseGeneralSettingsPage(); + void UseNetworkTime(bool UseNetworkTime); void ShowZTLogViewerPage(); void HideZTLogViewerPage();