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 d7191e9..d4476a5 100644 Binary files a/Configuration/ZTSettings.ztc and b/Configuration/ZTSettings.ztc differ diff --git a/ZT.pro b/ZT.pro index a373713..3a80b1e 100644 --- a/ZT.pro +++ b/ZT.pro @@ -249,7 +249,8 @@ HEADERS += \ sources/NetDriveMgr.h \ sources/SFTPServerManager.h \ sources/Modbus/PIHistorianManager.h \ - sources/Modbus/PIHistorianSession.h + sources/Modbus/PIHistorianSession.h \ + sources/Modbus/PIHistorianDefs.h #QMAKE_LIBDIR += ./ExtLib diff --git a/sftpbatch b/sftpbatch index 8977671..ea11de0 100644 --- a/sftpbatch +++ b/sftpbatch @@ -1,3 +1,3 @@ -put ./Trains/LOGZT1_2024-06-04-10-54-27-273.bin CVRT-D-LOGZT1_2024-06-04-10-54-27-273.bin +put ./Trains/LOGZT1_2024-06-07-14-19-16-025.bin CVRT-D-LOGZT1_2024-06-07-14-19-16-025.bin put ./LOG/LogZT.txt CVRT-LogZT.txt put ./ING/IngLog.txt CVRT-IngLog.txt \ No newline at end of file diff --git a/sources/Modbus/PIHistorianDefs.h b/sources/Modbus/PIHistorianDefs.h index ac184b9..1751309 100644 --- a/sources/Modbus/PIHistorianDefs.h +++ b/sources/Modbus/PIHistorianDefs.h @@ -1,140 +1,83 @@ -#ifndef PROTOCOLDEFS_H -#define PROTOCOLDEFS_H +#ifndef PIHISTORIANDEFS_H +#define PIHISTORIANDEFS_H -#define MODBUS_ZT_WATCHDOG_TIMEOUT 3000 -#define MODBUS_CC_WATCHDOG_TIMEOUT 7000 - -//ZT - CC modbus table masks +#define HISTORIAN_WATCHDOG_TIMEOUT 3000 +//PI HISTORIAN modbus table masks +#define HISTORIAN_ZT_DATA_BASE_REG 2000 +#define HISTORIAN_MODBUS_ZT_TABLE_DATA_SIZE 50 //Taille de la table = 50 registres (2000 à 2049) //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 +#define HISTORIAN_ZT1_FN_ENABLED_FLAG_MASK 0x0001 +#define HISTORIAN_ZT1_PP_ENABLED_FLAG_MASK 0x0002 +#define HISTORIAN_ZT1_PG_ENABLED_FLAG_MASK 0x0004 +#define HISTORIAN_ZT2_PP_ENABLED_FLAG_MASK 0x0008 +#define HISTORIAN_ZT_MAINTENANCE_MODE_FLAG_MASK 0x0010 +#define HISTORIAN_ZT_HPC_COMM_HEALTH_FLAG_MASK 0x0020 +#define HISTORIAN_ZT_SEI_COMM_FLAG_MASK 0x0040 +#define HISTORIAN_ZT_ZT1_ENABLED_FLAG_MASK 0x0080 +#define HISTORIAN_ZT_ZT2_ENABLED_FLAG_MASK 0x0100 +#define HISTORIAN_ZT_RESERVED_FLAG_MASK_7 0x0200 +#define HISTORIAN_ZT_RESERVED_FLAG_MASK_6 0x0400 +#define HISTORIAN_ZT_RESERVED_FLAG_MASK_5 0x0800 +#define HISTORIAN_ZT_RESERVED_FLAG_MASK_4 0x1000 +#define HISTORIAN_ZT_RESERVED_FLAG_MASK_3 0x2000 +#define HISTORIAN_ZT_RESERVED_FLAG_MASK_2 0x4000 +#define HISTORIAN_ZT_RESERVED_FLAG_MASK_1 0x8000 -//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 - /////////////////////////////////////////////////////////////////// +#define HISTORIAN_ZT_STATUS_FLAGS_REG_ADD 2000 +#define HISTORIAN_PG_CALIBRATION_REG_ADD 2001 +#define HISTORIAN_BOOT_DATE_YEAR_REG_ADD 2002 +#define HISTORIAN_BOOT_DATE_MONTH_REG_ADD 2003 +#define HISTORIAN_BOOT_DATE_DAY_REG_ADD 2004 +#define HISTORIAN_BOOT_DATE_HOUR_REG_ADD 2005 +#define HISTORIAN_BOOT_DATE_MINUTES_REG_ADD 2006 +#define HISTORIAN_BOOT_DATE_SECONDS_REG_ADD 2007 +#define HISTORIAN_TRAINS_TOTAL_REG_ADD 2008 +#define HISTORIAN_DETECTIONS_TOTAL_REG_ADD 2009 +#define HISTORIAN_TRAINS_TODAY_REG_ADD 2010 +#define HISTORIAN_DETECTIONS_TODAY_REG_ADD 2011 +#define HISTORIAN_FN_DETECTS_TODAY_REG_ADD 2012 +#define HISTORIAN_PPI_ZT1_DETECTS_TODAY_REG_ADD 2013 +#define HISTORIAN_PPE_ZT1_DETECTS_TODAY_REG_ADD 2014 +#define HISTORIAN_PG_DETECTS_TODAY_REG_ADD 2015 +#define HISTORIAN_PPI_ZT2_DETECTS_TODAY_REG_ADD 2016 +#define HISTORIAN_PPE_ZT2_DETECTS_TODAY_REG_ADD 2017 +#define HISTORIAN_LAST_TRAIN_YEAR_REG_ADD 2018 +#define HISTORIAN_LAST_TRAIN_MONTH_REG_ADD 2019 +#define HISTORIAN_LAST_TRAIN_DAY_REG_ADD 2020 +#define HISTORIAN_LAST_TRAIN_HOUR_REG_ADD 2021 +#define HISTORIAN_LAST_TRAIN_MINUTE_REG_ADD 2022 +#define HISTORIAN_LAST_TRAIN_SECONDS_REG_ADD 2023 +#define HISTORIAN_LAST_TRAIN_ZONE_REG_ADD 2024 +#define HISTORIAN_LAST_TRAIN_NB_DETECTS_REG_ADD 2025 +#define HISTORIAN_LAST_TRAIN_PPI_RK_1_REG_ADD 2026 +#define HISTORIAN_LAST_TRAIN_PPI_RK_2_REG_ADD 2027 +#define HISTORIAN_LAST_TRAIN_PPI_RK_3_REG_ADD 2028 +#define HISTORIAN_LAST_TRAIN_PPI_RK_4_REG_ADD 2029 +#define HISTORIAN_LAST_TRAIN_PPE_RK_1_REG_ADD 2030 +#define HISTORIAN_LAST_TRAIN_PPE_RK_2_REG_ADD 2031 +#define HISTORIAN_LAST_TRAIN_PPE_RK_3_REG_ADD 2032 +#define HISTORIAN_LAST_TRAIN_PPE_RK_4_REG_ADD 2033 +#define HISTORIAN_LAST_TRAIN_PG_RK_1_REG_ADD 2034 +#define HISTORIAN_LAST_TRAIN_PG_RK_2_REG_ADD 2035 +#define HISTORIAN_LAST_TRAIN_PG_RK_3_REG_ADD 2036 +#define HISTORIAN_LAST_TRAIN_PG_RK_4_REG_ADD 2037 +#define HISTORIAN_LAST_TRAIN_FN_RK_1_REG_ADD 2038 +#define HISTORIAN_LAST_TRAIN_FN_RK_2_REG_ADD 2039 +#define HISTORIAN_LAST_TRAIN_FN_RK_3_REG_ADD 2040 +#define HISTORIAN_LAST_TRAIN_FN_RK_4_REG_ADD 2041 +#define HISTORIAN_LAST_TRAIN_COMPTAGE_DET_REG_ADD 2042 +#define HISTORIAN_LAST_TRAIN_PEQ_REG_ADD 2043 +#define HISTORIAN_LAST_TRAIN_TYPE_REG_ADD 2044 +#define HISTORIAN_LAST_TRAIN_ID1_REG_ADD 2045 +#define HISTORIAN_LAST_TRAIN_ID2_REG_ADD 2046 +#define HISTORIAN_LAST_TRAIN_ID3_REG_ADD 2047 +#define HISTORIAN_RESERVED_1_REG_ADD 2048 +#define HISTORIAN_RESERVED_2_REG_ADD 2049 -//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 +#endif // PIHISTORIANDEFS_H diff --git a/sources/Modbus/PIHistorianManager.cpp b/sources/Modbus/PIHistorianManager.cpp index d3baa9b..f71a860 100644 --- a/sources/Modbus/PIHistorianManager.cpp +++ b/sources/Modbus/PIHistorianManager.cpp @@ -1,18 +1,36 @@ #include "PIHistorianManager.h" #include "ZTLog.h" +#include "ModbusRepository.h" +#include "PIHistorianDefs.h" -CPIHistorianManager::CPIHistorianManager(CModbusRepository *PIHistorianRepo, int ModbusPort) +CPIHistorianManager::CPIHistorianManager(CModbusRepository *PIHistorianRepo, int ModbusPort, int ModbusDevID) { mModbusPort = ModbusPort; mModbusServer = new QTcpServer(); connect(mModbusServer,SIGNAL(newConnection()),this,SLOT(NewModbusConnection())); mPIHistorianRepo = PIHistorianRepo; + mModbusDevID = ModbusDevID; + + mHistorianTimer = new QTimer; + mHistorianTimer->setSingleShot(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);