From 0d885fe2e84ac5a6390ddc4d43ab701112eedc64 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 17 二月 2025 16:53:01 +0800
Subject: [PATCH] 1.各设备Alive状态获取,监听状态变化并回调应用层;

---
 SourceCode/Bond/Servo/CMaster.cpp |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 85bf38e..5ea975d 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -12,7 +12,7 @@
 
 	CMaster::CMaster()
 	{
-
+		m_listener = {nullptr};
 	}
 
 	CMaster::~CMaster()
@@ -21,6 +21,11 @@
 			delete item;
 		}
 		m_listEquipment.clear();
+	}
+
+	void CMaster::setListener(MasterListener listener)
+	{
+		m_listener.onEqAlive = listener.onEqAlive;
 	}
 
 	int CMaster::init()
@@ -93,7 +98,16 @@
 
 	int CMaster::addEquipment(CEquipment* pEquipment)
 	{
+		EquipmentListener listener;
+		listener.onAlive = [&](void* pEquipment, BOOL bAlive) -> void {
+			CEquipment* p = (CEquipment*)pEquipment;
+			if (m_listener.onEqAlive != nullptr) {
+				m_listener.onEqAlive(this, p, bAlive);
+			}
+		};
+		pEquipment->setListener(listener);
 		m_listEquipment.push_back(pEquipment);
+
 		return 0;
 	}
 
@@ -104,7 +118,7 @@
 		}
 
 
-		// 以下为测试代码
+		// 按一定频率扫描LB数据
 		static int i = 0;
 		i++;
 		if (i % (4 * 1) == 0) {
@@ -113,14 +127,11 @@
 				const StationIdentifier& station = item->getStation();
 				MemoryBlock& block = item->getReadBitBlock();
 
-				char szBuffer[1024];
 				int nRet = m_cclink.ReadData2(station, (short)block.type,
-					block.start, block.size, szBuffer);
-				for (unsigned int i = 0; i < block.size; i++) {
-					if(szBuffer[i] != 0)
-						TRACE("%d[%x]\n", i, szBuffer[i]);
+					block.start, block.size, block.buffer);
+				if (0 == nRet) {
+					item->onReceiveLBData(block.buffer, block.size);
 				}
-				TRACE("nRet=%d\n", nRet);
 			}
 		}
 	}

--
Gitblit v1.9.3