From 93ad7c146c8ed9ca12448a54e1e32f7d573c044e Mon Sep 17 00:00:00 2001 From: jfmartel Date: Thu, 6 Jun 2024 09:18:29 -0400 Subject: [PATCH 1/4] test branch --- sources/ZTVersion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/ZTVersion.h b/sources/ZTVersion.h index 5a02589..393c73e 100755 --- a/sources/ZTVersion.h +++ b/sources/ZTVersion.h @@ -29,7 +29,7 @@ #ifndef ZTVERSION_H #define ZTVERSION_H -#define ZT_SOFT_VERSION "V1.26" +#define ZT_SOFT_VERSION "V1.26_PI" //LOG DES CHANGEMENTS //Version 1.26 From 49c3d8d84c528f50af7b4eea79c1baef81d1c195 Mon Sep 17 00:00:00 2001 From: jfmartel Date: Thu, 6 Jun 2024 16:00:29 -0400 Subject: [PATCH 2/4] Dev Historien PI --- Configuration/ZT.cfg | 12 ++ ZT.pro | 6 +- sources/Modbus/PIHistorianDefs.h | 140 ++++++++++++++++++++++ sources/Modbus/PIHistorianDefs.h.autosave | 139 +++++++++++++++++++++ sources/Modbus/PIHistorianManager.cpp | 63 ++++++++++ sources/Modbus/PIHistorianManager.h | 32 +++++ sources/Modbus/PIHistorianSession.cpp | 51 ++++++++ sources/Modbus/PIHistorianSession.h | 30 +++++ sources/PIHistorianManager.cpp | 5 - sources/PIHistorianManager.h | 10 -- sources/ZTconfigmgr.cpp | 60 +++++++++- sources/ZTconfigmgr.h | 8 ++ sources/Zonetest.cpp | 17 ++- sources/Zonetest.h | 4 +- 14 files changed, 556 insertions(+), 21 deletions(-) create mode 100644 sources/Modbus/PIHistorianDefs.h create mode 100644 sources/Modbus/PIHistorianDefs.h.autosave create mode 100644 sources/Modbus/PIHistorianManager.cpp create mode 100644 sources/Modbus/PIHistorianManager.h create mode 100644 sources/Modbus/PIHistorianSession.cpp create mode 100644 sources/Modbus/PIHistorianSession.h delete mode 100644 sources/PIHistorianManager.cpp delete mode 100644 sources/PIHistorianManager.h 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; From 428ef3bfb211fd4fdac76176779a8f178a1873e3 Mon Sep 17 00:00:00 2001 From: jfmartel Date: Fri, 7 Jun 2024 14:20:16 -0400 Subject: [PATCH 3/4] Dev Historien PI --- Configuration/ZT.cfg | 2 +- Configuration/ZTSettings.ztc | Bin 41 -> 41 bytes ZT.pro | 3 +- sftpbatch | 2 +- sources/Modbus/PIHistorianDefs.h | 203 ++++------ sources/Modbus/PIHistorianManager.cpp | 527 +++++++++++++++++++++++++- sources/Modbus/PIHistorianManager.h | 33 +- sources/Modbus/PIHistorianSession.cpp | 4 +- sources/ZTData.h | 14 + sources/ZTStateMachine.cpp | 26 ++ sources/ZTStateMachine.h | 2 + sources/Zonetest.cpp | 142 +++---- sources/Zonetest.h | 2 + 13 files changed, 730 insertions(+), 230 deletions(-) diff --git a/Configuration/ZT.cfg b/Configuration/ZT.cfg index 5bc6b89..0894139 100644 --- a/Configuration/ZT.cfg +++ b/Configuration/ZT.cfg @@ -72,7 +72,7 @@ ACTIVER_HISTORIEN_PI=OUI #Adresse modbus de la ZT HISTORIEN_PI_DEVID=1 #Port Modbus/TCP du serveur historien -HISTORIEN_PI_PORT=503 +HISTORIEN_PI_PORT=2183 #---------------------------------- diff --git a/Configuration/ZTSettings.ztc b/Configuration/ZTSettings.ztc index d7191e9c232797e572a1119ffeafe29553d8f0fc..d4476a56d4d00519ab4bbaca6ff9d0338fd98e77 100644 GIT binary patch delta 14 VcmdPYsetSingleShot(true); + + + mNbPassagesToday = 0; + mNbDeclToday = 0; + mNbDeclTotal = 0; + mNbFNToday = 0; + mNbPGToday = 0; + mNbPPIZT1Today = 0; + mNbPPEZT1Today = 0; + mNbPPIZT2Today = 0; + mNbPPEZT2Today = 0; } CPIHistorianManager::~CPIHistorianManager() { StopPIHistorian(); delete mModbusServer; + delete mHistorianTimer; } void CPIHistorianManager::NewModbusConnection() @@ -20,7 +38,7 @@ void CPIHistorianManager::NewModbusConnection() QTcpSocket* SessionSocket = mModbusServer->nextPendingConnection(); if(SessionSocket != 0) { - CPIHistorianSession *NewSession = new CPIHistorianSession(mPIHistorianRepo,PI_HISTORIAN_MODBUS_DEVICE_ID); + CPIHistorianSession *NewSession = new CPIHistorianSession(mPIHistorianRepo,mModbusDevID); connect(NewSession,SIGNAL(PIHistorianSessionClosed(CPIHistorianSession*)),this,SLOT(HistorianSessionClosed(CPIHistorianSession*))); mHistorianSessionsList.append(NewSession); NewSession->OpenSession(SessionSocket); @@ -35,6 +53,7 @@ void CPIHistorianManager::HistorianSessionClosed(CPIHistorianSession *SessionPtr if(mHistorianSessionsList.at(i) == SessionPtr) { CPIHistorianSession *Session = mHistorianSessionsList.takeAt(i); + Session->CloseSession(); delete Session; return; } @@ -46,7 +65,8 @@ 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; + StartHistorianTimer(); + return RET_OK; } int CPIHistorianManager::StopPIHistorian() @@ -59,5 +79,506 @@ int CPIHistorianManager::StopPIHistorian() delete Session; } + mHistorianTimer->stop(); + return RET_OK; +} + +int CPIHistorianManager::UpdateDetectionFunctions(CZTDetectionFunctionConfig *DetectionCfg) +{ + bool OK; + quint16 StatusReg = mPIHistorianRepo->GetSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,&OK); + if(OK == false) + return RET_ERROR; + + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_FN].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_FN].TKActive == true) + { + StatusReg |= HISTORIAN_ZT1_FN_ENABLED_FLAG_MASK; + } + else + { + StatusReg &= ~HISTORIAN_ZT1_FN_ENABLED_FLAG_MASK; + } + + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PG].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PG].TKActive == true) + { + StatusReg |= HISTORIAN_ZT1_PG_ENABLED_FLAG_MASK; + } + else + { + StatusReg &= ~HISTORIAN_ZT1_PG_ENABLED_FLAG_MASK; + } + + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP].TKActive == true) + { + StatusReg |= HISTORIAN_ZT1_PP_ENABLED_FLAG_MASK; + } + else + { + StatusReg &= ~HISTORIAN_ZT1_PP_ENABLED_FLAG_MASK; + } + + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP2].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP2].TKActive == true) + { + StatusReg |= HISTORIAN_ZT2_PP_ENABLED_FLAG_MASK; + } + else + { + StatusReg &= ~HISTORIAN_ZT2_PP_ENABLED_FLAG_MASK; + } + + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT1].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT1].TKActive == true) + { + StatusReg |= HISTORIAN_ZT_ZT1_ENABLED_FLAG_MASK; + } + else + { + StatusReg &= ~HISTORIAN_ZT_ZT1_ENABLED_FLAG_MASK; + } + + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT2].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT2].TKActive == true) + { + StatusReg |= HISTORIAN_ZT_ZT2_ENABLED_FLAG_MASK; + } + else + { + StatusReg &= ~HISTORIAN_ZT_ZT2_ENABLED_FLAG_MASK; + } + + return mPIHistorianRepo->WriteSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,StatusReg); + +} + + +int CPIHistorianManager::UpdatePGTreshold(int Treshold) +{ + return mPIHistorianRepo->WriteSingleReg(HISTORIAN_PG_CALIBRATION_REG_ADD,(quint16)Treshold); + +} + +int CPIHistorianManager::UpdateMaintenanceMode(bool MaintenanceON) +{ + bool OK; + quint16 StatusReg = mPIHistorianRepo->GetSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,&OK); + if(OK == false) + return RET_ERROR; + + if(MaintenanceON) + { + StatusReg |= HISTORIAN_ZT_MAINTENANCE_MODE_FLAG_MASK; + } + else + { + StatusReg &= ~HISTORIAN_ZT_MAINTENANCE_MODE_FLAG_MASK; + } + + return mPIHistorianRepo->WriteSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,StatusReg); + +} + +int CPIHistorianManager::SetSystemStartDateTime(QDateTime StartDateTime) +{ + quint16 year, month, day, hour, minute, seconds; + year = (quint16)StartDateTime.date().year(); + day = (quint16)StartDateTime.date().day(); + month = (quint16)StartDateTime.date().month(); + hour = (quint16)StartDateTime.time().hour(); + minute = (quint16)StartDateTime.time().minute(); + seconds = (quint16)StartDateTime.time().second(); + + int ret; + + ret = mPIHistorianRepo->WriteSingleReg(HISTORIAN_BOOT_DATE_YEAR_REG_ADD,year); + ret |= mPIHistorianRepo->WriteSingleReg(HISTORIAN_BOOT_DATE_DAY_REG_ADD,day); + ret |= mPIHistorianRepo->WriteSingleReg(HISTORIAN_BOOT_DATE_MONTH_REG_ADD,month); + ret |= mPIHistorianRepo->WriteSingleReg(HISTORIAN_BOOT_DATE_HOUR_REG_ADD,hour); + ret |= mPIHistorianRepo->WriteSingleReg(HISTORIAN_BOOT_DATE_MINUTES_REG_ADD,minute); + ret |= mPIHistorianRepo->WriteSingleReg(HISTORIAN_BOOT_DATE_SECONDS_REG_ADD,seconds); + + return ret; +} + +void CPIHistorianManager::HPCDisconnected() +{ + bool OK; + quint16 StatusReg = mPIHistorianRepo->GetSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,&OK); + if(OK == false) + return; + + StatusReg &= ~HISTORIAN_ZT_HPC_COMM_HEALTH_FLAG_MASK; + + + mPIHistorianRepo->WriteSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,StatusReg); +} + +void CPIHistorianManager::HPCConnected(qint32 IP1,qint32 IP2) +{ + Q_UNUSED(IP1) + Q_UNUSED(IP2) + + bool OK; + quint16 StatusReg = mPIHistorianRepo->GetSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,&OK); + if(OK == false) + return; + + StatusReg |= HISTORIAN_ZT_HPC_COMM_HEALTH_FLAG_MASK; + + + mPIHistorianRepo->WriteSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,StatusReg); +} + +void CPIHistorianManager::SEIConnected(qint32 IP1,qint32 IP2) +{ + Q_UNUSED(IP1) + Q_UNUSED(IP2) + + bool OK; + quint16 StatusReg = mPIHistorianRepo->GetSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,&OK); + if(OK == false) + return; + + StatusReg |= HISTORIAN_ZT_SEI_COMM_FLAG_MASK; + + + mPIHistorianRepo->WriteSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,StatusReg); + +} + +void CPIHistorianManager::SEIDisconnected() +{ bool OK; + quint16 StatusReg = mPIHistorianRepo->GetSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,&OK); + if(OK == false) + return; + + StatusReg &= ~HISTORIAN_ZT_SEI_COMM_FLAG_MASK; + + + mPIHistorianRepo->WriteSingleReg(HISTORIAN_ZT_STATUS_FLAGS_REG_ADD,StatusReg); + +} + +int CPIHistorianManager::NewZT1Passage(CZTPassageInfo ZT1PassageInfo) +{ + QByteArray EmptyList; //create an empty buffer to reset modbus table values + EmptyList.fill(0x00, 18*2); + //Reset last declenchements values in the modbus table + mPIHistorianRepo->WriteHRData(HISTORIAN_LAST_TRAIN_PPI_RK_1_REG_ADD,18,EmptyList); + + mPIHistorianRepo->WriteSingleReg(HISTORIAN_TRAINS_TOTAL_REG_ADD,ZT1PassageInfo.mNbPassages); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_ZONE_REG_ADD,1); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_TYPE_REG_ADD,ZT1PassageInfo.mTrainType); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_ID1_REG_ADD,ZT1PassageInfo.mTrainCompo1); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_ID2_REG_ADD,ZT1PassageInfo.mTrainCompo2); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_ID3_REG_ADD,ZT1PassageInfo.mTrainCompo3); + + QDateTime PassageDateTime = ZT1PassageInfo.mPassageDateTime; + quint16 year, month, day, hour, minute, seconds; + year = (quint16)PassageDateTime.date().year(); + day = (quint16)PassageDateTime.date().day(); + month = (quint16)PassageDateTime.date().month(); + hour = (quint16)PassageDateTime.time().hour(); + minute = (quint16)PassageDateTime.time().minute(); + seconds = (quint16)PassageDateTime.time().second(); + + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_YEAR_REG_ADD,year); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_DAY_REG_ADD,day); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_MONTH_REG_ADD,month); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_HOUR_REG_ADD,hour); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_MINUTE_REG_ADD,minute); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_SECONDS_REG_ADD,seconds); + + + quint16 NbDecl = ZT1PassageInfo.mDetections->size(); + + quint16 NbDeclFN = 0, NbDeclPG = 0, NbDeclPPI = 0, NbDeclPPE = 0; + quint16 PEQ = 0, ErrComptage = 0; + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_NB_DETECTS_REG_ADD,NbDecl); + if(NbDecl != 0) + { + for(int i = 0; i < NbDecl; i++) + { + CZTDetectionData *CurDetection = ZT1PassageInfo.mDetections->at(i); + + switch(CurDetection->mDetectionID) + { + case DETECTION_MAGNETIC_SENSOR_COUNT: + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_COMPTAGE_DET_REG_ADD,1); + break; + } + case DETECTION_FN_DETECTION: + { + NbDeclFN++; + if(NbDeclFN == 1) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_FN_RK_1_REG_ADD,CurDetection->mRank); + } + else if(NbDeclFN == 2) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_FN_RK_2_REG_ADD,CurDetection->mRank); + } + else if(NbDeclFN == 3) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_FN_RK_3_REG_ADD,CurDetection->mRank); + } + else if(NbDeclFN == 4) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_FN_RK_4_REG_ADD,CurDetection->mRank); + } + else + { + //Ignore if more than 4 + } + + break; + } + case DETECTION_PG_DETECTION: + { + NbDeclPG++; + if(NbDeclPG == 1) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PG_RK_1_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPG == 2) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PG_RK_2_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPG == 3) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PG_RK_3_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPG == 4) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PG_RK_4_REG_ADD,CurDetection->mRank); + } + else + { + //Ignore if more than 4 + } + break; + } + case DETECTION_PPI_DETECTION: + { + NbDeclPPI++; + if(NbDeclPPI == 1) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPI_RK_1_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPI == 2) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPI_RK_2_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPI == 3) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPI_RK_3_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPI == 4) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPI_RK_4_REG_ADD,CurDetection->mRank); + } + else + { + //Ignore if more than 4 + } + break; + } + case DETECTION_PPE_DETECTION: + { + NbDeclPPE++; + if(NbDeclPPE == 1) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPE_RK_1_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPE == 2) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPE_RK_2_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPE == 3) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPE_RK_3_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPE == 4) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPE_RK_4_REG_ADD,CurDetection->mRank); + } + else + { + //Ignore if more than 4 + } + break; + } + case DETECTION_PEQ1_DETECTION: + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PEQ_REG_ADD,1); + break; + } + } + } + + + mNbPassagesToday ++; + mNbDeclToday += NbDecl; + mNbDeclTotal += NbDecl; + mNbFNToday += NbDeclFN; + mNbPGToday += NbDeclPG; + mNbPPIZT1Today += NbDeclPPI; + mNbPPEZT1Today += NbDeclPPE; + + mPIHistorianRepo->WriteSingleReg(HISTORIAN_TRAINS_TODAY_REG_ADD,mNbPassagesToday); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_DETECTIONS_TOTAL_REG_ADD,ZT1PassageInfo.mNbDeclenchements); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_DETECTIONS_TODAY_REG_ADD,mNbDeclToday); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_FN_DETECTS_TODAY_REG_ADD,mNbFNToday); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_PPI_ZT1_DETECTS_TODAY_REG_ADD,mNbPPIZT1Today); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_PPE_ZT1_DETECTS_TODAY_REG_ADD,mNbPPEZT1Today); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_PG_DETECTS_TODAY_REG_ADD,mNbPGToday); + + } + + return RET_OK; +} + + +int CPIHistorianManager::NewZT2Passage(CZTPassageInfo ZT2PassageInfo) +{ + QByteArray EmptyList; //create an empty buffer to reset modbus table values + EmptyList.fill(0x00, 18*2); + //Reset last declenchements values in the modbus table + mPIHistorianRepo->WriteHRData(HISTORIAN_LAST_TRAIN_PPI_RK_1_REG_ADD,18,EmptyList); + + mPIHistorianRepo->WriteSingleReg(HISTORIAN_TRAINS_TOTAL_REG_ADD,ZT2PassageInfo.mNbPassages); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_ZONE_REG_ADD,2); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_TYPE_REG_ADD,ZT2PassageInfo.mTrainType); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_ID1_REG_ADD,ZT2PassageInfo.mTrainCompo1); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_ID2_REG_ADD,ZT2PassageInfo.mTrainCompo2); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_ID3_REG_ADD,ZT2PassageInfo.mTrainCompo3); + + QDateTime PassageDateTime = ZT2PassageInfo.mPassageDateTime; + quint16 year, month, day, hour, minute, seconds; + year = (quint16)PassageDateTime.date().year(); + day = (quint16)PassageDateTime.date().day(); + month = (quint16)PassageDateTime.date().month(); + hour = (quint16)PassageDateTime.time().hour(); + minute = (quint16)PassageDateTime.time().minute(); + seconds = (quint16)PassageDateTime.time().second(); + + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_YEAR_REG_ADD,year); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_DAY_REG_ADD,day); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_MONTH_REG_ADD,month); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_HOUR_REG_ADD,hour); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_MINUTE_REG_ADD,minute); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_SECONDS_REG_ADD,seconds); + + + quint16 NbDecl = ZT2PassageInfo.mDetections->size(); + + quint16 NbDeclPPI = 0, NbDeclPPE = 0; + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_NB_DETECTS_REG_ADD,NbDecl); + if(NbDecl != 0) + { + for(int i = 0; i < NbDecl; i++) + { + CZTDetectionData *CurDetection = ZT2PassageInfo.mDetections->at(i); + + switch(CurDetection->mDetectionID) + { + case DETECTION_ZT2_MAGNETIC_SENSOR_COUNT: + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_COMPTAGE_DET_REG_ADD,1); + break; + } + case DETECTION_ZT2_PPI_DETECTION: + { + NbDeclPPI++; + if(NbDeclPPI == 1) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPI_RK_1_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPI == 2) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPI_RK_2_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPI == 3) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPI_RK_3_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPI == 4) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPI_RK_4_REG_ADD,CurDetection->mRank); + } + else + { + //Ignore if more than 4 + } + break; + } + case DETECTION_ZT2_PPE_DETECTION: + { + NbDeclPPE++; + if(NbDeclPPE == 1) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPE_RK_1_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPE == 2) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPE_RK_2_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPE == 3) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPE_RK_3_REG_ADD,CurDetection->mRank); + } + else if(NbDeclPPE == 4) + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PPE_RK_4_REG_ADD,CurDetection->mRank); + } + else + { + //Ignore if more than 4 + } + break; + } + case DETECTION_PEQ2_DETECTION: + { + mPIHistorianRepo->WriteSingleReg(HISTORIAN_LAST_TRAIN_PEQ_REG_ADD,1); + break; + } + } + } + + + mNbDeclToday += NbDecl; + mNbDeclTotal += NbDecl; + mNbPPIZT2Today += NbDeclPPI; + mNbPPEZT2Today += NbDeclPPE; + + mPIHistorianRepo->WriteSingleReg(HISTORIAN_TRAINS_TODAY_REG_ADD,mNbPassagesToday); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_DETECTIONS_TOTAL_REG_ADD,ZT2PassageInfo.mNbDeclenchements); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_DETECTIONS_TODAY_REG_ADD,mNbDeclToday); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_PPI_ZT2_DETECTS_TODAY_REG_ADD,mNbPPIZT2Today); + mPIHistorianRepo->WriteSingleReg(HISTORIAN_PPE_ZT2_DETECTS_TODAY_REG_ADD,mNbPPEZT2Today); + + } + return RET_OK; +} +void CPIHistorianManager::StartHistorianTimer() +{ + QTime Time = QTime::currentTime(); + int Delay = Time.msecsTo(QTime(23,59,59)); + if(Delay < 0) + { + Delay += MSECS_IN_A_DAY; + } + + mHistorianTimer->start(Delay); +} + +void CPIHistorianManager::HistorianTimerExpired() +{ + mNbFNToday = 0; + mNbPGToday = 0; + mNbPPIZT1Today = 0; + mNbPPEZT1Today = 0; + mNbPPIZT2Today = 0; + mNbPPEZT2Today = 0; + + StartHistorianTimer(); } diff --git a/sources/Modbus/PIHistorianManager.h b/sources/Modbus/PIHistorianManager.h index 7d83c73..23534f4 100644 --- a/sources/Modbus/PIHistorianManager.h +++ b/sources/Modbus/PIHistorianManager.h @@ -5,28 +5,59 @@ #include "PIHistorianSession.h" #include #include +#include "ZTData.h" #define PI_HISTORIAN_MODBUS_DEVICE_ID 1 +#define MSECS_IN_A_DAY (24 * 60 * 60 * 1000) class CPIHistorianManager : public QObject { Q_OBJECT public: - CPIHistorianManager(CModbusRepository *PIHistorianRepo, int ModbusPort); + CPIHistorianManager(CModbusRepository *PIHistorianRepo, int ModbusPort, int ModbusDevID); virtual ~CPIHistorianManager(); int StartPIHistorian(); int StopPIHistorian(); + int UpdateDetectionFunctions(CZTDetectionFunctionConfig* DetectionCfg); + int UpdatePGTreshold(int Treshold); + int UpdateMaintenanceMode(bool MaintenanceON); + int SetSystemStartDateTime(QDateTime StartDateTime); + int NewZT1Passage(CZTPassageInfo ZT1PassageInfo); + int NewZT2Passage(CZTPassageInfo ZT2PassageInfo); + QTcpServer *mModbusServer; //L'instance du serveur TCP int mModbusPort; + int mModbusDevID; CModbusRepository *mPIHistorianRepo; + QTimer *mHistorianTimer; + void StartHistorianTimer(); + private: QList mHistorianSessionsList; //Les sessions établies par le serveur sont gardées dans cette liste + quint16 mNbPassagesToday; + quint16 mNbDeclToday; + quint16 mNbDeclTotal; + quint16 mNbFNToday; + quint16 mNbPGToday; + quint16 mNbPPIZT1Today; + quint16 mNbPPEZT1Today; + quint16 mNbPPIZT2Today; + quint16 mNbPPEZT2Today; public slots: void NewModbusConnection(); void HistorianSessionClosed(CPIHistorianSession*); + + void HPCDisconnected(); + void HPCConnected(qint32 IP1, qint32 IP2); + void SEIConnected(qint32, qint32 IP2); + void SEIDisconnected(); + void HistorianTimerExpired(); + + + }; #endif // PIHISTORIANMANAGER_H diff --git a/sources/Modbus/PIHistorianSession.cpp b/sources/Modbus/PIHistorianSession.cpp index 9902b8b..0388957 100644 --- a/sources/Modbus/PIHistorianSession.cpp +++ b/sources/Modbus/PIHistorianSession.cpp @@ -17,7 +17,7 @@ int CPIHistorianSession::OpenSession(QTcpSocket *ModbusSocket) { mModbusTCPSocketHandle = ModbusSocket; connect(mModbusTCPSocketHandle,SIGNAL(readyRead()),this,SLOT(ModbusDataReady())); - connect(mModbusTCPSocketHandle,SIGNAL(disconnected()),this,SLOT(ConnectionLost())); + connect(mModbusTCPSocketHandle,SIGNAL(disconnected()),this,SLOT(HistorianConnectionLost())); CZTLog::instance()->AddLogString(QString("Session avec Historien PI établie. IP locale [%1] - IP HPC [%2]").arg(mModbusTCPSocketHandle->localAddress().toString()).arg(mModbusTCPSocketHandle->peerAddress().toString()),true); @@ -28,7 +28,7 @@ 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.")); + CZTLog::instance()->AddLogString(QString("Session avec Historien PI fermée avec succès."),true); return RET_OK; } diff --git a/sources/ZTData.h b/sources/ZTData.h index 4a897f1..086e71b 100644 --- a/sources/ZTData.h +++ b/sources/ZTData.h @@ -379,4 +379,18 @@ class CZTPGCalibrationData qint32 mPGIntValue; }; +class CZTPassageInfo +{ +public: + QVector *mDetections; + quint16 mNbPassages; + quint16 mNbDeclenchements; + qint16 mTrainCompo1; + qint16 mTrainCompo2; + qint16 mTrainCompo3; + qint16 mTrainType; + QDateTime mPassageDateTime; + +}; + #endif // ZTDATA_H diff --git a/sources/ZTStateMachine.cpp b/sources/ZTStateMachine.cpp index 6a3aa27..e109ca9 100755 --- a/sources/ZTStateMachine.cpp +++ b/sources/ZTStateMachine.cpp @@ -377,6 +377,7 @@ unsigned int CZTStateMachine::ZT1StateMachine(unsigned int Event, unsigned int S mZT1ActiveStatus = SB_ZT_ACTIVE_STATUS; mZTPagePTr->SetZTStatus(mNbPassages,mNbTriggers,mZT1ActiveStatus,mZT2ActiveStatus); mZTPagePTr->SetZT1ActivationState(true); + mZTActivationDateTime = QDateTime::currentDateTime(); mZTPagePTr->ResetZT1Stats(); if(mModbusCCMgr != 0) @@ -1168,6 +1169,19 @@ unsigned int CZTStateMachine::AnalyzeZT1PostDetection() CZTLog::instance()->ClearBufferString(); //2015-03-03 To avoid potention memory leak. Computer Crash problem resolution tentative... } + CZTPassageInfo PassageInfo; + PassageInfo.mDetections = &mZT1DetectionsLog; + PassageInfo.mNbPassages = mNbPassages; + PassageInfo.mNbDeclenchements = mNbTriggers; + PassageInfo.mTrainType = mZT1Log.mZT1Flags.mModbusTrainType; + PassageInfo.mTrainCompo1 = mZT1Log.mZT1Flags.mTrainCompo1; + PassageInfo.mTrainCompo2 = mZT1Log.mZT1Flags.mTrainCompo2; + PassageInfo.mTrainCompo3 = mZT1Log.mZT1Flags.mTrainCompo3; + PassageInfo.mPassageDateTime = mZTActivationDateTime; + + + mProgramPtr->NewZT1Passage(PassageInfo); + mZTPagePTr->SetZTStatus(mNbPassages,mNbTriggers,mZT1ActiveStatus,mZT2ActiveStatus); return RET_POST_DETECTION_VALID; @@ -1240,6 +1254,7 @@ unsigned int CZTStateMachine::ZT2StateMachine(unsigned int Event, unsigned int S mEventsRefTimer.start(); mZTPagePTr->SetZT2ActivationSTate(true); mZT2ActiveStatus = SB_ZT_ACTIVE_STATUS; + mZTActivationDateTime = QDateTime::currentDateTime(); mZTPagePTr->SetZTStatus(mNbPassages,mNbTriggers,mZT1ActiveStatus,mZT2ActiveStatus); mZTPagePTr->ResetZT2Stats(); if(mModbusCCMgr != 0) @@ -1442,6 +1457,17 @@ unsigned int CZTStateMachine::AnalyzeZT2PostDetection() CZTLog::instance()->ClearBufferString(); //2015-03-03 To avoid potention memory leak. Computer Crash problem resolution tentative... } + CZTPassageInfo PassageInfo; + PassageInfo.mDetections = &mZT2DetectionsLog; + PassageInfo.mNbPassages = mNbPassages; + PassageInfo.mNbDeclenchements = mNbTriggers; + PassageInfo.mTrainType = mZT2Log.mZT2Flags.mModbusTrainType; + PassageInfo.mTrainCompo1 = mZT2Log.mZT2Flags.mTrainCompo1; + PassageInfo.mTrainCompo2 = mZT2Log.mZT2Flags.mTrainCompo2; + PassageInfo.mTrainCompo3 = mZT2Log.mZT2Flags.mTrainCompo3; + PassageInfo.mPassageDateTime = mZTActivationDateTime; + mProgramPtr->NewZT2Passage(PassageInfo); + //mZTPagePTr->SetZTStatus(mNbPassages,mNbTriggers,mZT1Active,mZT2Active); mZTPagePTr->SetZTStatus(mNbPassages,mNbTriggers,mZT1ActiveStatus,mZT2ActiveStatus); diff --git a/sources/ZTStateMachine.h b/sources/ZTStateMachine.h index 5e5cd8f..b77cc25 100644 --- a/sources/ZTStateMachine.h +++ b/sources/ZTStateMachine.h @@ -230,6 +230,8 @@ private: QElapsedTimer mFSSyncTimer; bool mTimeToForceSyncFS; + QDateTime mZTActivationDateTime; + signals: void PGCalibrationFinished(int); //Signal envoyé lorsque la calibration est terminée. Le paramètre est la valeur calculée. void PGCalibrationStatus(int,int); //Signal envoyé pour informer de l'état de la calibration. Le paramètre 1 est le nombre de passages à date et le 2è est le nombre requis. diff --git a/sources/Zonetest.cpp b/sources/Zonetest.cpp index f750119..e9d0af3 100644 --- a/sources/Zonetest.cpp +++ b/sources/Zonetest.cpp @@ -60,6 +60,7 @@ #include "ModbusTKTransport.h" #include "ModbusSEIDefs.h" #include +#include "PIHistorianDefs.h" @@ -424,44 +425,6 @@ unsigned int CZoneTest::InitZT() mAnalogModule = 0; -// //Open the DataQ datalogger module if present in config file -// QString DataQIP = CZTConfigMgr::instance()->GetDataQIPAddress(); -// if(DataQIP.isEmpty()) -// { -// CZTLog::instance()->AddLogString("Module DataQ non trouvé dans le fichier de configuration.",true); -// } -// else -// { -// mDI710Module = new CDI710Driver; -// if(mDI710Module->OpenDevice(DataQIP,DI710_TCP_PORT) != DI710_RET_OK) -// { -// mWelcomePagePtr->InsertTextBoxString(QString("Impossible d'initialiser le module DataQ")); -// mWelcomePagePtr->InsertTextBoxString(QString("Vérifier le fichier de configuration et la connexion.")); -// CZTLog::instance()->AddLogString("Impossible d'initialiser le module DataQ",true); -// delete mDI710Module; -// mDI710Module = 0; -// } -// else -// { -// mDataQThread = new QThread; -// mDI710Module->moveToThread(mDataQThread); -// connect(mDataQThread,SIGNAL(started()),mDI710Module,SLOT(Run())); -// mDataQThread->start(); -// mWelcomePagePtr->InsertTextBoxString(QString("Initialisation du module DataQ: OK")); -// } -// } - - //Now, determine which of the analog module is detected. - -// if((mIOManager->GetModule(IO_MODULE_MIXED_TYPE,1) != 0)) -// { -// mAnalogModule = (CMixedModule*)mIOManager->GetModule(IO_MODULE_MIXED_TYPE,1); -// } -// else if(mDI710Module != 0) -// { -// mAnalogModule = mDI710Module; -// } - //Open advantech USB-4704 analog acquisition module. CUSB4704Interface *USBAnalogModule = new CUSB4704Interface(); @@ -517,57 +480,6 @@ unsigned int CZoneTest::InitZT() mExtIOThread->start(QThread::NormalPriority); bool UseModbusInterface = mZTSettings->mUseModbusCC; -// if(CZTConfigMgr::instance()->GetModbusCCEnabled() != ZT_CONFIG_MODBUS_ENABLE_FORCE_OFF) -// { -// if(CZTConfigMgr::instance()->GetModbusCCEnabled() == ZT_CONFIG_MODBUS_ENABLE_FORCE_ON) -// { -// CEngLog::instance()->AddLogString("Interface Modbus activée (forcée)",1); -// UseModbusInterface = true; -// } -// else -// { -//// //autodetect modbus interface... -// int ModbusPort = CZTConfigMgr::instance()->GetModbusCCPort(); -// mWelcomePagePtr->InsertTextBoxString(QString("Détection Modbus CC...")); -// if(CModbusCCMgr::CheckForCCPartner(3000,ModbusPort) == true) -// { -// UseModbusInterface = true; -// mWelcomePagePtr->InsertTextBoxString(QString("Modbus CC détecté et activé")); -// } -// else -// { -// mWelcomePagePtr->InsertTextBoxString(QString("Modbus CC non-détecté")); -// } - -//// CEngLog::instance()->AddLogString("Auto-Détection de l'interface Modbus",1); -//// QString IFName = CZTConfigMgr::instance()->GetModbusCCIFName(); -//// if(IFName != "INVALID") -//// { -//// QString CarrierFile = QString("/sys/class/net/%1/carrier").arg(IFName); -//// QFile *EthIfStateFile = new QFile(CarrierFile); -//// if(EthIfStateFile) -//// { -//// CEngLog::instance()->AddLogString(QString("Ouverture du fichier %1 ...").arg(IFName),3); -//// if(EthIfStateFile->open(QIODevice::ReadOnly | QIODevice::Text) == true) -//// { -//// QByteArray val = EthIfStateFile->readAll(); -//// QString State(val); -//// if(State.contains("1")) -//// { -//// CZTLog::instance()->AddLogString(QString("Connexion Ethernet CC détectée sur %1").arg(IFName),true); -//// UseModbusInterface = true; -//// } -//// else -//// { -//// CZTLog::instance()->AddLogString(QString("Connexion Ethernet CC inactive ou non-détectée sur %1").arg(IFName),true); -//// } -//// EthIfStateFile->close(); -//// } -//// delete EthIfStateFile; -//// } -//// } -// } -// } if(UseModbusInterface == true) { @@ -690,8 +602,23 @@ unsigned int CZoneTest::InitZT() 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); + mPIHistorianRepository->AddHRDataMap(HISTORIAN_ZT_DATA_BASE_REG,HISTORIAN_MODBUS_ZT_TABLE_DATA_SIZE); //Add the ZT data map + mPIHistorianManager = new CPIHistorianManager(mPIHistorianRepository,PIHistorianPort,PIHistorianDevID); + + if(UseModbusInterface) + { + connect(mModbusCCMgr,SIGNAL(ModbusCCConnected(qint32,qint32)),mPIHistorianManager,SLOT(HPCConnected(qint32,qint32))); + connect(mModbusCCMgr,SIGNAL(ModbusCCDisconnected()),mPIHistorianManager,SLOT(HPCDisconnected())); + connect(mModbusSEIMgr,SIGNAL(ModbusMasterConnected(qint32,qint32)),mPIHistorianManager,SLOT(SEIConnected(qint32,qint32))); + connect(mModbusSEIMgr,SIGNAL(ModbusMasterDisconnected()),mPIHistorianManager,SLOT(SEIDisconnected())); + } + + mPIHistorianManager->UpdateDetectionFunctions(mZTSettings->mDetectionFunctionSettings); + mPIHistorianManager->UpdatePGTreshold(mZTSettings->mPGTreshold); + mPIHistorianManager->UpdateMaintenanceMode(false); + mPIHistorianManager->SetSystemStartDateTime(mZTStartDateTime); + + mPIHistorianManager->StartPIHistorian(); } @@ -1036,6 +963,9 @@ unsigned int CZoneTest::DetectionFunctionsConfigChanged(CZTDetectionFunctionConf mZTSettingsFileMgr.SaveSettings(mZTSettings); mEventMgr->UpdateEvents(mZTSettings->mDetectionFunctionSettings); + if(mPIHistorianManager != 0) + mPIHistorianManager->UpdateDetectionFunctions(NewConfig); + return RET_OK; } @@ -1166,6 +1096,9 @@ unsigned int CZoneTest::SetPGTreshold(int NewTreshold) mZTSettings->mPGTreshold = NewTreshold; mZTSettingsFileMgr.SaveSettings(mZTSettings); + if(mPIHistorianManager != 0) + mPIHistorianManager->UpdatePGTreshold(NewTreshold); + return RET_OK; } @@ -1175,6 +1108,11 @@ bool CZoneTest::EnterMaintenanceModeRequest() if(mZTStateMachine->EnterMaintenanceMode() == RET_OK) { mEventMgr->AddSingleEvent(EVENT_MAINTENANCE); + + if(mPIHistorianManager != 0) + { + mPIHistorianManager->UpdateMaintenanceMode(true); + } return true; } else @@ -1193,6 +1131,11 @@ void CZoneTest::ExitMaintenanceModeRequest() } mZTStateMachine->QuitMaintenanceMode(); mEventMgr->RemoveSingleEvent(EVENT_MAINTENANCE); + + if(mPIHistorianManager != 0) + { + mPIHistorianManager->UpdateMaintenanceMode(false); + } } unsigned int CZoneTest::ClearMaintenanceCurTKRequest() @@ -1514,6 +1457,23 @@ int CZoneTest::SetZT2InhibitionState(bool InhibitionON) return RET_OK; } +int CZoneTest::NewZT1Passage(CZTPassageInfo ZT1PassageInfo) +{ + if(mPIHistorianManager != 0) + { + mPIHistorianManager->NewZT1Passage(ZT1PassageInfo); + } + return RET_OK; +} + +int CZoneTest::NewZT2Passage(CZTPassageInfo ZT2PassageInfo) +{ + if(mPIHistorianManager != 0) + { + mPIHistorianManager->NewZT2Passage(ZT2PassageInfo); + } + return RET_OK; +} void CZoneTest::ApplicationQuit(int Reason) { diff --git a/sources/Zonetest.h b/sources/Zonetest.h index c4e4f86..280340a 100644 --- a/sources/Zonetest.h +++ b/sources/Zonetest.h @@ -170,6 +170,8 @@ public: //ZTStateMachine requests int SetZT1InhibitionState(bool InhibitionON); int SetZT2InhibitionState(bool InhibitionON); + int NewZT1Passage(CZTPassageInfo ZT1PassageInfo); + int NewZT2Passage(CZTPassageInfo ZT2PassageInfo); From 33ef17ff9568e2f4598c667b9b6a5e0e6a827204 Mon Sep 17 00:00:00 2001 From: jfmartel Date: Thu, 4 Jul 2024 16:00:03 -0400 Subject: [PATCH 4/4] Dev Historien... --- Configuration/ZTSettings.ztc | Bin 41 -> 41 bytes sftpbatch | 2 +- sources/Modbus/PIHistorianDefs.h.autosave | 139 ---------------------- sources/Modbus/PIHistorianManager.cpp | 12 +- 4 files changed, 7 insertions(+), 146 deletions(-) delete mode 100644 sources/Modbus/PIHistorianDefs.h.autosave diff --git a/Configuration/ZTSettings.ztc b/Configuration/ZTSettings.ztc index d4476a56d4d00519ab4bbaca6ff9d0338fd98e77..d7191e9c232797e572a1119ffeafe29553d8f0fc 100644 GIT binary patch literal 41 fcmdnB_B10hU;u$yAWi{dMn;AMDmZTDetectionConfig[DETECTION_FCT_FN].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_FN].TKActive == true) + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_FN].AnalysisActive == true && DetectionCfg->mZTDetectionConfig[DETECTION_FCT_FN].TKActive == true) { StatusReg |= HISTORIAN_ZT1_FN_ENABLED_FLAG_MASK; } @@ -99,7 +99,7 @@ int CPIHistorianManager::UpdateDetectionFunctions(CZTDetectionFunctionConfig *De StatusReg &= ~HISTORIAN_ZT1_FN_ENABLED_FLAG_MASK; } - if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PG].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PG].TKActive == true) + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PG].AnalysisActive == true && DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PG].TKActive == true) { StatusReg |= HISTORIAN_ZT1_PG_ENABLED_FLAG_MASK; } @@ -108,7 +108,7 @@ int CPIHistorianManager::UpdateDetectionFunctions(CZTDetectionFunctionConfig *De StatusReg &= ~HISTORIAN_ZT1_PG_ENABLED_FLAG_MASK; } - if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP].TKActive == true) + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP].AnalysisActive == true && DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP].TKActive == true) { StatusReg |= HISTORIAN_ZT1_PP_ENABLED_FLAG_MASK; } @@ -117,7 +117,7 @@ int CPIHistorianManager::UpdateDetectionFunctions(CZTDetectionFunctionConfig *De StatusReg &= ~HISTORIAN_ZT1_PP_ENABLED_FLAG_MASK; } - if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP2].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP2].TKActive == true) + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP2].AnalysisActive == true && DetectionCfg->mZTDetectionConfig[DETECTION_FCT_PP2].TKActive == true) { StatusReg |= HISTORIAN_ZT2_PP_ENABLED_FLAG_MASK; } @@ -126,7 +126,7 @@ int CPIHistorianManager::UpdateDetectionFunctions(CZTDetectionFunctionConfig *De StatusReg &= ~HISTORIAN_ZT2_PP_ENABLED_FLAG_MASK; } - if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT1].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT1].TKActive == true) + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT1].AnalysisActive == true && DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT1].TKActive == true) { StatusReg |= HISTORIAN_ZT_ZT1_ENABLED_FLAG_MASK; } @@ -135,7 +135,7 @@ int CPIHistorianManager::UpdateDetectionFunctions(CZTDetectionFunctionConfig *De StatusReg &= ~HISTORIAN_ZT_ZT1_ENABLED_FLAG_MASK; } - if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT2].AnalysisActive == true || DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT2].TKActive == true) + if(DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT2].AnalysisActive == true && DetectionCfg->mZTDetectionConfig[DETECTION_FCT_ZT2].TKActive == true) { StatusReg |= HISTORIAN_ZT_ZT2_ENABLED_FLAG_MASK; }