From 421aabbb83aa017f10be255b3b5a2e3f69abb816 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 21 七月 2025 08:50:19 +0800
Subject: [PATCH] 1.none
---
SourceCode/Bond/Servo/HsmsPassive.cpp | 169 ++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 133 insertions(+), 36 deletions(-)
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index 19b97dc..3f52f0e 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -133,26 +133,19 @@
return 0;
}
-void CHsmsPassive::deleteReport(unsigned int RPTID)
+SERVO::CReport* CHsmsPassive::defineReport(unsigned int RPTID, std::vector<unsigned int>& vids)
{
- for (auto it = m_mapValueIdToPRTID.begin(); it != m_mapValueIdToPRTID.end(); ) {
- if (it->second == RPTID) {
- m_mapValueIdToPRTID.erase(it++); // 鏇存柊杩唬鍣�
- }
- else {
- ++it;
+ // 娣诲姞瀹氫箟report
+ SERVO::CReport* pReport = new SERVO::CReport(RPTID, vids);
+ for (auto vid : vids) {
+ SERVO::CVariable* pVariable = getVariable(vid);
+ if (pVariable != nullptr) {
+ pReport->addVariable(pVariable);
}
}
-}
+ m_reports.push_back(pReport);
-void CHsmsPassive::deleteAllReport()
-{
- m_mapValueIdToPRTID.clear();
-}
-
-void CHsmsPassive::defineReport(unsigned int VID, unsigned int RPTID)
-{
- m_mapValueIdToPRTID[VID] = RPTID;
+ return pReport;
}
void CHsmsPassive::OnTimer(UINT nTimerid)
@@ -282,7 +275,7 @@
std::vector<SERVO::CReport*> reports;
int index;
CString strLine, strVariable;
- CString strId, strName, strFormat, strRemark;
+ CString strId;
while (file.ReadString(strLine)) {
if (!std::regex_match((LPTSTR)(LPCTSTR)strLine, pattern)) {
continue;
@@ -296,8 +289,7 @@
strVariable.Delete(strVariable.GetLength() - 1);
auto vids = parseVidList(strVariable);
-
- SERVO::CReport* pReport = new SERVO::CReport(atoi((LPTSTR)(LPCTSTR)strId));
+ SERVO::CReport* pReport = new SERVO::CReport(atoi((LPTSTR)(LPCTSTR)strId), vids);
for (auto vid : vids) {
SERVO::CVariable* pVariable = getVariable(vid);
if (pVariable != nullptr) {
@@ -325,6 +317,30 @@
return m_reports;
}
+SERVO::CReport* CHsmsPassive::getReport(int rptid)
+{
+ for (auto item : m_reports) {
+ if (item->getReportId() == rptid) {
+ return item;
+ }
+ }
+
+ return nullptr;
+}
+
+bool CHsmsPassive::removeReport(int rptid)
+{
+ for (auto iter = m_reports.begin(); iter != m_reports.end(); ++iter) {
+ if ((*iter)->getReportId() == rptid) {
+ delete (*iter);
+ m_reports.erase(iter);
+ return true;
+ }
+ }
+
+ return false;
+}
+
void CHsmsPassive::clearAllReport()
{
for (auto item : m_reports) {
@@ -333,13 +349,85 @@
m_reports.clear();
}
-std::vector<int> CHsmsPassive::parseVidList(CString& strNums)
+int CHsmsPassive::loadCollectionEvents(const char* pszFilepath)
+{
+ CStdioFile file;
+ if (!file.Open(pszFilepath, CFile::modeRead)) {
+ return -1;
+ }
+
+ std::regex pattern("^\\d+,[^,]*,[^,]*,\\(\\d+(,\\d+)*\\).*"); // 鍖归厤浠ユ暟瀛�+閫楀彿寮�澶寸殑瀛楃涓�
+ std::vector<SERVO::CCollectionEvent*> events;
+ int index, last;
+ CString strLine, strRPTIDs;
+ CString strId, strName, strDescription;
+ while (file.ReadString(strLine)) {
+ if (!std::regex_match((LPTSTR)(LPCTSTR)strLine, pattern)) {
+ continue;
+ }
+
+ last = 0;
+ index = strLine.Find(",", last);
+ if (index < 0) continue;
+ strId = strLine.Left(index);
+ last = index + 1;
+
+ index = strLine.Find(",", last);
+ if (index < 0) continue;
+ strName = strLine.Mid(last, index - last);
+ last = index + 1;
+
+ index = strLine.Find(",", last);
+ if (index < 0) continue;
+ strDescription = strLine.Mid(last, index - last);
+ strRPTIDs = strLine.Right(strLine.GetLength() - index - 1);
+ strRPTIDs.Delete(0);
+ strRPTIDs.Delete(strRPTIDs.GetLength() - 1);
+ auto prtids = parseVidList(strRPTIDs);
+
+ SERVO::CCollectionEvent* pEvent = new SERVO::CCollectionEvent(
+ atoi(strId), (LPTSTR)(LPCTSTR)strName, (LPTSTR)(LPCTSTR)strDescription, prtids);
+ for (auto rptid : prtids) {
+ SERVO::CReport* pReport = getReport(rptid);
+ if (pReport != nullptr) {
+ pEvent->addReport(pReport);
+ }
+ }
+ events.push_back(pEvent);
+ }
+
+ if (!events.empty()) {
+ clearAllCollectionEvent();
+ for (auto item : events) {
+ m_collectionEvent.push_back(item);
+ }
+ }
+
+
+ file.Close();
+ return 0;
+}
+
+std::vector<SERVO::CCollectionEvent*>& CHsmsPassive::getCollectionEvents()
+{
+ return m_collectionEvent;
+}
+
+void CHsmsPassive::clearAllCollectionEvent()
+{
+ for (auto item : m_collectionEvent) {
+ delete item;
+ }
+ m_collectionEvent.clear();
+}
+
+std::vector<unsigned int> CHsmsPassive::parseVidList(CString& strNums)
{
// 1. 鍏堝幓鎺夊彲鑳藉嚭鐜扮殑绌虹櫧绗︼紙绌烘牸銆佸埗琛ㄧ绛夛級
strNums.Trim();
// 2锔�.
- std::vector<int> result;
+ std::vector<unsigned int> result;
int i = 0;
CString strVid;
while (1) {
@@ -487,6 +575,8 @@
}
clearAllVariabel();
+ clearAllReport();
+ clearAllCollectionEvent();
return 0;
}
@@ -805,40 +895,47 @@
ISECS2Item* pBody = pRecv->getBody();
ISECS2Item* defineItem, *rptListItem, * vidListItem;
unsigned int dataId, rptid, vid;
+
if (!pBody->getSubItemU4(0, dataId)) goto MYREPLY;
rptListItem = pBody->getSubItem(1);
if (rptListItem == nullptr) goto MYREPLY;
if (rptListItem->getSubItemSize() == 0) {
- deleteAllReport();
+ clearAllReport();
goto MYREPLY;
}
+
for (int i = 0; i < rptListItem->getSubItemSize(); i++) {
defineItem = rptListItem->getSubItem(i);
if (defineItem == nullptr) continue;
+
+ std::vector<unsigned int> vids;
+ SERVO::CReport* pReport = nullptr;
vidListItem = defineItem->getSubItem(1);
if (defineItem->getSubItemU4(0, rptid)
&& vidListItem != nullptr) {
- int vidCount = vidListItem->getSubItemSize();
- if (vidCount == 0) {
- deleteReport(rptid);
- }
- else {
- for (int k = 0; k < vidCount; k++) {
- if (vidListItem->getSubItemU4(k, vid)) {
- defineReport(vid, rptid);
- }
+ for (int k = 0; k < vidListItem->getSubItemSize(); k++) {
+ if (vidListItem->getSubItemU4(k, vid)) {
+ vids.push_back(vid);
}
+ }
+ }
+
+ removeReport(rptid);
+ if (!vids.empty()) {
+ pReport = defineReport(rptid, vids);
+ }
+
+ // 妫�楠岀粨鏋滄槸鍚︽纭�
+ if (pReport != nullptr) {
+ auto variables = pReport->getVariables();
+ for (auto item : variables) {
+ LOGE("=== prtid:%d, vid:%d", rptid, item->getVarialbleId());
}
}
}
MYREPLY:
- // 妫�楠岀粨鏋滄槸鍚︽纭�
- for (auto item : m_mapValueIdToPRTID) {
- LOGE("=== vid:%d, prtid:%d", item.first, item.second);
- }
-
replyAck(2, 34, pRecv->getHeader()->systemBytes, BYTE(0), "DRACK");
return 0;
}
--
Gitblit v1.9.3