Changement de l'interface pour l'heure Modbus
This commit is contained in:
parent
ffd2a4383d
commit
a3cde7b718
@ -35,11 +35,12 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QGraphicsProxyWidget>
|
#include <QGraphicsProxyWidget>
|
||||||
#include <sys/time.h>
|
//#include <sys/time.h>
|
||||||
#include "ZTLog.h"
|
#include "ZTLog.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CGeneralSettingsPage::CGeneralSettingsPage(QGraphicsWidget *Parent)
|
CGeneralSettingsPage::CGeneralSettingsPage(QGraphicsWidget *Parent)
|
||||||
{
|
{
|
||||||
Q_UNUSED(Parent)
|
Q_UNUSED(Parent)
|
||||||
@ -78,6 +79,12 @@ CGeneralSettingsPage::CGeneralSettingsPage(QGraphicsWidget *Parent)
|
|||||||
mTimeEdit->setTime(QTime::currentTime());
|
mTimeEdit->setTime(QTime::currentTime());
|
||||||
mTimeEdit->setDisplayFormat("hh:mm");
|
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 = new CTextButtonWidget("Changer date & heure");
|
||||||
mApplyDateTimeBtn->setParentItem(this);
|
mApplyDateTimeBtn->setParentItem(this);
|
||||||
mApplyDateTimeBtn->setPos(450,250);
|
mApplyDateTimeBtn->setPos(450,250);
|
||||||
@ -135,31 +142,37 @@ void CGeneralSettingsPage::ButtonClicked(CTextButtonWidget *BtnPtr)
|
|||||||
else if(BtnPtr == mApplyDateTimeBtn)
|
else if(BtnPtr == mApplyDateTimeBtn)
|
||||||
{
|
{
|
||||||
|
|
||||||
time_t time_data = time(0);
|
QDateTime DateTime;
|
||||||
struct tm* tm_ptr = localtime(&time_data);
|
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};
|
// time_t time_data = time(0);
|
||||||
if(settimeofday(&tv,0) < 0)
|
// struct tm* tm_ptr = localtime(&time_data);
|
||||||
{
|
|
||||||
qDebug("Settimeofday failed");
|
// tm_ptr->tm_min = mTimeEdit->time().minute();
|
||||||
CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure",true);
|
// tm_ptr->tm_hour = mTimeEdit->time().hour();
|
||||||
}
|
// tm_ptr->tm_mday = mCalendarWidget->selectedDate().day();
|
||||||
else
|
// tm_ptr->tm_mon = mCalendarWidget->selectedDate().month()-1;
|
||||||
{
|
// tm_ptr->tm_year = mCalendarWidget->selectedDate().year()-1900;
|
||||||
if ( system("/sbin/hwclock --systohc") < 0 )
|
|
||||||
{
|
// const struct timeval tv = {mktime(tm_ptr),0};
|
||||||
//qDebug("hwclock sync failed");
|
// if(settimeofday(&tv,0) < 0)
|
||||||
CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure (hwsync failure)",true);
|
// {
|
||||||
}
|
// qDebug("Settimeofday failed");
|
||||||
else
|
// CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure",true);
|
||||||
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 ( 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)
|
else if(BtnPtr == mPGValueSetBtn)
|
||||||
{
|
{
|
||||||
@ -177,6 +190,18 @@ void CGeneralSettingsPage::showEvent(QShowEvent *event)
|
|||||||
mPGTresholdValueSpinBox->setValue(mProgramHandle->GetPGTreshold());
|
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
|
//Grab the mouse if the user clicks outside buttons
|
||||||
void CGeneralSettingsPage::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void CGeneralSettingsPage::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -39,6 +39,7 @@
|
|||||||
#include <QCalendarWidget>
|
#include <QCalendarWidget>
|
||||||
#include <QTimeEdit>
|
#include <QTimeEdit>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
#include <QCheckBox>
|
||||||
|
|
||||||
|
|
||||||
class CZoneTest;
|
class CZoneTest;
|
||||||
@ -69,10 +70,12 @@ private:
|
|||||||
QSpinBox *mPGTresholdValueSpinBox;
|
QSpinBox *mPGTresholdValueSpinBox;
|
||||||
CTextButtonWidget *mPGValueSetBtn;
|
CTextButtonWidget *mPGValueSetBtn;
|
||||||
QGraphicsTextItem *mActualPGTresholdValueText;
|
QGraphicsTextItem *mActualPGTresholdValueText;
|
||||||
|
QCheckBox *mUseNetworkTimeChkBx;
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void ButtonClicked(CTextButtonWidget *);
|
void ButtonClicked(CTextButtonWidget *);
|
||||||
|
void NetworkTimeChkBxClicked(int);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@ CModbusCCMgr::CModbusCCMgr(CModbusRepository *Repo, int ModbusPort, int DevID) :
|
|||||||
mZTWatchdog = 0;
|
mZTWatchdog = 0;
|
||||||
mCCWatchdogState = 0;
|
mCCWatchdogState = 0;
|
||||||
mCCLinkState = false;
|
mCCLinkState = false;
|
||||||
|
mLastDateTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CModbusCCMgr::~CModbusCCMgr()
|
CModbusCCMgr::~CModbusCCMgr()
|
||||||
@ -116,9 +117,16 @@ void CModbusCCMgr::RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length
|
|||||||
NetworkTime.setTimeSpec(Qt::UTC);
|
NetworkTime.setTimeSpec(Qt::UTC);
|
||||||
NetworkTime.setDate(QDate(Year,Month,Day));
|
NetworkTime.setDate(QDate(Year,Month,Day));
|
||||||
NetworkTime.setTime(QTime(Hours,Minutes,Secs));
|
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);
|
mModbusRepo->WriteSingleReg(MODBUS_CC_CLK_UPDATE_BASE_REG_ADD,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,7 @@ private:
|
|||||||
qint16 mZTWatchdog;
|
qint16 mZTWatchdog;
|
||||||
qint16 mCCWatchdogState;
|
qint16 mCCWatchdogState;
|
||||||
bool mCCLinkState;
|
bool mCCLinkState;
|
||||||
|
QDateTime *mLastDateTime;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void RepoHasChanged();
|
void RepoHasChanged();
|
||||||
@ -36,6 +37,7 @@ signals:
|
|||||||
void ModbusCCDisconnected();
|
void ModbusCCDisconnected();
|
||||||
void ModbusCCLinkLost();
|
void ModbusCCLinkLost();
|
||||||
void ModbusCCLinkRecovered();
|
void ModbusCCLinkRecovered();
|
||||||
|
void ModbusDateTimeReceived(QDateTime *DateTime);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void NewModbusConnection();
|
void NewModbusConnection();
|
||||||
|
|||||||
@ -57,6 +57,7 @@
|
|||||||
#include "ZTVersion.h"
|
#include "ZTVersion.h"
|
||||||
#include "ModbusCCDefs.h"
|
#include "ModbusCCDefs.h"
|
||||||
#include "ModbusTKTransport.h"
|
#include "ModbusTKTransport.h"
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#ifdef USE_NETWORKING
|
#ifdef USE_NETWORKING
|
||||||
#include "NetworkManager.h"
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -131,6 +131,8 @@ public:
|
|||||||
|
|
||||||
bool IsZT2PresentInStation();
|
bool IsZT2PresentInStation();
|
||||||
|
|
||||||
|
int SetSystemDateTime(QDateTime *DateTime);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Networking requests
|
//Networking requests
|
||||||
@ -150,6 +152,7 @@ private:
|
|||||||
void EnterDeadlockState(void);
|
void EnterDeadlockState(void);
|
||||||
void CheckAndCreateDirectories();
|
void CheckAndCreateDirectories();
|
||||||
|
|
||||||
|
|
||||||
Panel panel;
|
Panel panel;
|
||||||
|
|
||||||
CStation *mZTStation; //The instance of the station in which the ZT is installed.
|
CStation *mZTStation; //The instance of the station in which the ZT is installed.
|
||||||
@ -215,6 +218,7 @@ public slots:
|
|||||||
void SMTimerExpired();
|
void SMTimerExpired();
|
||||||
void ACPISocketConnected();
|
void ACPISocketConnected();
|
||||||
void ACPISocketEvent();
|
void ACPISocketEvent();
|
||||||
|
void ModbusDateTimeUpdate(QDateTime *NewDateTime);
|
||||||
|
|
||||||
|
|
||||||
// CSeaIOLibInterface mSeaIOLibInterface;
|
// CSeaIOLibInterface mSeaIOLibInterface;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user