+ Options de configuration de l'adresse IP du réseau exploitation. + Option d'activation du réseau Modbus CC
226 lines
7.0 KiB
C++
226 lines
7.0 KiB
C++
/*******************************************************************************
|
|
* *
|
|
* Société de Transports de Montréal. *
|
|
* 2012 *
|
|
* *
|
|
* Projet Zones Tests *
|
|
* *
|
|
* *
|
|
* *
|
|
*******************************************************************************/
|
|
/*
|
|
Description:
|
|
Page offrant différentes option pour l'entretien de la ZT
|
|
|
|
*/
|
|
|
|
/* ************************************************************************** */
|
|
/* Revision:
|
|
### 20131021 JFM
|
|
Verision d'origine.
|
|
|
|
### YYYMMDD Description du besoin ou du bug
|
|
Description du changement.
|
|
*/
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
#include "ModbusSettingsPage.h"
|
|
#include <QPainter>
|
|
#include "GlobalDefine.h"
|
|
#include <QDialog>
|
|
#include <QMainWindow>
|
|
#include "Zonetest.h"
|
|
#include <QDateTime>
|
|
#include <QFont>
|
|
#include <QGraphicsProxyWidget>
|
|
#include <QMessageBox>
|
|
//#include <sys/time.h>
|
|
#include "ZTLog.h"
|
|
|
|
|
|
|
|
|
|
CModbusSettingsPage::CModbusSettingsPage(QGraphicsWidget *Parent)
|
|
{
|
|
Q_UNUSED(Parent)
|
|
|
|
|
|
mProgramHandle = 0;
|
|
|
|
mBackgroundRect = new QGraphicsRectItem(boundingRect(), this);
|
|
QBrush BackgroundBrush(QColor(245, 245, 255));
|
|
mBackgroundRect->setBrush(BackgroundBrush);
|
|
|
|
QGraphicsTextItem *Title = new QGraphicsTextItem("Paramètres Modbus",this);
|
|
QFont font;
|
|
font.setPointSize(18);
|
|
Title->setFont(font);
|
|
Title->setPos(40,10);
|
|
|
|
mCancelButton = new CTextButtonWidget("Annuler");
|
|
mCancelButton->setParentItem(this);
|
|
mCancelButton->setPos(550,550);
|
|
connect(mCancelButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));
|
|
|
|
mApplyButton = new CTextButtonWidget("Appliquer");
|
|
mApplyButton->setParentItem(this);
|
|
mApplyButton->setPos(650,550);
|
|
connect(mApplyButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));
|
|
|
|
|
|
QGraphicsProxyWidget *Proxy = new QGraphicsProxyWidget(this);
|
|
QGraphicsTextItem *Dot = new QGraphicsTextItem(".",this);
|
|
Dot->setFont(font);
|
|
|
|
|
|
int IpSettingsPosx = 120, IpSettingsPosy = 200;
|
|
Title = new QGraphicsTextItem("Adresse IP",this);
|
|
font.setPointSize(16);
|
|
Title->setFont(font);
|
|
Title->setPos(IpSettingsPosx,IpSettingsPosy-35);
|
|
|
|
mIPChunk1 = new QSpinBox();
|
|
Proxy->setWidget(mIPChunk1);
|
|
Proxy->setPos(IpSettingsPosx,IpSettingsPosy);
|
|
mIPChunk1->resize(70,30);
|
|
mIPChunk1->setMinimum(0);
|
|
mIPChunk1->setMaximum(255);
|
|
IpSettingsPosx += 90;
|
|
Dot->setPos(IpSettingsPosx-17,IpSettingsPosy-5);
|
|
|
|
Proxy = new QGraphicsProxyWidget(this);
|
|
Dot = new QGraphicsTextItem(".",this);
|
|
Dot->setFont(font);
|
|
mIPChunk2 = new QSpinBox();
|
|
Proxy->setWidget(mIPChunk2);
|
|
Proxy->setPos(IpSettingsPosx,IpSettingsPosy);
|
|
mIPChunk2->resize(70,30);
|
|
mIPChunk2->setMinimum(0);
|
|
mIPChunk2->setMaximum(255);
|
|
IpSettingsPosx += 90;
|
|
Dot->setPos(IpSettingsPosx-17,IpSettingsPosy-5);
|
|
|
|
Proxy = new QGraphicsProxyWidget(this);
|
|
Dot = new QGraphicsTextItem(".",this);
|
|
Dot->setFont(font);
|
|
mIPChunk3 = new QSpinBox();
|
|
Proxy->setWidget(mIPChunk3);
|
|
Proxy->setPos(IpSettingsPosx,IpSettingsPosy);
|
|
mIPChunk3->resize(70,30);
|
|
mIPChunk3->setMinimum(0);
|
|
mIPChunk3->setMaximum(255);
|
|
IpSettingsPosx += 90;
|
|
Dot->setPos(IpSettingsPosx-17,IpSettingsPosy - 5);
|
|
|
|
Proxy = new QGraphicsProxyWidget(this);
|
|
mIPChunk4 = new QSpinBox();
|
|
Proxy->setWidget(mIPChunk4);
|
|
mIPChunk4->setMinimum(0);
|
|
mIPChunk4->setMaximum(255);
|
|
Proxy->setPos(IpSettingsPosx,IpSettingsPosy);
|
|
mIPChunk4->resize(70,30);
|
|
|
|
Proxy = new QGraphicsProxyWidget(this);
|
|
mUseModbusChkBox = new QCheckBox("Activer la communication Modbus avec la Commande Centralisée");
|
|
Proxy->setWidget(mUseModbusChkBox);
|
|
Proxy->setPos(100,100);
|
|
|
|
|
|
|
|
// mCalendarWidget = new QCalendarWidget();
|
|
// Proxy->setWidget(mCalendarWidget);
|
|
// Proxy->setPos(100,150);
|
|
|
|
QGraphicsRectItem *Frame = new QGraphicsRectItem(80,70,600,400,this);
|
|
QPen FramePen;
|
|
FramePen.setWidth(3);
|
|
Frame->setPen(FramePen);
|
|
|
|
|
|
// Title = new QGraphicsTextItem("Seuil Pneu de Guidage",this);
|
|
// Title->setFont(font);
|
|
// Title->setPos(270,400);
|
|
// Frame = new QGraphicsRectItem(80,405,600,175,this);
|
|
// Frame->setPen(FramePen);
|
|
}
|
|
|
|
|
|
void CModbusSettingsPage::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
mBackgroundRect->setRect(boundingRect());
|
|
}
|
|
|
|
void CModbusSettingsPage::ButtonClicked(CTextButtonWidget *BtnPtr)
|
|
{
|
|
if(BtnPtr == mCancelButton)
|
|
{
|
|
mProgramHandle->CloseModbusSettingsPage();
|
|
hide();
|
|
}
|
|
else if(BtnPtr == mApplyButton)
|
|
{
|
|
QMessageBox msgBox;
|
|
msgBox.setText("Redémarrage requis");
|
|
msgBox.setInformativeText("Les paramètres modbus ont été changés\nVoulez-vous vraiment redémarrer l'ordinateur ZT?");
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
int ret = msgBox.exec();
|
|
|
|
if(ret == QMessageBox::Ok)
|
|
{
|
|
qint32 Address = 0;
|
|
Address = (mIPChunk1->value() & 0x000000FF);
|
|
Address <<= 8;
|
|
Address |= (mIPChunk2->value() & 0x000000FF);
|
|
Address <<= 8;
|
|
Address |= (mIPChunk3->value() & 0x000000FF);
|
|
Address <<= 8;
|
|
Address |= (mIPChunk4->value() & 0x000000FF);
|
|
QHostAddress IPAddress(Address);
|
|
|
|
bool UseModbus = (mUseModbusChkBox->checkState() == Qt::Checked);
|
|
|
|
QString LogEntry = QString("Changement des paramètres Modbus CC -> Modbus Activé : %1, Adresse IP %2").arg(UseModbus).arg(IPAddress.toString().toAscii().data());
|
|
CZTLog::instance()->AddLogString(LogEntry,true);
|
|
|
|
mProgramHandle->ModbusSettingsChangedReboot(UseModbus,IPAddress);
|
|
// mProgramHandle->CloseModbusSettingsPage();
|
|
}
|
|
}
|
|
}
|
|
|
|
void CModbusSettingsPage::showEvent(QShowEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
}
|
|
|
|
int CModbusSettingsPage::SetActualSettings(bool UseModbus, QHostAddress CCHostAdd)
|
|
{
|
|
mUseModbusChkBox->setChecked(UseModbus);
|
|
|
|
qint32 add = CCHostAdd.toIPv4Address();
|
|
mIPChunk4->setValue(add & 0x000000FF);
|
|
add >>= 8;
|
|
mIPChunk3->setValue(add & 0x000000FF);
|
|
add >>= 8;
|
|
mIPChunk2->setValue(add & 0x000000FF);
|
|
add >>= 8;
|
|
mIPChunk1->setValue(add & 0x000000FF);
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
|
|
//Grab the mouse if the user clicks outside buttons
|
|
void CModbusSettingsPage::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
}
|
|
void CModbusSettingsPage::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
}
|