From f0928d2abc4f3b5875d27b1beeb393cf5edf8c4a Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 24 三月 2025 15:30:38 +0800
Subject: [PATCH] 1.Master数据的缓存,主动关闭程序,或程序闪退,可重启还原。

---
 SourceCode/Bond/Servo/CMaster.cpp |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 8c4f87d..0975cde 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -85,6 +85,10 @@
 		addBakeCooling(listener);
 		connectEquipments();
 
+		
+		// 读缓存数据
+		readCache();
+
 
 		// 定时器
 		g_pMaster = this;
@@ -101,6 +105,8 @@
 		for (auto item : m_listEquipment) {
 			item->term();
 		}
+		saveCache();
+
 
 		return 0;
 	}
@@ -569,6 +575,10 @@
 				}
 			}
 		}
+
+
+		// 自动保存缓存
+		saveCache();
 	}
 
 	void CMaster::connectEquipments()
@@ -643,4 +653,46 @@
 			LOGE("连接BakeCooling-LoadPort4失败");
 		}
 	}
+
+	int CMaster::saveCache()
+	{
+		CFile file;
+		if (!file.Open(m_strFilepath.c_str(), CFile::modeCreate | CFile::modeWrite)) {
+			return -1;
+		}
+
+		CArchive ar(&file, CArchive::store);
+		serialize(ar);
+		ar.Close();
+		file.Close();
+
+		return 0;
+	}
+
+	void CMaster::setCacheFilepath(const char* pszFilepath)
+	{
+		m_strFilepath = pszFilepath;
+	}
+
+	int CMaster::readCache()
+	{
+		CFile file;
+		if (!file.Open(m_strFilepath.c_str(), CFile::modeRead)) {
+			return -1;
+		}
+
+		CArchive ar(&file, CArchive::load);
+		serialize(ar);
+		ar.Close();
+		file.Close();
+
+		return 0;
+	}
+
+	void CMaster::serialize(CArchive& ar)
+	{
+		for (auto item : m_listEquipment) {
+			item->serialize(ar);
+		}
+	}
 }

--
Gitblit v1.9.3