SourceCode/Bond/Servo/CLoadPort.cpp
@@ -1,27 +1,23 @@
#include "stdafx.h"
#include "stdafx.h"
#include "CLoadPort.h"
#include "CGlassPool.h"
#include "Servo.h"
#include "ServoCommo.h"
#define CHECK_READ_STEP_SIGNAL2(addr, data, size) {                     \
   BOOL bFlag = isBitOn(data, size, addr);                           \
   SERVO::CStep* pStep = getStep(addr);                           \
   if (pStep != nullptr) {                                       \
      ((CReadStep*)pStep)->onReadSignal(bFlag ? addr : 0);            \
   }                                                      \
}
namespace SERVO {
   CLoadPort::CLoadPort() : CEquipment()
   {
      m_nIndex = 0;
      m_portType = PortType::Loading;
      m_portMode = PortMode::ReadyToLoad;
      m_portType = PortType::Both;
      m_portMode = PortMode::OutOfService;
      m_cassetteType = CassetteType::G1;
      m_transferMode = TransferMode::AGVMode;
      m_bEnable = TRUE;
      m_bEnable = FALSE;
      m_bAutoChangeEnable = FALSE;
      m_nNextCassetteSequenceNo = 0;
      m_isCompareMapsBeforeProceeding = FALSE;
      m_downloadCassetteMap = 0;
   }
   CLoadPort::~CLoadPort()
@@ -45,43 +41,24 @@
      CEquipment::term();
   }
   // 必须要实现的虚函数,在此初始化Pin列表
   // 必须要实现的虚函数,在此初始化Pin列表
   void CLoadPort::initPins()
   {
      // 加入Pin初始化代码
      LOGI("<CLoadPort>initPins");
      // 加入Pin初始化代码
      LOGD("<CLoadPort>initPins");
      addPin(SERVO::PinType::INPUT, _T("In"));
      addPin(SERVO::PinType::OUTPUT, _T("Out1"));
      addPin(SERVO::PinType::OUTPUT, _T("Out2"));
      addPin(SERVO::PinType::OUTPUT, _T("Out"));
   }
   // 必须要实现的虚函数,在此初始化Slot信息
   // 必须要实现的虚函数,在此初始化Slot信息
   void CLoadPort::initSlots()
   {
      m_slot[0].enable();
      m_slot[0].setPosition(m_nID);
      m_slot[0].setNo(1);
      m_slot[0].setName("Slot 1");
      m_slot[1].enable();
      m_slot[1].setPosition(m_nID);
      m_slot[1].setNo(2);
      m_slot[1].setName("Slot 2");
      m_slot[2].setPosition(m_nID);
      m_slot[2].enable();
      m_slot[2].setNo(3);
      m_slot[2].setName("Slot 3");
      m_slot[3].setPosition(m_nID);
      m_slot[3].enable();
      m_slot[3].setNo(4);
      m_slot[3].setName("Slot 4");
      m_slot[4].setPosition(m_nID);
      m_slot[4].enable();
      m_slot[4].setNo(5);
      m_slot[4].setName("Slot 5");
      m_slot[5].setPosition(m_nID);
      m_slot[5].enable();
      m_slot[5].setNo(6);
      m_slot[5].setName("Slot 6");
      for (int i = 0; i < SLOT_MAX; i++) {
         m_slot[i].enable();
         m_slot[i].setPosition(m_nID);
         m_slot[i].setNo(i + 1);
         m_slot[i].setName((std::string("Slot") + std::to_string(i+1)).c_str());
      }
   }
   void CLoadPort::initSteps()
@@ -93,15 +70,15 @@
      {
         // Cassette Ctrl Cmd
         static char* pszName[] = { STEP_EQ_P1_CASSETTE_CTRL_CMD,   STEP_EQ_P2_CASSETTE_CTRL_CMD, STEP_EQ_P3_CASSETTE_CTRL_CMD,   STEP_EQ_P4_CASSETTE_CTRL_CMD };
         static int writeSignalDev[] = { 0x120, 0x121, 0x122, 0x123 };
         static char* pszName[] = { STEP_EQ_P1_CASSETTE_CTRL_CMD, STEP_EQ_P2_CASSETTE_CTRL_CMD, STEP_EQ_P3_CASSETTE_CTRL_CMD, STEP_EQ_P4_CASSETTE_CTRL_CMD };
         static int writeSignalDev[] = { 0x130, 0x131, 0x132, 0x133 };
         static int dev[] = { 0x45, 0x1a5, 0x305, 0x465 };
         static int addr[] = { 0x480, 0x481, 0x482, 0x483 };
         static int addr[] = { STEP_ID_PROT1_CASSETTE_CTR_CMD_REPLY, STEP_ID_PROT2_CASSETTE_CTR_CMD_REPLY, STEP_ID_PROT3_CASSETTE_CTR_CMD_REPLY, STEP_ID_PROT4_CASSETTE_CTR_CMD_REPLY };
         CEqCassetteCtrlCmdStep* pStep = new CEqCassetteCtrlCmdStep();
         CEqWriteStep* pStep = new CEqWriteStep();
         pStep->setName(pszName[m_nIndex]);
         pStep->setWriteSignalDev(writeSignalDev[m_nIndex]);
         pStep->setCtrlCmdDev(dev[m_nIndex]);
         pStep->setDataDev(dev[m_nIndex]);
         if (addStep(addr[m_nIndex], pStep) != 0) {
            delete pStep;
         }
@@ -111,7 +88,7 @@
         // Type
         static char* pszName[] = { STEP_EQ_PORT1_TYPE, STEP_EQ_PORT2_TYPE, STEP_EQ_PORT3_TYPE, STEP_EQ_PORT4_TYPE };
         static int dev[] = { 0x6010 , 0x6020, 0x6030, 0x6040 };
         static int writeSignalDev[] = { 0xa0, 0xa1, 0xa2, 0xa3 };
         static int writeSignalDev[] = { 0x90, 0x91, 0x92, 0x93 };
         static int addr[] = { STEP_ID_PORT1_TYPE_CHANGE, STEP_ID_PORT2_TYPE_CHANGE, STEP_ID_PORT3_TYPE_CHANGE, STEP_ID_PORT4_TYPE_CHANGE };
         CEqReadStep* pStep = new CEqReadStep(dev[m_nIndex], sizeof(short),
@@ -132,13 +109,14 @@
         // Mode
         static char* pszName[] = { STEP_EQ_PORT1_MODE, STEP_EQ_PORT2_MODE, STEP_EQ_PORT3_MODE, STEP_EQ_PORT4_MODE };
         static int dev[] = { 0x6011, 0x6021, 0x6031, 0x6041 };
         static int writeSignalDev[] = { 0xa8, 0xa9, 0xaa, 0xab };
         static int writeSignalDev[] = { 0x98, 0x99, 0x9a, 0x9b };
         static int addr[] = { STEP_ID_PORT1_MODE_CHANGE, STEP_ID_PORT2_MODE_CHANGE, STEP_ID_PORT3_MODE_CHANGE, STEP_ID_PORT4_MODE_CHANGE };
         CEqReadStep* pStep = new CEqReadStep(dev[m_nIndex], sizeof(short),
            [&](void* pFrom, int code, const char* pszData, size_t size) -> int {
               if (code == ROK && pszData != nullptr && size > 0) {
                  m_portMode = (PortMode)CToolUnits::toInt16(pszData);
                  LOGI("<LoadPort-%d>m_portMode:%d", m_nIndex, m_portMode);
               }
               return 0;
            });
@@ -153,13 +131,13 @@
         // Cassette type
         static char* pszName[] = { STEP_EQ_PORT1_CASSETTE_TYPE, STEP_EQ_PORT2_CASSETTE_TYPE, STEP_EQ_PORT3_CASSETTE_TYPE, STEP_EQ_PORT4_CASSETTE_TYPE };
         static int dev[] = { 0x6012, 0x6022, 0x6032, 0x6042 };
         static int writeSignalDev[] = { 0xb0, 0xb1, 0xb2, 0xb3 };
         static int writeSignalDev[] = { 0xa0, 0xa1, 0xa2, 0xa3 };
         static int addr[] = { STEP_ID_PORT1_CASSETTE_TYPE_CHANGE, STEP_ID_PORT2_CASSETTE_TYPE_CHANGE, STEP_ID_PORT3_CASSETTE_TYPE_CHANGE, STEP_ID_PORT4_CASSETTE_TYPE_CHANGE };
         CEqReadStep* pStep = new CEqReadStep(dev[m_nIndex], sizeof(short),
            [&](void* pFrom, int code, const char* pszData, size_t size) -> int {
               if (code == ROK && pszData != nullptr && size > 0) {
                  m_cassetteType = (CassetteType)CToolUnits::toInt16(pszData);
                  //m_cassetteType = (CassetteType)CToolUnits::toInt16(pszData);
               }
               return 0;
            });
@@ -174,7 +152,7 @@
         // Transfer type
         static char* pszName[] = { STEP_EQ_PORT1_TRANSFER_MODE, STEP_EQ_PORT2_TRANSFER_MODE, STEP_EQ_PORT3_TRANSFER_MODE, STEP_EQ_PORT4_TRANSFER_MODE };
         static int dev[] = { 0x6014, 0x6024, 0x6034, 0x6044 };
         static int writeSignalDev[] = { 0xb8, 0xb9, 0xba, 0xbb };
         static int writeSignalDev[] = { 0xa8, 0xa9, 0xaa, 0xab };
         static int addr[] = { STEP_ID_PORT1_TRANSFER_MODE_CHANGE, STEP_ID_PORT2_TRANSFER_MODE_CHANGE, STEP_ID_PORT3_TRANSFER_MODE_CHANGE, STEP_ID_PORT4_TRANSFER_MODE_CHANGE };
         CEqReadStep* pStep = new CEqReadStep(dev[m_nIndex], sizeof(short),
@@ -195,7 +173,7 @@
         // Port enable
         static char* pszName[] = { STEP_EQ_PORT1_ENABLE, STEP_EQ_PORT2_ENABLE, STEP_EQ_PORT3_ENABLE, STEP_EQ_PORT4_ENABLE };
         static int dev[] = { 0x6015, 0x6025, 0x6035, 0x6045 };
         static int writeSignalDev[] = { 0xc0, 0xc1, 0xc2, 0xc3 };
         static int writeSignalDev[] = { 0xb0, 0xb1, 0xb2, 0xb3 };
         static int addr[] = { STEP_ID_PORT1_ENABLE_MODE_CHANGE, STEP_ID_PORT2_ENABLE_MODE_CHANGE, STEP_ID_PORT3_ENABLE_MODE_CHANGE, STEP_ID_PORT4_ENABLE_MODE_CHANGE };
         CEqReadStep* pStep = new CEqReadStep(dev[m_nIndex], sizeof(short),
@@ -318,7 +296,7 @@
         pStep->setName(pszName[m_nIndex]);
         pStep->setWriteSignalDev(0x128 + m_nIndex);
         pStep->setDataDev(dev[m_nIndex]);
         if (addStep(STEP_ID_PROT1_TYPE_AUTO_CHANGE_REPLY + m_nIndex, pStep) != 0) {
         if (addStep(STEP_ID_PROT1_CASSETTE_TYPE_CHANGE_REPLY + m_nIndex, pStep) != 0) {
            delete pStep;
         }
      }
@@ -334,12 +312,12 @@
         };
         static int dev[] = { 0x6050, 0x6070, 0x6090, 0x60b0 };
         static int writeSignalDev[6][4] = {
            {0xc8, 0xc9, 0xca, 0xcb},
            {0xd0, 0xd1, 0xd2, 0xd3},
            {0xd8, 0xd9, 0xda, 0xdb},
            {0xe0, 0xe1, 0xe2, 0xe3},
            {0xe8, 0xe9, 0xea, 0xeb},
            {0xf0, 0xf1, 0xf2, 0xf3},
            {0xf8, 0xf9, 0xfa, 0xfb},
            {0x100, 0x101, 0x102, 0x103}
            {0xf0, 0xf1, 0xf2, 0xf3}
         };
         static int addr[6][4] = {
            { STEP_ID_PORT1_EMPTY, STEP_ID_PORT2_EMPTY, STEP_ID_PORT3_EMPTY, STEP_ID_PORT4_EMPTY },
@@ -355,6 +333,7 @@
               [&](void* pFrom, int code, const char* pszData, size_t size) -> int {
                  if (code == ROK && pszData != nullptr && size > 0) {
                     decodePortStatusReport((CStep*)pFrom, pszData, size);
                     return 0;
                  }
                  return -1;
               });
@@ -371,11 +350,64 @@
   void CLoadPort::onTimer(UINT nTimerid)
   {
      CEquipment::onTimer(nTimerid);
      // 从配置读出的enable,初始化时写给efem
      static int i_enable[4] = { 0 };
      if ((++i_enable[m_nIndex]) == 20 + m_nIndex) {
         eablePort(m_bEnable, [&](int code) -> int {
            LOGI("<LoadPort-%d>eablePort:code=%d", m_nIndex, code);
            return 0;
            });
      }
      // 模拟测试
      if (m_nIndex == 0) {
         static int ii = 0;
         ii++;
         if (ii == 50) {
            char szBuffer[64] = {0};
            CStep* pStep = getStepWithName(STEP_EQ_PORT1_BLOCKED);
            CPortStatusReport portStatusReport;
            portStatusReport.setPortStatus(PORT_BLOCKED);
            portStatusReport.setJobExistenceSlot(0xf);
            portStatusReport.setCassetteId("CID1001");
            int nRet = portStatusReport.serialize(szBuffer, 64);
            decodePortStatusReport(pStep, szBuffer, 64);
            LOGI("<CLoadPort>Port1载入模拟数据, id:CID1001 map: 0xf");
         }
      }
      if (m_nIndex == 1) {
         static int ii = 0;
         ii++;
         if (ii == 55) {
            char szBuffer[64] = { 0 };
            CStep* pStep = getStepWithName(STEP_EQ_PORT2_BLOCKED);
            CPortStatusReport portStatusReport;
            portStatusReport.setPortStatus(PORT_BLOCKED);
            portStatusReport.setJobExistenceSlot(0xff );
            portStatusReport.setCassetteId("CID1004");
            int nRet = portStatusReport.serialize(szBuffer, 64);
            decodePortStatusReport(pStep, szBuffer, 64);
            LOGI("<CLoadPort>Port2载入模拟数据, id:CID1004 map: 0xff");
         }
      }
   }
   void CLoadPort::serialize(CArchive& ar)
   {
      CEquipment::serialize(ar);
      if (ar.IsStoring()) {
         ar << m_nIndex;
         m_portStatusReport.serialize(ar);
      }
      else {
         ar >> m_nIndex;
         m_portStatusReport.serialize(ar);
      }
   }
   void CLoadPort::getAttributeVector(CAttributeVector& attrubutes)
@@ -410,17 +442,25 @@
      int jobExistenceSize,
      short slotProcess,
      short jopCount,
      CJobDataA* pJobDataA)
      CJobDataA* pJobDataA,
      ONWRITED onWritedBlock)
   {
      int id = getID();
      if ( !(id == EQ_ID_LOADPORT1 || id == EQ_ID_LOADPORT2) ) {
         return -1;
      SERVO::CEqWriteStep* pStep = (SERVO::CEqWriteStep*)getCassetteCtrlCmdStep();
      ASSERT(pStep);
      char szBuffer[1024] = { 0 };
      memcpy(&szBuffer[0], &cmd, sizeof(short));
      if (jobExistence != nullptr && jobExistenceSize == 12) {
         memcpy(&szBuffer[2], jobExistence, sizeof(short) * jobExistenceSize);
      }
      memcpy(&szBuffer[26], &slotProcess, sizeof(short));
      memcpy(&szBuffer[36], &jopCount, sizeof(short));
      if (pJobDataA != nullptr) {
         pJobDataA->serialize(&szBuffer[38], 1024 - 38);
      }
      SERVO::CEqCassetteCtrlCmdStep* pStep = (SERVO::CEqCassetteCtrlCmdStep*)getCassetteCtrlCmdStep();
      ASSERT(pStep);
      return pStep->sendCtrlCmd(cmd, jobExistence, jobExistenceSize, slotProcess, jopCount, pJobDataA);
      return pStep->writeDataEx(szBuffer, 352 * 2, onWritedBlock);
   }
   CStep* CLoadPort::getCassetteCtrlCmdStep()
@@ -440,9 +480,35 @@
      return pStep;
   }
   short CLoadPort::getNextCassetteSequenceNo()
   {
      m_nNextCassetteSequenceNo++;
      if (m_nNextCassetteSequenceNo >= 1000) {
         m_nNextCassetteSequenceNo = 0;
      }
      return (m_nIndex + 1) * 1000 + m_nNextCassetteSequenceNo;
   }
   int CLoadPort::getPortCassetteSnSeed()
   {
      return m_nNextCassetteSequenceNo;
   }
   void CLoadPort::setPortCassetteSnSeed(int seed)
   {
      m_nNextCassetteSequenceNo = seed;
      if (m_nNextCassetteSequenceNo >= 1000) {
         m_nNextCassetteSequenceNo = 0;
      }
   }
   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()
@@ -493,6 +559,11 @@
   std::string& CLoadPort::getCassetteId()
   {
      return m_portStatusReport.getCassetteId();
   }
   void CLoadPort::simulateSetCassetteId(const char* pszCarrierId)
   {
      m_portStatusReport.setCassetteId(pszCarrierId);
   }
   int CLoadPort::getLoadingCassetteType()
@@ -817,6 +888,8 @@
   void CLoadPort::onReceiveLBData(const char* pszData, size_t size)
   {
      __super::onReceiveLBData(pszData, size);
      static int type[] = { STEP_ID_PORT1_TYPE_CHANGE, STEP_ID_PORT2_TYPE_CHANGE,
         STEP_ID_PORT3_TYPE_CHANGE, STEP_ID_PORT4_TYPE_CHANGE };
      static int mode[] = { STEP_ID_PORT1_MODE_CHANGE, STEP_ID_PORT2_MODE_CHANGE,
@@ -830,12 +903,12 @@
      static int autoType[] = { STEP_ID_PORT1_TYPE_AUTO_CHANGE, STEP_ID_PORT2_TYPE_AUTO_CHANGE,
         STEP_ID_PORT3_TYPE_AUTO_CHANGE, STEP_ID_PORT4_TYPE_AUTO_CHANGE };
      CHECK_READ_STEP_SIGNAL2(type[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL2(mode[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL2(cassetteType[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL2(transferMode[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL2(enable[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL2(autoType[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL(type[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL(mode[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL(cassetteType[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL(transferMode[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL(enable[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL(autoType[m_nIndex], pszData, size);
      static int typeReply[] = { STEP_ID_PROT1_TYPE_CHANGE_REPLY, STEP_ID_PROT2_TYPE_CHANGE_REPLY,
@@ -851,12 +924,12 @@
      static int cassetteTypeReply[] = { STEP_ID_PROT1_CASSETTE_TYPE_CHANGE_REPLY, STEP_ID_PROT2_CASSETTE_TYPE_CHANGE_REPLY,
         STEP_ID_PROT3_CASSETTE_TYPE_CHANGE_REPLY, STEP_ID_PROT4_CASSETTE_TYPE_CHANGE_REPLY };
      CHECK_READ_STEP_SIGNAL2(typeReply[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL2(modeReply[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL2(transferModeReply[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL2(enableModeReply[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL2(typeAutoReply[m_nIndex], pszData, size);
      CHECK_READ_STEP_SIGNAL2(cassetteTypeReply[m_nIndex], pszData, size);
      CHECK_WRITE_STEP_SIGNAL(typeReply[m_nIndex], pszData, size);
      CHECK_WRITE_STEP_SIGNAL(modeReply[m_nIndex], pszData, size);
      CHECK_WRITE_STEP_SIGNAL(transferModeReply[m_nIndex], pszData, size);
      CHECK_WRITE_STEP_SIGNAL(enableModeReply[m_nIndex], pszData, size);
      CHECK_WRITE_STEP_SIGNAL(typeAutoReply[m_nIndex], pszData, size);
      CHECK_WRITE_STEP_SIGNAL(cassetteTypeReply[m_nIndex], pszData, size);
   }
   int CLoadPort::decodePortStatusReport(CStep* pStep, const char* pszData, size_t size)
@@ -867,15 +940,35 @@
      m_portStatusReport.copyEx(portStatusReport);
      // 缓存Attribute,用于调试时显示信息
      // 当port状态为InUse, 比较map
      if (m_portStatusReport.getPortStatus() == PORT_INUSE) {
         // 生成玻璃列表:来自 EFEM 扫描到的 map
         generateGlassList(getScanCassetteMap());
         // CompareMapsBeforeProceeding:不在此处自动 Start/Cancel,改为等待 Host 决策(ProceedWithCarrier/ProceedWithSlotMap/CarrierRelease)
         // Host 决策入口:S3F17 CarrierAction -> listener.onCarrierAction -> CMaster::proceedWithCarrier()/carrierRelease()
         if (m_isCompareMapsBeforeProceeding) {
            // 这里仅等待,具体上报由上层在 PORT_INUSE 事件中触发(S6F11 CheckSlotMap)
         }
      }
      if (m_listener.onPortStatusChanged != nullptr) {
         m_listener.onPortStatusChanged(this, portStatusReport.getPortStatus(),
            getScanCassetteMap());
      }
      // 缓存Attribute,用于调试时显示信息
      unsigned int weight = 201;
      CAttributeVector attrubutes;
      CAttributeVector& attrubutes = pStep->attributeVector();
      m_portStatusReport.getAttributeVector(attrubutes, weight);
      pStep->addAttributeVector(attrubutes);
      LOGI("<CCassetteTranserStateStep>decodePortStatusReport<Status:%d, CassetteSequenceNo:%d>",
         m_portStatusReport.getPortStatus(), m_portStatusReport.getCassetteSequenceNo());
      LOGI("<CCassetteTranserStateStep>decodePortStatusReport<Status:%d, CassetteSequenceNo:%d, CassetteId:%s>",
         m_portStatusReport.getPortStatus(), m_portStatusReport.getCassetteSequenceNo(),
         m_portStatusReport.getCassetteId().c_str());
      if (m_portStatusReport.getPortStatus() == 3) {
         LOGI("<CCassetteTranserStateStep>InUse<JobExistenceSlot:%d>",
            m_portStatusReport.getJobExistenceSlot());
      }
      return nRet;
@@ -889,23 +982,24 @@
         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;
      if (onWritedBlock != nullptr) {
         pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
      }
      else {
         pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
            if (code == WOK) {
               LOGI("<CLoadPort-%d>设置Port type成功.", m_nIndex);
            }
            else {
               LOGI("<CLoadPort-%d>设置Port type失败,code:%d", m_nIndex, code);
            }
      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);
         }
         else {
            LOGE("<CLoadPort-%d>设置Port type失败,code:%d", m_nIndex, code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
         }
            return 0;
            });
      }
         return 0;
         });
      return 0;
   }
@@ -918,23 +1012,23 @@
         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;
      if (onWritedBlock != nullptr) {
         pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
      }
      else {
         pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
            if (code == WOK) {
               LOGI("<CLoadPort-%d>%s Port成功.", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
            }
            else {
               LOGI("<CLoadPort-%d>%s  Port失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
            }
            return 0;
            });
      }
      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("禁用"));
         }
         else {
            LOGE("<CLoadPort-%d>%s  Port失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
         }
         return 0;
         });
      return 0;
   }
@@ -947,52 +1041,52 @@
         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;
      if (onWritedBlock != nullptr) {
         pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
      }
      else {
         pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
            if (code == WOK) {
               LOGI("<CLoadPort-%d>设置Port mode成功.", m_nIndex);
            }
            else {
               LOGI("<CLoadPort-%d>设置Port mode失败,code:%d", m_nIndex, code);
            }
            return 0;
            });
      }
      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);
         }
         else {
            LOGE("<CLoadPort-%d>设置Port mode失败,code:%d", m_nIndex, code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
         }
         return 0;
         });
      return 0;
   }
   int CLoadPort::setCassetteType(CassetteType type, ONWRITED onWritedBlock/* = nullptr*/)
   {
      m_cassetteType = type;
      static char* pszName[] = { STEP_PORT1_CASSETTE_TYPE_CHANGE, STEP_PORT2_CASSETTE_TYPE_CHANGE, STEP_PORT3_CASSETTE_TYPE_CHANGE, STEP_PORT4_CASSETTE_TYPE_CHANGE };
      SERVO::CEqWriteStep* pStep = (SERVO::CEqWriteStep*)getStepWithName(pszName[m_nIndex]);
      if (pStep == nullptr) {
         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;
      if (onWritedBlock != nullptr) {
         pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
      }
      else {
         pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
            if (code == WOK) {
               LOGI("<CLoadPort-%d>设置Cassette Type成功.", m_nIndex);
            }
            else {
               LOGI("<CLoadPort-%d>设置Cassette Type失败,code:%d", m_nIndex, code);
            }
            return 0;
            });
      }
      pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
         // test
         code = WOK;
         if (code == WOK) {
            LOGI("<CLoadPort-%d>设置Cassette Type成功.", m_nIndex);
         }
         else {
            LOGE("<CLoadPort-%d>设置Cassette Type失败,code:%d", m_nIndex, code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
         }
         return 0;
         });
      return 0;
   }
@@ -1005,23 +1099,23 @@
         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;
      if (onWritedBlock != nullptr) {
         pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
      }
      else {
         pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
            if (code == WOK) {
               LOGI("<CLoadPort-%d>设置Transfer mode成功.", m_nIndex + 1);
            }
            else {
               LOGI("<CLoadPort-%d>设置Transfer mode失败,code:%d", m_nIndex + 1, code);
            }
            return 0;
            });
      }
      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);
         }
         else {
            LOGE("<CLoadPort-%d>设置Transfer mode失败,code:%d", m_nIndex + 1, code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
         }
         return 0;
         });
      return 0;
   }
@@ -1034,38 +1128,78 @@
         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;
      if (onWritedBlock != nullptr) {
         pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
      }
      else {
         pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
            if (code == WOK) {
               LOGI("<CLoadPort-%d>%s Auto Change成功.", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
            }
            else {
               LOGI("<CLoadPort-%d>%s  Auto Change失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
            }
            return 0;
            });
      }
      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("禁用"));
         }
         else {
            LOGE("<CLoadPort-%d>%s  Auto Change失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
         }
         if (onWritedBlock != nullptr) {
            return onWritedBlock(code);
         }
         return 0;
         });
      return 0;
   }
   /*
    * 生成测试用的玻璃列表
    */
   int CLoadPort::testGenerateGlassList(MaterialsType type, const char* pszPrefix, int startSuffix)
   void CLoadPort::localEanblePort(BOOL bEnable)
   {
      static unsigned short nJobSequenceNo = 0;
      static unsigned short nCassetteSequenceNo = 0;
      nCassetteSequenceNo++;
      m_bEnable = bEnable;
   }
   void CLoadPort::localSetPortType(PortType type)
   {
      m_portType = type;
   }
      // 如果非空就不生成了
   void CLoadPort::localSetPortMode(PortMode mode)
   {
      m_portMode = mode;
   }
   void CLoadPort::localSetCessetteType(CassetteType type)
   {
      m_cassetteType = type;
   }
   void CLoadPort::localSetTransferMode(TransferMode mode)
   {
      m_transferMode = mode;
   }
   void CLoadPort::localAutoChangeEnable(BOOL bEnable)
   {
      m_bAutoChangeEnable = bEnable;
   }
   short CLoadPort::getScanCassetteMap()
   {
      return m_portStatusReport.getJobExistenceSlot();
   }
   short CLoadPort::getDownloadCassetteMap()
   {
      return m_downloadCassetteMap;
   }
   void CLoadPort::setDownloadCassetteMap(short map)
   {
      m_downloadCassetteMap = map;
   }
   /*
    * 生成测试用的玻璃列表
    */
   int CLoadPort::testGenerateGlassList(MaterialsType type)
   {
      // 如果非空就不生成了
      Lock();
      if (hasGlass()) {
         Unlock();
@@ -1075,32 +1209,21 @@
      char szBuffer[64];
      int suffix = startSuffix;
      for (int i = 0; i < SLOT_MAX; i++) {
         if (!m_slot[i].isEnable()) continue;
         CJobDataB jb;
         CJobDataS js;
         sprintf_s(szBuffer, "%s%d", pszPrefix, suffix++);
         jb.setGlassId(szBuffer);
         jb.setCassetteSequenceNo(nCassetteSequenceNo);
         jb.setJobSequenceNo(++nJobSequenceNo);
         js.setCassetteSequenceNo(getNextCassetteSequenceNo());
         js.setJobSequenceNo(m_slot[i].getNo());
         sprintf_s(szBuffer, 64, "%05d%05d", js.getCassetteSequenceNo(), js.getJobSequenceNo());
         js.setJobType(1);
         js.setMaterialsType((int)type);
         js.setCassetteSequenceNo(nCassetteSequenceNo);
         js.setJobSequenceNo(nJobSequenceNo);
         if (type == MaterialsType::G1) {
            js.setGlass1Id(szBuffer);
         }
         else if (type == MaterialsType::G2) {
            js.setGlass2Id(szBuffer);
         }
         CGlass* pGlass = theApp.m_model.m_glassPool.allocaGlass();
         pGlass->addPath(m_nID, 0);
         pGlass->setOriginPort(m_nIndex, i);
         pGlass->addPath(m_nID, 0, i + 1);
         pGlass->processEnd(m_nID, 0);
         pGlass->setID(szBuffer);
         pGlass->setJobDataB(&jb);
         pGlass->setType(type);
         pGlass->setJobDataS(&js);
         m_slot[i].setContext(pGlass);
@@ -1109,4 +1232,94 @@
      return 0;
   }
   /*
    * 根据efem扫描到的map,生成玻璃列表
    */
   int CLoadPort::generateGlassList(short map)
   {
      // 先释放较早前的数据
      Lock();
      for (int i = 0; i < SLOT_MAX; i++) {
         m_slot[i].setContext(nullptr);
      }
      Unlock();
      // 根据map生成新的
      char szBuffer[64];
      for (int i = 0; i < SLOT_MAX; i++) {
         if (!m_slot[i].isEnable()) continue;
         if (((map >> i) & 1) == 0) continue;
         CJobDataS js;
         js.setCassetteSequenceNo(getNextCassetteSequenceNo());
         js.setJobSequenceNo(m_slot[i].getNo());
         sprintf_s(szBuffer, 64, "%05d%05d", js.getCassetteSequenceNo(), js.getJobSequenceNo());
         js.setJobType(1);
         js.setMaterialsType((int)m_cassetteType);
         CGlass* pGlass = theApp.m_model.m_glassPool.allocaGlass();
         pGlass->setOriginPort(m_nIndex, i);
         pGlass->setScheduledForProcessing(i % 2 == 1);
         pGlass->addPath(m_nID, 0, i + 1);
         pGlass->processEnd(m_nID, 0);
         pGlass->setID(szBuffer);
         pGlass->setType(m_cassetteType);
         pGlass->setJobDataS(&js);
         m_slot[i].setContext(pGlass);
      }
      return 0;
   }
   int CLoadPort::testGenerateGlassListFromConfig(const SERVO::PortConfig& config)
   {
      char szBuffer[64];
      for (const auto& slot : config.vecSlot) {
         int nSlotIndex = slot.nSlotID - 1;
         if (nSlotIndex < 0 || nSlotIndex >= SLOT_MAX) {
            continue;
         }
         if (!slot.isEnabled) {
            m_slot[nSlotIndex].setContext(nullptr);
            continue;
         }
         CJobDataS js;
         js.setCassetteSequenceNo(getNextCassetteSequenceNo());
         js.setJobSequenceNo(m_slot[nSlotIndex].getNo());
         sprintf_s(szBuffer, 64, "%05d%05d", js.getCassetteSequenceNo(), js.getJobSequenceNo());
         js.setJobType(1);
         js.setMaterialsType(config.nMaterialType);
         js.setLotId(config.strLotID.c_str());
         js.setProductId(config.strProductID.c_str());
         js.setOperationId(config.strOperationID.c_str());
         js.setGlass1Id(szBuffer);
         CGlass* pGlass = theApp.m_model.m_glassPool.allocaGlass();
         pGlass->setOriginPort(m_nIndex, nSlotIndex);
         pGlass->addPath(m_nID, 0, slot.nSlotID);
         pGlass->processEnd(m_nID, 0);
         pGlass->setID(szBuffer);
         pGlass->setType(static_cast<SERVO::MaterialsType>(config.nMaterialType));
         pGlass->setJobDataS(&js);
         m_slot[nSlotIndex].setContext(pGlass);
      }
      return 0;
   }
   void CLoadPort::setCompareMapsBeforeProceeding(BOOL bCompare)
   {
      m_isCompareMapsBeforeProceeding = bCompare;
   }
   BOOL CLoadPort::isCompareMapsBeforeProceeding() const
   {
      return m_isCompareMapsBeforeProceeding;
   }
}