From e937700184e21d263b771921b269fbdda341dfc4 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期二, 27 五月 2025 14:39:40 +0800
Subject: [PATCH] 1.master调试线程实现,状态,运行时间等;

---
 SourceCode/Bond/Servo/CMaster.h |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/CMaster.h b/SourceCode/Bond/Servo/CMaster.h
index 2a0286b..be53515 100644
--- a/SourceCode/Bond/Servo/CMaster.h
+++ b/SourceCode/Bond/Servo/CMaster.h
@@ -15,6 +15,14 @@
 
 
 namespace SERVO {
+    enum MASTERSTATE {
+        READY = 0,
+        STARTING,
+        RUNNING,
+        STOPPING
+    };
+
+    typedef std::function<void(void* pMaster, MASTERSTATE state)> ONMASTERSTATECHANGED;
     typedef std::function<void(void* pMaster, CEquipment* pEiuipment, BOOL bAlive)> ONEQALIVE;
     typedef std::function<void(CStep* pStep, int code, void* pData)> ONEQSTEPEVENT;
     typedef std::function<void(void* pMaster, CEquipment* pEquipment, int state, int alarmId, int unitId, int level)> ONEQALARM;
@@ -22,6 +30,7 @@
     typedef std::function<void(void* pMaster, CEquipment* pEquipment, int code)> ONEQDATACHANGED;
     typedef struct _MasterListener
     {
+        ONMASTERSTATECHANGED    onMasterStateChanged;
         ONEQALIVE				onEqAlive;
         ONEQALIVE		        onEqCimStateChanged;
         ONEQALARM               onEqAlarm;
@@ -42,6 +51,9 @@
         int term();
         int start();
         int stop();
+        ULONGLONG getRunTime();
+        MASTERSTATE getState();
+        unsigned DispatchProc();
         unsigned ReadBitsProc();
         void onTimer(UINT nTimerid);
         std::list<CEquipment*>& getEquipmentList();
@@ -49,6 +61,8 @@
         void setCacheFilepath(const char* pszFilepath);
 
     private:
+        inline void lock() { EnterCriticalSection(&m_criticalSection); }
+        inline void unlock() { LeaveCriticalSection(&m_criticalSection); }
         int addToEquipmentList(CEquipment* pEquipment);
         CLoadPort* addLoadPort(int index);
         CFliper* addFliper();
@@ -65,8 +79,10 @@
         int saveCacheAndBackups();
         int readCache();
         void serialize(CArchive& ar);
+        void setState(MASTERSTATE state);
 
     private:
+        CRITICAL_SECTION m_criticalSection;
         MasterListener m_listener;
         CCCLinkIEControl m_cclink;
         std::list<CEquipment*> m_listEquipment;
@@ -74,9 +90,21 @@
         BOOL m_bDataModify;
 
     private:
+        /* 监控比特位的线程*/
         HANDLE m_hEventReadBitsThreadExit[2];
         HANDLE m_hReadBitsThreadHandle;
         unsigned m_nReadBitsThreadAddr;
+
+        // 调度线程
+        HANDLE m_hDispatchEvent;
+        HANDLE m_hEventDispatchThreadExit[2];
+        HANDLE m_hDispatchThreadHandle;
+        unsigned m_nDispatchThreadAddr;
+
+        // 启动时间,运行时间,状态
+        ULONGLONG m_ullStartTime;
+        ULONGLONG m_ullRunTime;
+        MASTERSTATE m_state;
     };
 }
 

--
Gitblit v1.9.3