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/GlassJson.cpp | 65 +++++++++++++++++++++++++++++++-
1 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/SourceCode/Bond/Servo/GlassJson.cpp b/SourceCode/Bond/Servo/GlassJson.cpp
index 91e7bed..5cbdd6d 100644
--- a/SourceCode/Bond/Servo/GlassJson.cpp
+++ b/SourceCode/Bond/Servo/GlassJson.cpp
@@ -190,7 +190,38 @@
root["path"] = std::move(arr);
}
- root["payload_version"] = 1;
+ // SV数据:三层结构序列化
+ {
+ Json::Value svDataObj(Json::objectValue);
+ const auto& allSVData = g.getAllSVData();
+
+ for (const auto& machinePair : allSVData) {
+ int machineId = machinePair.first;
+ const auto& dataTypes = machinePair.second;
+
+ Json::Value machineObj(Json::objectValue);
+ for (const auto& dataTypePair : dataTypes) {
+ const std::string& dataType = dataTypePair.first;
+ const auto& dataItems = dataTypePair.second;
+
+ Json::Value dataArray(Json::arrayValue);
+ for (const auto& item : dataItems) {
+ Json::Value itemObj(Json::objectValue);
+ // 时间戳转换为毫秒字符串
+ auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
+ item.timestamp.time_since_epoch()).count();
+ itemObj["t"] = std::to_string(ms);
+ itemObj["v"] = item.value;
+ dataArray.append(itemObj);
+ }
+ machineObj[dataType] = dataArray;
+ }
+ svDataObj[std::to_string(machineId)] = machineObj;
+ }
+ root["sv_datas"] = svDataObj;
+ }
+
+ root["payload_version"] = 2; // 版本升级,因为新增了sv_datas字段
return root;
}
@@ -308,6 +339,36 @@
if (JBool(n, "processed", false)) tail->processEnd();
}
}
+
+ // SV数据:反序列化三层结构
+ if (root.isMember("sv_datas") && root["sv_datas"].isObject()) {
+ g.clearAllSVData(); // 清空现有数据
+
+ const auto& svDataObj = root["sv_datas"];
+ auto memberNames = svDataObj.getMemberNames();
+
+ for (const auto& machineIdStr : memberNames) {
+ int machineId = std::stoi(machineIdStr);
+ const auto& machineObj = svDataObj[machineIdStr];
+
+ auto dataTypeNames = machineObj.getMemberNames();
+ for (const auto& dataType : dataTypeNames) {
+ const auto& dataArray = machineObj[dataType];
+ if (dataArray.isArray()) {
+ for (const auto& itemObj : dataArray) {
+ long long timestampMs = 0;
+ double value = 0.0;
+
+ if (get_ll_from_json(itemObj, "t", timestampMs)) {
+ value = JDouble(itemObj, "v", 0.0);
+ // 添加SV数据
+ g.addSVData(machineId, dataType, timestampMs, value);
+ }
+ }
+ }
+ }
+ }
+ }
}
// ==================== 便捷封装 ====================
@@ -333,4 +394,4 @@
}
FromJson(j, g);
return true;
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3