LAPTOP-SNT8I5JK\Boounion
2025-09-19 81df82be1f5f401b80780f65e5811685d9a8e4c4
SourceCode/Bond/Servo/CMaster.cpp
@@ -213,10 +213,9 @@
      // 读缓存数据
      readCache();
      loadState();
      // 定时器
@@ -2576,13 +2575,9 @@
      return true;
   }
   bool CMaster::loadState(const std::string& path)
   bool CMaster::loadState()
   {
      // 保存文件路径
      m_strStatePath = path;
      std::ifstream ifs(path, std::ios::binary);
      std::ifstream ifs(m_strStatePath, std::ios::binary);
      if (!ifs) return false;
      // 文件头
@@ -2635,10 +2630,33 @@
      m_pControlJob->setPJs(tempPjs);
      // 更新contexts
      auto pjs = m_pControlJob->getPjs();
      for (auto pj : pjs) {
         for (auto& c : pj->carriers()) {
            auto p = getPortWithCarrierId(c.carrierId);
            if (p == nullptr) continue;
            std::vector<void*> contexts;
            for (auto s : c.slots) {
               auto g = getGlass(p->getIndex(), s - 1);
               if (g == nullptr) continue;
               contexts.push_back(g);
            }
            pj->setCarrierContexts(c.carrierId, contexts);
         }
      }
      // 如果版本升级,可在这里判断 version 来加载新字段
      return true;
   }
   void CMaster::setStateFile(const std::string& path)
   {
      m_strStatePath = path;
   }
   CProcessJob* CMaster::acquireNextProcessJob()
@@ -2899,4 +2917,21 @@
      return true;
   }
   CGlass* CMaster::getGlass(int scrPort, int scrSlot)
   {
      for (auto eq : m_listEquipment) {
         std::vector<CGlass*> glasses;
         eq->getAllGlass(glasses);
         for (auto g : glasses) {
            int p, s;
            g->getOrginPort(p, s);
            if (p == scrPort && s == scrSlot) {
               return g;
            }
         }
      }
      return nullptr;
   }
}