#pragma once #define MONITOR_NOTIFY_EVENT_MAX 64 namespace DIOS::Dev::Detail::MachineryECOM { const std::string MONITOR_EVENT_WAIT_BEGIN_MONITOR = "MONITOR_EVENT_WAIT_BEGIN_MONITOR"; const std::string MONITOR_EVENT_WAIT_END_MONITOR = "MONITOR_EVENT_WAIT_END_MONITOR"; const std::string MONITOR_EVENT_TUBEANGLE_MOVE_STOP = "MONITOR_EVENT_TUBEANGLE_MOVE_STOP"; const std::string MONITOR_EVENT_TUBEHEIGHT_MOVE_STOP = "MONITOR_EVENT_TUBEHEIGHT_MOVE_STOP"; const std::string MONITOR_EVENT_TUBEHORIZONTAL_MOVE_STOP = "MONITOR_EVENT_TUBEHORIZONTAL_MOVE_STOP"; enum MONITOR_OFFSET { MO_ALL, MO_TUBE_ANGLE, MO_TUBE_HEIGHT, MO_TUBE_HORIZONTAL, }; class MotionMonitorThread; class IMotionEventReceiver; class MotionMonitorWorkThread; class IPositionManager; class MechnicalMonitor { public: MechnicalMonitor(); ~MechnicalMonitor(); public: static MechnicalMonitor *Instance(); void Initialize(IPositionManager *coordinates,int dofTubeAngleAxis,int dofTubeHeightAxis); void BeginMonitor(IMotionEventReceiver *receiver, int offset = MO_ALL); void EndMonitor(); void ReceiveEvent(const std::string &name); public: //以下函数的代码在 MotionMonitorThread 线程中执行 bool OnMotionMonitorThreadExecute(); bool OnMotionMonitorWorkThreadExecute(); private: //以下函数的代码在 MotionMonitorThread 线程中执行 void OnStartMonitorInThread(); void OnStopMonitorInThread(); private: void AddThreadWaitEventHandle(const std::string &name,HANDLE eventHandle); void AddThreadNotifyEventHandle(const std::string &name, HANDLE eventHandle); private: static MechnicalMonitor *m_instance; IPositionManager *m_positionManager; IMotionEventReceiver *m_eventReceiver; MotionMonitorThread *m_monitorThread; MotionMonitorWorkThread *m_monitorworkThread; std::map m_notifyEventsIndexNameMap; std::map m_waitEventsIndexNameMap; DWORD m_notifyEventHandleCount; HANDLE m_notifyEventHandles[MONITOR_NOTIFY_EVENT_MAX]; DWORD m_waitEventHandleCount; HANDLE m_waitEventHandles[MONITOR_NOTIFY_EVENT_MAX]; BOOL m_isMonitorStoped; int m_angleStopedNotifyTime; int m_heightStopedNotifyTime; int m_horizontalStopedNotifyTime; int m_dofTubeAngleAxis; int m_dofTubeHeightAxis; int m_dofTubeHorizontalAxis; }; class MotionMonitorThread : public Thread_Base,public DiosLock { public: MotionMonitorThread() :m_monitor(nullptr){} ~MotionMonitorThread(){} void Initialize(MechnicalMonitor *monitor); protected: virtual bool Exec() override; private: MechnicalMonitor *m_monitor; }; class MotionMonitorWorkThread : public Thread_Base { public: MotionMonitorWorkThread() :m_monitor(nullptr){} ~MotionMonitorWorkThread(){} void Initialize(MechnicalMonitor *monitor); protected: virtual bool Exec() override; private: MechnicalMonitor *m_monitor; }; }