MechnicalMonitor.h 2.6 KB

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