From 0393d1ff2ebc378b3c4cff9b45f72ebc8a4ea516 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期二, 03 六月 2025 15:13:42 +0800
Subject: [PATCH] Merge branch 'master' into liuyang

---
 SourceCode/Bond/Servo/CEquipment.cpp |   58 +++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index 319cb86..7cb8a5b 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -27,7 +27,7 @@
 
 	CEquipment::CEquipment() : m_nID(0), m_strName(""), m_strDescription(""), m_station(0, 255)
 	{
-		m_listener = { nullptr, nullptr, nullptr, nullptr, nullptr };
+		m_listener = { };
 		m_alive = { FALSE, 0, FALSE };
 		m_bCimState = FALSE;
 		m_bUpstreamInline = FALSE;
@@ -71,11 +71,7 @@
 
 	void CEquipment::setListener(EquipmentListener listener)
 	{
-		m_listener.onAlive = listener.onAlive;
-		m_listener.onCimStateChanged = listener.onCimStateChanged;
-		m_listener.onAlarm = listener.onAlarm;
-		m_listener.onDataChanged = listener.onDataChanged;
-		m_listener.onVcrEventReport = listener.onVcrEventReport;
+		m_listener = listener;
 	}
 
 	void CEquipment::setCcLink(CCCLinkIEControl* pCcLink)
@@ -754,15 +750,14 @@
 		Unlock();
 
 		if (m_listener.onDataChanged != nullptr) {
-			m_listener.onDataChanged(this, 0);
+			m_listener.onDataChanged(this, EDCC_FETCHOUT_JOB);
 		}
 
 		return 0;
 	}
 
-	int CEquipment::storedJob(CJobDataB* pJobDataB)
+	int CEquipment::storedJob(CJobDataB* pJobDataB, short& putSlot)
 	{
-		/*
 		if (m_pArm == nullptr) {
 			return -1;
 		}
@@ -776,13 +771,13 @@
 		ASSERT(pGlass);
 		Lock();
 		pGlass->addPath(m_nID);
-		pGlass->addRef();					// 加入list,addRef
-		m_glassList.push_back(pGlass);
+		m_slot[putSlot - 1].setContext(pGlass);
 		pGlass->release();				// tempFetchOut需要调用一次release
 		Unlock();
 
 
 		// 如果此玻璃已经贴合,贴合的玻璃也要从加入到列表中
+		/*
 		CGlass* pBuddy = pGlass->getBuddy();
 		if (pBuddy != nullptr) {
 			Lock();
@@ -791,12 +786,12 @@
 			m_glassList.push_back(pBuddy);
 			Unlock();
 		}
-
+		*/
 
 		if (m_listener.onDataChanged != nullptr) {
-			m_listener.onDataChanged(this, 0);
+			m_listener.onDataChanged(this, EDCC_STORED_JOB);
 		}
-		*/
+		
 		return 0;
 	}
 
@@ -1104,6 +1099,15 @@
 		return nullptr;
 	}
 
+	BOOL CEquipment::canPlaceGlassInSlot(const short slotIndex)
+	{
+		if (slotIndex >= SLOT_MAX) return FALSE;
+		if (!m_slot[slotIndex].isEnable()) return FALSE;
+		if (m_slot[slotIndex].getContext() != nullptr) return FALSE;
+
+		return TRUE;
+	}
+
 	short CEquipment::decodeRecipeListReport(const char* pszData, size_t size)
 	{
 		return m_recipesManager.decodeRecipeListReport(pszData, size);
@@ -1233,10 +1237,14 @@
 		return index;
 	}
 
-	int CEquipment::onPreFetchedOutJob(int port, CJobDataB* pJobDataB)
+	BOOL CEquipment::onPreFetchedOutJob(int port, CJobDataB* pJobDataB)
 	{
 		LOGI("<CEquipment-%s>onPreFetchedOutJob:port:%d|GlassId:%s",
 			m_strName.c_str(), port, pJobDataB->getGlassId().c_str());
+		if (m_listener.onPreFethedOutJob != nullptr) {
+			return m_listener.onPreFethedOutJob(this, pJobDataB);
+		}
+
 		return TRUE;
 	}
 
@@ -1319,7 +1327,7 @@
 		return 0;
 	}
 
-	int CEquipment::onPreStoredJob(int port, CJobDataB* pJobDataB)
+	int CEquipment::onPreStoredJob(int port, CJobDataB* pJobDataB, short& putSlot)
 	{
 		LOGI("<CEquipment-%s>onPreStoredJob:port:%d|GlassId:%s",
 			m_strName.c_str(), port, pJobDataB->getGlassId().c_str());
@@ -1331,7 +1339,7 @@
 			return FALSE;
 		}
 
-		// 当前不能有任何玻璃,且当前准备进的片是G2
+		// 如果没有可用位置,报错
 		Lock();
 		CSlot* pSlot = getAvailableSlotForGlass((MaterialsType)pJobDataS->getMaterialsType());
 		if (pSlot == nullptr) {
@@ -1341,6 +1349,17 @@
 		}
 		Unlock();
 
+
+		if (m_listener.onPreStoredJob != nullptr) {
+			if (!m_listener.onPreStoredJob(this, pJobDataB, putSlot)) {
+				return FALSE;
+			}
+
+			if(!canPlaceGlassInSlot(putSlot - 1)) {
+				return FALSE;
+			}
+		}
+
 		return TRUE;
 	}
 
@@ -1349,10 +1368,11 @@
 		LOGI("<CEquipment-%s>onStore:port:%d|GlassId:%s",
 			m_strName.c_str(), port, pJobDataB->getGlassId().c_str());
 
-		BOOL bCheck = onPreStoredJob(port, pJobDataB);
+		short putSlot = 0;
+		BOOL bCheck = onPreStoredJob(port, pJobDataB, putSlot);
 		if (bCheck) {
 			addJobDataB(pJobDataB);
-			return storedJob(pJobDataB);
+			return storedJob(pJobDataB, putSlot);
 		}
 
 		// 数据异常,处理或显示

--
Gitblit v1.9.3