LAPTOP-SNT8I5JK\Boounion
2025-07-16 789af4f4a7baee07bd6c2c03588afcb19555343b
SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -282,7 +282,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;
@@ -324,12 +324,95 @@
   return m_reports;
}
SERVO::CReport* CHsmsPassive::getReport(int rptid)
{
   for (auto item : m_reports) {
      if (item->getReportId() == rptid) {
         return item;
      }
   }
   return nullptr;
}
void CHsmsPassive::clearAllReport()
{
   for (auto item : m_reports) {
      delete item;
   }
   m_reports.clear();
}
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)
@@ -487,6 +570,7 @@
   clearAllVariabel();
   clearAllReport();
   clearAllCollectionEvent();
   return 0;
}