chenluhua1980
2026-01-10 ded981a2ac5dbb456bafce5468d7289bc45e313b
SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -3,6 +3,7 @@
#include "Log.h"
#include "Model.h"
#include "Common.h"
#include "RecipeManager.h"
#include <time.h>
#include <iostream>  
#include <time.h>  
@@ -11,6 +12,7 @@
#include <algorithm>
#include <set>
#include <regex>
#include <sstream>
// ControlState values (keep in sync with Model::ControlState / VariableList.txt)
static constexpr uint8_t kControlStateOnlineRemote = 5;
@@ -587,8 +589,8 @@
   Lock();
   int maxId = 0;
   for (auto v : m_variabels) {
      if (v != nullptr && v->getVarialbleId() > maxId) {
         maxId = v->getVarialbleId();
      if (v != nullptr && static_cast<int>(v->getVarialbleId()) > maxId) {
         maxId = static_cast<int>(v->getVarialbleId());
      }
   }
   outId = maxId + 1;
@@ -1370,6 +1372,12 @@
      else if (nStream == 7 && pHeader->function == 19) {
         replyQueryPPIDList(pMessage);
      }
      else if (nStream == 7 && pHeader->function == 17) {
         replyDeletePPID(pMessage);
      }
      else if (nStream == 7 && pHeader->function == 5) {
         replyProcessProgramRequest(pMessage);
      }
      else if (nStream == 10 && pHeader->function == 3) {
         replyTerminalDisplay(pMessage);
      }
@@ -1409,7 +1417,12 @@
      return -1;
   }
   int nBufSize = file.GetLength();
   ULONGLONG len = file.GetLength();
   if (len > INT_MAX) {
      file.Close();
      return -1;
   }
   int nBufSize = static_cast<int>(len);
   char* pszBuffer = new char[nBufSize];
   file.Read(pszBuffer, nBufSize);
   file.Close();
@@ -2544,6 +2557,86 @@
   return 0;
}
// S7F17 Delete Process Program (PPID list) / S7F18
int CHsmsPassive::replyDeletePPID(IMessage* pRecv)
{
   if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
      return ER_NOTSELECT;
   }
   bool allOk = true;
   const bool deleteAll = (pRecv->getBody() == nullptr || pRecv->getBody()->getSubItemSize() == 0);
   std::vector<std::string> ppids;
   ISECS2Item* pBody = pRecv->getBody();
   const int nCount = pBody ? pBody->getSubItemSize() : 0;
   for (int i = 0; i < nCount; ++i) {
      const char* pszPPID = nullptr;
      if (pBody->getSubItemString(i, pszPPID) && pszPPID != nullptr) {
         ppids.emplace_back(pszPPID);
      }
      else {
         allOk = false;
      }
   }
   if (deleteAll || !ppids.empty()) {
      if (m_listener.onDeletePPID != nullptr) {
         allOk = m_listener.onDeletePPID(this, ppids);
      }
      else {
         // no handler provided; treat as failure
         allOk = false;
         LOGW("<HSMS>DeletePPID request ignored: no onDeletePPID listener");
      }
   }
   replyAck(7, 18, pRecv->getHeader()->systemBytes, allOk ? BYTE(0) : BYTE(1), "ACKC7");
   return 0;
}
// S7F5 Process Program Request -> reply S7F6 with PPID + PPBODY
int CHsmsPassive::replyProcessProgramRequest(IMessage* pRecv)
{
   if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
      return ER_NOTSELECT;
   }
   ISECS2Item* pBody = pRecv->getBody();
   const char* pszPPID = nullptr;
   if (pBody == nullptr || !pBody->getString(pszPPID) || pszPPID == nullptr) {
      return ER_PARAM_ERROR;
   }
   std::string ppid(pszPPID);
   std::string ppbody;
   // 简单聚合:从 RecipeManager 取设备配方,拼成文本
   auto recipeInfo = RecipeManager::getInstance().getRecipeByPPID(ppid);
   if (!recipeInfo.strPPID.empty()) {
      for (const auto& dev : recipeInfo.vecDeviceList) {
         if (!ppbody.empty()) ppbody.append("\n");
         ppbody.append(dev.strDeviceName);
         ppbody.append(",");
         ppbody.append(std::to_string(dev.nRecipeID));
         ppbody.append(",");
         ppbody.append(dev.strRecipeName);
         // 附加参数大小信息(目前缺少具体参数列表)
         ppbody.append(",paramsSize=");
         ppbody.append(std::to_string(dev.paramsRawData.size()));
      }
   }
   IMessage* pMessage = nullptr;
   if (HSMS_Create1Message(pMessage, m_nSessionId, 7, 6, pRecv->getHeader()->systemBytes) != 0 || pMessage == nullptr) {
      return ER_CREATED_MESSAGE;
   }
   ISECS2Item* pRspBody = pMessage->getBody(); // top-level L:2
   pRspBody->addItem(ppid.c_str(), "PPID");
   pRspBody->addItem(ppbody.c_str(), "PPBODY");
   m_pPassive->sendMessage(pMessage);
   LogSecsMessageBrief("<HSMS>[SEND]", pMessage);
   HSMS_Destroy1Message(pMessage);
   return 0;
}
// S7F19
int CHsmsPassive::replyQueryPPIDList(IMessage* pRecv)
{