From 2ffaec40444a4add7d8e638e5b20a2f81daa18af Mon Sep 17 00:00:00 2001
From: Darker <mr.darker@163.com>
Date: 星期二, 25 二月 2025 17:27:42 +0800
Subject: [PATCH] 1. 合并代码
---
SourceCode/Bond/Servo/CEqModeStep.cpp | 15 +-
SourceCode/Bond/Servo/CStep.h | 18 +++
SourceCode/Bond/Servo/CEqAlarmStep.cpp | 21 +-
SourceCode/Bond/Servo/CEqStatusStep.cpp | 40 +++---
SourceCode/Bond/Servo/CEquipment.cpp | 1
SourceCode/Bond/Servo/CMaster.cpp | 173 ++++++++++++++++------------
SourceCode/Bond/Servo/CMaster.h | 3
SourceCode/Bond/Servo/Model.cpp | 10 +
SourceCode/Bond/Servo/CStep.cpp | 39 ++++++
SourceCode/Bond/Servo/Common.h | 2
10 files changed, 210 insertions(+), 112 deletions(-)
diff --git a/SourceCode/Bond/Servo/CEqAlarmStep.cpp b/SourceCode/Bond/Servo/CEqAlarmStep.cpp
index 9d2b593..307f814 100644
--- a/SourceCode/Bond/Servo/CEqAlarmStep.cpp
+++ b/SourceCode/Bond/Servo/CEqAlarmStep.cpp
@@ -26,18 +26,19 @@
char szBuffer[64];
int nRet = m_pCclink->ReadData2(m_station, DeviceType::W,
m_nAlarmDev, 64, szBuffer);
- if (0 == nRet) {
- m_nAlarmState = (unsigned int)CToolUnits::toInt16(&szBuffer[0]);
- m_nUnitId = (unsigned int)CToolUnits::toInt16(&szBuffer[2]);
- m_nAlarmId = (unsigned int)CToolUnits::toInt16(&szBuffer[4]);
- m_nAlarmCode = (unsigned int)CToolUnits::toInt16(&szBuffer[6]);
- m_nAlarmLevel = (unsigned int)CToolUnits::toInt16(&szBuffer[8]);
-
- LOGI("<CEqAlarmStep> Equipment Alarm state Changed<State:%d, Unit:%d, Level:%d, Code:%d, ID:%d>\n",
- m_nAlarmState, m_nUnitId, m_nAlarmLevel, m_nAlarmCode, m_nAlarmId,
- m_strText.c_str(), m_strDescription.c_str());
+ if (0 != nRet) {
+ return -1;
}
+ m_nAlarmState = (unsigned int)CToolUnits::toInt16(&szBuffer[0]);
+ m_nUnitId = (unsigned int)CToolUnits::toInt16(&szBuffer[2]);
+ m_nAlarmId = (unsigned int)CToolUnits::toInt16(&szBuffer[4]);
+ m_nAlarmCode = (unsigned int)CToolUnits::toInt16(&szBuffer[6]);
+ m_nAlarmLevel = (unsigned int)CToolUnits::toInt16(&szBuffer[8]);
+
+ LOGI("<CEqAlarmStep> Equipment Alarm state Changed<State:%d, Unit:%d, Level:%d, Code:%d, ID:%d>\n",
+ m_nAlarmState, m_nUnitId, m_nAlarmLevel, m_nAlarmCode, m_nAlarmId,
+ m_strText.c_str(), m_strDescription.c_str());
return 0;
}
diff --git a/SourceCode/Bond/Servo/CEqModeStep.cpp b/SourceCode/Bond/Servo/CEqModeStep.cpp
index 149075d..888117b 100644
--- a/SourceCode/Bond/Servo/CEqModeStep.cpp
+++ b/SourceCode/Bond/Servo/CEqModeStep.cpp
@@ -20,14 +20,17 @@
CStep::onReadData();
DWordContainer dc;
- if (0 == m_pCclink->ReadDWordData(m_station, DeviceType::W, m_nModeDev, 1, dc)
- && dc.size() >= 1) {
- m_nMode = dc.at(0);
- std::string strTemp;
- LOGI("<CEqModeStep> Equipment Mode Changed<%s>\n",
- getModeDescription(strTemp).c_str());
+ if (0 != m_pCclink->ReadDWordData(m_station, DeviceType::W, m_nModeDev, 1, dc)) {
+ return -2;
+ }
+ if (dc.size() < 1) {
+ return -2;
}
+ m_nMode = dc.at(0);
+ std::string strTemp;
+ LOGI("<CEqModeStep> Equipment Mode Changed<%s>\n",
+ getModeDescription(strTemp).c_str());
return 0;
}
diff --git a/SourceCode/Bond/Servo/CEqStatusStep.cpp b/SourceCode/Bond/Servo/CEqStatusStep.cpp
index edf4572..9df8a03 100644
--- a/SourceCode/Bond/Servo/CEqStatusStep.cpp
+++ b/SourceCode/Bond/Servo/CEqStatusStep.cpp
@@ -28,28 +28,28 @@
char szBuffer[64];
int nRet = m_pCclink->ReadData2(m_station, DeviceType::W,
m_nStatusDev, 64, szBuffer);
- if (0 == nRet) {
- unsigned int unitId = (unsigned int)CToolUnits::toInt16(&szBuffer[0]);
- if (unitId < STATUS_MAX) {
- if (unitId == 0) {
- m_nStatus[unitId] = CToolUnits::toInt16(&szBuffer[2 + unitId * 4]);
- m_nReasonCode[unitId] = CToolUnits::toInt16(&szBuffer[2 + unitId * 4 + 2]);
- }
- else {
- m_nStatus[unitId] = CToolUnits::toInt16(&szBuffer[2 + 3 * 2 + unitId * 4]);
- m_nReasonCode[unitId] = CToolUnits::toInt16(&szBuffer[2 + 3 * 2 + unitId * 4 + 2]);
- }
-
- for (int i = 0; i < 64; i++) {
- TRACE("bbb %d, %x\n", i, szBuffer[i]);
- }
- TRACE("cccc %d %d %d\n", unitId, m_nStatus[unitId], m_nReasonCode[unitId]);
- std::string strTemp;
- LOGI("<CEqStatusStep> Equipment Status Changed<Unit:%d, %s, ReasonCode=%d>\n",
- unitId, getStatusDescription(unitId, strTemp).c_str(), m_nReasonCode[unitId]);
- }
+ if (0 != nRet) {
+ return -1;
}
+ unsigned int unitId = (unsigned int)CToolUnits::toInt16(&szBuffer[0]);
+ if (unitId >= STATUS_MAX) {
+ return -2;
+ }
+
+ if (unitId == 0) {
+ m_nStatus[unitId] = CToolUnits::toInt16(&szBuffer[2 + unitId * 4]);
+ m_nReasonCode[unitId] = CToolUnits::toInt16(&szBuffer[2 + unitId * 4 + 2]);
+ }
+ else {
+ m_nStatus[unitId] = CToolUnits::toInt16(&szBuffer[2 + 3 * 2 + unitId * 4]);
+ m_nReasonCode[unitId] = CToolUnits::toInt16(&szBuffer[2 + 3 * 2 + unitId * 4 + 2]);
+ }
+
+ std::string strTemp;
+ LOGI("<CEqStatusStep> Equipment Status Changed<Unit:%d, %s, ReasonCode=%d>\n",
+ unitId, getStatusDescription(unitId, strTemp).c_str(), m_nReasonCode[unitId]);
+
return 0;
}
diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index 82c261e..2c6b8e6 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -60,6 +60,7 @@
{
auto iter = m_mapStep.find(addr);
if (iter != m_mapStep.end()) return -1;
+ pStep->setEquipment(this);
pStep->setCcLink(m_pCclink);
m_mapStep[addr] = pStep;
return 0;
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 5e0cb50..82d77ca 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -13,7 +13,7 @@
CMaster::CMaster()
{
- m_listener = {nullptr, nullptr};
+ m_listener = {nullptr, nullptr, nullptr};
}
CMaster::~CMaster()
@@ -28,11 +28,21 @@
{
m_listener.onEqAlive = listener.onEqAlive;
m_listener.onEqCimStateChanged = listener.onEqCimStateChanged;
+ m_listener.onEqStepEvent = listener.onEqStepEvent;
}
int CMaster::init()
{
LOGI("<Master>正在初始化...");
+
+
+ StepListener listener;
+ listener.onEvent = [&](void* pStep, int code, void* pData) -> void {
+ TRACE("<CEquipment>onEvent<%d, 0x%x>.\n", code, pData);
+ if (m_listener.onEqStepEvent != nullptr) {
+ m_listener.onEqStepEvent((CStep*)pStep, code, pData);
+ }
+ };
// cclink
@@ -62,78 +72,8 @@
// 初始化添加各子设备
- {
- CEFEM* pEquipment = new CEFEM();
- pEquipment->setID(EQ_ID_EFEM);
- pEquipment->setName("EFEM(ROBOT)");
- pEquipment->setDescription("EFEM(ROBOT).");
- pEquipment->setReadBitBlock(0x4000, 0x45ff);
- pEquipment->setStation(0, 255);
- addEquipment(pEquipment);
+ addEFEM(listener);
-
- // 添加 step
- {
- CEqModeStep* pStep = new CEqModeStep();
- pStep->setWriteSignalDev(0x30);
- pStep->setModeDev(0x4a8c);
- if (pEquipment->addStep(0x360, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqStatusStep* pStep = new CEqStatusStep();
- pStep->setWriteSignalDev(0x31);
- pStep->setStatusDev(0x4a68);
- if (pEquipment->addStep(0x361, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqAlarmStep* pStep = new CEqAlarmStep();
- pStep->setWriteSignalDev(0x32);
- pStep->setAlarmDev(0x4c1d);
- if (pEquipment->addStep(0x362, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqAlarmStep* pStep = new CEqAlarmStep();
- pStep->setWriteSignalDev(0x33);
- pStep->setAlarmDev(0x4c4a);
- if (pEquipment->addStep(0x363, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqAlarmStep* pStep = new CEqAlarmStep();
- pStep->setWriteSignalDev(0x34);
- pStep->setAlarmDev(0x4c77);
- if (pEquipment->addStep(0x364, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqAlarmStep* pStep = new CEqAlarmStep();
- pStep->setWriteSignalDev(0x35);
- pStep->setAlarmDev(0x4ca4);
- if (pEquipment->addStep(0x365, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqAlarmStep* pStep = new CEqAlarmStep();
- pStep->setWriteSignalDev(0x36);
- pStep->setAlarmDev(0x4cd1);
- if (pEquipment->addStep(0x366, pStep) != 0) {
- delete pStep;
- }
- }
-
-
- pEquipment->init();
- LOGE("已添加“EFEM(ROBOT)”.");
- }
/*
{
CBonder* pBonder = new CBonder();
@@ -196,6 +136,95 @@
return nullptr;
}
+ int CMaster::addEFEM(StepListener& listener)
+ {
+ CEFEM* pEquipment = new CEFEM();
+ pEquipment->setID(EQ_ID_EFEM);
+ pEquipment->setName("EFEM(ROBOT)");
+ pEquipment->setDescription("EFEM(ROBOT).");
+ pEquipment->setReadBitBlock(0x4000, 0x45ff);
+ pEquipment->setStation(0, 255);
+ addEquipment(pEquipment);
+
+
+ // 添加 step
+ {
+ CEqModeStep* pStep = new CEqModeStep();
+ pStep->setName("EQMode");
+ pStep->setListener(listener);
+ pStep->setWriteSignalDev(0x30);
+ pStep->setModeDev(0x4a8c);
+ if (pEquipment->addStep(0x360, pStep) != 0) {
+ delete pStep;
+ }
+ }
+ {
+ CEqStatusStep* pStep = new CEqStatusStep();
+ pStep->setName("EQStatus");
+ pStep->setListener(listener);
+ pStep->setWriteSignalDev(0x31);
+ pStep->setStatusDev(0x4a68);
+ if (pEquipment->addStep(0x361, pStep) != 0) {
+ delete pStep;
+ }
+ }
+ {
+ CEqAlarmStep* pStep = new CEqAlarmStep();
+ pStep->setName("EQAlarm1");
+ pStep->setListener(listener);
+ pStep->setWriteSignalDev(0x32);
+ pStep->setAlarmDev(0x4c1d);
+ if (pEquipment->addStep(0x362, pStep) != 0) {
+ delete pStep;
+ }
+ }
+ {
+ CEqAlarmStep* pStep = new CEqAlarmStep();
+ pStep->setName("EQAlarm2");
+ pStep->setListener(listener);
+ pStep->setWriteSignalDev(0x33);
+ pStep->setAlarmDev(0x4c4a);
+ if (pEquipment->addStep(0x363, pStep) != 0) {
+ delete pStep;
+ }
+ }
+ {
+ CEqAlarmStep* pStep = new CEqAlarmStep();
+ pStep->setName("EQAlarm3");
+ pStep->setListener(listener);
+ pStep->setWriteSignalDev(0x34);
+ pStep->setAlarmDev(0x4c77);
+ if (pEquipment->addStep(0x364, pStep) != 0) {
+ delete pStep;
+ }
+ }
+ {
+ CEqAlarmStep* pStep = new CEqAlarmStep();
+ pStep->setName("EQAlarm4");
+ pStep->setListener(listener);
+ pStep->setWriteSignalDev(0x35);
+ pStep->setAlarmDev(0x4ca4);
+ if (pEquipment->addStep(0x365, pStep) != 0) {
+ delete pStep;
+ }
+ }
+ {
+ CEqAlarmStep* pStep = new CEqAlarmStep();
+ pStep->setName("EQAlarm5");
+ pStep->setListener(listener);
+ pStep->setWriteSignalDev(0x36);
+ pStep->setAlarmDev(0x4cd1);
+ if (pEquipment->addStep(0x366, pStep) != 0) {
+ delete pStep;
+ }
+ }
+
+
+ pEquipment->init();
+ LOGE("已添加“EFEM(ROBOT)”.");
+ return 0;
+ }
+
void CMaster::onTimer(UINT nTimerid)
{
for (auto item : m_listEquipment) {
diff --git a/SourceCode/Bond/Servo/CMaster.h b/SourceCode/Bond/Servo/CMaster.h
index 704b502..73ae99b 100644
--- a/SourceCode/Bond/Servo/CMaster.h
+++ b/SourceCode/Bond/Servo/CMaster.h
@@ -8,10 +8,12 @@
namespace SERVO {
typedef std::function<void(void* pMaster, CEquipment* pEiuipment, BOOL bAlive)> ONEQALIVE;
+ typedef std::function<void(CStep* pStep, int code, void* pData)> ONEQSTEPEVENT;
typedef struct _MasterListener
{
ONEQALIVE onEqAlive;
ONEQALIVE onEqCimStateChanged;
+ ONEQSTEPEVENT onEqStepEvent;
} MasterListener;
class CMaster
@@ -30,6 +32,7 @@
private:
int addEquipment(CEquipment* pEquipment);
+ int addEFEM(StepListener& listener);
private:
MasterListener m_listener;
diff --git a/SourceCode/Bond/Servo/CStep.cpp b/SourceCode/Bond/Servo/CStep.cpp
index 74e072c..2e43de3 100644
--- a/SourceCode/Bond/Servo/CStep.cpp
+++ b/SourceCode/Bond/Servo/CStep.cpp
@@ -13,6 +13,7 @@
CStep::CStep()
{
+ m_listener = {nullptr};
m_nWordThreadAddr = 0;
m_hWorkStop = nullptr;
m_hWorkThreadHandle = nullptr;
@@ -37,9 +38,34 @@
DeleteCriticalSection(&m_criticalSection);
}
+ void CStep::setListener(StepListener listener)
+ {
+ m_listener.onEvent = listener.onEvent;
+ }
+
void CStep::setCcLink(CCCLinkIEControl* pCcLink)
{
m_pCclink = pCcLink;
+ }
+
+ void CStep::setEquipment(CEquipment* pEquipment)
+ {
+ m_pEquipment = pEquipment;
+ }
+
+ CEquipment* CStep::getEquipment()
+ {
+ return m_pEquipment;
+ }
+
+ void CStep::setName(const char* pszName)
+ {
+ m_strName = pszName;
+ }
+
+ std::string& CStep::getName()
+ {
+ return m_strName;
}
void CStep::setWriteSignalDev(int dev)
@@ -92,8 +118,11 @@
// 1.读取数据
nextStep();
ASSERT(m_pCclink);
- onReadData();
-
+ if (0 == onReadData()) {
+ if (m_listener.onEvent != nullptr) {
+ m_listener.onEvent(this, STEP_EVENT_READDATA, nullptr);
+ }
+ }
// 2.给对方写ON
nextStep();
@@ -118,7 +147,11 @@
// 6.完成
nextStep();
- onComplete();
+ if (0 == onComplete()) {
+ if (m_listener.onEvent != nullptr) {
+ m_listener.onEvent(this, STEP_EVENT_COMPLETE, nullptr);
+ }
+ }
}
}
diff --git a/SourceCode/Bond/Servo/CStep.h b/SourceCode/Bond/Servo/CStep.h
index 052d4e4..628f116 100644
--- a/SourceCode/Bond/Servo/CStep.h
+++ b/SourceCode/Bond/Servo/CStep.h
@@ -3,6 +3,16 @@
namespace SERVO {
+#define STEP_EVENT_READDATA 0x01
+#define STEP_EVENT_COMPLETE 0x02
+
+ typedef std::function<void(void* pStep, int code, void* pData)> ONSTEPEVENT;
+ typedef struct _StepListener
+ {
+ ONSTEPEVENT onEvent;
+ } StepListener;
+
+ class CEquipment;
class CStep
{
public:
@@ -11,7 +21,12 @@
public:
unsigned WorkingProc();
+ void setListener(StepListener listener);
void setCcLink(CCCLinkIEControl* pCcLink);
+ void setEquipment(CEquipment* pEquipment);
+ CEquipment* getEquipment();
+ void setName(const char* pszName);
+ std::string& getName();
virtual void setWriteSignalDev(int dev);
virtual void init();
virtual void CStep::term();
@@ -27,7 +42,10 @@
inline void resetStep();
protected:
+ StepListener m_listener;
StationIdentifier m_station;
+ std::string m_strName;
+ CEquipment* m_pEquipment;
CCCLinkIEControl* m_pCclink;
CRITICAL_SECTION m_criticalSection;
std::string strName;
diff --git a/SourceCode/Bond/Servo/Common.h b/SourceCode/Bond/Servo/Common.h
index f6ab0b4..22cd941 100644
--- a/SourceCode/Bond/Servo/Common.h
+++ b/SourceCode/Bond/Servo/Common.h
@@ -8,7 +8,7 @@
#define RX_CODE_MES_MESSAGE 1002
#define RX_HSMS_TERMINAL_TEXT 1003
#define RX_CODE_EQ_ALIVE 1004
-
+#define RX_CODE_STEP_EVENT_READDATA 1005
/* Channel Name */
#define MC_CHANNEL1_NAME "McChannel1"
diff --git a/SourceCode/Bond/Servo/Model.cpp b/SourceCode/Bond/Servo/Model.cpp
index 66cf9a7..38ad39f 100644
--- a/SourceCode/Bond/Servo/Model.cpp
+++ b/SourceCode/Bond/Servo/Model.cpp
@@ -99,8 +99,18 @@
masterListener.onEqCimStateChanged = [&](void* pMaster, SERVO::CEquipment* pEquipment, BOOL bOn) -> void {
LOGI("<CModel>Equipment Cim State:%s(%s).\n", pEquipment->getName().c_str(),
bOn ? _T("ON") : _T("OFF"));
+ notifyPtr(RX_CODE_EQ_ALIVE, pEquipment);
};
+ masterListener.onEqStepEvent = [&](SERVO::CStep* pStep, int code, void* pData) -> void {
+ if (code == STEP_EVENT_READDATA) {
+ LOGI("<CModel>onEqStepEvent,数据变化:%s(%s, 0x%x).\n", pStep->getEquipment()->getName().c_str(),
+ pStep->getName().c_str(), pData);
+ notifyPtr(RX_CODE_STEP_EVENT_READDATA, pStep);
+
+ }
+ };
+
m_master.setListener(masterListener);
return 0;
--
Gitblit v1.9.3