MechnicalMonitor.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #pragma once
  2. #define MONITOR_NOTIFY_EVENT_MAX 64
  3. namespace DIOS::Dev::Detail::MachineryECOM
  4. {
  5. const std::string MONITOR_EVENT_WAIT_BEGIN_MONITOR = "MONITOR_EVENT_WAIT_BEGIN_MONITOR";
  6. const std::string MONITOR_EVENT_WAIT_END_MONITOR = "MONITOR_EVENT_WAIT_END_MONITOR";
  7. const std::string MONITOR_EVENT_TUBEANGLE_MOVE_STOP = "MONITOR_EVENT_TUBEANGLE_MOVE_STOP";
  8. const std::string MONITOR_EVENT_TUBEHEIGHT_MOVE_STOP = "MONITOR_EVENT_TUBEHEIGHT_MOVE_STOP";
  9. const std::string MONITOR_EVENT_TUBEHORIZONTAL_MOVE_STOP = "MONITOR_EVENT_TUBEHORIZONTAL_MOVE_STOP";
  10. enum MONITOR_OFFSET
  11. {
  12. MO_ALL,
  13. MO_TUBE_ANGLE,
  14. MO_TUBE_HEIGHT,
  15. MO_TUBE_HORIZONTAL,
  16. };
  17. class MotionMonitorThread;
  18. class IMotionEventReceiver;
  19. class MotionMonitorWorkThread;
  20. class IPositionManager;
  21. class MechnicalMonitor
  22. {
  23. public:
  24. MechnicalMonitor();
  25. ~MechnicalMonitor();
  26. public:
  27. static MechnicalMonitor *Instance();
  28. void Initialize(IPositionManager *coordinates,int dofTubeAngleAxis,int dofTubeHeightAxis);
  29. void BeginMonitor(IMotionEventReceiver *receiver, int offset = MO_ALL);
  30. void EndMonitor();
  31. void ReceiveEvent(const std::string &name);
  32. public:
  33. //以下函数的代码在 MotionMonitorThread 线程中执行
  34. bool OnMotionMonitorThreadExecute();
  35. bool OnMotionMonitorWorkThreadExecute();
  36. private:
  37. //以下函数的代码在 MotionMonitorThread 线程中执行
  38. void OnStartMonitorInThread();
  39. void OnStopMonitorInThread();
  40. private:
  41. void AddThreadWaitEventHandle(const std::string &name,HANDLE eventHandle);
  42. void AddThreadNotifyEventHandle(const std::string &name, HANDLE eventHandle);
  43. private:
  44. static MechnicalMonitor *m_instance;
  45. IPositionManager *m_positionManager;
  46. IMotionEventReceiver *m_eventReceiver;
  47. MotionMonitorThread *m_monitorThread;
  48. MotionMonitorWorkThread *m_monitorworkThread;
  49. std::map<int, std::string> m_notifyEventsIndexNameMap;
  50. std::map<int, std::string> m_waitEventsIndexNameMap;
  51. DWORD m_notifyEventHandleCount;
  52. HANDLE m_notifyEventHandles[MONITOR_NOTIFY_EVENT_MAX];
  53. DWORD m_waitEventHandleCount;
  54. HANDLE m_waitEventHandles[MONITOR_NOTIFY_EVENT_MAX];
  55. BOOL m_isMonitorStoped;
  56. int m_angleStopedNotifyTime;
  57. int m_heightStopedNotifyTime;
  58. int m_horizontalStopedNotifyTime;
  59. int m_dofTubeAngleAxis;
  60. int m_dofTubeHeightAxis;
  61. int m_dofTubeHorizontalAxis;
  62. };
  63. class MotionMonitorThread : public Thread_Base,public DiosLock
  64. {
  65. public:
  66. MotionMonitorThread() :m_monitor(nullptr){}
  67. ~MotionMonitorThread(){}
  68. void Initialize(MechnicalMonitor *monitor);
  69. protected:
  70. virtual bool Exec() override;
  71. private:
  72. MechnicalMonitor *m_monitor;
  73. };
  74. class MotionMonitorWorkThread : public Thread_Base
  75. {
  76. public:
  77. MotionMonitorWorkThread() :m_monitor(nullptr){}
  78. ~MotionMonitorWorkThread(){}
  79. void Initialize(MechnicalMonitor *monitor);
  80. protected:
  81. virtual bool Exec() override;
  82. private:
  83. MechnicalMonitor *m_monitor;
  84. };
  85. }