From df4d0e875ccfe40add25100a75dedee54e566aaa Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 18 九月 2025 09:06:24 +0800
Subject: [PATCH] 1.CConrolJobManagerDlg临时数据存储。

---
 SourceCode/Bond/Servo/CRecipeList.cpp |   96 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 94 insertions(+), 2 deletions(-)

diff --git a/SourceCode/Bond/Servo/CRecipeList.cpp b/SourceCode/Bond/Servo/CRecipeList.cpp
index 5f1fbd1..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 {
@@ -53,6 +54,8 @@
 		}
 
 		if (m_nCurrentGroupCount == m_nToatlGroupCount) {
+			m_nToatlGroupCount = 0;
+			m_nCurrentGroupCount = 0;
 			return MRLRC_CURRENT_RECIPE_COMPLETE;
 		}
 
@@ -90,17 +93,23 @@
 		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) {
-			reset();
+			reset2();
 			return MRLRC_GROUP_COUNT_NG;
 		}
 		if (currentGroup == 0) {
-			reset();
+			reset2();
 		}
 		if (m_nCurrentGroupCount + 1 > currentGroup) {
 			return MRLRC_DUPLICATION_GROUP_COUNT_NG;
@@ -113,6 +122,8 @@
 		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;
 		}
 
@@ -120,4 +131,85 @@
 		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*>(&paramsSize), 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*>(&paramsSize), 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