mrDarker
2025-05-20 2a803976ed12e59f3e082e7c08941ef5004e6ea1
SourceCode/Bond/Servo/CEFEM.cpp
@@ -1,5 +1,6 @@
#include "stdafx.h"
#include "CEFEM.h"
#include "Log.h"
#define ADD_EQ_CASSETTE_TRANSFER_STATE_STEP(name,ws,index,psd) {            \
@@ -56,6 +57,73 @@
      if (index < 2) {
         m_pArmTray[index] = pArmTray;
      }
   }
   int CEFEM::robotCmd(ROBOT_CMD_PARAM& robotCmdParam, ONWRITED onWritedBlock/* = nullptr*/)
   {
      SERVO::CEqWriteStep* pStep = (SERVO::CEqWriteStep*)getStepWithName(STEP_EFEM_ROBOT_CMD);
      if (pStep == nullptr) {
         return -1;
      }
      LOGI("<CEFEM-%s>准备发送RobotCmd<%d>", m_strName.c_str(), (int)robotCmdParam.rcmd);
      if (onWritedBlock != nullptr) {
         pStep->writeDataEx((const char*)&robotCmdParam, ROBOT_CMD_PARAM_SIZE, onWritedBlock);
      }
      else {
         pStep->writeDataEx((const char*)&robotCmdParam, ROBOT_CMD_PARAM_SIZE, [&](int code) -> int {
            if (code == WOK) {
               LOGI("<CEFEM-%s>发送RobotCmd成功.", m_strName.c_str());
            }
            else {
               LOGI("<CEFEM-%s>发送RobotCmd失败,code:%d", m_strName.c_str(), code);
            }
            return 0;
            });
      }
      return 0;
   }
   int CEFEM::robotCmds(ROBOT_CMD_PARAM* robotCmdParam, unsigned int count, ONWRITED onWritedBlock/* = nullptr*/)
   {
      SERVO::CEqWriteStep* pStep = (SERVO::CEqWriteStep*)getStepWithName(STEP_EFEM_ROBOT_CMD);
      if (pStep == nullptr) {
         return -1;
      }
      // 平铺到内存中,如果ROBOT_CMD_PARAM不是4的整数倍,只能一个一个复制
      std::string strLog = "准备发送RobotCmds<";
      char szBuffer[ROBOT_CMD_PARAM_SIZE * 4];
      for (int i = 0; i < min(4, count); i++) {
         memcpy(&szBuffer[i * ROBOT_CMD_PARAM_SIZE], (robotCmdParam + i), ROBOT_CMD_PARAM_SIZE);
         strLog += std::to_string((robotCmdParam + i)->rcmd);
         strLog += ",";
         LOGI("%d", (robotCmdParam + 1)->rcmd);
      }
      strLog += ">.";
      LOGI("<CEFEM-%s>%s", m_strName.c_str(), strLog.c_str());
      if (onWritedBlock != nullptr) {
         pStep->writeDataEx(szBuffer, ROBOT_CMD_PARAM_SIZE * min(4, count), onWritedBlock);
      }
      else {
         pStep->writeDataEx(szBuffer, ROBOT_CMD_PARAM_SIZE * min(4, count), [&](int code) -> int {
            if (code == WOK) {
               LOGI("<CEquipment-%s>发送RobotCmdS成功.", m_strName.c_str());
            }
            else {
               LOGI("<CEquipment-%s>发送RobotCmds失败,code:%d", m_strName.c_str(), code);
            }
            return 0;
            });
      }
      return 0;
   }
   void CEFEM::init()
@@ -294,6 +362,30 @@
         STEP_ID_PORT4_CASSETTIE_BLOCKED, 0x60b0);
      {
         // Received Job Report Upstream#1~9
         char szBuffer[256];
         for (int i = 0; i < 9; i++) {
            CEqReadStep* pStep = new CEqReadStep(0x4c90 + 320 * i, 320 * 2,
               [&](void* pFrom, int code, const char* pszData, size_t size) -> int {
                  if (code == ROK && pszData != nullptr && size > 0) {
                     int port = (int)(__int64)((CEqReadStep*)pFrom)->getProp("Port");
                     if (port > 0) {
                        decodeFetchedOutJobReport((CStep*)pFrom, port, pszData, size);
                     }
                  }
                  return -1;
               });
            sprintf_s(szBuffer, "%s%d", STEP_EQ_RECEIVED_JOBn, i + 1);
            pStep->setName(szBuffer);
            pStep->setProp("Upstream", (void*)(__int64)(i + 1));
            pStep->setWriteSignalDev(0x0 + i);
            if (addStep(STEP_ID_FETCHED_OUT_JOB_REPORT1 + i, pStep) != 0) {
               delete pStep;
            }
         }
      }
      {
         // Fetched Out Job Report #1~15
         char szBuffer[256];
         for (int i = 0; i < 15; i++) {
@@ -302,7 +394,7 @@
                  if (code == ROK && pszData != nullptr && size > 0) {
                     int port = (int)(__int64)((CEqReadStep*)pFrom)->getProp("Port");
                     if (port > 0) {
                        decodeFetchedOutJobReport(port, pszData, size);
                        decodeFetchedOutJobReport((CStep*)pFrom, port, pszData, size);
                     }
                  }
                  return -1;
@@ -326,7 +418,7 @@
                  if (code == ROK && pszData != nullptr && size > 0) {
                     int port = (int)(__int64)((CEqReadStep*)pFrom)->getProp("Port");
                     if (port > 0) {
                        decodeStoredJobReport(port, pszData, size);
                        decodeStoredJobReport((CStep*)pFrom, port, pszData, size);
                     }
                  }
                  return -1;
@@ -338,6 +430,28 @@
            if (addStep(STEP_ID_STORE_JOB_REPORT1 + i, pStep) != 0) {
               delete pStep;
            }
         }
      }
      {
         // Dispatching Mode Change Command
         CEqWriteStep* pStep = new CEqWriteStep();
         pStep->setName(STEP_EQ_DISPATCHINT_MODE_CHANGE);
         pStep->setWriteSignalDev(0x071);
         pStep->setDataDev(0x5c6);
         if (addStep(STEP_ID_DISPATCHING_MODE_CHANGE_REPLY, pStep) != 0) {
            delete pStep;
         }
      }
      {
         // Robot CMD
         CEqWriteStep* pStep = new CEqWriteStep();
         pStep->setName(STEP_EFEM_ROBOT_CMD);
         pStep->setWriteSignalDev(0x14D);
         pStep->setDataDev(0x90a);
         if (addStep(STEP_ID_ROBOT_CMD_REPLY, pStep) != 0) {
            delete pStep;
         }
      }
   }
@@ -402,61 +516,89 @@
      }
   }
   int CEFEM::onFetchedOut(int port, const char* pszGlassId)
   int CEFEM::onReceivedJob(int port, CJobDataS* pJobDataS)
   {
      m_pPort[0]->onReceivedJob(port, pJobDataS);
      m_pPort[1]->onReceivedJob(port, pJobDataS);
      m_pPort[2]->onReceivedJob(port, pJobDataS);
      m_pPort[3]->onReceivedJob(port, pJobDataS);
      m_pArmTray[0]->onReceivedJob(port, pJobDataS);
      m_pArmTray[1]->onReceivedJob(port, pJobDataS);
      m_pAligner->onReceivedJob(port, pJobDataS);
      m_pFliper->onReceivedJob(port, pJobDataS);
      return 0;
   }
   int CEFEM::onSentOutJob(int port, CJobDataS* pJobDataS)
   {
      m_pPort[0]->onSentOutJob(port, pJobDataS);
      m_pPort[1]->onSentOutJob(port, pJobDataS);
      m_pPort[2]->onSentOutJob(port, pJobDataS);
      m_pPort[3]->onSentOutJob(port, pJobDataS);
      m_pArmTray[0]->onSentOutJob(port, pJobDataS);
      m_pArmTray[1]->onSentOutJob(port, pJobDataS);
      m_pAligner->onSentOutJob(port, pJobDataS);
      m_pFliper->onSentOutJob(port, pJobDataS);
      return 0;
   }
   int CEFEM::onFetchedOutJob(int port, CJobDataB* pJobDataB)
   {
      if (port == 1) {
         return m_pPort[0]->fetchedOut(pszGlassId);
         return m_pPort[0]->onFetchedOutJob(port, pJobDataB);
      }
      if (port == 2) {
         return m_pPort[1]->fetchedOut(pszGlassId);
         return m_pPort[1]->onFetchedOutJob(port, pJobDataB);
      }
      if (port == 3) {
         return m_pPort[2]->fetchedOut(pszGlassId);
         return m_pPort[2]->onFetchedOutJob(port, pJobDataB);
      }
      if (port == 4) {
         return m_pPort[3]->fetchedOut(pszGlassId);
         return m_pPort[3]->onFetchedOutJob(port, pJobDataB);
      }
      if (port == 5) {
         return m_pArmTray[0]->fetchedOut(pszGlassId);
         return m_pArmTray[0]->onFetchedOutJob(port, pJobDataB);
      }
      if (port == 6) {
         return m_pArmTray[1]->fetchedOut(pszGlassId);
         return m_pArmTray[1]->onFetchedOutJob(port, pJobDataB);
      }
      if (port == 7) {
         return m_pAligner->fetchedOut(pszGlassId);
         return m_pAligner->onFetchedOutJob(port, pJobDataB);
      }
      if (port == 8) {
         return m_pFliper->fetchedOut(pszGlassId);
         return m_pFliper->onFetchedOutJob(port, pJobDataB);
      }
      return -1;
   }
   int CEFEM::onStore(int port, const char* pszGlassId)
   int CEFEM::onStoredJob(int port, CJobDataB* pJobDataB)
   {
      if (port == 1) {
         return m_pPort[0]->storedJob(pszGlassId);
         return m_pPort[0]->onStoredJob(port, pJobDataB);
      }
      if (port == 2) {
         return m_pPort[1]->storedJob(pszGlassId);
         return m_pPort[1]->onStoredJob(port, pJobDataB);
      }
      if (port == 3) {
         return m_pPort[2]->storedJob(pszGlassId);
         return m_pPort[2]->onStoredJob(port, pJobDataB);
      }
      if (port == 4) {
         return m_pPort[3]->storedJob(pszGlassId);
         return m_pPort[3]->onStoredJob(port, pJobDataB);
      }
      if (port == 5) {
         return m_pArmTray[0]->storedJob(pszGlassId);
         return m_pArmTray[0]->onStoredJob(port, pJobDataB);
      }
      if (port == 6) {
         return m_pArmTray[1]->storedJob(pszGlassId);
         return m_pArmTray[1]->onStoredJob(port, pJobDataB);
      }
      if (port == 7) {
         return m_pAligner->storedJob(pszGlassId);
         return m_pAligner->onStoredJob(port, pJobDataB);
      }
      if (port == 8) {
         return m_pFliper->storedJob(pszGlassId);
         return m_pFliper->onStoredJob(port, pJobDataB);
      }
      return -1;