chenluhua1980
2025-12-15 cacf29e9e6a5c080688e25e87850ddfb5148f0f2
SourceCode/Bond/Servo/CLoadPort.cpp
@@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "CLoadPort.h"
#include "CGlassPool.h"
#include "Servo.h"
@@ -17,6 +17,7 @@
      m_bAutoChangeEnable = FALSE;
      m_nNextCassetteSequenceNo = 0;
      m_isCompareMapsBeforeProceeding = FALSE;
      m_downloadCassetteMap = 0;
   }
   CLoadPort::~CLoadPort()
@@ -40,16 +41,16 @@
      CEquipment::term();
   }
   // 必须要实现的虚函数,在此初始化Pin列表
   // 必须要实现的虚函数,在此初始化Pin列表
   void CLoadPort::initPins()
   {
      // 加入Pin初始化代码
      // 加入Pin初始化代码
      LOGD("<CLoadPort>initPins");
      addPin(SERVO::PinType::INPUT, _T("In"));
      addPin(SERVO::PinType::OUTPUT, _T("Out"));
   }
   // 必须要实现的虚函数,在此初始化Slot信息
   // 必须要实现的虚函数,在此初始化Slot信息
   void CLoadPort::initSlots()
   {
      for (int i = 0; i < SLOT_MAX; i++) {
@@ -351,7 +352,7 @@
      CEquipment::onTimer(nTimerid);
      // 从配置读出的enable,初始化时写给efem
      // 从配置读出的enable,初始化时写给efem
      static int i_enable[4] = { 0 };
      if ((++i_enable[m_nIndex]) == 20 + m_nIndex) {
         eablePort(m_bEnable, [&](int code) -> int {
@@ -362,7 +363,7 @@
      // 模拟测试
      // 模拟测试
      /*
      if (m_nIndex == 0) {
         static int ii = 0;
@@ -505,6 +506,9 @@
   void CLoadPort::setIndex(unsigned int index)
   {
      m_nIndex = index;
      std::string id = "Port" + std::to_string(index + 1);
      m_portStatusReport.setCassetteId(id.c_str());
   }
   unsigned int CLoadPort::getIndex()
@@ -931,7 +935,7 @@
      m_portStatusReport.copyEx(portStatusReport);
      // 当port状态为InUse, 比较map
      // 当port状态为InUse, 比较map
      if (m_portStatusReport.getPortStatus() == PORT_INUSE) {
         if (m_isCompareMapsBeforeProceeding) {
            short scanMap = getScanCassetteMap();
@@ -943,14 +947,14 @@
            else {
               this->sendCassetteCtrlCmd(CCC_PROCESS_CANCEL, nullptr, 0, 0, 0, nullptr, nullptr);
               // 抛出到应用层做提示
               // 抛出到应用层做提示
               if (m_listener.onMapMismatch != nullptr) {
                  m_listener.onMapMismatch(this, scanMap, downloadMap);
               }
            }
         }
         else {
            // 抛出到应用层做选择要加工的片子
            // 抛出到应用层做选择要加工的片子
            generateGlassList(getScanCassetteMap());
         }
      }
@@ -960,7 +964,7 @@
      }
      // 缓存Attribute,用于调试时显示信息
      // 缓存Attribute,用于调试时显示信息
      unsigned int weight = 201;
      CAttributeVector& attrubutes = pStep->attributeVector();
      m_portStatusReport.getAttributeVector(attrubutes, weight);
@@ -985,17 +989,17 @@
         return -1;
      }
      LOGI("<CLoadPort-%d>准备设置Port type<%d>", m_nIndex, (int)type);
      LOGI("<CLoadPort-%d>准备设置Port type<%d>", m_nIndex, (int)type);
      short value = (short)type;
      pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
         // test
         code = WOK;
         if (code == WOK) {
            m_portType = type;
            LOGI("<CLoadPort-%d>设置Port type成功.", m_nIndex);
            LOGI("<CLoadPort-%d>设置Port type成功.", m_nIndex);
         }
         else {
            LOGE("<CLoadPort-%d>设置Port type失败,code:%d", m_nIndex, code);
            LOGE("<CLoadPort-%d>设置Port type失败,code:%d", m_nIndex, code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
@@ -1015,17 +1019,17 @@
         return -1;
      }
      LOGI("<CLoadPort-%d>准备%s Port", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
      LOGI("<CLoadPort-%d>准备%s Port", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
      short value = bEnable ? 1 : 2;
      pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
         // test
         code = WOK;
         if (code == WOK) {
            m_bEnable = bEnable;
            LOGI("<CLoadPort-%d>%s Port成功.", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
            LOGI("<CLoadPort-%d>%s Port成功.", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
         }
         else {
            LOGE("<CLoadPort-%d>%s  Port失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
            LOGE("<CLoadPort-%d>%s  Port失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
@@ -1044,17 +1048,17 @@
         return -1;
      }
      LOGI("<CLoadPort-%d>准备设置Port mode<%d>", m_nIndex, (int)mode);
      LOGI("<CLoadPort-%d>准备设置Port mode<%d>", m_nIndex, (int)mode);
      short value = (short)mode;
      pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
         // test
         code = WOK;
         if (code == WOK) {
            m_portMode = mode;
            LOGI("<CLoadPort-%d>设置Port mode成功.", m_nIndex);
            LOGI("<CLoadPort-%d>设置Port mode成功.", m_nIndex);
         }
         else {
            LOGE("<CLoadPort-%d>设置Port mode失败,code:%d", m_nIndex, code);
            LOGE("<CLoadPort-%d>设置Port mode失败,code:%d", m_nIndex, code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
@@ -1074,16 +1078,16 @@
         return -1;
      }
      LOGI("<CLoadPort-%d>准备设置Cassette Type<%d>", m_nIndex, (int)type);
      LOGI("<CLoadPort-%d>准备设置Cassette Type<%d>", m_nIndex, (int)type);
      short value = (short)type;
      pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
         // test
         code = WOK;
         if (code == WOK) {
            LOGI("<CLoadPort-%d>设置Cassette Type成功.", m_nIndex);
            LOGI("<CLoadPort-%d>设置Cassette Type成功.", m_nIndex);
         }
         else {
            LOGE("<CLoadPort-%d>设置Cassette Type失败,code:%d", m_nIndex, code);
            LOGE("<CLoadPort-%d>设置Cassette Type失败,code:%d", m_nIndex, code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
@@ -1102,17 +1106,17 @@
         return -1;
      }
      LOGI("<CLoadPort-%d>准备设置Transfer mode<%d>", m_nIndex, (int)mode);
      LOGI("<CLoadPort-%d>准备设置Transfer mode<%d>", m_nIndex, (int)mode);
      short value = (short)mode;
      pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
         // test
         code = WOK;
         if (code == WOK) {
            m_transferMode = mode;
            LOGI("<CLoadPort-%d>设置Transfer mode成功.", m_nIndex + 1);
            LOGI("<CLoadPort-%d>设置Transfer mode成功.", m_nIndex + 1);
         }
         else {
            LOGE("<CLoadPort-%d>设置Transfer mode失败,code:%d", m_nIndex + 1, code);
            LOGE("<CLoadPort-%d>设置Transfer mode失败,code:%d", m_nIndex + 1, code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
@@ -1131,17 +1135,17 @@
         return -1;
      }
      LOGI("<CLoadPort-%d>准备%s Auto Change", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
      LOGI("<CLoadPort-%d>准备%s Auto Change", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
      short value = bEnable ? 1 : 2;
      pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
         // test
         code = WOK;
         if (code == WOK) {
            m_bAutoChangeEnable = bEnable;
            LOGI("<CLoadPort-%d>%s Auto Change成功.", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
            LOGI("<CLoadPort-%d>%s Auto Change成功.", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
         }
         else {
            LOGE("<CLoadPort-%d>%s  Auto Change失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
            LOGE("<CLoadPort-%d>%s  Auto Change失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
@@ -1189,17 +1193,20 @@
   short CLoadPort::getDownloadCassetteMap()
   {
      // 暂时未实现此功能
      short map = 0;
      return map;
      return m_downloadCassetteMap;
   }
   void CLoadPort::setDownloadCassetteMap(short map)
   {
      m_downloadCassetteMap = map;
   }
   /*
    * 生成测试用的玻璃列表
    * 生成测试用的玻璃列表
    */
   int CLoadPort::testGenerateGlassList(MaterialsType type)
   {
      // 如果非空就不生成了
      // 如果非空就不生成了
      Lock();
      if (hasGlass()) {
         Unlock();
@@ -1233,11 +1240,11 @@
   }
   /*
    * 根据efem扫描到的map,生成玻璃列表
    * 根据efem扫描到的map,生成玻璃列表
    */
   int CLoadPort::generateGlassList(short map)
   {
      // 先释放较早前的数据
      // 先释放较早前的数据
      Lock();
      for (int i = 0; i < SLOT_MAX; i++) {
         m_slot[i].setContext(nullptr);
@@ -1245,7 +1252,7 @@
      Unlock();
      // 根据map生成新的
      // 根据map生成新的
      char szBuffer[64];
      for (int i = 0; i < SLOT_MAX; i++) {
         if (!m_slot[i].isEnable()) continue;