diff --git a/Configuration/ZT.cfg b/Configuration/ZT.cfg index 8c3fb09..0693f0b 100644 --- a/Configuration/ZT.cfg +++ b/Configuration/ZT.cfg @@ -47,7 +47,7 @@ SONDE_LASER_EXT_1=ttyS0 #---------------------------------- #Changer cette valeur à OUI ou NON pour sélectionner la communication Modbus #avec la CC -UTILISER_MODBUS_CC=NON +UTILISER_MODBUS_CC=OUI #Adresse modbus de la ZT MODBUS_CC_DEVID=9 #Port Modbus/TCP diff --git a/sources/DiscreteTKTransport.cpp b/sources/DiscreteTKTransport.cpp index acf82fb..5eab6f9 100644 --- a/sources/DiscreteTKTransport.cpp +++ b/sources/DiscreteTKTransport.cpp @@ -39,7 +39,7 @@ CDiscreteTKTransport::CDiscreteTKTransport() mZT2TKStateMachineTimer->setSingleShot(false); connect(mZT2TKStateMachineTimer,SIGNAL(timeout()),this,SLOT(ExecZT2SM())); - ResetAlarmCount(); + ResetAlarmCount(ZTGLOBAL_TYPE_ID); } CDiscreteTKTransport::~CDiscreteTKTransport() @@ -255,7 +255,7 @@ void CDiscreteTKTransport::ExecZT1SM() mZT1TKDataList.clear(); mZT1CurTKIndex = 0; mZT1TKStateMachineTimer->stop(); - ResetAlarmCount(); + ResetAlarmCount(ZTGLOBAL_TYPE_ID); //In maintenance mode, it is possible to have ZT2 events at the same time //than ZT1. So if any ZT2 events are waiting in the qeue, send them... @@ -388,7 +388,7 @@ void CDiscreteTKTransport::ExecZT2SM() mZT2TKDataList.clear(); mZT2CurTKIndex = 0; mZT2TKStateMachineTimer->stop(); - ResetAlarmCount(); + ResetAlarmCount(ZTGLOBAL_TYPE_ID); //In maintenance mode, it is possible to have ZT2 events at the same time //than ZT1. So if any ZT1 events are waiting in the qeue, send them... @@ -507,7 +507,7 @@ unsigned int CDiscreteTKTransport::CancelAllTK() //exec the SM once mZT1TKStateMachineTimer->start(); mZT2TKStateMachineTimer->start(); - ResetAlarmCount(); + ResetAlarmCount(ZTGLOBAL_TYPE_ID); return RET_OK; } diff --git a/sources/GuiElements/GraphItem.cpp b/sources/GuiElements/GraphItem.cpp index d9df71f..1181752 100644 --- a/sources/GuiElements/GraphItem.cpp +++ b/sources/GuiElements/GraphItem.cpp @@ -79,7 +79,7 @@ unsigned int CGraphItem::DisplayData(quint64 StartTime, quint64 StopTime) //Find the index of the first and last point in the timespan. int StartIndex = 0, StopIndex = 0; - quint64 StartDeltaTime, StopDeltaTime; + //quint64 StartDeltaTime, StopDeltaTime; int i = 0; bool StartFound = false, StopFound = false; while(StartFound == false || StopFound == false) @@ -94,13 +94,13 @@ unsigned int CGraphItem::DisplayData(quint64 StartTime, quint64 StopTime) if(CurTime <= StartTime) { StartIndex = i; - StartDeltaTime = CurTime - StartTime; + // StartDeltaTime = CurTime - StartTime; StartFound = true; } if(CurTime >= StopTime && !StopFound) { StopIndex = i; - StopDeltaTime = StopTime - mDataSet->at(StopIndex)->mTime; +// StopDeltaTime = StopTime - mDataSet->at(StopIndex)->mTime; StopFound = true; } diff --git a/sources/Modbus/ModbusMaster.cpp b/sources/Modbus/ModbusMaster.cpp index 3b436cf..d2cf9fe 100644 --- a/sources/Modbus/ModbusMaster.cpp +++ b/sources/Modbus/ModbusMaster.cpp @@ -67,11 +67,15 @@ void CModbusMaster::SocketDisconnected() int CModbusMaster::ReadModbusRegisters() { //return SendReadHoldingRegistersRequest(ZT_DATA_BASE_REGISTER_ADDRESS,4); //Read all 3 registers from ZT (2000 - 2003) + return RET_OK; } void CModbusMaster::RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length) { + Q_UNUSED(StartAddress) + Q_UNUSED(Length) + emit ModbusMasterRepositoryUpdated(); qDebug("Database updated with ZT data..."); } @@ -85,10 +89,12 @@ int CModbusMaster::SendAN1ToZT() { //return SendWriteHoldingRegistersRequest(CC_AN1_REGISTER_ADDRESS,1); //return SendWriteSingleRegisterRequest(CC_AN1_REGISTER_ADDRESS); + return RET_OK; } int CModbusMaster::SendAN2ToZT() { //return SendWriteHoldingRegistersRequest(CC_AN2_REGISTER_ADDRESS,1); //return SendWriteSingleRegisterRequest(CC_AN2_REGISTER_ADDRESS); + return RET_OK; } diff --git a/sources/Modbus/ModbusTKTransport.cpp b/sources/Modbus/ModbusTKTransport.cpp index 382da55..3d0c97b 100644 --- a/sources/Modbus/ModbusTKTransport.cpp +++ b/sources/Modbus/ModbusTKTransport.cpp @@ -11,6 +11,7 @@ CModbusTKTransport::CModbusTKTransport(CModbusRepository *Repo) mMaintenanceMode = mForceZT1Clear = mForceZT2Clear = false; mZT1TKDataList.clear(); mZT2TKDataList.clear(); + mZT1Clear = mZT2Clear = false; mModbusTKZT1SMState = MODBUS_ZT1_TK_STANDBY_STATE; mModbusTKZT2SMState = MODBUS_ZT2_TK_STANDBY_STATE; @@ -24,6 +25,8 @@ CModbusTKTransport::CModbusTKTransport(CModbusRepository *Repo) mZT2TKStateMachineTimer->setSingleShot(false); mZT2TKStateMachineTimer->setInterval(0); connect(mZT2TKStateMachineTimer,SIGNAL(timeout()),this,SLOT(ExecZT2SM())); + + ResetAlarmCount(ZTGLOBAL_TYPE_ID); } CModbusTKTransport::~CModbusTKTransport() @@ -53,9 +56,9 @@ int CModbusTKTransport::ClearTK(int ZT) return RET_ERROR; } - PannesReg ^= ZT1_V00_ALARM_FLAG_MASK; - PannesReg ^= ZT1_PEQ1_ALARM_FLAG_MASK; - PannesReg ^= ZT1_ALARM_ITI_FLAG_MASK; + PannesReg &= ~ZT1_V00_ALARM_FLAG_MASK; + PannesReg &= ~ZT1_PEQ1_ALARM_FLAG_MASK; + PannesReg &= ~ZT1_ALARM_ITI_FLAG_MASK; //Clear repo now... mModbusRepo->WriteMultipleRegs(MODBUS_ZT1_ALARM_DATA_BASE_REG_ADD,Data); @@ -81,8 +84,8 @@ int CModbusTKTransport::ClearTK(int ZT) return RET_ERROR; } - PannesReg ^= ZT2_V02_ALARM_FLAG_MASK; - PannesReg ^= ZT2_PEQ2_ALARM_FLAG_MASK; + PannesReg &= ~ZT2_V02_ALARM_FLAG_MASK; + PannesReg &= ~ZT2_PEQ2_ALARM_FLAG_MASK; //Clear repo now... mModbusRepo->WriteMultipleRegs(MODBUS_ZT2_ALARM_DATA_BASE_REG_ADD,Data); @@ -223,17 +226,17 @@ int CModbusTKTransport::SendTKToCC(int ZT) } else if(PPExtIndex == 1) { - FlagsReg |= ZT1_PP_EXT_FLAG_MASK_1; + FlagsReg |= ZT1_PP_EXT_FLAG_MASK_2; DataBuf[RegOffset(MODBUS_ZT1_RANK_PP_EXT_2_REG_ADD)] = (qint16)TKData.mRank; } else if(PPExtIndex == 2) { - FlagsReg |= ZT1_PP_EXT_FLAG_MASK_1; + FlagsReg |= ZT1_PP_EXT_FLAG_MASK_3; DataBuf[RegOffset(MODBUS_ZT1_RANK_PP_EXT_3_REG_ADD)] = (qint16)TKData.mRank; } else if(PPExtIndex == 3) { - FlagsReg |= ZT1_PP_EXT_FLAG_MASK_1; + FlagsReg |= ZT1_PP_EXT_FLAG_MASK_4; DataBuf[RegOffset(MODBUS_ZT1_RANK_PP_EXT_4_REG_ADD)] = (qint16)TKData.mRank; } else @@ -275,9 +278,9 @@ int CModbusTKTransport::SendTKToCC(int ZT) PannesReg = DataBuf.at(RegOffset(MODBUS_MISC_DATA_BASE_REG_ADD)); - for(int i = 0; i < mZT1TKDataList.size(); i++) + for(int i = 0; i < mZT2TKDataList.size(); i++) { - CZTDetectionData TKData = mZT1TKDataList.at(i); + CZTDetectionData TKData = mZT2TKDataList.at(i); switch(TKData.mDetectionID) { @@ -330,17 +333,17 @@ int CModbusTKTransport::SendTKToCC(int ZT) } else if(PPExtIndex == 1) { - FlagsReg |= ZT2_PP_EXT_FLAG_MASK_1; + FlagsReg |= ZT2_PP_EXT_FLAG_MASK_2; DataBuf[RegOffset(MODBUS_ZT2_RANK_PP_EXT_2_REG_ADD)] = (qint16)TKData.mRank; } else if(PPExtIndex == 2) { - FlagsReg |= ZT2_PP_EXT_FLAG_MASK_1; + FlagsReg |= ZT2_PP_EXT_FLAG_MASK_3; DataBuf[RegOffset(MODBUS_ZT2_RANK_PP_EXT_3_REG_ADD)] = (qint16)TKData.mRank; } else if(PPExtIndex == 3) { - FlagsReg |= ZT2_PP_EXT_FLAG_MASK_1; + FlagsReg |= ZT2_PP_EXT_FLAG_MASK_4; DataBuf[RegOffset(MODBUS_ZT2_RANK_PP_EXT_4_REG_ADD)] = (qint16)TKData.mRank; } else @@ -354,7 +357,7 @@ int CModbusTKTransport::SendTKToCC(int ZT) } //Update the modbus repo to send the alarms... - DataBuf[RegOffset(MODBUS_ZT2_ALARM_RANKS_BASE_ADD)] = FlagsReg; + DataBuf[RegOffset(MODBUS_ZT2_ALARM_DATA_BASE_REG_ADD)] = FlagsReg; DataBuf[RegOffset(MODBUS_MISC_DATA_BASE_REG_ADD)] = PannesReg; mModbusRepo->WriteMultipleRegs(MODBUS_ZT_DATA_BASE_REG,DataBuf); @@ -420,6 +423,11 @@ unsigned int CModbusTKTransport::BeginTKEmission() mModbusTKZT1SMState = MODBUS_ZT1_TK_SHOW_STATE; mZT1TKStateMachineTimer->start(0); } + else if(mMaintenanceMode == true && mModbusTKZT1SMState == MODBUS_ZT1_TK_WAIT_FOR_CLEAR_STATE) + { + //When we are in maintenance mode and we are already sending the alarms, just add the new alarm to the modbus buffer. + SendTKToCC(ZT1_TYPE_ID); + } } @@ -434,6 +442,11 @@ unsigned int CModbusTKTransport::BeginTKEmission() mModbusTKZT2SMState = MODBUS_ZT2_TK_SHOW_STATE; mZT2TKStateMachineTimer->start(0); } + else if(mMaintenanceMode == true && mModbusTKZT2SMState == MODBUS_ZT2_TK_WAIT_FOR_CLEAR_STATE) + { + //In maintenance mode, just add the new alarm to the modbus buffer. + SendTKToCC(ZT2_TYPE_ID); + } } @@ -451,12 +464,48 @@ unsigned int CModbusTKTransport::SetInputStates(bool AN1State, bool ZT1CDVState, unsigned int CModbusTKTransport::CancelAllTK() { + + ClearTK(ZT1_TYPE_ID); + ClearTK(ZT2_TYPE_ID); + + mModbusTKZT1SMState = MODBUS_ZT1_TK_STANDBY_STATE; + mModbusTKZT2SMState = MODBUS_ZT2_TK_STANDBY_STATE; + + mZT1TKDataList.clear(); + mZT2TKDataList.clear(); + + + //exec the SM once + mZT1TKStateMachineTimer->start(); + mZT2TKStateMachineTimer->start(); + ResetAlarmCount(ZTGLOBAL_TYPE_ID); + return RET_OK; } unsigned int CModbusTKTransport::CancelMaintenanceCurrentTK() { - return RET_OK; + int ret = RET_ERROR; + + if(mMaintenanceMode == false) + { + return ret; + } + + if(mModbusTKZT1SMState == MODBUS_ZT1_TK_WAIT_FOR_CLEAR_STATE) + { + mForceZT1Clear = true; + ret = RET_OK; + } + + if(mModbusTKZT2SMState == MODBUS_ZT2_TK_WAIT_FOR_CLEAR_STATE) + { + mForceZT2Clear = true; + ret = RET_OK; + } + + return ret; + } unsigned int CModbusTKTransport::ExitMaintenance() @@ -550,16 +599,17 @@ void CModbusTKTransport::ExecZT1SM() { mZT1TKDataList.clear(); mZT1TKStateMachineTimer->stop(); + ResetAlarmCount(ZT1_TYPE_ID); - //In maintenance mode, it is possible to have ZT2 events at the same time - //than ZT1. So if any ZT2 events are waiting in the qeue, send them... - if(mMaintenanceMode) - { - if(mZT2TKDataList.size() > 0) - { - BeginTKEmission(); - } - } +// //In maintenance mode, it is possible to have ZT2 events at the same time +// //than ZT1. So if any ZT2 events are waiting in the qeue, send them... +// if(mMaintenanceMode) +// { +// if(mZT2TKDataList.size() > 0) +// { +// BeginTKEmission(); +// } +// } break; } @@ -575,7 +625,7 @@ void CModbusTKTransport::ExecZT2SM() SendTKToCC(ZT2_TYPE_ID); //Mise à jour de la table Modbus avec les données des alarmes actives. - mModbusTKZT1SMState = MODBUS_ZT2_TK_WAIT_FOR_CLEAR_STATE; + mModbusTKZT2SMState = MODBUS_ZT2_TK_WAIT_FOR_CLEAR_STATE; CZTLog::instance()->AddLogString("Émission des alarmes PCC",true); for(int i = 0; i < mZT2TKDataList.size(); i++) @@ -631,16 +681,17 @@ void CModbusTKTransport::ExecZT2SM() { mZT2TKDataList.clear(); mZT2TKStateMachineTimer->stop(); + ResetAlarmCount(ZT2_TYPE_ID); - //In maintenance mode, it is possible to have ZT1 events at the same time - //than ZT2. So if any ZT1 events are waiting in the qeue, send them... - if(mMaintenanceMode) - { - if(mZT1TKDataList.size() > 0) - { - BeginTKEmission(); - } - } +// //In maintenance mode, it is possible to have ZT1 events at the same time +// //than ZT2. So if any ZT1 events are waiting in the qeue, send them... +// if(mMaintenanceMode) +// { +// if(mZT1TKDataList.size() > 0) +// { +// BeginTKEmission(); +// } +// } break; } diff --git a/sources/Modbus/ModbusTKTransport.h b/sources/Modbus/ModbusTKTransport.h index 8b349d0..46061c2 100644 --- a/sources/Modbus/ModbusTKTransport.h +++ b/sources/Modbus/ModbusTKTransport.h @@ -9,6 +9,7 @@ class CModbusTKTransport : public CTKTransportInterface { + Q_OBJECT public: enum eModbusTKSMStates { @@ -29,6 +30,7 @@ public: int SendTKToCC(int ZT); int ClearTK(int ZT); + unsigned int CancelAllTK(); virtual bool IsZT2TKProcessing(); virtual bool IsZT1TKProcessing(); @@ -38,7 +40,7 @@ public: virtual unsigned int BeginTKEmission(); virtual unsigned int SetInputStates(bool AN1State, bool ZT1CDVState, bool AN2State, bool ZT2CDVState); - virtual unsigned int CancelAllTK(); + virtual unsigned int CancelMaintenanceCurrentTK(); virtual unsigned int ExitMaintenance(); virtual unsigned int EnterMaintenance(); diff --git a/sources/Simulator/ZTSimulator.cpp b/sources/Simulator/ZTSimulator.cpp index 8c5e5ee..0aca6c2 100644 --- a/sources/Simulator/ZTSimulator.cpp +++ b/sources/Simulator/ZTSimulator.cpp @@ -44,8 +44,8 @@ CZTSimulator::CZTSimulator(CSimulatorIOManager *IOMgrPtr) { - static QGraphicsTextItem *Label; - Label = new QGraphicsTextItem("Simulateur",this); + //static QGraphicsTextItem *Label; +// Label = new QGraphicsTextItem("Simulateur",this); mIOMgrPtr = IOMgrPtr; mStationPtr = 0; mUSBDriveInterfacePtr = 0; @@ -953,7 +953,7 @@ void CZTSimulator::LazerProbesSimTimerExpired() qreal sine = qSin(++inc/10); sine += 1; sine /= 2; - int Calib = 500000;//CZTConfigMgr::instance()->GetLaserSensorCalib(); +// int Calib = 500000;//CZTConfigMgr::instance()->GetLaserSensorCalib(); //int value = (int)(Calib*sine); //mPGEValue = mPGIValue = value; diff --git a/sources/TKGenerator.cpp b/sources/TKGenerator.cpp index 62da299..c7e1ebc 100644 --- a/sources/TKGenerator.cpp +++ b/sources/TKGenerator.cpp @@ -71,7 +71,7 @@ CTKGenerator::CTKGenerator(CTKTransportInterface *IF) // mZT2TKStateMachineTimer->setSingleShot(false); // connect(mZT2TKStateMachineTimer,SIGNAL(timeout()),this,SLOT(ExecZT2SM())); - ResetAlarmCount(); + ResetAlarmCount(ZTGLOBAL_TYPE_ID); } CTKGenerator::~CTKGenerator() @@ -601,11 +601,31 @@ unsigned int CTKGenerator::ProcessDetectionsTK(CZTDetectionData *NewDetection) // } //} -void CTKGenerator::ResetAlarmCount() +void CTKGenerator::ResetAlarmCount(int ZT) { - for(int i = 0; i < DETECTION_MAX_DETECTION_ID; i++) + if(ZT == ZT1_TYPE_ID) { - mAlarmCount[i] = 0; + mAlarmCount[DETECTION_MAGNETIC_SENSOR_COUNT] = 0; + mAlarmCount[DETECTION_FN_DETECTION] = 0; + mAlarmCount[DETECTION_PG_DETECTION] = 0; + mAlarmCount[DETECTION_PPI_DETECTION] = 0; + mAlarmCount[DETECTION_PPE_DETECTION] = 0; + mAlarmCount[DETECTION_PEQ1_DETECTION] = 0; + + } + else if(ZT == ZT2_TYPE_ID) + { + mAlarmCount[DETECTION_ZT2_MAGNETIC_SENSOR_COUNT] = 0; + mAlarmCount[DETECTION_ZT2_PPI_DETECTION] = 0; + mAlarmCount[DETECTION_ZT2_PPE_DETECTION] = 0; + mAlarmCount[DETECTION_PEQ2_DETECTION] = 0; + } + else if(ZT == ZTGLOBAL_TYPE_ID) + { + for(int i = 0; i < DETECTION_MAX_DETECTION_ID; i++) + { + mAlarmCount[i] = 0; + } } } diff --git a/sources/TKGenerator.h b/sources/TKGenerator.h index 5193813..488de59 100644 --- a/sources/TKGenerator.h +++ b/sources/TKGenerator.h @@ -56,9 +56,9 @@ class CTKGenerator : public QObject //virtual void BindTransportInterface(CTKTransportInterface* IF) = 0; unsigned int ProcessDetectionsTK(CZTDetectionData *NewDetection); bool UpdateDetectionConfig(CZTDetectionFunctionConfig*); - void ResetAlarmCount(); + void ResetAlarmCount(int ZT); - virtual unsigned int CancelAllTK() = 0; + // virtual unsigned int CancelAllTK() = 0; virtual unsigned int CancelMaintenanceCurrentTK() = 0; virtual unsigned int ExitMaintenance() = 0; virtual unsigned int EnterMaintenance() = 0; diff --git a/sources/ZTData.cpp b/sources/ZTData.cpp index 1894a40..6b8b5e1 100644 --- a/sources/ZTData.cpp +++ b/sources/ZTData.cpp @@ -160,6 +160,7 @@ QDataStream &operator<<(QDataStream &out, const CZT2FlagsData &source) QDataStream &operator>>(QDataStream &in, CZT2FlagsData &dest) { in >> dest.mIsProblematicPassage; + return in; } QDataStream& operator<<(QDataStream &out, const CZT1LogData &source) diff --git a/sources/ZTStateMachine.cpp b/sources/ZTStateMachine.cpp index 24890f9..875063f 100644 --- a/sources/ZTStateMachine.cpp +++ b/sources/ZTStateMachine.cpp @@ -1310,6 +1310,8 @@ bool CZTStateMachine::IsZT2Active() void CZTStateMachine::BindPointers(CStation *ptr,CInputModule *InputModule,COutputModule *OutputModule,CZTPage *ZTPagePTr,CPCIIOMgr *PCIIOPtr,CAbstractLazerProbe *PGIntProbePtr, CAbstractLazerProbe *PGExtProbePTr,CLogMgr *LogMgr,CTKTransportInterface *TKTransport,CZTSimulator *ZTSimPtr,CAnalogInputModule *DataQInterface) { + Q_UNUSED(OutputModule) + mZTStationPtr = ptr; mSDFAnalogMonitorInterface = DataQInterface; mInputModule = InputModule;