From 7ddca21fdb798123239eab9daa390e2702afdff7 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 10 十月 2025 18:02:19 +0800
Subject: [PATCH] 1.ProcessStart和ProcessEnd加调上层时加上SlotNo, 状态也关联到SlotNo, 因为多腔可能 并行工作。 2.加入曲线采集服务端到项目中。

---
 SourceCode/Bond/Servo/CMaster.cpp |  272 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 265 insertions(+), 7 deletions(-)

diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 7b2da65..037d0f5 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -9,6 +9,11 @@
 
 
 namespace SERVO {
+	static inline int64_t now_ms_epoch() {
+		using namespace std::chrono;
+		return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
+	}
+
 	CMaster* g_pMaster = NULL;
 
 	unsigned __stdcall DispatchThreadFunction(LPVOID lpParam)
@@ -262,6 +267,12 @@
 		}
 		m_listEquipment.clear();
 
+
+		if (m_pCollector != nullptr) {
+			m_pCollector->stopLoop();
+			delete m_pCollector;
+			m_pCollector = nullptr;
+		}
 
 		return 0;
 	}
@@ -1481,7 +1492,7 @@
 									m_listener.onCjEnd(this, pJob);
 								}
 
-								completeControlJob("工艺正常完成");
+								completeControlJob();
 							}
 						}
 					}
@@ -1520,8 +1531,20 @@
 				unlock();
 			}
 		};
-		listener.onProcessStateChanged = [&](void* pEquipment, PROCESS_STATE state) -> void {
+		listener.onProcessStateChanged = [&](void* pEquipment, int slotNo, PROCESS_STATE state) -> void {
+			ASSERT(1 <= slotNo && slotNo <= 8);
+			int eqid = ((CEquipment*)pEquipment)->getID();
+			CGlass* pGlass = ((CEquipment*)pEquipment)->getGlassFromSlot(slotNo);
 			LOGI("<Master>onProcessStateChanged<%d>", (int)state);
+			if (state == PROCESS_STATE::Processing) {
+				if (pGlass != nullptr) {
+					m_pCollector->batchStart(eqid,
+						pGlass->getID().c_str(), 10 * 60 * 1000ULL);
+				}
+			}
+			else if (state == PROCESS_STATE::Complete) {
+				m_pCollector->batchStop(eqid);
+			}
 		};
 		listener.onMapMismatch = [&](void* pEquipment, short scanMap, short downMap) {
 			LOGE("<Master-%s>Port InUse, map(%d!=%d)不一致,请检查。",
@@ -1535,17 +1558,58 @@
 				for (auto pj : pjs) {
 					auto carrier = pj->getCarrier(pPort->getCassetteId());
 					if (carrier != nullptr) {
+						carrier->contexts.clear();
 						for (auto slot : carrier->slots) {
 							CGlass* pGlass = pPort->getGlassFromSlot(slot);
 							carrier->contexts.push_back((void*)pGlass);
 							if (pGlass != nullptr) {
 								pGlass->setProcessJob(pj);
+
+								PJWarp& jpWarp = pj->getPjWarp();
+								int nRecipeID = RecipeManager::getInstance().getIdByPPID(pj->recipeSpec());
+								RecipeInfo stRecipeInfo = RecipeManager::getInstance().getRecipeByPPID(pj->recipeSpec());
+								std::vector<DeviceRecipe> vecRecipeInfo = stRecipeInfo.vecDeviceList;
+
+								pGlass->setScheduledForProcessing(jpWarp.checkSlot[slot-1]);
+								pGlass->setType(static_cast<SERVO::MaterialsType>(jpWarp.material[slot-1]));
+
+								SERVO::CJobDataS* pJobDataS = pGlass->getJobDataS();
+								if (pJobDataS != nullptr) {
+									SERVO::CJobDataS* pJobDataS = pGlass->getJobDataS();
+									pJobDataS->setLotId(pj->getLotId().c_str());
+									pJobDataS->setProductId(pj->getProductId().c_str());
+									pJobDataS->setOperationId(pj->getOperationId().c_str());
+									pJobDataS->setMaterialsType(jpWarp.material[slot - 1]);
+									pJobDataS->setMasterRecipe(nRecipeID);
+									for (const auto& info : vecRecipeInfo) {
+										const std::string& name = info.strDeviceName;
+										short nRecipeID = (short)info.nRecipeID;
+
+										if (name == EQ_NAME_EFEM) {
+											pJobDataS->setDeviceRecipeId(0, nRecipeID);
+										}
+										else if (name == EQ_NAME_BONDER1) {
+											pJobDataS->setDeviceRecipeId(1, nRecipeID);
+										}
+										else if (name == EQ_NAME_BONDER2) {
+											pJobDataS->setDeviceRecipeId(2, nRecipeID);
+										}
+										else if (name == EQ_NAME_BAKE_COOLING) {
+											pJobDataS->setDeviceRecipeId(3, nRecipeID);
+										}
+										else if (name == EQ_NAME_VACUUMBAKE) {
+											pJobDataS->setDeviceRecipeId(4, nRecipeID);
+										}
+										else if (name == EQ_NAME_MEASUREMENT) {
+											pJobDataS->setDeviceRecipeId(5, nRecipeID);
+										}
+									}
+
+								}
 							}
 						}
 					}
 				}
-
-
 			}
 			
 			if (m_listener.onLoadPortStatusChanged != nullptr) {
@@ -1558,6 +1622,61 @@
 			std::vector<CParam> params;
 			((CEquipment*)pEquipment)->parsingSVData((const char*)rawData.data(), rawData.size(), params);
 		
+
+			// 以下加入到曲线数据中
+			const int64_t ts = now_ms_epoch();
+			int eqid = ((CEquipment*)pEquipment)->getID();
+			if (eqid == EQ_ID_Bonder1 || eqid == EQ_ID_Bonder2) {
+				m_pCollector->buffersPush(eqid, 1, ts, params.at(1).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 2, ts, params.at(2).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 3, ts, params.at(3).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 4, ts, params.at(4).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 5, ts, params.at(5).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 6, ts, params.at(6).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 7, ts, params.at(7).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 8, ts, params.at(8).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 9, ts, params.at(9).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 10, ts, params.at(10).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 11, ts, params.at(11).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 12, ts, params.at(12).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 13, ts, params.at(13).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 14, ts, params.at(14).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 15, ts, params.at(15).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 16, ts, params.at(16).getDoubleValue());
+			}
+			else if (eqid == EQ_ID_VACUUMBAKE) {
+				m_pCollector->buffersPush(eqid, 1, ts, params.at(1).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 2, ts, params.at(2).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 3, ts, params.at(3).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 4, ts, params.at(4).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 5, ts, params.at(5).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 6, ts, params.at(6).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 7, ts, params.at(7).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 8, ts, params.at(10).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 9, ts, params.at(11).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 10, ts, params.at(12).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 11, ts, params.at(13).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 12, ts, params.at(14).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 13, ts, params.at(15).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 14, ts, params.at(16).getDoubleValue());
+			}
+			else if (eqid == EQ_ID_BAKE_COOLING) {
+				m_pCollector->buffersPush(eqid, 1, ts, params.at(1).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 2, ts, params.at(2).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 3, ts, params.at(3).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 4, ts, params.at(4).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 5, ts, params.at(5).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 6, ts, params.at(6).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 7, ts, params.at(11).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 8, ts, params.at(12).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 9, ts, params.at(13).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 10, ts, params.at(14).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 11, ts, params.at(15).getDoubleValue());
+				m_pCollector->buffersPush(eqid, 12, ts, params.at(16).getDoubleValue());
+			}
+
+
+			// 以下是输出测试
 			std::string strOut;
 			char szBuffer[256];
 			for (auto p : params) {
@@ -2270,11 +2389,19 @@
 		return 0;
 	}
 
-	void CMaster::setPortType(unsigned int index, BOOL enable, int type, int mode,
-		int cassetteType, int transferMode, BOOL autoChangeEnable)
+	void CMaster::setPortType(unsigned int index, int type)
 	{
 		ASSERT(index < 4);
 		int eqid[] = { EQ_ID_LOADPORT1, EQ_ID_LOADPORT2, EQ_ID_LOADPORT3, EQ_ID_LOADPORT4};
+		CLoadPort* pPort = (CLoadPort*)getEquipment(eqid[index]);
+		pPort->localSetPortType((SERVO::PortType)type);
+	}
+
+	void CMaster::setPortTypeEx(unsigned int index, BOOL enable, int type, int mode,
+		int cassetteType, int transferMode, BOOL autoChangeEnable)
+	{
+		ASSERT(index < 4);
+		int eqid[] = { EQ_ID_LOADPORT1, EQ_ID_LOADPORT2, EQ_ID_LOADPORT3, EQ_ID_LOADPORT4 };
 		CLoadPort* pPort = (CLoadPort*)getEquipment(eqid[index]);
 		pPort->localEanblePort(enable);
 		pPort->localSetPortType((SERVO::PortType)type);
@@ -2781,7 +2908,43 @@
 	}
 
 
-	bool CMaster::completeControlJob(std::string description)
+	bool CMaster::completeControlJob()
+	{
+		if (m_pControlJob == nullptr) {
+			return false;
+		}
+		for (auto item : m_processJobs) {
+			if (item->state() != PJState::Completed) return false;
+		}
+		if (m_pControlJob->state() != CJState::Completed)
+			return false;
+
+
+
+		// 释放Job相关
+		for (auto item : m_processJobs) {
+			delete item;
+		}
+		m_processJobs.clear();
+		if (m_pControlJob != nullptr) {
+			delete m_pControlJob;
+			m_pControlJob = nullptr;
+		}
+
+		// 注意要释放引用
+		m_inProcesJobs.clear();
+		m_completeProcessJobs.clear();
+		m_queueGlasses.clear();
+		m_inProcesGlasses.clear();
+		m_completeGlasses.clear();
+
+
+		saveState();
+
+		return true;
+	}
+
+	bool CMaster::forceCompleteControlJob(std::string description)
 	{
 		if (m_pControlJob == nullptr || m_state != SERVO::MASTERSTATE::READY) {
 			return false;
@@ -2923,4 +3086,99 @@
 
 		return nullptr;
 	}
+
+	void CMaster::CreateDAQBridgeServer()
+	{
+		auto connectionStatusCallback = [&](int code, const std::string& status) {
+			LOGI("<DAQBridge>status:", status.c_str());
+		};
+		auto rawDataCallback = [](const std::vector<uint8_t>& bytes) {
+
+		};
+
+		// 事件:有人连入/断开就上日志
+		auto clieintEventCallback = [](const std::string& ip, uint16_t port, bool connected) {
+			LOGI("<DAQBridge>[Client %s] %s:%u", connected ? _T("JOIN") : _T("LEAVE"), ip.c_str(), port);
+		};
+
+		if (m_pCollector == nullptr) {
+			m_pCollector = new Collector();
+			m_pCollector->setConnectionStatusCallback(connectionStatusCallback);
+			m_pCollector->setRawDataCallback(rawDataCallback);
+			m_pCollector->setClientEventCallback(clieintEventCallback);
+			m_pCollector->createServer(8081);
+			m_pCollector->startLoop(10);
+
+			// 1) 注册机台(推荐:先注册 id + 机器名称)
+			RetentionPolicy defP; defP.mode = RetainMode::ByCount; defP.maxSamples = 200;
+			m_pCollector->registryAddMachine(EQ_ID_Bonder1, "Bonder1", defP);
+			m_pCollector->registryAddMachine(EQ_ID_Bonder2, "Bonder2", defP);
+			m_pCollector->registryAddMachine(EQ_ID_VACUUMBAKE, "前烘烤", defP);
+			m_pCollector->registryAddMachine(EQ_ID_BAKE_COOLING, "烘烤冷却", defP);
+
+
+			// 2) 为通道设置“曲线名称”
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 1, "气囊压力");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 2, "上腔压力");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 3, "管道真空规值");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 4, "腔体真空规值");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 5, "上腔温度1");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 6, "上腔温度2");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 7, "上腔温度3");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 8, "上腔温度4");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 9, "上腔温度5");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 10, "上腔温度6");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 11, "下腔温度1");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 12, "下腔温度2");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 13, "下腔温度3");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 14, "下腔温度4");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 15, "下腔温度5");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, 16, "下腔温度6");
+
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 1, "气囊压力");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 2, "上腔压力");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 3, "管道真空规值");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 4, "腔体真空规值");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 5, "上腔温度1");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 6, "上腔温度2");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 7, "上腔温度3");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 8, "上腔温度4");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 9, "上腔温度5");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 10, "上腔温度6");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 11, "下腔温度1");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 12, "下腔温度2");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 13, "下腔温度3");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 14, "下腔温度4");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 15, "下腔温度5");
+			m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, 16, "下腔温度6");
+
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 1, "A腔真空规值");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 2, "A腔温控1");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 3, "A腔温控2");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 4, "A腔温控4");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 5, "A腔温控5");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 6, "A腔温控6");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 7, "A腔温控7");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 8, "B腔真空规值");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 9, "B腔温控1");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 10, "B腔温控2");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 11, "B腔温控4");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 12, "B腔温控5");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 13, "B腔温控6");
+			m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, 14, "B腔温控7");
+
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 1, "A烘烤温控1");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 2, "A烘烤温控2");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 3, "A烘烤温控4");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 4, "A烘烤温控5");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 5, "A烘烤温控6");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 6, "A烘烤温控7");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 7, "B烘烤温控1");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 8, "B烘烤温控2");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 9, "B烘烤温控4");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 10, "B烘烤温控5");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 11, "B烘烤温控6");
+			m_pCollector->buffersSetChannelName(EQ_ID_BAKE_COOLING, 12, "B烘烤温控7");
+		}
+	}
 }

--
Gitblit v1.9.3