From bea6407b376a4e426f0b120bae569fba6ab867db Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期六, 08 十一月 2025 17:55:47 +0800
Subject: [PATCH] 1.CMaster.cpp 第 1644/1667/1691 行在记录 SV 曲线时通过 getGlassFromSlot(0) 取玻璃,而各设备的 initSlots() 都是从 1 开始编号(例如 CBonder.cpp (line 408)、CVacuumBake.cpp (line 415) 等)。槽位 0 永远不存在,所以 pGlass 始终是 nullptr,pGlass->addSVData(...) 的分支从未执行。结果 SERVO::CGlass::m_svDatas 里没有任何曲线数据,GlassJson::ToPrettyString 生成的 pretty 字符串也就没有 sv_datas,导出 CSV 时自然读不到曲线。 同一段代码还有一个潜在 Bug:虽然判断了 channel - 1 < bonderTypes.size(),但真正索引却用的是 bonderTypes[channel]。索引偏移会导致数据类型错位,最后一个通道甚至可能越界。即使修正了槽位,这里也需要同步改成 bonderTypes[channel - 1](另外两处 vacuumbakeTypes、coolingTypes 也一样)。
---
SourceCode/Bond/Servo/SECSRuntimeManager.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 109 insertions(+), 3 deletions(-)
diff --git a/SourceCode/Bond/Servo/SECSRuntimeManager.cpp b/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
index 3f8d08a..ccbcf77 100644
--- a/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
+++ b/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
@@ -1401,8 +1401,8 @@
// 创建 EqpPPID 表
std::string createTableSQL =
"CREATE TABLE IF NOT EXISTS EqpPPID ("
- "BitNo INTEGER PRIMARY KEY AUTOINCREMENT, "
- "PPID INTEGER NULL);";
+ "RecipeNo INTEGER PRIMARY KEY, "
+ "PPID TEXT NULL);";
if (!m_pDB->executeQuery(createTableSQL)) {
throw std::runtime_error("Failed to create EqpPPID table.");
}
@@ -1412,7 +1412,7 @@
if (nCount == 0) {
// 插入初始数据(512 行)
for (int nBitNo = 0; nBitNo < 512; ++nBitNo) {
- std::string insertSQL = "INSERT INTO EqpPPID (BitNo) VALUES (" + std::to_string(nBitNo) + ");";
+ std::string insertSQL = "INSERT INTO EqpPPID (RecipeNo) VALUES (" + std::to_string(nBitNo) + ");";
if (!m_pDB->executeQuery(insertSQL)) {
throw std::runtime_error("Failed to insert data into EqpPPID table.");
}
@@ -1420,6 +1420,112 @@
}
}
+std::vector<std::string> SECSRuntimeManager::getAllPPID() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return {};
+ }
+
+ std::string querySQL = "SELECT PPID FROM EqpPPID;";
+ auto rows = m_pDB->fetchResults(querySQL);
+
+ std::vector<std::string> vecResult;
+ for (const auto& row : rows) {
+ vecResult.push_back(row[0]);
+ }
+ return vecResult;
+}
+
+void SECSRuntimeManager::setAllPPID(const std::vector<std::string>& vecPPIDList) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) return;
+
+ // 开启事务
+ m_pDB->executeQuery("BEGIN TRANSACTION;");
+
+ for (size_t i = 0; i < vecPPIDList.size(); ++i) {
+ std::string safePPID = vecPPIDList[i];
+ size_t pos = 0;
+ while ((pos = safePPID.find('\'', pos)) != std::string::npos) {
+ safePPID.insert(pos, 1, '\'');
+ pos += 2;
+ }
+ std::string sql = "UPDATE EqpPPID SET PPID = '" + safePPID + "' WHERE RecipeNo = " + std::to_string(i) + ";";
+ m_pDB->executeQuery(sql);
+ }
+
+ // 提交事务
+ m_pDB->executeQuery("COMMIT;");
+}
+
+bool SECSRuntimeManager::updatePPIDForRecipe(int nRecipeNo, const std::string& strPPID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return false;
+ }
+
+ // 转义单引号,防止 SQL 注入
+ std::string safePPID = strPPID;
+ size_t pos = 0;
+ while ((pos = safePPID.find('\'', pos)) != std::string::npos) {
+ safePPID.insert(pos, 1, '\'');
+ pos += 2;
+ }
+
+ std::string updateSQL = "UPDATE EqpPPID SET PPID = '" + safePPID + "' WHERE RecipeNo = " + std::to_string(nRecipeNo) + ";";
+ return m_pDB->executeQuery(updateSQL);
+}
+
+std::string SECSRuntimeManager::getPPIDForRecipe(int nRecipeNo) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return "";
+ }
+
+ std::string querySQL = "SELECT PPID FROM EqpPPID WHERE RecipeNo = " + std::to_string(nRecipeNo) + ";";
+ std::vector<std::vector<std::string>> results = m_pDB->fetchResults(querySQL);
+ if (!results.empty() && !results[0].empty()) {
+ return results[0][0];
+ }
+
+ return "";
+}
+
+int SECSRuntimeManager::getRecipeForPPID(std::string strPPID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return -1;
+ }
+
+ std::string querySQL = "SELECT RecipeNo FROM EqpPPID WHERE PPID = '" + strPPID + "';";
+ std::vector<std::vector<std::string>> results = m_pDB->fetchResults(querySQL);
+ if (!results.empty() && !results[0].empty()) {
+ return std::stoi(results[0][0]);
+ }
+
+ return -1;
+}
+
+bool SECSRuntimeManager::deletePPIDForRecipe(int nRecipeNo) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return false;
+ }
+
+ std::string deleteSQL = "UPDATE EqpPPID SET PPID = NULL WHERE RecipeNo = " + std::to_string(nRecipeNo) + ";";
+ return m_pDB->executeQuery(deleteSQL);
+}
+
+bool SECSRuntimeManager::deletePPIDForAllRecipes() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return false;
+ }
+
+ std::string deleteSQL = "UPDATE EqpPPID SET PPID = NULL WHERE RecipeNo BETWEEN 0 AND 511;";
+ return m_pDB->executeQuery(deleteSQL);
+}
+
// 初始化 RPTID 表
void SECSRuntimeManager::initRPTIDTable() {
std::lock_guard<std::mutex> lock(m_mutex);
--
Gitblit v1.9.3