From bf55b2f3083cbfdeb83611b2fa2dd552bf5b0775 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 03 三月 2025 16:20:00 +0800
Subject: [PATCH] 1.开始处理Step属性值; 2.增加左侧master面板;

---
 SourceCode/Bond/Servo/CStep.cpp |  111 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 94 insertions(+), 17 deletions(-)

diff --git a/SourceCode/Bond/Servo/CStep.cpp b/SourceCode/Bond/Servo/CStep.cpp
index 6f98ac8..6690b0f 100644
--- a/SourceCode/Bond/Servo/CStep.cpp
+++ b/SourceCode/Bond/Servo/CStep.cpp
@@ -1,5 +1,6 @@
 #include "stdafx.h"
 #include "CStep.h"
+#include "Common.h"
 
 
 namespace SERVO {
@@ -7,18 +8,21 @@
 
 	unsigned __stdcall StepWorkThreadFunction(LPVOID lpParam)
 	{
-		CStep* pScale = (CStep*)lpParam;
-		return pScale->WorkingProc();
+		CStep* pStep = (CStep*)lpParam;
+		return pStep->WorkingProc();
 	}
 
 	CStep::CStep()
 	{
+		m_listener = {nullptr};
 		m_nWordThreadAddr = 0;
 		m_hWorkStop = nullptr;
 		m_hWorkThreadHandle = nullptr;
 		m_hSignalOn = ::CreateEvent(NULL, TRUE, FALSE, NULL);
 		m_hSignalOff = ::CreateEvent(NULL, TRUE, FALSE, NULL);
 		m_nCurStep = 0;
+		m_pCclink = nullptr;
+		m_nWriteSignalDev = 0;
 		InitializeCriticalSection(&m_criticalSection);
 	}
 
@@ -33,6 +37,54 @@
 		m_hSignalOff = nullptr;
 
 		DeleteCriticalSection(&m_criticalSection);
+	}
+
+	void CStep::setListener(StepListener listener)
+	{
+		m_listener.onEvent = listener.onEvent;
+	}
+
+	void CStep::setCcLink(CCCLinkIEControl* pCcLink)
+	{
+		m_pCclink = pCcLink;
+	}
+
+	void CStep::setEquipment(CEquipment* pEquipment)
+	{
+		m_pEquipment = pEquipment;
+	}
+
+	CEquipment* CStep::getEquipment()
+	{
+		return m_pEquipment;
+	}
+
+	void CStep::setName(const char* pszName)
+	{
+		m_strName = pszName;
+	}
+
+	std::string& CStep::getName()
+	{
+		return m_strName;
+	}
+
+	void CStep::getAttributeVector(CAttributeVector& attrubutes)
+	{
+		attrubutes.clear();
+		attrubutes.addAttribute(new CAttribute("Network", 
+			std::to_string(m_station.nNetNo).c_str(), ""));
+		attrubutes.addAttribute(new CAttribute("Station",
+			std::to_string(m_station.nStNo).c_str(), ""));
+		attrubutes.addAttribute(new CAttribute("Current Step",
+			std::to_string(m_nCurStep).c_str(), ""));
+		attrubutes.addAttribute(new CAttribute("Signal Dev",
+			std::to_string(m_nWriteSignalDev).c_str(), ""));
+	}
+
+	void CStep::setWriteSignalDev(int dev)
+	{
+		m_nWriteSignalDev = dev;
 	}
 
 	void CStep::init()
@@ -79,20 +131,24 @@
 
 				// 1.读取数据
 				nextStep();
-				TRACE("m_nCurStep:%d\n", m_nCurStep);
-
+				ASSERT(m_pCclink);
+				if (0 == onReadData()) {
+					if (m_listener.onEvent != nullptr) {
+						m_listener.onEvent(this, STEP_EVENT_READDATA, nullptr);
+					}
+				}
 
 				// 2.给对方写ON
 				nextStep();
-				TRACE("m_nCurStep:%d\n", m_nCurStep);
+				m_pCclink->SetBitDevice(m_station, DeviceType::B, m_nWriteSignalDev);
 
 
 				// 3.等待对方OFF
 				nextStep();
-				TRACE("m_nCurStep:%d\n", m_nCurStep);
 				int nStep3Ret = ::WaitForSingleObject(m_hSignalOff, TIMEOUT * 1000);
 				if (nStep3Ret == WAIT_TIMEOUT) {
-					timeout();
+					m_pCclink->ResetBitDevice(m_station, DeviceType::B, m_nWriteSignalDev);
+					onTimeout();
 					goto RESET;
 				}
 				ResetEvent(m_hSignalOff);
@@ -100,17 +156,16 @@
 
 				// 4.给对方写OFF
 				nextStep();
-				TRACE("m_nCurStep:%d\n", m_nCurStep);
-
-
-				// 5.对接CIM等
-				nextStep();
-				TRACE("m_nCurStep:%d\n", m_nCurStep);
+				m_pCclink->ResetBitDevice(m_station, DeviceType::B, m_nWriteSignalDev);
 
 
 				// 6.完成
 				nextStep();
-				TRACE("m_nCurStep:%d\n", m_nCurStep);
+				if (0 == onComplete()) {
+					if (m_listener.onEvent != nullptr) {
+						m_listener.onEvent(this, STEP_EVENT_COMPLETE, nullptr);
+					}
+				}
 			}
 		}
 
@@ -125,7 +180,6 @@
 
 	void CStep::onSignal(BOOL bSignal)
 	{
-		TRACE(">>>>>>>>>>>>>>>>>>>> setSignal:%s\n", bSignal ? "ON" : "OFF");
 		Lock();
 		if (m_nCurStep == 0 && bSignal) {
 			SetEvent(m_hSignalOn);
@@ -135,6 +189,21 @@
 		}
 
 		Unlock();
+	}
+
+	int CStep::onReadData()
+	{
+		return 0;
+	}
+
+	int CStep::onComplete()
+	{
+		return 0;
+	}
+
+	int CStep::onTimeout()
+	{
+		return 0;
 	}
 
 	void CStep::resetStep()
@@ -151,9 +220,17 @@
 		Unlock();
 	}
 
-	void CStep::timeout()
+	void CStep::convertString(const char* pszBuffer, int size, std::string& strOut)
 	{
-		TRACE(">>>>>>>>>>>>>>>> timeout:%d\n", m_nCurStep);
+		strOut.clear();
+		int nLength = 0;
+		for (int i = 0; i < size; i++) {
+			if (pszBuffer[i] == '\0') break;
+			nLength++;
+		}
+		if (nLength > 0) {
+			strOut = std::string(pszBuffer, nLength);
+		}
 	}
 }
 

--
Gitblit v1.9.3