diff --git a/Configuration/ZT.cfg b/Configuration/ZT.cfg index ec5efe7..5bc6b89 100644 --- a/Configuration/ZT.cfg +++ b/Configuration/ZT.cfg @@ -63,6 +63,18 @@ MODBUS_SEI_DEVID=1 #Port Modbus/TCP MODBUS_SEI_PORT=502 +#---------------------------------- +#Paramètres de communication Modbus avec le SEI (Serveur NetTrac). +#Changer cette valeur à OUI, NON ou AUTO pour activer la communication Modbus l'historienPI. +# OUI: Active la communication avec l'historien. +# NON: Désactive la communication avec l'historien. +ACTIVER_HISTORIEN_PI=OUI +#Adresse modbus de la ZT +HISTORIEN_PI_DEVID=1 +#Port Modbus/TCP du serveur historien +HISTORIEN_PI_PORT=503 + + #---------------------------------- #Changer cette valeur à OUI ou NON pour activer le SIMULATEUR=OUI diff --git a/ZT.pro b/ZT.pro index 4754332..a373713 100644 --- a/ZT.pro +++ b/ZT.pro @@ -123,7 +123,8 @@ SOURCES += \ sources/GuiElements/ModbusDisplayPage.cpp \ sources/NetDriveMgr.cpp \ sources/SFTPServerManager.cpp \ - sources/PIHistorianManager.cpp + sources/Modbus/PIHistorianManager.cpp \ + sources/Modbus/PIHistorianSession.cpp HEADERS += \ sources/MainPanel.h \ @@ -247,7 +248,8 @@ HEADERS += \ sources/GuiElements/ModbusDisplayPage.h \ sources/NetDriveMgr.h \ sources/SFTPServerManager.h \ - sources/PIHistorianManager.h + sources/Modbus/PIHistorianManager.h \ + sources/Modbus/PIHistorianSession.h #QMAKE_LIBDIR += ./ExtLib diff --git a/sources/Modbus/PIHistorianDefs.h b/sources/Modbus/PIHistorianDefs.h new file mode 100644 index 0000000..ac184b9 --- /dev/null +++ b/sources/Modbus/PIHistorianDefs.h @@ -0,0 +1,140 @@ +#ifndef PROTOCOLDEFS_H +#define PROTOCOLDEFS_H + +#define MODBUS_ZT_WATCHDOG_TIMEOUT 3000 +#define MODBUS_CC_WATCHDOG_TIMEOUT 7000 + +//ZT - CC modbus table masks + + +//Flags definitions for HR2000 +#define ZT1_PP_INT_FLAG_MASK_1 0x0001 +#define ZT1_PP_INT_FLAG_MASK_2 0x0002 +#define ZT1_PP_INT_FLAG_MASK_3 0x0004 +#define ZT1_PP_INT_FLAG_MASK_4 0x0008 +#define ZT1_PP_EXT_FLAG_MASK_1 0x0010 +#define ZT1_PP_EXT_FLAG_MASK_2 0x0020 +#define ZT1_PP_EXT_FLAG_MASK_3 0x0040 +#define ZT1_PP_EXT_FLAG_MASK_4 0x0080 +#define ZT1_PG_FLAG_MASK_1 0x0100 +#define ZT1_PG_FLAG_MASK_2 0x0200 +#define ZT1_PG_FLAG_MASK_3 0x0400 +#define ZT1_PG_FLAG_MASK_4 0x0800 +#define ZT1_FN_FLAG_MASK_1 0x1000 +#define ZT1_FN_FLAG_MASK_2 0x2000 +#define ZT1_FN_FLAG_MASK_3 0x4000 +#define ZT1_FN_FLAG_MASK_4 0x8000 + +//Flags definitions for HR2017 +#define ZT2_PP_INT_FLAG_MASK_1 0x0001 +#define ZT2_PP_INT_FLAG_MASK_2 0x0002 +#define ZT2_PP_INT_FLAG_MASK_3 0x0004 +#define ZT2_PP_INT_FLAG_MASK_4 0x0008 +#define ZT2_PP_EXT_FLAG_MASK_1 0x0010 +#define ZT2_PP_EXT_FLAG_MASK_2 0x0020 +#define ZT2_PP_EXT_FLAG_MASK_3 0x0040 +#define ZT2_PP_EXT_FLAG_MASK_4 0x0080 + ///UNUSED FLAGS NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_PG_DUMMY_MASK_1 0x0100 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_PG_DUMMY_MASK_2 0x0200 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_PG_DUMMY_MASK_3 0x0400 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_PG_DUMMY_MASK_4 0x0800 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_FN_DUMMY_MASK_5 0x1000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_FN_DUMMY_MASK_6 0x2000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_FN_DUMMY_MASK_7 0x4000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_FV_DUMMY_MASK_8 0x8000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 + //////////////////////////////////////////////////////////////////// + +//Flags definitions for HR2026 +#define ZT1_V00_ALARM_FLAG_MASK 0x0001 +#define ZT1_PEQ1_ALARM_FLAG_MASK 0x0002 +#define ZT1_ALARM_ITI_FLAG_MASK 0x8000 +#define ZT2_V02_ALARM_FLAG_MASK 0x0004 +#define ZT2_PEQ2_ALARM_FLAG_MASK 0x0008 +#define ZT2_ACTIVATED_ITI_DUMMY_MASK 0x4000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT_ACTIVATED_ITI_FLAG_MASK 0x8000 + +//Flags definitions for HR2027 +#define ZT_WATCHDOG_ON_VALUE 0x8000 +//#define ZT_WATCHDOG_ON_VALUE 0x0001 //JFM 2020-09-25 modifie pour essais ATS (V1.21_TEST_ATS), doit etre 0x8000 en exploitation +#define ZT_WATCHDOG_OFF_VALUE 0x0000 + + +//Register addressing +//Outgoing +#define MODBUS_ZT_DATA_BASE_REG 2000 +#define MODBUS_ZT_TABLE_DATA_SIZE 36 //Taille de la table en écriture = 36 registres (2000 à 2035) //28 //Taille de la table en écriture = 28 registres (2000 à 2027) + +#define MODBUS_ZT1_ALARM_DATA_BASE_REG_ADD 2000 +#define MODBUS_ZT2_ALARM_DATA_BASE_REG_ADD 2017 +#define MODBUS_MISC_DATA_BASE_REG_ADD 2026 +#define MODBUS_ZT_WATCHDOG_REG_ADD 2027 + +#define MODBUS_ZT1_ALARM_RANKS_BASE_ADD 2001 +#define MODBUS_ZT1_RANK_PP_INT_1_REG_ADD 2001 +#define MODBUS_ZT1_RANK_PP_INT_2_REG_ADD 2002 +#define MODBUS_ZT1_RANK_PP_INT_3_REG_ADD 2003 +#define MODBUS_ZT1_RANK_PP_INT_4_REG_ADD 2004 +#define MODBUS_ZT1_RANK_PP_EXT_1_REG_ADD 2005 +#define MODBUS_ZT1_RANK_PP_EXT_2_REG_ADD 2006 +#define MODBUS_ZT1_RANK_PP_EXT_3_REG_ADD 2007 +#define MODBUS_ZT1_RANK_PP_EXT_4_REG_ADD 2008 +#define MODBUS_ZT1_RANK_PG_1_REG_ADD 2009 +#define MODBUS_ZT1_RANK_PG_2_REG_ADD 2010 +#define MODBUS_ZT1_RANK_PG_3_REG_ADD 2011 +#define MODBUS_ZT1_RANK_PG_4_REG_ADD 2012 +#define MODBUS_ZT1_RANK_FN_1_REG_ADD 2013 +#define MODBUS_ZT1_RANK_FN_2_REG_ADD 2014 +#define MODBUS_ZT1_RANK_FN_3_REG_ADD 2015 +#define MODBUS_ZT1_RANK_FN_4_REG_ADD 2016 + +#define MODBUS_ZT2_ALARM_RANKS_BASE_ADD 2018 +#define MODBUS_ZT2_RANK_PP_INT_1_REG_ADD 2018 +#define MODBUS_ZT2_RANK_PP_INT_2_REG_ADD 2019 +#define MODBUS_ZT2_RANK_PP_INT_3_REG_ADD 2020 +#define MODBUS_ZT2_RANK_PP_INT_4_REG_ADD 2021 +#define MODBUS_ZT2_RANK_PP_EXT_1_REG_ADD 2022 +#define MODBUS_ZT2_RANK_PP_EXT_2_REG_ADD 2023 +#define MODBUS_ZT2_RANK_PP_EXT_3_REG_ADD 2024 +#define MODBUS_ZT2_RANK_PP_EXT_4_REG_ADD 2025 + ///UNUSED FLAGS NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_RK_PG_1_REG_ADD 2028 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_RK_PG_2_REG_ADD 2029 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_RK_PG_3_REG_ADD 2030 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_RK_PG_4_REG_ADD 2031 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_FN_PG_1_REG_ADD 2032 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_FN_PG_2_REG_ADD 2033 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_FN_PG_3_REG_ADD 2034 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_FN_PG_4_REG_ADD 2035 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 + /////////////////////////////////////////////////////////////////// + + +//Incoming +#define MODBUS_CC_FCYCLE_ZT1_FLAG_MASK 0x0001 +#define MODBUS_CC_FCYCLE_ZT2_FLAG_MASK 0x0002 +#define MODBUS_CC_INHIBIT_ZT1_FLAG_MASK 0x0004 +#define MODBUS_CC_INHIBIT_ZT2_FLAG_MASK 0x0008 +#define MODBUS_CC_CLK_UPDATE_FLAG_MASK 0x8000 + +#define MODBUS_CC_DATA_BASE_REG_ADD 2036//2028 +#define MODBUS_CC_TABLE_DATA_SIZE 15 //Taille de la table en lecture = 15 registres (2036 à 2050 ///(2028 à 2042) + + +#define MODBUS_CC_WATCHDOG_BASE_REG_ADD 2036 +#define MODBUS_CC_AN_BASE_REG_ADD 2037 +#define MODBUS_CC_ZT1_TRAIN_TYPE_REG_ADD 2038 +#define MODBUS_CC_ZT2_TRAIN_TYPE_REG_ADD 2039 +#define MODBUS_CC_ZT1_TRAIN_ID_1_REG_ADD 2040 +#define MODBUS_CC_ZT1_TRAIN_ID_2_REG_ADD 2041 +#define MODBUS_CC_ZT1_TRAIN_ID_3_REG_ADD 2042 +#define MODBUS_CC_ZT2_TRAIN_ID_1_REG_ADD 2043 +#define MODBUS_CC_ZT2_TRAIN_ID_2_REG_ADD 2044 +#define MODBUS_CC_ZT2_TRAIN_ID_3_REG_ADD 2045 +#define MODBUS_CC_CLK_UPDATE_BASE_REG_ADD 2046 +#define MODUBS_CC_CLK_SEC_BASE_REG_ADD 2047 +#define MODUBS_CC_CLK_HR_MIN_BASE_REG_ADD 2048 +#define MODUBS_CC_CLK_MNT_DAY_BASE_REG_ADD 2049 +#define MODUBS_CC_CLK_YEAR_BASE_REG_ADD 2050 + + +#endif // PROTOCOLDEFS_H diff --git a/sources/Modbus/PIHistorianDefs.h.autosave b/sources/Modbus/PIHistorianDefs.h.autosave new file mode 100644 index 0000000..d5b76ca --- /dev/null +++ b/sources/Modbus/PIHistorianDefs.h.autosave @@ -0,0 +1,139 @@ +#ifndef PIHISTORIANDEFS_H +#define PIHISTORIANDEFS_H + +#define PI_HISTORIAN_WATCHDOG_TIMEOUT 3000 + +//PI HISTORIAN modbus table masks + + +//Flags definitions for HR2000 +#define ZT1_FN_ACTIVE_FLAG_MASK 0x0001 +#define ZT1_PP_INT_ACTIVE_FLAG_MASK 0x0002 +#define ZT1_PP_EXT_ACTIVE_FLAG_MASK 0x0004 +#define ZT1_PG_ACTIVE_FLAG_MASK_4 0x0008 +#define ZT2_PP_INT_ACTIVE_FLAG_MASK 0x0010 +#define ZT2_PP_EXT_ACTIVE_FLAG_MASK 0x0020 +#define ZT_MAINTENANCE_MODE_FLAG_MASK 0x0040 +#define ZT1_PP_EXT_FLAG_MASK 0x0080 +#define ZT1_PG_FLAG_MASK_1 0x0100 +#define ZT1_PG_FLAG_MASK_2 0x0200 +#define ZT1_PG_FLAG_MASK_3 0x0400 +#define ZT1_PG_FLAG_MASK_4 0x0800 +#define ZT1_FN_FLAG_MASK_1 0x1000 +#define ZT1_FN_FLAG_MASK_2 0x2000 +#define ZT1_FN_FLAG_MASK_3 0x4000 +#define ZT1_FN_FLAG_MASK_4 0x8000 + +//Flags definitions for HR2017 +#define ZT2_PP_INT_FLAG_MASK_1 0x0001 +#define ZT2_PP_INT_FLAG_MASK_2 0x0002 +#define ZT2_PP_INT_FLAG_MASK_3 0x0004 +#define ZT2_PP_INT_FLAG_MASK_4 0x0008 +#define ZT2_PP_EXT_FLAG_MASK_1 0x0010 +#define ZT2_PP_EXT_FLAG_MASK_2 0x0020 +#define ZT2_PP_EXT_FLAG_MASK_3 0x0040 +#define ZT2_PP_EXT_FLAG_MASK_4 0x0080 + ///UNUSED FLAGS NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_PG_DUMMY_MASK_1 0x0100 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_PG_DUMMY_MASK_2 0x0200 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_PG_DUMMY_MASK_3 0x0400 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_PG_DUMMY_MASK_4 0x0800 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_FN_DUMMY_MASK_5 0x1000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_FN_DUMMY_MASK_6 0x2000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_FN_DUMMY_MASK_7 0x4000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT2_FV_DUMMY_MASK_8 0x8000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 + //////////////////////////////////////////////////////////////////// + +//Flags definitions for HR2026 +#define ZT1_V00_ALARM_FLAG_MASK 0x0001 +#define ZT1_PEQ1_ALARM_FLAG_MASK 0x0002 +#define ZT1_ALARM_ITI_FLAG_MASK 0x8000 +#define ZT2_V02_ALARM_FLAG_MASK 0x0004 +#define ZT2_PEQ2_ALARM_FLAG_MASK 0x0008 +#define ZT2_ACTIVATED_ITI_DUMMY_MASK 0x4000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define ZT_ACTIVATED_ITI_FLAG_MASK 0x8000 + +//Flags definitions for HR2027 +#define ZT_WATCHDOG_ON_VALUE 0x8000 +//#define ZT_WATCHDOG_ON_VALUE 0x0001 //JFM 2020-09-25 modifie pour essais ATS (V1.21_TEST_ATS), doit etre 0x8000 en exploitation +#define ZT_WATCHDOG_OFF_VALUE 0x0000 + + +//Register addressing +//Outgoing +#define MODBUS_ZT_DATA_BASE_REG 2000 +#define MODBUS_ZT_TABLE_DATA_SIZE 36 //Taille de la table en écriture = 36 registres (2000 à 2035) //28 //Taille de la table en écriture = 28 registres (2000 à 2027) + +#define MODBUS_ZT1_ALARM_DATA_BASE_REG_ADD 2000 +#define MODBUS_ZT2_ALARM_DATA_BASE_REG_ADD 2017 +#define MODBUS_MISC_DATA_BASE_REG_ADD 2026 +#define MODBUS_ZT_WATCHDOG_REG_ADD 2027 + +#define MODBUS_ZT1_ALARM_RANKS_BASE_ADD 2001 +#define MODBUS_ZT1_RANK_PP_INT_1_REG_ADD 2001 +#define MODBUS_ZT1_RANK_PP_INT_2_REG_ADD 2002 +#define MODBUS_ZT1_RANK_PP_INT_3_REG_ADD 2003 +#define MODBUS_ZT1_RANK_PP_INT_4_REG_ADD 2004 +#define MODBUS_ZT1_RANK_PP_EXT_1_REG_ADD 2005 +#define MODBUS_ZT1_RANK_PP_EXT_2_REG_ADD 2006 +#define MODBUS_ZT1_RANK_PP_EXT_3_REG_ADD 2007 +#define MODBUS_ZT1_RANK_PP_EXT_4_REG_ADD 2008 +#define MODBUS_ZT1_RANK_PG_1_REG_ADD 2009 +#define MODBUS_ZT1_RANK_PG_2_REG_ADD 2010 +#define MODBUS_ZT1_RANK_PG_3_REG_ADD 2011 +#define MODBUS_ZT1_RANK_PG_4_REG_ADD 2012 +#define MODBUS_ZT1_RANK_FN_1_REG_ADD 2013 +#define MODBUS_ZT1_RANK_FN_2_REG_ADD 2014 +#define MODBUS_ZT1_RANK_FN_3_REG_ADD 2015 +#define MODBUS_ZT1_RANK_FN_4_REG_ADD 2016 + +#define MODBUS_ZT2_ALARM_RANKS_BASE_ADD 2018 +#define MODBUS_ZT2_RANK_PP_INT_1_REG_ADD 2018 +#define MODBUS_ZT2_RANK_PP_INT_2_REG_ADD 2019 +#define MODBUS_ZT2_RANK_PP_INT_3_REG_ADD 2020 +#define MODBUS_ZT2_RANK_PP_INT_4_REG_ADD 2021 +#define MODBUS_ZT2_RANK_PP_EXT_1_REG_ADD 2022 +#define MODBUS_ZT2_RANK_PP_EXT_2_REG_ADD 2023 +#define MODBUS_ZT2_RANK_PP_EXT_3_REG_ADD 2024 +#define MODBUS_ZT2_RANK_PP_EXT_4_REG_ADD 2025 + ///UNUSED FLAGS NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_RK_PG_1_REG_ADD 2028 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_RK_PG_2_REG_ADD 2029 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_RK_PG_3_REG_ADD 2030 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_RK_PG_4_REG_ADD 2031 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_FN_PG_1_REG_ADD 2032 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_FN_PG_2_REG_ADD 2033 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_FN_PG_3_REG_ADD 2034 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 +#define MODBUS_ZT2_DUMMY_FN_PG_4_REG_ADD 2035 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION. MUST ALWAYS BE 0 + /////////////////////////////////////////////////////////////////// + + +//Incoming +#define MODBUS_CC_FCYCLE_ZT1_FLAG_MASK 0x0001 +#define MODBUS_CC_FCYCLE_ZT2_FLAG_MASK 0x0002 +#define MODBUS_CC_INHIBIT_ZT1_FLAG_MASK 0x0004 +#define MODBUS_CC_INHIBIT_ZT2_FLAG_MASK 0x0008 +#define MODBUS_CC_CLK_UPDATE_FLAG_MASK 0x8000 + +#define MODBUS_CC_DATA_BASE_REG_ADD 2036//2028 +#define MODBUS_CC_TABLE_DATA_SIZE 15 //Taille de la table en lecture = 15 registres (2036 à 2050 ///(2028 à 2042) + + +#define MODBUS_CC_WATCHDOG_BASE_REG_ADD 2036 +#define MODBUS_CC_AN_BASE_REG_ADD 2037 +#define MODBUS_CC_ZT1_TRAIN_TYPE_REG_ADD 2038 +#define MODBUS_CC_ZT2_TRAIN_TYPE_REG_ADD 2039 +#define MODBUS_CC_ZT1_TRAIN_ID_1_REG_ADD 2040 +#define MODBUS_CC_ZT1_TRAIN_ID_2_REG_ADD 2041 +#define MODBUS_CC_ZT1_TRAIN_ID_3_REG_ADD 2042 +#define MODBUS_CC_ZT2_TRAIN_ID_1_REG_ADD 2043 +#define MODBUS_CC_ZT2_TRAIN_ID_2_REG_ADD 2044 +#define MODBUS_CC_ZT2_TRAIN_ID_3_REG_ADD 2045 +#define MODBUS_CC_CLK_UPDATE_BASE_REG_ADD 2046 +#define MODUBS_CC_CLK_SEC_BASE_REG_ADD 2047 +#define MODUBS_CC_CLK_HR_MIN_BASE_REG_ADD 2048 +#define MODUBS_CC_CLK_MNT_DAY_BASE_REG_ADD 2049 +#define MODUBS_CC_CLK_YEAR_BASE_REG_ADD 2050 + + +#endif // PIHISTORIANDEFS_H diff --git a/sources/Modbus/PIHistorianManager.cpp b/sources/Modbus/PIHistorianManager.cpp new file mode 100644 index 0000000..d3baa9b --- /dev/null +++ b/sources/Modbus/PIHistorianManager.cpp @@ -0,0 +1,63 @@ +#include "PIHistorianManager.h" +#include "ZTLog.h" + +CPIHistorianManager::CPIHistorianManager(CModbusRepository *PIHistorianRepo, int ModbusPort) +{ + mModbusPort = ModbusPort; + mModbusServer = new QTcpServer(); + connect(mModbusServer,SIGNAL(newConnection()),this,SLOT(NewModbusConnection())); + mPIHistorianRepo = PIHistorianRepo; +} + +CPIHistorianManager::~CPIHistorianManager() +{ + StopPIHistorian(); + delete mModbusServer; +} + +void CPIHistorianManager::NewModbusConnection() +{ + QTcpSocket* SessionSocket = mModbusServer->nextPendingConnection(); + if(SessionSocket != 0) + { + CPIHistorianSession *NewSession = new CPIHistorianSession(mPIHistorianRepo,PI_HISTORIAN_MODBUS_DEVICE_ID); + connect(NewSession,SIGNAL(PIHistorianSessionClosed(CPIHistorianSession*)),this,SLOT(HistorianSessionClosed(CPIHistorianSession*))); + mHistorianSessionsList.append(NewSession); + NewSession->OpenSession(SessionSocket); + } + +} + +void CPIHistorianManager::HistorianSessionClosed(CPIHistorianSession *SessionPtr) +{ + for(int i = 0; i < mHistorianSessionsList.size(); i++) + { + if(mHistorianSessionsList.at(i) == SessionPtr) + { + CPIHistorianSession *Session = mHistorianSessionsList.takeAt(i); + delete Session; + return; + } + } + CZTLog::instance()->AddLogString(QString("Erreur de logique dans PIHistorianManager::HistorianSessionClosed. [Session fermée inconnue] ")); +} + +int CPIHistorianManager::StartPIHistorian() +{ + mModbusServer->listen(QHostAddress::Any,mModbusPort); + CZTLog::instance()->AddLogString(QString("Gestionnaire de l'historien PI démarré sur le port %1").arg(mModbusPort),true); + return 1; +} + +int CPIHistorianManager::StopPIHistorian() +{ + mModbusServer->close(); + for(int i = 0; i < mHistorianSessionsList.size(); i++) + { + CPIHistorianSession *Session = mHistorianSessionsList.takeFirst(); + Session->CloseSession(); + delete Session; + + } + +} diff --git a/sources/Modbus/PIHistorianManager.h b/sources/Modbus/PIHistorianManager.h new file mode 100644 index 0000000..7d83c73 --- /dev/null +++ b/sources/Modbus/PIHistorianManager.h @@ -0,0 +1,32 @@ +#ifndef PIHISTORIANMANAGER_H +#define PIHISTORIANMANAGER_H + +#include +#include "PIHistorianSession.h" +#include +#include + +#define PI_HISTORIAN_MODBUS_DEVICE_ID 1 + +class CPIHistorianManager : public QObject +{ + Q_OBJECT +public: + CPIHistorianManager(CModbusRepository *PIHistorianRepo, int ModbusPort); + virtual ~CPIHistorianManager(); + int StartPIHistorian(); + int StopPIHistorian(); + + QTcpServer *mModbusServer; //L'instance du serveur TCP + int mModbusPort; + CModbusRepository *mPIHistorianRepo; + +private: + QList mHistorianSessionsList; //Les sessions établies par le serveur sont gardées dans cette liste + +public slots: + void NewModbusConnection(); + void HistorianSessionClosed(CPIHistorianSession*); +}; + +#endif // PIHISTORIANMANAGER_H diff --git a/sources/Modbus/PIHistorianSession.cpp b/sources/Modbus/PIHistorianSession.cpp new file mode 100644 index 0000000..9902b8b --- /dev/null +++ b/sources/Modbus/PIHistorianSession.cpp @@ -0,0 +1,51 @@ +#include "PIHistorianSession.h" +#include "ZTLog.h" + +CPIHistorianSession::CPIHistorianSession(CModbusRepository *Repo, int DevID) : + CModbusBackend(Repo) +{ + mDeviceID = DevID; + mModbusMode = MODBUS_SLAVE_MODE; +} + +CPIHistorianSession::~CPIHistorianSession() +{ + +} + +int CPIHistorianSession::OpenSession(QTcpSocket *ModbusSocket) +{ + mModbusTCPSocketHandle = ModbusSocket; + connect(mModbusTCPSocketHandle,SIGNAL(readyRead()),this,SLOT(ModbusDataReady())); + connect(mModbusTCPSocketHandle,SIGNAL(disconnected()),this,SLOT(ConnectionLost())); + + CZTLog::instance()->AddLogString(QString("Session avec Historien PI établie. IP locale [%1] - IP HPC [%2]").arg(mModbusTCPSocketHandle->localAddress().toString()).arg(mModbusTCPSocketHandle->peerAddress().toString()),true); + + return RET_OK; +} + +int CPIHistorianSession::CloseSession() +{ + disconnect(mModbusTCPSocketHandle,SIGNAL(readyRead()),this,SLOT(ModbusDataReady())); + mModbusTCPSocketHandle->close(); + CZTLog::instance()->AddLogString(QString("Session avec Historien PI fermée avec succès.")); + + return RET_OK; +} + +void CPIHistorianSession::RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length) +{ + +} + +void CPIHistorianSession::ModbusRequestException(quint8 ExceptionCode, quint8 FctCode) +{ + +} + +void CPIHistorianSession::HistorianConnectionLost() +{ + CZTLog::instance()->AddLogString(QString("Session avec Historien PI fermée (connexion perdue).")); + emit PIHistorianSessionClosed(this); +} + diff --git a/sources/Modbus/PIHistorianSession.h b/sources/Modbus/PIHistorianSession.h new file mode 100644 index 0000000..d0afae9 --- /dev/null +++ b/sources/Modbus/PIHistorianSession.h @@ -0,0 +1,30 @@ +#ifndef PIHISTORIANSESSION_H +#define PIHISTORIANSESSION_H + +#include "ModbusBackend.h" + +class CPIHistorianSession : public CModbusBackend +{ + Q_OBJECT +public: + CPIHistorianSession(CModbusRepository *Repo,int DevID); + virtual ~CPIHistorianSession(); + + int OpenSession(QTcpSocket *ModbusSocket); + int CloseSession(); + + + + virtual void RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length); + virtual void ModbusRequestException(quint8 ExceptionCode, quint8 FctCode); + +signals: + void PIHistorianSessionClosed(CPIHistorianSession *Sender); + +public slots: + void HistorianConnectionLost(); + + +}; + +#endif // PIHISTORIANSESSION_H diff --git a/sources/PIHistorianManager.cpp b/sources/PIHistorianManager.cpp deleted file mode 100644 index 8cefeff..0000000 --- a/sources/PIHistorianManager.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "PIHistorianManager.h" - -CPIHistorianManager::CPIHistorianManager() -{ -} diff --git a/sources/PIHistorianManager.h b/sources/PIHistorianManager.h deleted file mode 100644 index df4f78a..0000000 --- a/sources/PIHistorianManager.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef PIHISTORIANMANAGER_H -#define PIHISTORIANMANAGER_H - -class CPIHistorianManager -{ -public: - CPIHistorianManager(); -}; - -#endif // PIHISTORIANMANAGER_H diff --git a/sources/ZTconfigmgr.cpp b/sources/ZTconfigmgr.cpp index ec91962..3d5e0ef 100644 --- a/sources/ZTconfigmgr.cpp +++ b/sources/ZTconfigmgr.cpp @@ -66,6 +66,11 @@ CZTConfigMgr::CZTConfigMgr() //SFTP server parameters mActivateSFTPClient = false; + + //PI historian parameters + mEnablePIHistorian = false; + mPIHistorianModbusPort = 503; + mPIHistorianModbusDevID = 1; } ZTConfigResult CZTConfigMgr::LoadZTConfig() @@ -221,7 +226,7 @@ ZTConfigResult CZTConfigMgr::LoadZTConfig() CEngLog::instance()->AddLogString(QString().sprintf("Invalid MODBUS_SEI_DEVID parameter: %s",string.mid(pos).toUtf8().constData())); mModbusSEIDevID = 0; } - CEngLog::instance()->AddLogString(QString().sprintf("Port DevID SEI = %d",mModbusSEIDevID)); + CEngLog::instance()->AddLogString(QString().sprintf("Modbus DevID SEI = %d",mModbusSEIDevID)); } else if(string.contains("MODBUS_SEI_PORT")) { @@ -232,7 +237,7 @@ ZTConfigResult CZTConfigMgr::LoadZTConfig() CEngLog::instance()->AddLogString(QString().sprintf("Invalid MODBUS_SEI_PORT parameter: %s",string.mid(pos).toUtf8().constData())); mModbusSEIPort = 6060; } - CEngLog::instance()->AddLogString(QString().sprintf("Port DevID SEI = %d",mModbusSEIPort)); + CEngLog::instance()->AddLogString(QString().sprintf("Port Modbus SEI = %d",mModbusSEIPort)); } //Station configuration parameters @@ -332,6 +337,42 @@ ZTConfigResult CZTConfigMgr::LoadZTConfig() mSFTPRemoteDir = string.mid(pos); CEngLog::instance()->AddLogString(QString("Répertoire distant SFTP %1").arg(mSFTPRemoteDir),1); } + else if(string.contains("ACTIVER_HISTORIEN_PI")) + { + if(string.mid(pos) == "OUI") + { + mEnablePIHistorian = true; + CEngLog::instance()->AddLogString(QString().sprintf("Historien PI activé"),1); + } + else + { + mEnablePIHistorian = false; + CEngLog::instance()->AddLogString(QString().sprintf("Historien PI activé"),1); + } + } + else if(string.contains("HISTORIEN_PI_DEVID")) + { + bool OK; + mPIHistorianModbusDevID = (string.mid(pos).toInt(&OK)); + if(OK == false) + { + CEngLog::instance()->AddLogString(QString().sprintf("Invalid HISTORIEN_PI_DEVID parameter: %s",string.mid(pos).toUtf8().constData())); + mPIHistorianModbusDevID = 1; + } + CEngLog::instance()->AddLogString(QString().sprintf("Historien PI DevID = %d",mPIHistorianModbusDevID)); + } + else if(string.contains("HISTORIEN_PI_PORT")) + { + bool OK; + mPIHistorianModbusPort = (string.mid(pos).toInt(&OK)); + if(OK == false) + { + CEngLog::instance()->AddLogString(QString().sprintf("Invalid HISTORIEN_PI_PORT parameter: %s",string.mid(pos).toUtf8().constData())); + mPIHistorianModbusPort = 503; + } + CEngLog::instance()->AddLogString(QString().sprintf("Port Modbus Historien PI = %d",mPIHistorianModbusPort)); + } + } } @@ -457,3 +498,18 @@ QString CZTConfigMgr::GetSFTPServerRemoteDir() { return mSFTPRemoteDir; } + +bool CZTConfigMgr::GetPIHistorianEnabled() +{ + return mEnablePIHistorian; +} + +int CZTConfigMgr::GetPIHistorianModbusDevID() +{ + return mPIHistorianModbusDevID; +} + +int CZTConfigMgr::GetPIHistorianModbusPort() +{ + return mPIHistorianModbusPort; +} diff --git a/sources/ZTconfigmgr.h b/sources/ZTconfigmgr.h index 1a4bdda..6106444 100644 --- a/sources/ZTconfigmgr.h +++ b/sources/ZTconfigmgr.h @@ -107,6 +107,9 @@ public: QString GetSFTPPassword(); QString GetSFTPServerAddress(); QString GetSFTPServerRemoteDir(); + bool GetPIHistorianEnabled(); + int GetPIHistorianModbusDevID(); + int GetPIHistorianModbusPort(); @@ -146,6 +149,11 @@ private: QString mSFTPPassword; QString mSFTPAddress; QString mSFTPRemoteDir; + +//Historien PI parameters + bool mEnablePIHistorian; + int mPIHistorianModbusPort; + int mPIHistorianModbusDevID; }; #endif // ZTCONFIGMGR_H diff --git a/sources/Zonetest.cpp b/sources/Zonetest.cpp index c868604..f750119 100644 --- a/sources/Zonetest.cpp +++ b/sources/Zonetest.cpp @@ -103,7 +103,7 @@ CZoneTest::CZoneTest(): mExtIOWorkerThread->moveToThread(mExtIOThread); connect(mExtIOThread,SIGNAL(started()),mExtIOWorkerThread,SLOT(DoAcquisition())); - + mPIHistorianManager = 0; } CZoneTest::~CZoneTest() @@ -139,6 +139,9 @@ CZoneTest::~CZoneTest() if(mAnalogModule != 0) delete mAnalogModule; + + if(mPIHistorianManager != 0) + delete mPIHistorianManager; } unsigned int CZoneTest::ExecStateMachine(eZTSMEvents_t) @@ -680,6 +683,18 @@ unsigned int CZoneTest::InitZT() connect(mZTStateMachine,SIGNAL(NewTrainLogSaved(QString,bool)),&mSFTPManager,SLOT(NewTrainFileSaved(QString,bool))); } + //Start Historien PI server + bool EnableHistorian = CZTConfigMgr::instance()->GetPIHistorianEnabled(); + int PIHistorianPort = CZTConfigMgr::instance()->GetPIHistorianModbusPort(); + int PIHistorianDevID = CZTConfigMgr::instance()->GetPIHistorianModbusDevID(); + if(EnableHistorian == true) + { + mPIHistorianRepository = new CModbusRepository; + mPIHistorianRepository->AddHRDataMap(MODBUS_ZT_DATA_BASE_REG,MODBUS_ZT_TABLE_DATA_SIZE); //Add the ZT data map + mPIHistorianManager = new CPIHistorianManager(mPIHistorianRepository,PIHistorianPort); + + } + if(mSimulationON == true) { #ifdef USE_REAL_ANALOG_EXTERNAL_MODULE diff --git a/sources/Zonetest.h b/sources/Zonetest.h index 5404ec8..c4e4f86 100644 --- a/sources/Zonetest.h +++ b/sources/Zonetest.h @@ -61,6 +61,7 @@ #include "NetworkCfgMgr.h" #include "NetDriveMgr.h" #include "SFTPServerManager.h" +#include "PIHistorianManager.h" #include "TCPProtocol.h" @@ -200,12 +201,13 @@ private: CWatchdogCtrl *mInternalWatchdog; bool mWatchdogEnabled; CTKTransportInterface *mTKTransportInterface; - CModbusRepository *mCCModbusRepository, *mSEIModbusRepository; + CModbusRepository *mCCModbusRepository, *mSEIModbusRepository, *mPIHistorianRepository; CModbusCCMgr *mModbusCCMgr; CModbusSEIMgr *mModbusSEIMgr; CNetworkCfgMgr mNetworkCfgMgr; CNetDriveMgr mNetworkDriveMgr; CSFTPServerManager mSFTPManager; + CPIHistorianManager *mPIHistorianManager; QLocalSocket mACPISocket; // CWatchdogCtrl mWatchdogCtrl;