From 829fe6c6bc33d53fda9c31fd45a37e1df87befff Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 30 一月 2026 11:16:24 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/Servo/GlassJson.cpp | 69 +++++++++++++++++++++++++++++++++-
1 files changed, 66 insertions(+), 3 deletions(-)
diff --git a/SourceCode/Bond/Servo/GlassJson.cpp b/SourceCode/Bond/Servo/GlassJson.cpp
index e9c54fb..5cbdd6d 100644
--- a/SourceCode/Bond/Servo/GlassJson.cpp
+++ b/SourceCode/Bond/Servo/GlassJson.cpp
@@ -178,6 +178,7 @@
Json::Value n(Json::objectValue);
n["eq_id"] = p->getEqID();
n["unit"] = p->getUnit();
+ n["slot"] = p->getUnit();
put_ull_as_str(n, "time_in", static_cast<unsigned long long>(p->getInTime()));
put_ull_as_str(n, "time_out", static_cast<unsigned long long>(p->getOutTime()));
n["processed"] = p->isProcessEnd() ? true : false;
@@ -189,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;
}
@@ -293,7 +325,8 @@
for (const auto& n : root["path"]) {
unsigned eq = JUInt(n, "eq_id", 0);
unsigned unit = JUInt(n, "unit", 0);
- g.addPath(eq, unit);
+ unsigned slot = JUInt(n, "slot", 0);
+ g.addPath(eq, unit, slot);
CPath* tail = nullptr;
if (auto head = g.getPath()) tail = head->getTailPath();
@@ -304,6 +337,36 @@
if (get_ll_from_json(n, "time_out", tout)) tail->setOutTime(static_cast<ULONGLONG>(tout));
tail->setInspResult(static_cast<InspResult>(JInt(n, "insp_result", 0)));
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);
+ }
+ }
+ }
+ }
}
}
}
@@ -331,4 +394,4 @@
}
FromJson(j, g);
return true;
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3