From 375342c11638685d6b7fecc2a979825c56d770f9 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 14 七月 2025 17:57:15 +0800
Subject: [PATCH] 1.CCollectionEvent,CLoadPort, CVariable类实现; 2.从.txt或csv中加载CVariable列表; 3.添加菜单,准备添加相关查看或编辑 CVariable列表的界面;
---
SourceCode/Bond/Servo/HsmsPassive.cpp | 61 ++++++++++++++++++++++++++++++
1 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index 5660bf7..edcb481 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -8,6 +8,7 @@
#include <time.h>
#include <stdlib.h>
#include <string.h>
+#include <regex>
const char ACK[2] = {0, 1};
@@ -195,6 +196,64 @@
return 0;
}
+int CHsmsPassive::loadVarialbleList(const char* pszFilepath)
+{
+ CStdioFile file;
+ if (!file.Open(pszFilepath, CFile::modeRead)) {
+ return -1;
+ }
+
+ std::regex pattern("^\\d+,.*"); // 匹配以数字+逗号开头的字符串
+ std::vector<SERVO::CVariable*> variables;
+ int index, last;
+ CString strLine;
+ CString strId, strName, strFormat, strRemark;
+ 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;
+ strFormat = strLine.Mid(last, index - last);
+ strRemark = strLine.Right(strLine.GetLength() - index - 1);
+
+ SERVO::CVariable* pVarialble = new SERVO::CVariable(
+ (LPTSTR)(LPCTSTR)strId, (LPTSTR)(LPCTSTR)strName, (LPTSTR)(LPCTSTR)strFormat, (LPTSTR)(LPCTSTR)strRemark);
+ variables.push_back(pVarialble);
+ }
+
+ if (!variables.empty()) {
+ clearAllVariabel();
+ for (auto item : variables) {
+ m_variabels.push_back(item);
+ }
+ }
+
+
+ file.Close();
+ return 0;
+}
+
+void CHsmsPassive::clearAllVariabel()
+{
+ for (auto item : m_variabels) {
+ delete item;
+ }
+ m_variabels.clear();
+}
+
int CHsmsPassive::init(CModel* pModel, const char* pszName, unsigned int port)
{
m_pModel = pModel;
@@ -326,6 +385,8 @@
m_pPassive = NULL;
}
+ clearAllVariabel();
+
return 0;
}
--
Gitblit v1.9.3