From bc7f1c4e028e69be51079b59dae4ae5c4d43f5bb Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期六, 31 一月 2026 21:54:56 +0800
Subject: [PATCH] 1.状态指示图,目前灰色表示掉线,绿色表示在线。增加Slot的小点表示有没有料,及加工状态 。 2.增加图示

---
 SourceCode/Bond/Servo/CMaster.cpp |  390 ++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 254 insertions(+), 136 deletions(-)

diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 80ce726..d9fb326 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -62,6 +62,7 @@
 		m_ullStartTime = 0;
 		m_ullRunTime = 0;
 		m_state = MASTERSTATE::READY;
+		m_curveMode = CurveMode::Production;
 		m_pActiveRobotTask = nullptr;
 		m_nLastError = ER_CODE_NOERROR;
 		m_isCompareMapsBeforeProceeding = FALSE;
@@ -118,6 +119,7 @@
 			m_hEventDispatchThreadExit[1] = nullptr;
 		}
 
+
 		DeleteCriticalSection(&m_criticalSection);
 	}
 
@@ -153,132 +155,162 @@
 			LOGE("杩炴帴CC-Link澶辫触.");
 		}
 		else {
-				LOGI("杩炴帴CC-Link鎴愬姛.");
-				BoardVersion version{};
-				int nRet = m_cclink.GetBoardVersion(version);
-				if (nRet == 0) {
-					LOGD("鐗堟湰淇℃伅锛�%s.", version.toString().c_str());
-				}
-				else {
-					LOGE("鑾峰彇CC-Link鐗堟湰淇℃伅澶辫触.");
-				}
-
-				BoardStatus status;
-				nRet = m_cclink.GetBoardStatus(status);
-				if (nRet == 0) {
-					LOGD("鐘舵�侊細%s.", status.toString().c_str());
-				}
-				else {
-					LOGE("鑾峰彇CC-Link鐘舵�佸け璐�.");
-				}
+			LOGI("杩炴帴CC-Link鎴愬姛.");
+			BoardVersion version{};
+			int nRet = m_cclink.GetBoardVersion(version);
+			if (nRet == 0) {
+				LOGD("鐗堟湰淇℃伅锛�%s.", version.toString().c_str());
+			}
+			else {
+				LOGE("鑾峰彇CC-Link鐗堟湰淇℃伅澶辫触.");
 			}
 
-
-			// 鍒濆鍖栨坊鍔犲悇瀛愯澶�
-			CLoadPort* pPort1, * pPort2, * pPort3, * pPort4;
-			CBonder* pBonder1, * pBonder2;
-			CEFEM* pEfem;
-			CArm* pArm;
-			CArmTray* pArmTray1, * pArmTray2;
-			CFliper* pFliper;
-			CVacuumBake* pVacuumBake;
-			CAligner* pAligner;
-			CBakeCooling* pBakeCooling;
-			CMeasurement* pMeasurement;
-
-			pPort1 = addLoadPort(0);
-			pPort2 = addLoadPort(1);
-			pPort3 = addLoadPort(2);
-			pPort4 = addLoadPort(3);
-			pEfem = addEFEM();
-			pArm = addArm();
-			pArmTray1 = addArmTray(0);
-			pArmTray2 = addArmTray(1);
-			pFliper = addFliper();
-			pVacuumBake = addVacuumBake();
-			pAligner = addAligner();
-			pBonder1 = addBonder(0);
-			pBonder2 = addBonder(1);
-			pBakeCooling = addBakeCooling();
-			pMeasurement = addMeasurement();
-
-			ASSERT(pEfem);
-			ASSERT(pFliper);
-			ASSERT(pVacuumBake);
-			ASSERT(pAligner);
-			ASSERT(pBonder1);
-			ASSERT(pBonder2);
-			ASSERT(pBakeCooling);
-			ASSERT(pMeasurement);
-
-			pEfem->setPort(0, pPort1);
-			pEfem->setPort(1, pPort2);
-			pEfem->setPort(2, pPort3);
-			pEfem->setPort(3, pPort4);
-			pEfem->setFliper(pFliper);
-			pEfem->setAligner(pAligner);
-			pEfem->setArmTray(0, pArmTray1);
-			pEfem->setArmTray(1, pArmTray2);
-			pPort1->setArm(pArm);
-			pPort2->setArm(pArm);
-			pPort3->setArm(pArm);
-			pPort4->setArm(pArm);
-			pArmTray1->setArm(pArm);
-			pArmTray2->setArm(pArm);
-			pFliper->setArm(pArm);
-			pVacuumBake->setArm(pArm);
-			pAligner->setArm(pArm);
-			pBonder1->setArm(pArm);
-			pBonder2->setArm(pArm);
-			pBakeCooling->setArm(pArm);
-			pMeasurement->setArm(pArm);
-
-			connectEquipments();
-
-
-
-			// 璇荤紦瀛樻暟鎹�
-			const ULONGLONG boot_cache_begin = GetTickCount64();
-			const ULONGLONG boot_read_begin = GetTickCount64();
-			readCache();
-			LOGI("[BOOT][MASTER] readCache finished, cost=%llu ms", (unsigned long long)(GetTickCount64() - boot_read_begin));
-
-			const ULONGLONG boot_state_begin = GetTickCount64();
-			loadState();
-			LOGI("[BOOT][MASTER] loadState finished, cost=%llu ms", (unsigned long long)(GetTickCount64() - boot_state_begin));
-			if (m_listener.onControlJobChanged) {
-				notifyControlJobChanged();
+			BoardStatus status;
+			nRet = m_cclink.GetBoardStatus(status);
+			if (nRet == 0) {
+				LOGD("鐘舵�侊細%s.", status.toString().c_str());
 			}
-
-			LOGI("[BOOT][MASTER] cache/state loaded, cost=%llu ms (since init %llu ms)",
-				(unsigned long long)(GetTickCount64() - boot_cache_begin),
-				(unsigned long long)(GetTickCount64() - boot_master_begin));
-
-
-			// 瀹氭椂鍣�
-			g_pMaster = this;
-			SetTimer(NULL, 1, 250, (TIMERPROC)MasterTimerProc);
-
-
-			// 璋冨害绾跨▼
-			m_hDispatchThreadHandle = (HANDLE)_beginthreadex(NULL, 0, SERVO::DispatchThreadFunction, this,
-				0, &m_nDispatchThreadAddr);
-
-
-			// 鐩戞帶bit绾跨▼
-			m_hReadBitsThreadHandle = (HANDLE)_beginthreadex(NULL, 0, SERVO::ReadBitsThreadFunction, this,
-				0, &m_nReadBitsThreadAddr);
-
-
-			// 鏇茬嚎鏈嶅姟
-			CreateDAQBridgeServer();
-
-
-			LOGI("<Master>鍒濆鍖栧畬鎴�.");
-			LOGI("[BOOT][MASTER] init finished, total cost=%llu ms",
-				(unsigned long long)(GetTickCount64() - boot_master_begin));
-			return 0;
+			else {
+				LOGE("鑾峰彇CC-Link鐘舵�佸け璐�.");
+			}
 		}
+
+
+		// 鍒濆鍖栨坊鍔犲悇瀛愯澶�
+		CLoadPort* pPort1, * pPort2, * pPort3, * pPort4;
+		CBonder* pBonder1, * pBonder2;
+		CEFEM* pEfem;
+		CArm* pArm;
+		CArmTray* pArmTray1, * pArmTray2;
+		CFliper* pFliper;
+		CVacuumBake* pVacuumBake;
+		CAligner* pAligner;
+		CBakeCooling* pBakeCooling;
+		CMeasurement* pMeasurement;
+
+		pPort1 = addLoadPort(0);
+		pPort2 = addLoadPort(1);
+		pPort3 = addLoadPort(2);
+		pPort4 = addLoadPort(3);
+		pEfem = addEFEM();
+		pArm = addArm();
+		pArmTray1 = addArmTray(0);
+		pArmTray2 = addArmTray(1);
+		pFliper = addFliper();
+		pVacuumBake = addVacuumBake();
+		pAligner = addAligner();
+		pBonder1 = addBonder(0);
+		pBonder2 = addBonder(1);
+		pBakeCooling = addBakeCooling();
+		pMeasurement = addMeasurement();
+
+		ASSERT(pEfem);
+		ASSERT(pFliper);
+		ASSERT(pVacuumBake);
+		ASSERT(pAligner);
+		ASSERT(pBonder1);
+		ASSERT(pBonder2);
+		ASSERT(pBakeCooling);
+		ASSERT(pMeasurement);
+
+		pEfem->setPort(0, pPort1);
+		pEfem->setPort(1, pPort2);
+		pEfem->setPort(2, pPort3);
+		pEfem->setPort(3, pPort4);
+		pEfem->setFliper(pFliper);
+		pEfem->setAligner(pAligner);
+		pEfem->setArmTray(0, pArmTray1);
+		pEfem->setArmTray(1, pArmTray2);
+		pPort1->setArm(pArm);
+		pPort2->setArm(pArm);
+		pPort3->setArm(pArm);
+		pPort4->setArm(pArm);
+		pArmTray1->setArm(pArm);
+		pArmTray2->setArm(pArm);
+		pFliper->setArm(pArm);
+		pVacuumBake->setArm(pArm);
+		pAligner->setArm(pArm);
+		pBonder1->setArm(pArm);
+		pBonder2->setArm(pArm);
+		pBakeCooling->setArm(pArm);
+		pMeasurement->setArm(pArm);
+
+		connectEquipments();
+
+
+
+		// 璇荤紦瀛樻暟鎹�
+		const ULONGLONG boot_cache_begin = GetTickCount64();
+		const ULONGLONG boot_read_begin = GetTickCount64();
+		readCache();
+		LOGI("[BOOT][MASTER] readCache finished, cost=%llu ms", (unsigned long long)(GetTickCount64() - boot_read_begin));
+
+		const ULONGLONG boot_state_begin = GetTickCount64();
+		loadState();
+		LOGI("[BOOT][MASTER] loadState finished, cost=%llu ms", (unsigned long long)(GetTickCount64() - boot_state_begin));
+		if (m_listener.onControlJobChanged) {
+			notifyControlJobChanged();
+		}
+
+		LOGI("[BOOT][MASTER] cache/state loaded, cost=%llu ms (since init %llu ms)",
+			(unsigned long long)(GetTickCount64() - boot_cache_begin),
+			(unsigned long long)(GetTickCount64() - boot_master_begin));
+
+
+		// 瀹氭椂鍣�
+		g_pMaster = this;
+		SetTimer(NULL, 1, 250, (TIMERPROC)MasterTimerProc);
+
+
+		// 璋冨害绾跨▼
+		m_hDispatchThreadHandle = (HANDLE)_beginthreadex(NULL, 0, SERVO::DispatchThreadFunction, this,
+			0, &m_nDispatchThreadAddr);
+
+
+		// 鐩戞帶bit绾跨▼
+		m_hReadBitsThreadHandle = (HANDLE)_beginthreadex(NULL, 0, SERVO::ReadBitsThreadFunction, this,
+			0, &m_nReadBitsThreadAddr);
+
+
+		// 鏇茬嚎鏈嶅姟
+		CreateDAQBridgeServer();
+
+
+		LOGI("<Master>鍒濆鍖栧畬鎴�.");
+		LOGI("[BOOT][MASTER] init finished, total cost=%llu ms",
+			(unsigned long long)(GetTickCount64() - boot_master_begin));
+		return 0;
+	}
+
+	void CMaster::setCurveMode(CurveMode mode)
+	{
+		if (m_curveMode == mode) {
+			return;
+		}
+		m_curveMode = mode;
+		if (m_pCollector != nullptr) {
+			const uint32_t mids[] = {
+				MID_Bonder1, MID_Bonder2,
+				MID_VacuumBakeA, MID_VacuumBakeB,
+				MID_BakeCoolingA, MID_BakeCoolingB
+			};
+			for (uint32_t mid : mids) {
+				if (mode == CurveMode::EmptyChamber) {
+					m_pCollector->batchStart(mid, "EMPTY_CHAMBER", 30 * 60 * 1000ULL); // 绌鸿厰妯″紡锛氬惎鍔ㄩ噰鏍锋壒娆�
+				}
+				else {
+					m_pCollector->batchStop(mid);
+					m_pCollector->buffersClear(mid); // 鍒囧洖鐢熶骇妯″紡锛屾竻鎺夌┖鑵旀暟鎹�
+				}
+			}
+		}
+		LOGI("<Master>CurveMode=%s", mode == CurveMode::EmptyChamber ? "EmptyChamber" : "Production");
+	}
+
+	CurveMode CMaster::getCurveMode() const
+	{
+		return m_curveMode;
+	}
 
 	int CMaster::term()
 	{
@@ -305,6 +337,13 @@
 		}
 		m_listEquipment.clear();
 
+		// release manual-remove buffer before glass pool is torn down
+		for (auto* pGlass : m_bufGlass) {
+			if (pGlass != nullptr) {
+				pGlass->release();
+			}
+		}
+		m_bufGlass.clear();
 
 		if (m_pCollector != nullptr) {
 			m_pCollector->stopLoop();
@@ -1699,7 +1738,8 @@
 					m_state == MASTERSTATE::RUNNING_CONTINUOUS_TRANSFER ||
 					m_state == MASTERSTATE::RUNNING_BATCH ||
 					m_state == MASTERSTATE::STARTING);
-			if (!allowSvLog) {
+			const bool allowCurve = allowSvLog || (m_curveMode == CurveMode::EmptyChamber);
+			if (!allowCurve) {
 				return;
 			}
 			CSVData* pSVData = (CSVData*)pData;
@@ -1753,18 +1793,23 @@
 					int paramIndex = mapping.first;
 					int channel = mapping.second;
 
-					if (paramIndex < params.size() && channel - 1 < vacuumbakeTypes.size()) {
+					if (paramIndex < params.size()) {
 						auto& param = params.at(paramIndex);
 						double value = param.getDoubleValue();
-						const std::string& dataType = vacuumbakeTypes[channel - 1];
 						const std::string& paramName = param.getName();
 						const char slotTag = !paramName.empty() ? paramName[0] : '\0';
+						const int typeIndex = (slotTag == 'B') ? (channel - 8) : (channel - 1);
+						if (typeIndex < 0 || typeIndex >= (int)vacuumbakeTypes.size()) {
+							continue;
+						}
+						const int pushChannel = typeIndex + 1;
+						const std::string& dataType = vacuumbakeTypes[typeIndex];
 
 						if (m_pCollector != nullptr) {
 							if (slotTag == 'A')
-								m_pCollector->buffersPush(SlotToMid(eqid, 1), channel, ts, value);
+								m_pCollector->buffersPush(SlotToMid(eqid, 1), pushChannel, ts, value);
 							else if (slotTag == 'B')
-								m_pCollector->buffersPush(SlotToMid(eqid, 2), channel, ts, value);
+								m_pCollector->buffersPush(SlotToMid(eqid, 2), pushChannel, ts, value);
 						}
 
 						// 鏍规嵁鑵斾綋鍓嶇紑鍐欏叆瀵瑰簲 Slot 鐨勭幓鐠�
@@ -1798,20 +1843,25 @@
 					int paramIndex = mapping.first;
 					int channel = mapping.second;
 
-					if (paramIndex < params.size() && channel - 1 < coolingTypes.size()) {
+					if (paramIndex < params.size()) {
 						auto& param = params.at(paramIndex);
 						double value = param.getDoubleValue();
-						const std::string& dataType = coolingTypes[channel - 1];
 						const std::string& paramName = param.getName();
 						const char slotTag = !paramName.empty() ? paramName[0] : '\0';
 						const bool paramIsBake = paramName.find("鐑樼儰") != std::string::npos;
 						const bool paramIsCooling = paramName.find("鍐峰嵈") != std::string::npos;
+						const int typeIndex = (slotTag == 'B') ? (channel - 7) : (channel - 1);
+						if (typeIndex < 0 || typeIndex >= (int)coolingTypes.size()) {
+							continue;
+						}
+						const int pushChannel = typeIndex + 1;
+						const std::string& dataType = coolingTypes[typeIndex];
 
 						if (m_pCollector != nullptr && paramIsBake) {
 							if (slotTag == 'A')
-								m_pCollector->buffersPush(SlotToMid(eqid, 1), channel, ts, value);
+								m_pCollector->buffersPush(SlotToMid(eqid, 1), pushChannel, ts, value);
 							else if (slotTag == 'B')
-								m_pCollector->buffersPush(SlotToMid(eqid, 3), channel, ts, value);
+								m_pCollector->buffersPush(SlotToMid(eqid, 3), pushChannel, ts, value);
 						}
 
 						if (!dataType.empty()) {
@@ -1878,6 +1928,16 @@
 		listener.onReceivedJob = [&](void* pEquipment, int port, CJobDataS* pJobDataS) {
 			if (m_listener.onJobReceived != nullptr) {
 				m_listener.onJobReceived(this, (CEquipment*)pEquipment, port, pJobDataS);
+			}
+		};
+		listener.onSentOutJob = [&](void* pEquipment, int port, CJobDataS* pJobDataS) {
+			if (m_listener.onJobSentOut != nullptr) {
+				m_listener.onJobSentOut(this, (CEquipment*)pEquipment, port, pJobDataS);
+			}
+		};
+		listener.onEqStatusChanged = [&](void* pEquipment, int unitId, int status, int reason) {
+			if (m_listener.onEqStatusChanged != nullptr) {
+				m_listener.onEqStatusChanged(this, (CEquipment*)pEquipment, unitId, status, reason);
 			}
 		};
 		pEquipment->setListener(listener);
@@ -2847,7 +2907,40 @@
 
 		static int pid[] = { EQ_ID_LOADPORT1, EQ_ID_LOADPORT2, EQ_ID_LOADPORT3, EQ_ID_LOADPORT4};
 		CLoadPort* pPort = (CLoadPort*)getEquipment(pid[port]);
-		pPort->sendCassetteCtrlCmd(CCC_PROCESS_START, nullptr, 0, 0, 0, nullptr, nullptr);
+		if (pPort == nullptr) return -1;
+
+		short jobExistence[12] = { 0 };
+		short slotProcess = 0;
+		short jobCount = 0; // 0 = Process All Glass
+		bool anyScheduled = false;
+
+		// Prefer hardware scan map for job existence (first 16 slots).
+		const short scanMap = pPort->getScanCassetteMap();
+		if (scanMap != 0) {
+			jobExistence[0] = scanMap;
+		}
+
+		const int maxSlots = 12 * 16;
+		const int totalSlots = (SLOT_MAX < maxSlots) ? SLOT_MAX : maxSlots;
+		for (int slot = 1; slot <= totalSlots; ++slot) {
+			CGlass* pGlass = pPort->getGlassFromSlot(slot);
+			if (pGlass == nullptr) continue;
+
+			const int wordIndex = (slot - 1) / 16;
+			const int bitIndex = (slot - 1) % 16;
+			jobExistence[wordIndex] = (short)(jobExistence[wordIndex] | (1 << bitIndex));
+
+			if (slot <= 16 && pGlass->isScheduledForProcessing()) {
+				slotProcess = (short)(slotProcess | (1 << bitIndex));
+				anyScheduled = true;
+			}
+		}
+
+		if (!anyScheduled) {
+			slotProcess = jobExistence[0];
+		}
+
+		pPort->sendCassetteCtrlCmd(CCC_PROCESS_START, jobExistence, 12, slotProcess, jobCount, nullptr, nullptr);
 		return 0;
 	}
 
@@ -3435,6 +3528,11 @@
 		}
 		m_pControlJob->abort(description);
 
+		// 鍏堜笂鎶ヤ竴娆$姸鎬佸彉鍖栵紙渚夸簬 PrJobAbort 瑙﹀彂锛�
+		if (m_listener.onControlJobChanged) {
+			notifyControlJobChanged();
+		}
+
 
 		// 閲婃斁Job鐩稿叧
 		for (auto item : m_processJobs) {
@@ -3519,6 +3617,15 @@
 		if (pSlot == nullptr) return false;
 
 		CGlass* pGlass = (CGlass*)pSlot->getContext();
+		if (pGlass == nullptr) return false;
+
+		// Buffer 涓婇檺涓� 1锛氭柊鎼嚭鏃朵涪寮冩棫鐨�
+		if (!m_bufGlass.empty()) {
+			for (auto* oldGlass : m_bufGlass) {
+				if (oldGlass != nullptr) oldGlass->release();
+			}
+			m_bufGlass.clear();
+		}
 		m_bufGlass.push_back(pGlass);
 		pGlass->addRef();
 		pSlot->setContext(nullptr);
@@ -3607,14 +3714,14 @@
 			auto& dataTypes = CServoUtilsTool::getEqDataTypes();
 			auto& bonderTypes = dataTypes[MID_Bonder1];
 			for (size_t i = 0; i < bonderTypes.size(); ++i) {
-				m_pCollector->buffersSetChannelName(MID_Bonder1, i + 1, bonderTypes[i].c_str());
-				m_pCollector->buffersSetChannelName(MID_Bonder2, i + 1, bonderTypes[i].c_str());
+				m_pCollector->buffersSetChannelName(MID_Bonder1, (UINT)i + 1, bonderTypes[(UINT)i].c_str());
+				m_pCollector->buffersSetChannelName(MID_Bonder2, (UINT)i + 1, bonderTypes[(UINT)i].c_str());
 			}
 
 			auto& vacuumbakeTypes = dataTypes[MID_VacuumBakeA];
 			for (size_t i = 0; i < vacuumbakeTypes.size(); ++i) {
-				m_pCollector->buffersSetChannelName(MID_VacuumBakeA, i + 1, vacuumbakeTypes[i].c_str());
-				m_pCollector->buffersSetChannelName(MID_VacuumBakeB, i + 1, vacuumbakeTypes[i].c_str());
+				m_pCollector->buffersSetChannelName(MID_VacuumBakeA, (UINT)i + 1, vacuumbakeTypes[(UINT)i].c_str());
+				m_pCollector->buffersSetChannelName(MID_VacuumBakeB, (UINT)i + 1, vacuumbakeTypes[(UINT)i].c_str());
 			}
 
 			auto& coolingTypes = dataTypes[MID_BakeCoolingA];
@@ -3622,6 +3729,17 @@
 				m_pCollector->buffersSetChannelName(MID_BakeCoolingA, i + 1, coolingTypes[i].c_str());
 				m_pCollector->buffersSetChannelName(MID_BakeCoolingB, i + 1, coolingTypes[i].c_str());
 			}
+
+			if (m_curveMode == CurveMode::EmptyChamber) {
+				const uint32_t mids[] = {
+					MID_Bonder1, MID_Bonder2,
+					MID_VacuumBakeA, MID_VacuumBakeB,
+					MID_BakeCoolingA, MID_BakeCoolingB
+				};
+				for (uint32_t mid : mids) {
+					m_pCollector->batchStart(mid, "EMPTY_CHAMBER", 10 * 60 * 1000ULL);
+				}
+			}
 		}
 	}
 

--
Gitblit v1.9.3