From e321862aa976acc151da3e3b983b34288800d975 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 14 十一月 2024 08:37:51 +0800
Subject: [PATCH] 1.删简;
---
SourceCode/Bond/BondEq/Model.h | 6 +--
SourceCode/Bond/BondEq/CProjectPageRemoteEqs.cpp | 12 -----
SourceCode/Bond/BondEq/BondEqDlg.cpp | 6 --
SourceCode/Bond/BondEq/Model.cpp | 89 +++++++-------------------------------------
SourceCode/Bond/BondEq/Common.h | 2
5 files changed, 19 insertions(+), 96 deletions(-)
diff --git a/SourceCode/Bond/BondEq/BondEqDlg.cpp b/SourceCode/Bond/BondEq/BondEqDlg.cpp
index 63621f8..656307c 100644
--- a/SourceCode/Bond/BondEq/BondEqDlg.cpp
+++ b/SourceCode/Bond/BondEq/BondEqDlg.cpp
@@ -212,7 +212,6 @@
// Home页
m_pHomeDialog = CreateHomeDlg();
ShowWindow(SW_SHOWMAXIMIZED);
- SetTimer(2, 1000, nullptr);
InitRxWindows();
@@ -578,10 +577,7 @@
}
}
}
- else if (2 == nIDEvent) {
- KillTimer(2);
- theApp.m_model.createRemoteEqs();
- }
+
CDialogEx::OnTimer(nIDEvent);
}
diff --git a/SourceCode/Bond/BondEq/CProjectPageRemoteEqs.cpp b/SourceCode/Bond/BondEq/CProjectPageRemoteEqs.cpp
index 2eed02d..b10097f 100644
--- a/SourceCode/Bond/BondEq/CProjectPageRemoteEqs.cpp
+++ b/SourceCode/Bond/BondEq/CProjectPageRemoteEqs.cpp
@@ -55,7 +55,7 @@
// onNext
pAny->addRef();
int code = pAny->getCode();
- if (RX_CODE_REMOTEEQ_STATE_CHANGED == code) {
+ if (RX_CODE_EQ_STATE_CHANGED == code) {
BEQ::IRemoteEquipment* pRemoteEq;
if (pAny->getPtrValue("ptr", (void*&)pRemoteEq)) {
HTREEITEM hItem = getTreeItem(pRemoteEq);
@@ -195,16 +195,6 @@
if (1 == nIDEvent) {
KillTimer(1);
InitRxWindows();
-
- // 杩滅▼璁惧鍒楄〃
- char szEqName[256];
- BEQ::IRemoteEquipment* pRemoteEq = theApp.m_model.getBond1();
- ASSERT(pRemoteEq);
- pRemoteEq->getName(szEqName, 256);
-
- HTREEITEM hItemEq = m_treeRemoteEqs.InsertItem(szEqName);
- m_treeRemoteEqs.SetItemIcon(hItemEq, pRemoteEq->isConnected() ? m_hIconRemoteEqLight : m_hIconRemoteEqDark);
- m_treeRemoteEqs.SetItemData(hItemEq, (DWORD_PTR)pRemoteEq);
}
CDialogEx::OnTimer(nIDEvent);
diff --git a/SourceCode/Bond/BondEq/Common.h b/SourceCode/Bond/BondEq/Common.h
index 0ef4e64..0dadb20 100644
--- a/SourceCode/Bond/BondEq/Common.h
+++ b/SourceCode/Bond/BondEq/Common.h
@@ -28,7 +28,7 @@
#define RX_CODE_ALARM_EVENT 1012
#define RX_CODE_EQSTATE_EVENT 1013
#define RX_CODE_EFEM_STATUS_CHANGED 1014
-#define RX_CODE_REMOTEEQ_STATE_CHANGED 1015
+#define RX_CODE_EQ_STATE_CHANGED 1015
/* 广播代码 */
#define BC_CODE_DATA1_MATERIAL_RECEIVED 5000
diff --git a/SourceCode/Bond/BondEq/Model.cpp b/SourceCode/Bond/BondEq/Model.cpp
index 73e1d7e..30fd949 100644
--- a/SourceCode/Bond/BondEq/Model.cpp
+++ b/SourceCode/Bond/BondEq/Model.cpp
@@ -19,8 +19,7 @@
{
m_pObservableEmitter = nullptr;
m_pObservable = nullptr;
- m_pServo = nullptr;
- m_pEqBond1 = nullptr;
+ m_pEquipment = nullptr;
m_nTimerID = 0;
}
@@ -76,54 +75,19 @@
// 创建Servo
- BEQ_CreateServo(m_pServo, "BLServo");
- ASSERT(m_pServo);
- BEQ::ServoListener listener;
- listener.onRemoteEqConnecting = [&](void* pServo, void* pRemoteEiuipment) -> void {
- BEQ::IRemoteEquipment* p = (BEQ::IRemoteEquipment*)pRemoteEiuipment;
- char szBuffer[256];
- p->getName(szBuffer, 256);
- LOGI("<ServoListener>正在连接远程设备(%s)...", szBuffer);
+ BEQ_CreateEquipment(m_pEquipment, "BLBonder");
+ ASSERT(m_pEquipment);
+ BEQ::EquipmentListener listener;
+ listener.onConnected = [&](void* pEiuipment, const char* pszAddr, int port) -> void {
+ LOGI("<EquipmentListener>连接进入(%s:%d).", pszAddr, port);
+ notifyPtr(RX_CODE_EQ_STATE_CHANGED, pEiuipment);
};
- listener.onRemoteEqConnected = [&](void* pServo, void* pRemoteEiuipment) -> void {
- BEQ::IRemoteEquipment* p = (BEQ::IRemoteEquipment*)pRemoteEiuipment;
- char szBuffer[256];
- p->getName(szBuffer, 256);
- LOGI("<ServoListener>连接远程设备(%s)成功.", szBuffer);
- notifyPtr(RX_CODE_REMOTEEQ_STATE_CHANGED, pRemoteEiuipment);
+ listener.onDisconnected = [&](void* pEiuipment, const char* pszAddr, int port) -> void {
+ LOGI("<EquipmentListener>连接断开(%s:%d).", pszAddr, port);
+ notifyPtr(RX_CODE_EQ_STATE_CHANGED, pEiuipment);
};
- listener.onRemoteEqConnectFailed = [&](void* pServo, void* pRemoteEiuipment, int errorCode) -> void {
- BEQ::IRemoteEquipment* p = (BEQ::IRemoteEquipment*)pRemoteEiuipment;
- char szBuffer[256];
- p->getName(szBuffer, 256);
- LOGW("<ServoListener>连接远程设备(%s)失败.", szBuffer);
- };
- listener.onRemoteEqDisconnecting = [&](void* pServo, void* pRemoteEiuipment) -> void {
- BEQ::IRemoteEquipment* p = (BEQ::IRemoteEquipment*)pRemoteEiuipment;
- char szBuffer[256];
- p->getName(szBuffer, 256);
- LOGI("<ServoListener>正在断开远程设备(%s).", szBuffer);
- };
- listener.onRemoteEqDisconnected = [&](void* pServo, void* pRemoteEiuipment) -> void {
- BEQ::IRemoteEquipment* p = (BEQ::IRemoteEquipment*)pRemoteEiuipment;
- char szBuffer[256];
- p->getName(szBuffer, 256);
- LOGW("<ServoListener>远程设备(%s)连接断开.", szBuffer);
- notifyPtr(RX_CODE_REMOTEEQ_STATE_CHANGED, pRemoteEiuipment);
- };
- listener.onRemoteEqReadRawdata = [&](void* pServo, void* pRemoteEiuipment, const char* pszData, int len) -> void {
- BEQ::IRemoteEquipment* p = (BEQ::IRemoteEquipment*)pRemoteEiuipment;
- char szBuffer[256];
- p->getName(szBuffer, 256);
- LOGD("<ServoListener>收到远程设备(%s)原始数据(%s).", szBuffer, std::string(pszData, len).c_str());
- };
- listener.onRemoteEqEventUpdate = [&](void* pServo, void* pRemoteEiuipment, void* pUnit, BEQ::REMOTE_EQ_EVENT eventCode) -> void {
- BEQ::IRemoteEquipment* p = (BEQ::IRemoteEquipment*)pRemoteEiuipment;
- char szBuffer[256];
- p->getName(szBuffer, 256);
- LOGD("<ServoListener>远程设备(%s)onRemoteEqEventUpdate.", szBuffer);
- };
- m_pServo->setListener(listener);
+ // 注意此处还有几个回调函数未处理
+ m_pEquipment->setEquipmentListener(listener);
m_pObservable = RX_AllocaObservable([&](IObservableEmitter* e) -> void {
@@ -134,22 +98,6 @@
m_nTimerID = (int)SetTimer(NULL, 1, 1000, (TIMERPROC)ModerTimerProc);
g_pModel = this;
-
- return 0;
-}
-
-int CModel::createRemoteEqs()
-{
- // 从配置中读取远程机器配置
- CString strIp, strIniFile;
- UINT nPort, nDoorCount;
- strIniFile.Format(_T("%s\\Configuration.ini"), (LPTSTR)(LPCTSTR)m_strWorkDir);
- CConfiguration configuration((LPTSTR)(LPCTSTR)strIniFile);
- configuration.getBond1(strIp, nPort, nDoorCount);
- m_pServo->createRemoteEquipment(m_pEqBond1, (LPTSTR)(LPCTSTR)strIp, nPort);
- ASSERT(m_pEqBond1);
- m_pEqBond1->addUnit("UNITA", nDoorCount);
- m_pServo->connectRemoteEquipment(m_pEqBond1);
return 0;
}
@@ -165,9 +113,9 @@
return m_bonder;
}
-BEQ::IRemoteEquipment* CModel::getBond1()
+BEQ::IEquipment* CModel::getEquipment()
{
- return m_pEqBond1;
+ return m_pEquipment;
}
int CModel::notify(int code)
@@ -344,14 +292,5 @@
void CModel::onTimer(UINT nTimerid)
{
- ULONGLONG tick = GetTickCount64();
- int interval = m_configuration.getP2RemoteEqReconnectInterval() * 1000;
- if (m_pEqBond1 != nullptr) {
- if (!m_pEqBond1->isConnected()) {
- if (tick - m_pEqBond1->getConnectTick() > interval) {
- m_pEqBond1->connect();
- }
- }
- }
}
\ No newline at end of file
diff --git a/SourceCode/Bond/BondEq/Model.h b/SourceCode/Bond/BondEq/Model.h
index 9a74296..f9136b8 100644
--- a/SourceCode/Bond/BondEq/Model.h
+++ b/SourceCode/Bond/BondEq/Model.h
@@ -15,9 +15,8 @@
int init();
int term();
void onTimer(UINT nTimerid);
- int createRemoteEqs();
CBonder& getBonder();
- BEQ::IRemoteEquipment* getBond1();
+ BEQ::IEquipment* getEquipment();
public:
int notify(int code);
@@ -43,8 +42,7 @@
private:
CBonder m_bonder;
- BEQ::IServo* m_pServo;
- BEQ::IRemoteEquipment* m_pEqBond1;
+ BEQ::IEquipment* m_pEquipment;
int m_nTimerID;
};
--
Gitblit v1.9.3