LAPTOP-SNT8I5JK\Boounion
2025-07-14 375342c11638685d6b7fecc2a979825c56d770f9
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;
}