From b0184248350b34c0f90f36db8d2ad3b89095e74f Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 01 九月 2025 11:15:41 +0800
Subject: [PATCH] 1.调整调度算法逻辑,根据G1G2数量及配对确定取片类型,空闲等; 2.重命名两个和玻璃相关函数:Class修改为Glass

---
 SourceCode/Bond/Servo/HsmsPassive.h      |    2 
 SourceCode/Bond/Servo/Servo.vcxproj.user |    2 
 SourceCode/Bond/Servo/CEquipment.cpp     |    7 ++
 SourceCode/Bond/Servo/HsmsPassive.cpp    |   10 +++
 SourceCode/Bond/Servo/CMaster.cpp        |  121 +++++++++++++++++++++++-----------------
 SourceCode/Bond/Servo/CEquipment.h       |    1 
 SourceCode/Bond/Servo/CLoadPort.cpp      |    8 +-
 SourceCode/Bond/Servo/CBonder.h          |    4 
 SourceCode/Bond/Servo/CBonder.cpp        |    4 
 9 files changed, 99 insertions(+), 60 deletions(-)

diff --git a/SourceCode/Bond/Servo/CBonder.cpp b/SourceCode/Bond/Servo/CBonder.cpp
index 7ebd7be..ef46752 100644
--- a/SourceCode/Bond/Servo/CBonder.cpp
+++ b/SourceCode/Bond/Servo/CBonder.cpp
@@ -460,7 +460,7 @@
 		return m_nIndex;
 	}
 
-	BOOL CBonder::hasBondClass()
+	BOOL CBonder::hasBondGlass()
 	{
 		CGlass* pGlass = (CGlass*)m_slot[1].getContext();
 		if (pGlass == nullptr) return FALSE;
@@ -468,7 +468,7 @@
 		return pBuddy != nullptr;
 	}
 
-	BOOL CBonder::hasG2Class()
+	BOOL CBonder::hasG2Glass()
 	{
 		CGlass* pGlass = (CGlass*)m_slot[0].getContext();
 		return (pGlass != nullptr);
diff --git a/SourceCode/Bond/Servo/CBonder.h b/SourceCode/Bond/Servo/CBonder.h
index 4e8edcd..0746fa5 100644
--- a/SourceCode/Bond/Servo/CBonder.h
+++ b/SourceCode/Bond/Servo/CBonder.h
@@ -28,8 +28,8 @@
     public:
         void setIndex(unsigned int index);
         unsigned int getIndex();
-        BOOL hasBondClass();
-        BOOL hasG2Class();
+        BOOL hasBondGlass();
+        BOOL hasG2Glass();
 
     private:
         unsigned int m_nIndex;
diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index 8d8582d..d7f5698 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -1454,6 +1454,13 @@
 		return TRUE;
 	}
 
+	BOOL CEquipment::slotHasGlass(int slotIndex/* = 0*/)
+	{
+		ASSERT(slotIndex < 8);
+		CGlass* pGlass = (CGlass*)m_slot[slotIndex].getContext();
+		return (pGlass != nullptr);
+	}
+
 	int CEquipment::removeGlass(int slotNo)
 	{
 		CSlot* pSlot = nullptr;
diff --git a/SourceCode/Bond/Servo/CEquipment.h b/SourceCode/Bond/Servo/CEquipment.h
index c2e93cd..e23aa10 100644
--- a/SourceCode/Bond/Servo/CEquipment.h
+++ b/SourceCode/Bond/Servo/CEquipment.h
@@ -202,6 +202,7 @@
 
 		// 是否有玻璃
 		BOOL hasGlass();
+		BOOL slotHasGlass(int slotIndex = 0);
 
 		// 指定槽位是否可以放置玻璃
 		BOOL canPlaceGlassInSlot(const short slotIndex);
diff --git a/SourceCode/Bond/Servo/CLoadPort.cpp b/SourceCode/Bond/Servo/CLoadPort.cpp
index 454c1da..15a49fe 100644
--- a/SourceCode/Bond/Servo/CLoadPort.cpp
+++ b/SourceCode/Bond/Servo/CLoadPort.cpp
@@ -369,9 +369,9 @@
 			ii++;
 			if (ii == 50) {
 				char szBuffer[64] = {0};
-				CStep* pStep = getStepWithName(STEP_EQ_PORT1_INUSE);
+				CStep* pStep = getStepWithName(STEP_EQ_PORT1_BLOCKED);
 				CPortStatusReport portStatusReport;
-				portStatusReport.setPortStatus(PORT_INUSE);
+				portStatusReport.setPortStatus(PORT_BLOCKED);
 				portStatusReport.setJobExistenceSlot(0xf);
 				portStatusReport.setCassetteId("CID1001");
 				int nRet = portStatusReport.serialize(szBuffer, 64);
@@ -383,9 +383,9 @@
 			ii++;
 			if (ii == 55) {
 				char szBuffer[64] = { 0 };
-				CStep* pStep = getStepWithName(STEP_EQ_PORT2_INUSE);
+				CStep* pStep = getStepWithName(STEP_EQ_PORT2_BLOCKED);
 				CPortStatusReport portStatusReport;
-				portStatusReport.setPortStatus(PORT_INUSE);
+				portStatusReport.setPortStatus(PORT_BLOCKED);
 				portStatusReport.setJobExistenceSlot(0xff );
 				portStatusReport.setCassetteId("CID1004");
 				int nRet = portStatusReport.serialize(szBuffer, 64);
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 1716f9a..f88f104 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -506,13 +506,11 @@
 				}
 				
 				// 检查看是否都已经切换到START状态
-				/*
 				if (!bIomcOk[6]) {
 					unlock();
 					setState(MASTERSTATE::MSERROR);
 					continue;
 				}
-				*/
 
 				unlock();
 				if(m_bContinuousTransfer)
@@ -597,52 +595,62 @@
 				}
 
 
-				// 此处检测优先类型和次要类型(G1或G2)
-				// 如果其中一Bonder有单个玻璃,优先取它的配对类型,否则无所谓了
-				primaryType = MaterialsType::G2;
-				secondaryType = MaterialsType::G1;
+				// Bonder1、Bonder2、Fliper、VacuumBake、Aligner,统计G2和G1的数量, 配对组数, 多出的类型
+				int nG2Count = 0, nG1Count = 0, nGlassGroup, nExtraType;
+				if (pBonder1->slotHasGlass(0)) {
+					nG2Count++;
+				}
+				if (pBonder1->slotHasGlass(1)) {
+					nG1Count++;
+				}
 
+				if (pBonder2->slotHasGlass(0)) {
+					nG2Count++;
+				}
+				if (pBonder2->slotHasGlass(1)) {
+					nG1Count++;
+				}
 
-				if (!pBonder1->canPlaceGlassInSlot(0) && pBonder1->canPlaceGlassInSlot(1)) {
-					// 如果Bonder1有G2了,则取G1
-					primaryType = MaterialsType::G1;
-					secondaryType = MaterialsType::G0;
+				if (pFliper->slotHasGlass(0)) {
+					nG2Count++;
 				}
-				else if (!pBonder2->canPlaceGlassInSlot(0) && pBonder2->canPlaceGlassInSlot(1)) {
-					// 如果Bonder2有G2了,则取G1
-					primaryType = MaterialsType::G1;
-					secondaryType = MaterialsType::G0;
+
+				if (pVacuumBake->slotHasGlass(0)) {
+					nG1Count++;
 				}
-				else if (!pFliper->canPlaceGlassInSlot(0)) {
-					primaryType = MaterialsType::G1;
-					secondaryType = MaterialsType::G0;
+				if (pVacuumBake->slotHasGlass(1)) {
+					nG1Count++;
 				}
-				else if (pBonder1->canPlaceGlassInSlot(0)) {
-					// 如果Bonder1没有G2, 则先G2
-					primaryType = MaterialsType::G2;
-					secondaryType = MaterialsType::G0;
+
+				CGlass* pTempGlass = pAligner->getGlassFromSlot(0);
+				if (pTempGlass != nullptr) {
+					MaterialsType type = pTempGlass->getType();
+					if(type == MaterialsType::G1)
+						nG1Count++;
+					else if (type == MaterialsType::G2)
+						nG2Count++;
 				}
-				else if (pBonder2->canPlaceGlassInSlot(0)) {
-					// 如果Bonder2没有G2, 则先G2
-					primaryType = MaterialsType::G2;
-					secondaryType = MaterialsType::G0;
+				nGlassGroup = min(nG1Count, nG2Count);
+				
+				if (nG1Count == nG2Count) {
+					nExtraType = 0;
+				}
+				else if (nG1Count > nG2Count) {
+					nExtraType = 1;
 				}
 				else {
-					primaryType = MaterialsType::G2;
-					secondaryType = MaterialsType::G0;
+					nExtraType = 2;
 				}
+				secondaryType = MaterialsType::G0;
+
 
 				// Measurement -> LoadPort
-				if (rmd.armState[0] || rmd.armState[1]) {
-					LOGI("Arm1 %s, Arm2 %s.", rmd.armState[0] ? _T("不可用") : _T("可用"),
-						rmd.armState[1] ? _T("不可用") : _T("可用"));
-				}
 				for (int s = 0; s < 4; s++) {
 					PortType pt = pLoadPorts[s]->getPortType();
 					if (!rmd.armState[0] && pLoadPorts[s]->isEnable()
 						&& (pt == PortType::Unloading || pt == PortType::Both)
 						&& pLoadPorts[s]->getPortStatus() == PORT_INUSE) {
-						m_pActiveRobotTask = createTransferTask(pMeasurement, pLoadPorts[s], primaryType, secondaryType);
+						m_pActiveRobotTask = createTransferTask(pMeasurement, pLoadPorts[s], MaterialsType::G1, secondaryType);
 						if (m_pActiveRobotTask != nullptr) {
 							goto PORT_PUT;
 						}
@@ -689,29 +697,29 @@
 
 
 				// Fliper(G2) -> Bonder
-				auto pSrcSlot = pVacuumBake->getProcessedSlot(primaryType);
-				//LOGI("<Master>pSrcSlot = %x, primaryType:%d", pSrcSlot, primaryType);
+				//m_nTestFlag = 1;
+				//pVacuumBake->m_nTestFlag = 1;
+				auto pSrcSlot = pVacuumBake->getProcessedSlot(MaterialsType::G1);
+				//LOGI("<Master>pSrcSlot = %x", pSrcSlot,);
 				if (pSrcSlot != nullptr && !rmd.armState[1]
-					&& pBonder1->canPlaceGlassInSlot(0)
-					&& !pBonder1->hasBondClass()) {
+					&& pBonder1->canPlaceGlassInSlot(0)) {
 					m_pActiveRobotTask = createTransferTask(pFliper, pBonder1, MaterialsType::G2, MaterialsType::G0, 2);
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 				if (pSrcSlot != nullptr && !rmd.armState[1] 
-					&& pBonder2->canPlaceGlassInSlot(0)
-					&& !pBonder2->hasBondClass()) {
+					&& pBonder2->canPlaceGlassInSlot(0)) {
 					m_pActiveRobotTask = createTransferTask(pFliper, pBonder2, MaterialsType::G2, MaterialsType::G0, 2);
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
-
-
+				//m_nTestFlag = 0
+					;
 				// VacuumBake(G1) -> Bonder
-				if (!rmd.armState[0] && !pBonder1->hasBondClass()) {
+				if (!rmd.armState[0] && pBonder1->slotHasGlass(0) && !pBonder1->slotHasGlass(1)) {
 					m_pActiveRobotTask = createTransferTask(pVacuumBake, pBonder1, MaterialsType::G1, MaterialsType::G0);
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 
-				if (!rmd.armState[0] && !pBonder2->hasBondClass()) {
+				if (!rmd.armState[0] && pBonder2->slotHasGlass(0) && !pBonder2->slotHasGlass(1)) {
 					m_pActiveRobotTask = createTransferTask(pVacuumBake, pBonder2, MaterialsType::G1, MaterialsType::G0);
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
@@ -720,14 +728,14 @@
 				// Aligner -> Fliper(G2)
 				// Aligner -> VacuumBake(G1)
 				if (!rmd.armState[1]) {
-					m_pActiveRobotTask = createTransferTask(pAligner, pFliper, primaryType, secondaryType);
+					m_pActiveRobotTask = createTransferTask(pAligner, pFliper, MaterialsType::G2, secondaryType);
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 
 				if (!rmd.armState[0]) {
 					// m_nTestFlag = 1;
-					if (m_nTestFlag == 1) LOGI("createTransferTask 004df %d, %d", primaryType, secondaryType);
-					m_pActiveRobotTask = createTransferTask(pAligner, pVacuumBake, primaryType, secondaryType);
+					if (m_nTestFlag == 1) LOGI("createTransferTask 004df %d, %d", MaterialsType::G1, secondaryType);
+					m_pActiveRobotTask = createTransferTask(pAligner, pVacuumBake, MaterialsType::G1, secondaryType);
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 					m_nTestFlag = 0;
 				}
@@ -741,6 +749,17 @@
 
 
 				// LoadPort -> Aligner
+				if (nGlassGroup >= 2) {
+					unlock();
+					continue;
+				}
+
+				if(nExtraType == 0)
+					primaryType = MaterialsType::G2;
+				else {
+					primaryType = MaterialsType::G1;
+				}
+
 				for (int s = 0; s < 4; s++) {
 					PortType pt = pLoadPorts[s]->getPortType();
 					if (!rmd.armState[0] && pLoadPorts[s]->isEnable()
@@ -917,23 +936,23 @@
 
 				// Fliper(G2) -> Bonder
 				auto pSrcSlot = pVacuumBake->getProcessedSlot(primaryType);
-				if (pSrcSlot != nullptr && !rmd.armState[1] && !pBonder1->hasBondClass()) {
+				if (pSrcSlot != nullptr && !rmd.armState[1] && !pBonder1->hasBondGlass()) {
 					m_pActiveRobotTask = createTransferTask(pFliper, pBonder1, primaryType, secondaryType, 2);
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
-				if (pSrcSlot != nullptr && !rmd.armState[1] && !pBonder2->hasBondClass()) {
+				if (pSrcSlot != nullptr && !rmd.armState[1] && !pBonder2->hasBondGlass()) {
 					m_pActiveRobotTask = createTransferTask(pFliper, pBonder2, primaryType, secondaryType, 2);
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 
 
 				// VacuumBake(G1) -> Bonder
-				if (!rmd.armState[0] && !pBonder1->hasBondClass()) {
+				if (!rmd.armState[0] && !pBonder1->hasBondGlass()) {
 					m_pActiveRobotTask = createTransferTask(pVacuumBake, pBonder1, primaryType, secondaryType);
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 
-				if (!rmd.armState[0] && !pBonder2->hasBondClass()) {
+				if (!rmd.armState[0] && !pBonder2->hasBondGlass()) {
 					m_pActiveRobotTask = createTransferTask(pVacuumBake, pBonder2, primaryType, secondaryType);
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
@@ -1123,7 +1142,7 @@
 				
 				// Bonder1 -> Bonder2
 				if ((m_nContinuousTransferStep == CTStep_Unknow || m_nContinuousTransferStep == CTStep_Fliper_Bonder1)
-					&& !rmd.armState[0] && !pBonder2->hasBondClass()) {
+					&& !rmd.armState[0] && !pBonder2->hasBondGlass()) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pBonder1,
 						1, pBonder2, 1);
 					if (m_pActiveRobotTask != nullptr) {
@@ -1135,7 +1154,7 @@
 
 				// Fliper(G2) -> Bonder1
 				if ((m_nContinuousTransferStep == CTStep_Unknow || m_nContinuousTransferStep == CTStep_Aligner_Fliper)
-					&&!rmd.armState[0] && !pBonder1->hasBondClass()) {
+					&&!rmd.armState[0] && !pBonder1->hasBondGlass()) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pFliper,
 						0, pBonder1, 1);
 					if (m_pActiveRobotTask != nullptr) {
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index 4765d68..1b122ec 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -1879,6 +1879,16 @@
 	return requestEventReportSend("Port_Unload_Ready");
 }
 
+int CHsmsPassive::requestEventReportSend_Port_Load_Ready()
+{
+	return requestEventReportSend("Port_Load_Ready");
+}
+
+int CHsmsPassive::requestEventReportSend_Port_Blocked()
+{
+	return requestEventReportSend("Port_Blocked");
+}
+
 int CHsmsPassive::requestEventReportSend_PJ_Queued()
 {
 	return requestEventReportSend("PJ_Queued");
diff --git a/SourceCode/Bond/Servo/HsmsPassive.h b/SourceCode/Bond/Servo/HsmsPassive.h
index 5767836..1863abd 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.h
+++ b/SourceCode/Bond/Servo/HsmsPassive.h
@@ -192,6 +192,8 @@
 	int requestEventReportSend(const char* pszEventName);
 	int requestEventReportSend_CarrierID_Readed();
 	int requestEventReportSend_Port_Unload_Ready();
+	int requestEventReportSend_Port_Load_Ready();
+	int requestEventReportSend_Port_Blocked();
 	int requestEventReportSend_PJ_Queued();
 	int requestEventReportSend_PJ_Start();
 	int requestEventReportSend_PJ_End();
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj.user b/SourceCode/Bond/Servo/Servo.vcxproj.user
index 0c03257..82c7903 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj.user
+++ b/SourceCode/Bond/Servo/Servo.vcxproj.user
@@ -7,6 +7,6 @@
     <RemoteDebuggerCommand>\\DESKTOP-IODBVIQ\Servo\Debug\Servo.exe</RemoteDebuggerCommand>
     <RemoteDebuggerWorkingDirectory>\\DESKTOP-IODBVIQ\Servo\Debug\</RemoteDebuggerWorkingDirectory>
     <RemoteDebuggerServerName>DESKTOP-IODBVIQ</RemoteDebuggerServerName>
-    <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
+    <DebuggerFlavor>WindowsRemoteDebugger</DebuggerFlavor>
   </PropertyGroup>
 </Project>
\ No newline at end of file

--
Gitblit v1.9.3