diff --git a/ZT b/ZT index e5e2cfb..acfaad1 100755 Binary files a/ZT and b/ZT differ diff --git a/sources/GuiElements/GeneralSettingsPage.cpp b/sources/GuiElements/GeneralSettingsPage.cpp index b351aa7..56c26be 100644 --- a/sources/GuiElements/GeneralSettingsPage.cpp +++ b/sources/GuiElements/GeneralSettingsPage.cpp @@ -35,11 +35,12 @@ #include #include #include -#include +//#include #include "ZTLog.h" + CGeneralSettingsPage::CGeneralSettingsPage(QGraphicsWidget *Parent) { Q_UNUSED(Parent) @@ -78,6 +79,12 @@ CGeneralSettingsPage::CGeneralSettingsPage(QGraphicsWidget *Parent) mTimeEdit->setTime(QTime::currentTime()); mTimeEdit->setDisplayFormat("hh:mm"); + mUseNetworkTimeChkBx = new QCheckBox("Utiliser l'heure réseau"); + Proxy = new QGraphicsProxyWidget(this); + Proxy->setWidget(mUseNetworkTimeChkBx); + Proxy->setPos(450,220); + connect(mUseNetworkTimeChkBx,SIGNAL(stateChanged(int)),this,SLOT(NetworkTimeChkBxClicked(int))); + mApplyDateTimeBtn = new CTextButtonWidget("Changer date & heure"); mApplyDateTimeBtn->setParentItem(this); mApplyDateTimeBtn->setPos(450,250); @@ -135,31 +142,37 @@ void CGeneralSettingsPage::ButtonClicked(CTextButtonWidget *BtnPtr) else if(BtnPtr == mApplyDateTimeBtn) { - time_t time_data = time(0); - struct tm* tm_ptr = localtime(&time_data); + QDateTime DateTime; + DateTime.setTime(mTimeEdit->time()); + DateTime.setDate(mCalendarWidget->selectedDate()); + mProgramHandle->SetSystemDateTime(&DateTime); - 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); - } +// 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) { @@ -177,6 +190,18 @@ void CGeneralSettingsPage::showEvent(QShowEvent *event) mPGTresholdValueSpinBox->setValue(mProgramHandle->GetPGTreshold()); } +void CGeneralSettingsPage::NetworkTimeChkBxClicked(int state) +{ + if(state == Qt::Checked) + { + mApplyDateTimeBtn->hide(); + } + else + { + mApplyDateTimeBtn->show(); + } +} + //Grab the mouse if the user clicks outside buttons void CGeneralSettingsPage::mousePressEvent(QGraphicsSceneMouseEvent *event) { diff --git a/sources/GuiElements/GeneralSettingsPage.h b/sources/GuiElements/GeneralSettingsPage.h index 5b9d4c5..9ad9405 100644 --- a/sources/GuiElements/GeneralSettingsPage.h +++ b/sources/GuiElements/GeneralSettingsPage.h @@ -39,6 +39,7 @@ #include #include #include +#include class CZoneTest; @@ -69,10 +70,12 @@ private: QSpinBox *mPGTresholdValueSpinBox; CTextButtonWidget *mPGValueSetBtn; QGraphicsTextItem *mActualPGTresholdValueText; + QCheckBox *mUseNetworkTimeChkBx; public slots: void ButtonClicked(CTextButtonWidget *); + void NetworkTimeChkBxClicked(int); }; diff --git a/sources/Modbus/ModbusCCMgr.cpp b/sources/Modbus/ModbusCCMgr.cpp index 9214868..65aec0e 100644 --- a/sources/Modbus/ModbusCCMgr.cpp +++ b/sources/Modbus/ModbusCCMgr.cpp @@ -28,6 +28,7 @@ CModbusCCMgr::CModbusCCMgr(CModbusRepository *Repo, int ModbusPort, int DevID) : mZTWatchdog = 0; mCCWatchdogState = 0; mCCLinkState = false; + mLastDateTime = 0; } CModbusCCMgr::~CModbusCCMgr() @@ -116,9 +117,16 @@ void CModbusCCMgr::RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length NetworkTime.setTimeSpec(Qt::UTC); NetworkTime.setDate(QDate(Year,Month,Day)); NetworkTime.setTime(QTime(Hours,Minutes,Secs)); - QDateTime MyTime = NetworkTime.toLocalTime(); + // QDateTime MyTime = NetworkTime.toLocalTime(); - qDebug("Date & Heure reçue du SACL: %s",MyTime.toString("yyyy-MM-dd hh:mm:ss").toAscii().data()); + if(mLastDateTime != 0) + { + delete mLastDateTime; + } + mLastDateTime = new QDateTime(NetworkTime.toLocalTime()); + emit ModbusDateTimeReceived(mLastDateTime); + + qDebug("Date & Heure reçue du SACL: %s",mLastDateTime->toString("yyyy-MM-dd hh:mm:ss").toAscii().data()); mModbusRepo->WriteSingleReg(MODBUS_CC_CLK_UPDATE_BASE_REG_ADD,0); } diff --git a/sources/Modbus/ModbusCCMgr.h b/sources/Modbus/ModbusCCMgr.h index dd44c51..10b8b49 100644 --- a/sources/Modbus/ModbusCCMgr.h +++ b/sources/Modbus/ModbusCCMgr.h @@ -29,6 +29,7 @@ private: qint16 mZTWatchdog; qint16 mCCWatchdogState; bool mCCLinkState; + QDateTime *mLastDateTime; signals: void RepoHasChanged(); @@ -36,6 +37,7 @@ signals: void ModbusCCDisconnected(); void ModbusCCLinkLost(); void ModbusCCLinkRecovered(); + void ModbusDateTimeReceived(QDateTime *DateTime); public slots: void NewModbusConnection(); diff --git a/sources/Zonetest.cpp b/sources/Zonetest.cpp index 0f708c5..70ebbca 100644 --- a/sources/Zonetest.cpp +++ b/sources/Zonetest.cpp @@ -57,6 +57,7 @@ #include "ZTVersion.h" #include "ModbusCCDefs.h" #include "ModbusTKTransport.h" +#include #ifdef USE_NETWORKING #include "NetworkManager.h" @@ -1270,9 +1271,44 @@ void CZoneTest::ACPISocketEvent() } - - - +void CZoneTest::ModbusDateTimeUpdate(QDateTime *NewDateTime) +{ + +} + +int CZoneTest::SetSystemDateTime(QDateTime *DateTime) +{ + time_t time_data = time(0); + struct tm* tm_ptr = localtime(&time_data); + + tm_ptr->tm_min = DateTime->time().minute(); + tm_ptr->tm_hour = DateTime->time().hour(); + tm_ptr->tm_mday = DateTime->date().day(); + tm_ptr->tm_mon = DateTime->date().month()-1; + tm_ptr->tm_year = DateTime->date().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); + return RET_ERROR; + } + 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); + return RET_ERROR; + } + else + { + CZTLog::instance()->AddLogString(QString().sprintf("Changement de date & heure: %s %s",DateTime->date().toString("yyyy/MM/dd").toUtf8().data(),DateTime->time().toString("hh:mm").toUtf8().data()),true); + } + } + return RET_OK; +} diff --git a/sources/Zonetest.h b/sources/Zonetest.h index 08cf62b..3f006b7 100644 --- a/sources/Zonetest.h +++ b/sources/Zonetest.h @@ -131,6 +131,8 @@ public: bool IsZT2PresentInStation(); + int SetSystemDateTime(QDateTime *DateTime); + //Networking requests @@ -150,6 +152,7 @@ private: void EnterDeadlockState(void); void CheckAndCreateDirectories(); + Panel panel; CStation *mZTStation; //The instance of the station in which the ZT is installed. @@ -215,6 +218,7 @@ public slots: void SMTimerExpired(); void ACPISocketConnected(); void ACPISocketEvent(); + void ModbusDateTimeUpdate(QDateTime *NewDateTime); // CSeaIOLibInterface mSeaIOLibInterface;