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/CRecipeList.cpp | 140 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 137 insertions(+), 3 deletions(-)
diff --git a/SourceCode/Bond/Servo/CRecipeList.cpp b/SourceCode/Bond/Servo/CRecipeList.cpp
index 4d8e7d0..1bbe31c 100644
--- a/SourceCode/Bond/Servo/CRecipeList.cpp
+++ b/SourceCode/Bond/Servo/CRecipeList.cpp
@@ -2,6 +2,7 @@
#include "CRecipeList.h"
#include "Common.h"
#include "ToolUnits.h"
+#include <fstream>
namespace SERVO {
@@ -26,12 +27,15 @@
return m_nUnitNo;
}
- int CRecipeList::addRecipePacket(int totalGroup, int currentGroup, const char* pszData, size_t size)
+ int CRecipeList::addRecipePacket(int totalCount, int totalGroup, int currentGroup, const char* pszData, size_t size)
{
if (m_nToatlGroupCount == 0) m_nToatlGroupCount = totalGroup;
if (m_nToatlGroupCount != totalGroup) {
reset();
return MRLRC_GROUP_COUNT_NG;
+ }
+ if (currentGroup == 0) {
+ reset();
}
if (m_nCurrentGroupCount + 1 > currentGroup) {
return MRLRC_DUPLICATION_GROUP_COUNT_NG;
@@ -44,10 +48,14 @@
for (int i = 0; i < size; i += 4) {
int index = CToolUnits::toInt16(&pszData[i]);
short id = CToolUnits::toInt16(&pszData[i + 2]);
- addRecipe(index, id);
+ if (index != 0 && id != 0) {
+ addRecipe(index, id);
+ }
}
if (m_nCurrentGroupCount == m_nToatlGroupCount) {
+ m_nToatlGroupCount = 0;
+ m_nCurrentGroupCount = 0;
return MRLRC_CURRENT_RECIPE_COMPLETE;
}
@@ -64,7 +72,7 @@
}
m_ids[index] = id;
- return 0;
+ return (int)m_ids.size();
}
std::map<int, short>& CRecipeList::getIds()
@@ -72,10 +80,136 @@
return m_ids;
}
+ std::unordered_map<short, std::vector<uint8_t>>& CRecipeList::getParamsRawData()
+ {
+ return m_paramsRawData;
+ }
+
void CRecipeList::reset()
{
m_nToatlGroupCount = 0;
m_nCurrentGroupCount = 0;
m_ids.clear();
+ m_paramsRawData.clear();
+ }
+
+ void CRecipeList::reset2()
+ {
+ m_nToatlGroupCount = 0;
+ m_nCurrentGroupCount = 0;
+ }
+
+ int CRecipeList::addParamsPacket(int totalCount, int totalGroup, int currentGroup,
+ short unitId, short recipeId,
+ const char* pszData, size_t size)
+ {
+ if (m_nToatlGroupCount == 0) m_nToatlGroupCount = totalGroup;
+ if (m_nToatlGroupCount != totalGroup) {
+ reset2();
+ return MRLRC_GROUP_COUNT_NG;
+ }
+ if (currentGroup == 0) {
+ reset2();
+ }
+ if (m_nCurrentGroupCount + 1 > currentGroup) {
+ return MRLRC_DUPLICATION_GROUP_COUNT_NG;
+ }
+ if (m_nCurrentGroupCount + 1 < currentGroup) {
+ return ORDER_BY_GROUP_COUNT_NG;
+ }
+ m_nCurrentGroupCount++;
+
+ m_paramsRawData[recipeId].insert(m_paramsRawData[recipeId].end(), (uint8_t*)(pszData), (uint8_t*)(pszData) + size);
+ if (m_nCurrentGroupCount == m_nToatlGroupCount) {
+ // 解释数据就交给应用层吧
+ reset2();
+
+ return MRLRC_CURRENT_RECIPE_COMPLETE;
+ }
+
+
+ return MRLRC_CONTINUE;
+ }
+
+ // 序列化
+ bool CRecipeList::serialize(const std::string& filename) const
+ {
+ std::ofstream ofs(filename, std::ios::binary);
+ if (!ofs) return false;
+
+ // 写基本成员
+ ofs.write(reinterpret_cast<const char*>(&m_nUnitNo), sizeof(m_nUnitNo));
+ ofs.write(reinterpret_cast<const char*>(&m_nToatlGroupCount), sizeof(m_nToatlGroupCount));
+ ofs.write(reinterpret_cast<const char*>(&m_nCurrentGroupCount), sizeof(m_nCurrentGroupCount));
+
+ // 写 m_ids
+ size_t idsSize = m_ids.size();
+ ofs.write(reinterpret_cast<const char*>(&idsSize), sizeof(idsSize));
+ for (auto& kv : m_ids) {
+ ofs.write(reinterpret_cast<const char*>(&kv.first), sizeof(kv.first));
+ ofs.write(reinterpret_cast<const char*>(&kv.second), sizeof(kv.second));
+ }
+
+ // 写 m_paramsRawData
+ size_t paramsSize = m_paramsRawData.size();
+ ofs.write(reinterpret_cast<const char*>(¶msSize), sizeof(paramsSize));
+ for (auto& kv : m_paramsRawData) {
+ // 写 key
+ ofs.write(reinterpret_cast<const char*>(&kv.first), sizeof(kv.first));
+
+ // 写 vector 大小
+ size_t vecSize = kv.second.size();
+ ofs.write(reinterpret_cast<const char*>(&vecSize), sizeof(vecSize));
+
+ // 写 vector 内容
+ if (!kv.second.empty()) {
+ ofs.write(reinterpret_cast<const char*>(kv.second.data()), vecSize);
+ }
+ }
+
+ return true;
+ }
+
+ // 反序列化
+ bool CRecipeList::deserialize(const std::string& filename)
+ {
+ std::ifstream ifs(filename, std::ios::binary);
+ if (!ifs) return false;
+
+ reset(); // 清空旧数据
+
+ // 读基本成员
+ ifs.read(reinterpret_cast<char*>(&m_nUnitNo), sizeof(m_nUnitNo));
+ ifs.read(reinterpret_cast<char*>(&m_nToatlGroupCount), sizeof(m_nToatlGroupCount));
+ ifs.read(reinterpret_cast<char*>(&m_nCurrentGroupCount), sizeof(m_nCurrentGroupCount));
+
+ // 读 m_ids
+ size_t idsSize = 0;
+ ifs.read(reinterpret_cast<char*>(&idsSize), sizeof(idsSize));
+ for (size_t i = 0; i < idsSize; ++i) {
+ int key;
+ short value;
+ ifs.read(reinterpret_cast<char*>(&key), sizeof(key));
+ ifs.read(reinterpret_cast<char*>(&value), sizeof(value));
+ m_ids[key] = value;
+ }
+
+ // 读 m_paramsRawData
+ size_t paramsSize = 0;
+ ifs.read(reinterpret_cast<char*>(¶msSize), sizeof(paramsSize));
+ for (size_t i = 0; i < paramsSize; ++i) {
+ short key;
+ size_t vecSize = 0;
+ ifs.read(reinterpret_cast<char*>(&key), sizeof(key));
+ ifs.read(reinterpret_cast<char*>(&vecSize), sizeof(vecSize));
+
+ std::vector<uint8_t> buffer(vecSize);
+ if (vecSize > 0) {
+ ifs.read(reinterpret_cast<char*>(buffer.data()), vecSize);
+ }
+ m_paramsRawData[key] = std::move(buffer);
+ }
+
+ return true;
}
}
--
Gitblit v1.9.3