From fe1539643b86cebb50b44c59ae4b7809a165dc6c Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期四, 11 十二月 2025 15:13:08 +0800
Subject: [PATCH] 1.事件的新增和编辑;

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

diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index e11cc50..fc512d9 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -1020,6 +1020,17 @@
 	return m_collectionEvents;
 }
 
+unsigned int CHsmsPassive::getMaxCollectionEventId() const
+{
+	unsigned int maxId = 0;
+	for (auto item : m_collectionEvents) {
+		if (item && item->getEventId() > maxId) {
+			maxId = item->getEventId();
+		}
+	}
+	return maxId;
+}
+
 int CHsmsPassive::deleteCollectionEvent(unsigned short CEID)
 {
 	for (auto iter = m_collectionEvents.begin(); iter != m_collectionEvents.end(); ++iter) {
@@ -1032,6 +1043,41 @@
 	return -1;
 }
 
+int CHsmsPassive::addCollectionEvent(unsigned int CEID, const char* name, const char* desc, const std::vector<unsigned int>& rptids)
+{
+	if (getEvent((unsigned short)CEID) != nullptr) {
+		return -1;
+	}
+	auto* pEvent = new SERVO::CCollectionEvent(CEID, name, desc, const_cast<std::vector<unsigned int>&>(rptids));
+	for (auto rptid : rptids) {
+		SERVO::CReport* pReport = getReport((int)rptid);
+		if (pReport != nullptr) {
+			pEvent->addReport(pReport);
+		}
+	}
+	m_collectionEvents.push_back(pEvent);
+	return writeCollectionEventsToFile(m_strCollectionEventFilepath);
+}
+
+int CHsmsPassive::updateCollectionEvent(unsigned int CEID, const char* name, const char* desc, const std::vector<unsigned int>& rptids)
+{
+	for (auto iter = m_collectionEvents.begin(); iter != m_collectionEvents.end(); ++iter) {
+		if ((*iter)->getEventId() == CEID) {
+			delete (*iter);
+			auto* pEvent = new SERVO::CCollectionEvent(CEID, name, desc, const_cast<std::vector<unsigned int>&>(rptids));
+			for (auto rptid : rptids) {
+				SERVO::CReport* pReport = getReport((int)rptid);
+				if (pReport != nullptr) {
+					pEvent->addReport(pReport);
+				}
+			}
+			*iter = pEvent;
+			return writeCollectionEventsToFile(m_strCollectionEventFilepath);
+		}
+	}
+	return -1;
+}
+
 void CHsmsPassive::clearAllCollectionEvent()
 {
 	for (auto item : m_collectionEvents) {

--
Gitblit v1.9.3