From 8f0460c03589056aec7643c8ef625a207ae49f4d Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期二, 18 二月 2025 16:07:36 +0800
Subject: [PATCH] 1.添加Cim State

---
 SourceCode/Bond/Servo/CEquipment.cpp |   18 ++++++++++++++++--
 SourceCode/Bond/Servo/CMaster.cpp    |   14 +++++++++++++-
 SourceCode/Bond/Servo/CMaster.h      |    4 ++--
 SourceCode/Bond/Servo/Model.cpp      |    8 +++++++-
 SourceCode/Bond/Servo/CEquipment.h   |    6 +++++-
 5 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index 6534f88..29a448d 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -7,8 +7,9 @@
 
 	CEquipment::CEquipment()
 	{
+		m_listener = { nullptr, nullptr };
 		m_alive = {FALSE, 0, FALSE};
-		m_listener.onAlive = {nullptr};
+		m_bCimState = FALSE;
 		InitializeCriticalSection(&m_criticalSection);
 	}
 
@@ -20,6 +21,7 @@
 	void CEquipment::setListener(EquipmentListener listener)
 	{
 		m_listener.onAlive = listener.onAlive;
+		m_listener.onCimStateChanged = listener.onCimStateChanged;
 	}
 
 	void CEquipment::init()
@@ -121,7 +123,10 @@
 		}
 
 
-		// 解释数据
+		// 以下解释和处理数据
+
+		// alive
+		/*
 		BOOL bAliveFlag = isBitOn(pszData, size, 0x340);
 		if (m_alive.flag != bAliveFlag) {
 			m_alive.flag = bAliveFlag;
@@ -135,6 +140,15 @@
 				}
 			}
 		}
+		*/
+		// CIM State
+		BOOL bCimState = isBitOn(pszData, size, 0x341);
+		if ((bCimState && !m_bCimState) || (!bCimState && m_bCimState)) {
+			m_bCimState = bCimState;
+			if (m_listener.onCimStateChanged != nullptr) {
+				m_listener.onCimStateChanged(this, m_bCimState);
+			}
+		}
 	}
 
 	BOOL CEquipment::isBitOn(const char* pszData, size_t size, int index)
diff --git a/SourceCode/Bond/Servo/CEquipment.h b/SourceCode/Bond/Servo/CEquipment.h
index 37d8e2b..044fcd8 100644
--- a/SourceCode/Bond/Servo/CEquipment.h
+++ b/SourceCode/Bond/Servo/CEquipment.h
@@ -10,6 +10,7 @@
 	typedef struct _EquipmentListener
 	{
 		ONALIVE				onAlive;
+		ONALIVE				onCimStateChanged;
 	} EquipmentListener;
 
 	// Memory Block 结构体定义
@@ -54,7 +55,7 @@
 		virtual void serialize(CArchive& ar);
 		virtual void onReceiveLBData(const char* pszData, size_t size);
 		BOOL isAlive();
-
+	
 	private:
 		BOOL isBitOn(const char* pszData, size_t size, int index);
 
@@ -70,7 +71,10 @@
 		StationIdentifier m_station;
 		MemoryBlock m_blockReadBit;
 		MemoryBlock m_blockWriteBit;
+
+	private:
 		ALIVE m_alive;
+		BOOL m_bCimState;			// ON/OFF
 	};
 }
 
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 5ea975d..d33f26f 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -12,7 +12,7 @@
 
 	CMaster::CMaster()
 	{
-		m_listener = {nullptr};
+		m_listener = {nullptr, nullptr};
 	}
 
 	CMaster::~CMaster()
@@ -26,6 +26,7 @@
 	void CMaster::setListener(MasterListener listener)
 	{
 		m_listener.onEqAlive = listener.onEqAlive;
+		m_listener.onEqCimStateChanged = listener.onEqCimStateChanged;
 	}
 
 	int CMaster::init()
@@ -105,12 +106,23 @@
 				m_listener.onEqAlive(this, p, bAlive);
 			}
 		};
+		listener.onCimStateChanged = [&](void* pEquipment, BOOL bOn) -> void {
+			CEquipment* p = (CEquipment*)pEquipment;
+			if (m_listener.onEqCimStateChanged != nullptr) {
+				m_listener.onEqCimStateChanged(this, p, bOn);
+			}
+		};
 		pEquipment->setListener(listener);
 		m_listEquipment.push_back(pEquipment);
 
 		return 0;
 	}
 
+	CEquipment* CMaster::getEquipment(int id)
+	{
+		return nullptr;
+	}
+
 	void CMaster::onTimer(UINT nTimerid)
 	{
 		for (auto item : m_listEquipment) {
diff --git a/SourceCode/Bond/Servo/CMaster.h b/SourceCode/Bond/Servo/CMaster.h
index f120b12..704b502 100644
--- a/SourceCode/Bond/Servo/CMaster.h
+++ b/SourceCode/Bond/Servo/CMaster.h
@@ -11,6 +11,7 @@
     typedef struct _MasterListener
     {
         ONEQALIVE				onEqAlive;
+        ONEQALIVE		        onEqCimStateChanged;
     } MasterListener;
 
     class CMaster
@@ -25,11 +26,10 @@
         int init();
         int term();
         void onTimer(UINT nTimerid);
-
+        CEquipment* getEquipment(int id);
 
     private:
         int addEquipment(CEquipment* pEquipment);
-
 
     private:
         MasterListener m_listener;
diff --git a/SourceCode/Bond/Servo/Model.cpp b/SourceCode/Bond/Servo/Model.cpp
index a7db1b4..4382df1 100644
--- a/SourceCode/Bond/Servo/Model.cpp
+++ b/SourceCode/Bond/Servo/Model.cpp
@@ -91,8 +91,14 @@
 
 	SERVO::MasterListener masterListener;
 	masterListener.onEqAlive = [&](void* pMaster, SERVO::CEquipment* pEquipment, BOOL bAlive) -> void {
-		LOGI("<CModel>Equipment onAlive:%d.\n", pEquipment->getName().c_str(),
+		LOGI("<CModel>Equipment onAlive:%s(%s).\n", pEquipment->getName().c_str(),
 			bAlive ? _T("ON") : _T("OFF"));
+
+	};
+	masterListener.onEqCimStateChanged = [&](void* pMaster, SERVO::CEquipment* pEquipment, BOOL bOn) -> void {
+		LOGI("<CModel>Equipment Cim State:%s(%s).\n", pEquipment->getName().c_str(),
+			bOn ? _T("ON") : _T("OFF"));
+
 	};
 	m_master.setListener(masterListener);
 

--
Gitblit v1.9.3