From 58c44e7934c94f4a2327252fc017c19b9f802491 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 06 六月 2025 10:40:02 +0800
Subject: [PATCH] 1.绑定关系的保存和还原; 2.BakeCooling内部搬运检测逻辑(Bake->Cooling);

---
 SourceCode/Bond/Servo/CPageGraph2.cpp |   10 +++++
 SourceCode/Bond/Servo/CEquipment.cpp  |   47 ++++++++++++++++++-----
 SourceCode/Bond/Servo/CMaster.cpp     |   51 ++++++++++++++++++++-----
 SourceCode/Bond/Servo/CMaster.h       |    4 +-
 SourceCode/Bond/Servo/CEquipment.h    |    1 
 5 files changed, 91 insertions(+), 22 deletions(-)

diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index ff6f293..0aa06b1 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -335,22 +335,23 @@
 			}
 			
 			// 梳理各玻璃之间的绑定关系
-			/*
 			Lock();
-			std::list<CGlass*> list = m_glassList;
-			for (auto item : list) {
-				std::string& strBuddyId = item->getBuddyId();
-				if (!strBuddyId.empty()) {
-					for (auto item2 : m_glassList) {
-						if (strBuddyId.compare(item2->getID()) == 0) {
-							item->setBuddy(item2);
-							TRACE("绑定关系: %s <- %s\n", item->getID().c_str(), item2->getID().c_str());
+			for (int i = 0; i < SLOT_MAX; i++) {
+				CGlass* pGlass = (CGlass*)m_slot[i].getContext();
+				if (pGlass != nullptr) {
+					std::string& strBuddyId = pGlass->getBuddyId();
+					if (!strBuddyId.empty()) {
+						for (int j = 0; j < SLOT_MAX; j++) {
+							CGlass* pBudy = (CGlass*)m_slot[j].getContext();
+							if (pBudy != nullptr && strBuddyId.compare(pBudy->getID()) == 0) {
+								pGlass->setBuddy(pBudy);
+								TRACE("绑定关系: %s <- %s\n", pGlass->getID().c_str(), pBudy->getID().c_str());
+							}
 						}
 					}
 				}
 			}
 			Unlock();
-			*/
 		}
 	}
 
@@ -1163,6 +1164,32 @@
 		return nullptr;
 	}
 
+	CSlot* CEquipment::getProcessedSlot2(MaterialsType putSlotType, const std::vector<int>& candidates)
+	{
+		for (auto item : candidates) {
+			for (int i = 0; i < SLOT_MAX; i++) {
+				if (item == i + 1) {
+					if (!m_slot[i].isEnable()) continue;
+					if (m_slot[i].isLock()) continue;
+					CGlass* pGlass = (CGlass*)m_slot[i].getContext();
+					if (pGlass == nullptr) continue;
+					if (!m_bLinkSignal[0][SIGNAL_UPSTREAM_INLINE]
+						|| m_bLinkSignal[0][SIGNAL_UPSTREAM_TROUBLE]
+						|| !m_bLinkSignal[0][SIGNAL_INTERLOCK]
+						|| !m_bLinkSignal[0][SIGNAL_SEND_ABLE]) continue;
+
+					MaterialsType glassType = pGlass->getType();
+					if (glassType == MaterialsType::G1 && putSlotType == MaterialsType::G2) continue;
+					if (glassType == MaterialsType::G2 && putSlotType == MaterialsType::G1) continue;
+
+					return &m_slot[i];
+				}
+			}
+		}
+
+		return nullptr;
+	}
+
 	CGlass* CEquipment::getGlassFromSlot(int slotNo)
 	{
 		CSlot* pSlot = nullptr;
diff --git a/SourceCode/Bond/Servo/CEquipment.h b/SourceCode/Bond/Servo/CEquipment.h
index cb1a615..ac4b84c 100644
--- a/SourceCode/Bond/Servo/CEquipment.h
+++ b/SourceCode/Bond/Servo/CEquipment.h
@@ -164,6 +164,7 @@
 
 		// 获取一个指定物料类型(G1,G2,G1&G2)的且已经加工处理的槽位
 		CSlot* getProcessedSlot(MaterialsType putSlotType);
+		CSlot* getProcessedSlot2(MaterialsType putSlotType, const std::vector<int>& candidates);
 
 		// 获取玻璃物料
 		CGlass* getGlassFromSlot(int slotNo);
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 41b9205..a73e03c 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -367,8 +367,10 @@
 				}
 
 
-				// Bonder -> BakeCooling
-				m_pActiveRobotTask = createTransferTask_bonder_to_bakecooling(pBonder1, pBakeCooling, primaryType, secondaryType);
+
+				// BakeCooling内部
+				// Bake -> Cooling
+				m_pActiveRobotTask = createTransferTask_bake_to_cooling(pBakeCooling);
 				if (m_pActiveRobotTask != nullptr) {
 					std::string strDescription = m_pActiveRobotTask->getDescription();
 					unlock();
@@ -379,7 +381,20 @@
 					continue;
 				}
 
-				m_pActiveRobotTask = createTransferTask_bonder_to_bakecooling(pBonder2, pBakeCooling, primaryType, secondaryType);
+
+				// Bonder -> BakeCooling
+				m_pActiveRobotTask = createTransferTask_bonder_to_bakecooling(pBonder1, pBakeCooling);
+				if (m_pActiveRobotTask != nullptr) {
+					std::string strDescription = m_pActiveRobotTask->getDescription();
+					unlock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
+					LOGI("创建新任务<%s>...", strDescription.c_str());
+					continue;
+				}
+
+				m_pActiveRobotTask = createTransferTask_bonder_to_bakecooling(pBonder2, pBakeCooling);
 				if (m_pActiveRobotTask != nullptr) {
 					std::string strDescription = m_pActiveRobotTask->getDescription();
 					unlock();
@@ -525,6 +540,7 @@
 				break;
 			}
 
+			// 读标志位
 			for (auto item : m_listEquipment) {
 				if (item->getID() == EQ_ID_Bonder1 ||
 					item->getID() == EQ_ID_Bonder2) {
@@ -1112,21 +1128,36 @@
 		return pTask;
 	}
 
-	CRobotTask* CMaster::createTransferTask_bonder_to_bakecooling(CEquipment* pSrcEq, CEquipment* pTarEq,
-		MaterialsType primaryType/* = MaterialsType::G1*/, MaterialsType secondaryType/* = MaterialsType::G2*/)
+	CRobotTask* CMaster::createTransferTask_bonder_to_bakecooling(CEquipment* pSrcEq, CEquipment* pTarEq)
 	{
 		std::vector<int> slots = {1, 2};
 
 		CRobotTask* pTask = nullptr;
 		CSlot* pSrcSlot, * pTarSlot;
-		pTarSlot = pTarEq->getAvailableSlotForGlass2(primaryType, slots);
-		pSrcSlot = pSrcEq->getProcessedSlot(primaryType);
-		if (pSrcSlot == nullptr || nullptr == pTarSlot) {
-			pTarSlot = pTarEq->getAvailableSlotForGlass(secondaryType);
-			pSrcSlot = pSrcEq->getProcessedSlot(secondaryType);
+		pTarSlot = pTarEq->getAvailableSlotForGlass2(MaterialsType::G1, slots);
+		pSrcSlot = pSrcEq->getProcessedSlot(MaterialsType::G1);
+
+		if (pSrcSlot != nullptr && nullptr != pTarSlot) {
+			pTask = new CRobotTask();
+			pTask->setContext(pSrcSlot->getContext());
+			pTask->setRobotTransferParam(++taskSeqNo, 1, pSrcSlot->getPosition(),
+				pTarSlot->getPosition(), pSrcSlot->getNo(), pTarSlot->getNo());
 		}
 
 
+		return pTask;
+	}
+
+	CRobotTask* CMaster::createTransferTask_bake_to_cooling(CEquipment* pSrcEq)
+	{
+		std::vector<int> slotsTar = { 3, 4 };
+		std::vector<int> slotsSrc = { 1, 2 };
+
+		CRobotTask* pTask = nullptr;
+		CSlot* pSrcSlot, * pTarSlot;
+		pTarSlot = pSrcEq->getAvailableSlotForGlass2(MaterialsType::G1, slotsTar);
+		pSrcSlot = pSrcEq->getProcessedSlot2(MaterialsType::G1, slotsSrc);
+
 		if (pSrcSlot != nullptr && nullptr != pTarSlot) {
 			pTask = new CRobotTask();
 			pTask->setContext(pSrcSlot->getContext());
diff --git a/SourceCode/Bond/Servo/CMaster.h b/SourceCode/Bond/Servo/CMaster.h
index 7eeffad..2be2371 100644
--- a/SourceCode/Bond/Servo/CMaster.h
+++ b/SourceCode/Bond/Servo/CMaster.h
@@ -86,8 +86,8 @@
         void setState(MASTERSTATE state);
         CRobotTask* createTransferTask(CEquipment* pSrcEq, CEquipment* pTarEq,
             MaterialsType primaryType = MaterialsType::G1, MaterialsType secondaryType = MaterialsType::G2);
-        CRobotTask* createTransferTask_bonder_to_bakecooling(CEquipment* pSrcEq, CEquipment* pTarEq,
-            MaterialsType primaryType = MaterialsType::G1, MaterialsType secondaryType = MaterialsType::G2);
+        CRobotTask* createTransferTask_bonder_to_bakecooling(CEquipment* pSrcEq, CEquipment* pTarEq);
+        CRobotTask* createTransferTask_bake_to_cooling(CEquipment* pSrcEq);
 
     private:
         CRITICAL_SECTION m_criticalSection;
diff --git a/SourceCode/Bond/Servo/CPageGraph2.cpp b/SourceCode/Bond/Servo/CPageGraph2.cpp
index c929527..b16eae2 100644
--- a/SourceCode/Bond/Servo/CPageGraph2.cpp
+++ b/SourceCode/Bond/Servo/CPageGraph2.cpp
@@ -270,6 +270,16 @@
 				pEquipment->setLinkSignal(0, SIGNAL_INTERLOCK, TRUE);
 				pEquipment->setLinkSignal(0, SIGNAL_SEND_ABLE, TRUE);
 			}
+
+			if (pEquipment != nullptr && (pEquipment->getID() == EQ_ID_Bonder1
+				|| pEquipment->getID() == EQ_ID_Bonder2)) {
+				SERVO::CGlass* pGlass = pEquipment->getAnyGlass();
+				if (pGlass != nullptr) {
+					SERVO::CProcessData pd;
+					pd.setGlassId(pGlass->getID().c_str());
+					pEquipment->onProcessData(&pd);
+				}
+			}
 		}
 		else if (nCmd == ID_EQSGRAPHITEM_TEST5) {
 			SERVO::CEquipment* pEquipment = (SERVO::CEquipment*)pItem->pData;

--
Gitblit v1.9.3