From 1f5df45b8e213de70e91a7ca54d6e2219cd967ca Mon Sep 17 00:00:00 2001
From: darker <mr.darker@163.com>
Date: 星期二, 18 二月 2025 11:07:25 +0800
Subject: [PATCH] 1. 添加获取plc心跳修改状态

---
 SourceCode/Bond/Servo/CEquipment.cpp |   12 +++++++++++-
 SourceCode/Bond/Servo/CMaster.cpp    |    1 +
 SourceCode/Bond/Servo/Model.cpp      |    1 +
 SourceCode/Bond/Servo/CEquipment.h   |    3 +++
 SourceCode/Bond/Servo/ServoDlg.cpp   |   19 +++++++++++++++++--
 SourceCode/Bond/Servo/Common.h       |    1 +
 SourceCode/Bond/Servo/ServoDlg.h     |    4 ++--
 7 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index 6534f88..67a238b 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -5,7 +5,7 @@
 
 namespace SERVO {
 
-	CEquipment::CEquipment()
+	CEquipment::CEquipment() : m_nID(0), m_strName(""), m_strDescription(""), m_station(0, 255)
 	{
 		m_alive = {FALSE, 0, FALSE};
 		m_listener.onAlive = {nullptr};
@@ -32,6 +32,16 @@
 
 	}
 
+	void CEquipment::setID(int nID)
+	{
+		m_nID = nID;
+	}
+
+	int CEquipment::getID()
+	{
+		return m_nID;
+	}
+
 	void CEquipment::setName(const char* pszName)
 	{
 		m_strName = pszName;
diff --git a/SourceCode/Bond/Servo/CEquipment.h b/SourceCode/Bond/Servo/CEquipment.h
index 37d8e2b..769a8fe 100644
--- a/SourceCode/Bond/Servo/CEquipment.h
+++ b/SourceCode/Bond/Servo/CEquipment.h
@@ -38,6 +38,8 @@
 	public:
 		virtual const char* getClassName() = 0;
 		virtual void setListener(EquipmentListener listener);
+		void setID(int nID);
+		int getID();
 		void setName(const char* pszName);
 		std::string& getName();
 		void setDescription(const char* pszDescription);
@@ -64,6 +66,7 @@
 
 	protected:
 		EquipmentListener m_listener;
+		int m_nID;
 		std::string m_strName;
 		std::string m_strDescription;
 		CRITICAL_SECTION m_criticalSection;
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 5ea975d..92505c0 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -63,6 +63,7 @@
 		// 初始化添加各子设备
 		{
 			CEFEM* pEquipment = new CEFEM();
+			pEquipment->setID(1);
 			pEquipment->setName("EFEM(ROBOT)");
 			pEquipment->setDescription("EFEM(ROBOT).");
 			pEquipment->setReadBitBlock(0x4000, 0x45ff);
diff --git a/SourceCode/Bond/Servo/Common.h b/SourceCode/Bond/Servo/Common.h
index 50370d7..c33f6a0 100644
--- a/SourceCode/Bond/Servo/Common.h
+++ b/SourceCode/Bond/Servo/Common.h
@@ -7,6 +7,7 @@
 #define RX_CODE_PASSIVE_STATUS_CHANGED	1001
 #define RX_CODE_MES_MESSAGE				1002
 #define RX_HSMS_TERMINAL_TEXT			1003
+#define RX_CODE_EQ_ALIVE				1004
 
 
 /* Channel Name */
diff --git a/SourceCode/Bond/Servo/Model.cpp b/SourceCode/Bond/Servo/Model.cpp
index a7db1b4..f7d8571 100644
--- a/SourceCode/Bond/Servo/Model.cpp
+++ b/SourceCode/Bond/Servo/Model.cpp
@@ -93,6 +93,7 @@
 	masterListener.onEqAlive = [&](void* pMaster, SERVO::CEquipment* pEquipment, BOOL bAlive) -> void {
 		LOGI("<CModel>Equipment onAlive:%d.\n", pEquipment->getName().c_str(),
 			bAlive ? _T("ON") : _T("OFF"));
+		notifyPtr(RX_CODE_EQ_ALIVE, pEquipment);
 	};
 	m_master.setListener(masterListener);
 
diff --git a/SourceCode/Bond/Servo/ServoDlg.cpp b/SourceCode/Bond/Servo/ServoDlg.cpp
index 292467f..07bce45 100644
--- a/SourceCode/Bond/Servo/ServoDlg.cpp
+++ b/SourceCode/Bond/Servo/ServoDlg.cpp
@@ -144,6 +144,21 @@
 					ShowTerminalText(pszText);
 				}
 			}
+			else if (RX_CODE_EQ_ALIVE == code) {
+				// 通知设备状态
+				SERVO::CEquipment* pEquipment = nullptr;
+				if (pAny->getPtrValue("ptr", (void*&)pEquipment)) {
+					if (pEquipment != nullptr) {
+						int nID = pEquipment->getID();
+						BOOL bAlive = pEquipment->isAlive();
+						if (1 == nID) {
+							DeviceStatus status = bAlive ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE;
+							UpdateDeviceStatus(INDICATE_ROBOT_ARM1, status);
+							UpdateDeviceStatus(INDICATE_ROBOT_ARM2, status);
+						}
+					}
+				}
+			}
 			pAny->release();
 		}, [&]() -> void {
 			// onComplete
@@ -660,12 +675,12 @@
 	COLORREF newFrameColor2;
 
 	switch (status) {
-	case Online:
+	case ONLINE:
 		newBackgroundColor = RGB(255, 0, 0);
 		newFrameColor1 = RGB(22, 22, 22);
 		newFrameColor2 = RGB(255, 127, 39);
 		break;
-	case Offline:
+	case OFFLINE:
 		newBackgroundColor = RGB(0, 255, 0);
 		newFrameColor1 = RGB(22, 22, 22);
 		newFrameColor2 = RGB(255, 127, 39);
diff --git a/SourceCode/Bond/Servo/ServoDlg.h b/SourceCode/Bond/Servo/ServoDlg.h
index b6bec04..88ed43d 100644
--- a/SourceCode/Bond/Servo/ServoDlg.h
+++ b/SourceCode/Bond/Servo/ServoDlg.h
@@ -9,8 +9,8 @@
 #include "TerminalDisplayDlg.h"
 
 enum DeviceStatus {
-	Online,       // 在线
-	Offline,      // 离线
+	ONLINE,       // 在线
+	OFFLINE,      // 离线
 };
 
 // CServoDlg 对话框

--
Gitblit v1.9.3