From 2de4eb139c0cc595db761fedd822549384822fc9 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 11 七月 2025 16:25:00 +0800
Subject: [PATCH] 1.EAP模拟器,Eanble/Disable Event对话框,可以模拟EAP下发 Enable/Disable Event Report; 2.Master, 增加接口设置 Enable/Disable Event Report,目前仅处理enable/disable所有 event上报;

---
 SourceCode/Bond/Servo/HsmsPassive.h                       |    2 
 SourceCode/Bond/EAPSimulator/CHsmsActive.h                |    5 +
 SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.h            |    1 
 SourceCode/Bond/Servo/HsmsPassive.cpp                     |    8 +-
 SourceCode/Bond/EAPSimulator/EAPSimulator.rc              |    0 
 SourceCode/Bond/Servo/CMaster.h                           |    6 +
 SourceCode/Bond/Servo/Model.cpp                           |    7 +
 SourceCode/Bond/EAPSimulator/EAPSimulator.vcxproj.filters |    6 +
 SourceCode/Bond/EAPSimulator/CEDEventReportDlg.cpp        |   71 +++++++++++++++++
 SourceCode/Bond/EAPSimulator/CHsmsActive.cpp              |   16 ++++
 SourceCode/Bond/EAPSimulator/Resource.h                   |   10 ++
 SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp          |    9 ++
 SourceCode/Bond/EAPSimulator/EAPSimulator.vcxproj         |    2 
 SourceCode/Bond/Servo/CMaster.cpp                         |   12 +++
 SourceCode/Bond/EAPSimulator/CEDEventReportDlg.h          |   26 ++++++
 15 files changed, 174 insertions(+), 7 deletions(-)

diff --git a/SourceCode/Bond/EAPSimulator/CEDEventReportDlg.cpp b/SourceCode/Bond/EAPSimulator/CEDEventReportDlg.cpp
new file mode 100644
index 0000000..6851b13
--- /dev/null
+++ b/SourceCode/Bond/EAPSimulator/CEDEventReportDlg.cpp
@@ -0,0 +1,71 @@
+锘�// CEDEventReportDlg.cpp: 瀹炵幇鏂囦欢
+//
+
+#include "pch.h"
+#include "EAPSimulator.h"
+#include "CEDEventReportDlg.h"
+#include "afxdialogex.h"
+#include <vector>
+
+
+// CEDEventReportDlg 瀵硅瘽妗�
+
+IMPLEMENT_DYNAMIC(CEDEventReportDlg, CDialogEx)
+
+CEDEventReportDlg::CEDEventReportDlg(CWnd* pParent /*=nullptr*/)
+	: CDialogEx(IDD_DIALOG_ED_EVENT_REPORT, pParent)
+{
+
+}
+
+CEDEventReportDlg::~CEDEventReportDlg()
+{
+}
+
+void CEDEventReportDlg::DoDataExchange(CDataExchange* pDX)
+{
+	CDialogEx::DoDataExchange(pDX);
+}
+
+
+BEGIN_MESSAGE_MAP(CEDEventReportDlg, CDialogEx)
+	ON_BN_CLICKED(IDC_BUTTON_SEND, &CEDEventReportDlg::OnBnClickedButtonSend)
+END_MESSAGE_MAP()
+
+
+// CEDEventReportDlg 娑堟伅澶勭悊绋嬪簭
+
+
+BOOL CEDEventReportDlg::OnInitDialog()
+{
+	CDialogEx::OnInitDialog();
+
+	CButton* pButton = (CButton*)GetDlgItem(IDC_RADIO_ENABLE);
+	pButton->SetCheck(BST_CHECKED);
+
+
+	return TRUE;  // return TRUE unless you set the focus to a control
+				  // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
+}
+
+void CEDEventReportDlg::OnBnClickedButtonSend()
+{
+	CButton* pButton = (CButton*)GetDlgItem(IDC_RADIO_ENABLE);
+	bool bEnable = pButton->GetCheck() == BST_CHECKED;
+
+	CString strText, strId;
+	GetDlgItemText(IDC_EDIT_CEID, strText);
+	std::vector<int> ids;
+	if (!strText.IsEmpty()) {
+		int i = 0;
+		while (1) {
+			if (!AfxExtractSubString(strId, (LPCTSTR)strText, i++, ',')) {
+				break;
+			}
+			ids.push_back(atoi(strId));
+		}
+	}
+
+
+	theApp.m_model.m_pHsmsActive->hsmsEDEventReport(bEnable, ids);
+}
diff --git a/SourceCode/Bond/EAPSimulator/CEDEventReportDlg.h b/SourceCode/Bond/EAPSimulator/CEDEventReportDlg.h
new file mode 100644
index 0000000..8150dd1
--- /dev/null
+++ b/SourceCode/Bond/EAPSimulator/CEDEventReportDlg.h
@@ -0,0 +1,26 @@
+锘�#pragma once
+
+
+// CEDEventReportDlg 瀵硅瘽妗�
+
+class CEDEventReportDlg : public CDialogEx
+{
+	DECLARE_DYNAMIC(CEDEventReportDlg)
+
+public:
+	CEDEventReportDlg(CWnd* pParent = nullptr);   // 鏍囧噯鏋勯�犲嚱鏁�
+	virtual ~CEDEventReportDlg();
+
+// 瀵硅瘽妗嗘暟鎹�
+#ifdef AFX_DESIGN_TIME
+	enum { IDD = IDD_DIALOG_ED_EVENT_REPORT };
+#endif
+
+protected:
+	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 鏀寔
+
+	DECLARE_MESSAGE_MAP()
+public:
+	virtual BOOL OnInitDialog();
+	afx_msg void OnBnClickedButtonSend();
+};
diff --git a/SourceCode/Bond/EAPSimulator/CHsmsActive.cpp b/SourceCode/Bond/EAPSimulator/CHsmsActive.cpp
index 94f5bb7..f610450 100644
--- a/SourceCode/Bond/EAPSimulator/CHsmsActive.cpp
+++ b/SourceCode/Bond/EAPSimulator/CHsmsActive.cpp
@@ -170,6 +170,22 @@
 	return 0;
 }
 
+int CHsmsActive::hsmsEDEventReport(bool bEnable, std::vector<int>& ids)
+{
+	IMessage* pMessage = nullptr;
+	int nRet = HSMS_Create1Message(pMessage, m_nSessionId, 2 | REPLY, 37, ++m_nSystemByte);
+	ISECS2Item* pItem = pMessage->getBody();
+	pItem->addBoolItem(bEnable, "CEED");
+	ISECS2Item* pItem2 = pItem->addItem();
+	for (auto item : ids) {
+		pItem2->addU4Item(item, "CEID");
+	}
+	m_pActive->sendMessage(pMessage);
+	HSMS_Destroy1Message(pMessage);
+
+	return 0;
+}
+
 int CHsmsActive::replyAck0(IMessage* pMessage)
 {
 	return 0;
diff --git a/SourceCode/Bond/EAPSimulator/CHsmsActive.h b/SourceCode/Bond/EAPSimulator/CHsmsActive.h
index 9b839cd..8d8f423 100644
--- a/SourceCode/Bond/EAPSimulator/CHsmsActive.h
+++ b/SourceCode/Bond/EAPSimulator/CHsmsActive.h
@@ -1,5 +1,7 @@
 #pragma once
 #include <string>
+#include <vector>
+
 
 typedef std::function<void(void* pFrom, ACTIVESTATE state)> STATECHANGED;
 typedef struct _ACTIVEListener
@@ -37,6 +39,9 @@
 	// terminal display
 	int hsmsTerminalDisplay(BYTE tid, const char* pszText);
 
+	// Enable/Disable Event Report
+	int hsmsEDEventReport(bool bEnable, std::vector<int>& ids);
+
 	// 通过的reply函数
 	void replyAck(int s, int f, unsigned int systemBytes, BYTE ack, const char* pszAckName);
 
diff --git a/SourceCode/Bond/EAPSimulator/EAPSimulator.rc b/SourceCode/Bond/EAPSimulator/EAPSimulator.rc
index 559cb5c..f5318f1 100644
--- a/SourceCode/Bond/EAPSimulator/EAPSimulator.rc
+++ b/SourceCode/Bond/EAPSimulator/EAPSimulator.rc
Binary files differ
diff --git a/SourceCode/Bond/EAPSimulator/EAPSimulator.vcxproj b/SourceCode/Bond/EAPSimulator/EAPSimulator.vcxproj
index c7d4d5c..a8b9b26 100644
--- a/SourceCode/Bond/EAPSimulator/EAPSimulator.vcxproj
+++ b/SourceCode/Bond/EAPSimulator/EAPSimulator.vcxproj
@@ -183,6 +183,7 @@
     </ResourceCompile>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClInclude Include="CEDEventReportDlg.h" />
     <ClInclude Include="CHsmsActive.h" />
     <ClInclude Include="CModel.h" />
     <ClInclude Include="Common.h" />
@@ -198,6 +199,7 @@
     <ClInclude Include="targetver.h" />
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="CEDEventReportDlg.cpp" />
     <ClCompile Include="CHsmsActive.cpp" />
     <ClCompile Include="CModel.cpp" />
     <ClCompile Include="Context.cpp" />
diff --git a/SourceCode/Bond/EAPSimulator/EAPSimulator.vcxproj.filters b/SourceCode/Bond/EAPSimulator/EAPSimulator.vcxproj.filters
index 84e59fd..d868d86 100644
--- a/SourceCode/Bond/EAPSimulator/EAPSimulator.vcxproj.filters
+++ b/SourceCode/Bond/EAPSimulator/EAPSimulator.vcxproj.filters
@@ -54,6 +54,9 @@
     <ClInclude Include="CTerminalDisplayDlg.h">
       <Filter>澶存枃浠�</Filter>
     </ClInclude>
+    <ClInclude Include="CEDEventReportDlg.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="EAPSimulator.cpp">
@@ -83,6 +86,9 @@
     <ClCompile Include="CTerminalDisplayDlg.cpp">
       <Filter>婧愭枃浠�</Filter>
     </ClCompile>
+    <ClCompile Include="CEDEventReportDlg.cpp">
+      <Filter>婧愭枃浠�</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="EAPSimulator.rc">
diff --git a/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp b/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp
index 4609d25..ef31282 100644
--- a/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp
+++ b/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp
@@ -10,6 +10,7 @@
 #include "Common.h"
 #include <regex>
 #include "CTerminalDisplayDlg.h"
+#include "CEDEventReportDlg.h"
 
 
 #ifdef _DEBUG
@@ -77,6 +78,7 @@
 	ON_BN_CLICKED(IDC_BUTTON_ARE_YOU_THERE, &CEAPSimulatorDlg::OnBnClickedButtonAreYouThere)
 	ON_BN_CLICKED(IDC_BUTTON_DATETIME_SYNC, &CEAPSimulatorDlg::OnBnClickedButtonDatetimeSync)
 	ON_BN_CLICKED(IDC_BUTTON_TERMINAL_DISPLAY, &CEAPSimulatorDlg::OnBnClickedButtonTerminalDisplay)
+	ON_BN_CLICKED(IDC_BUTTON_ED_EVENT_REPORT, &CEAPSimulatorDlg::OnBnClickedButtonEdEventReport)
 END_MESSAGE_MAP()
 
 
@@ -255,6 +257,7 @@
 	GetDlgItem(IDC_BUTTON_ARE_YOU_THERE)->EnableWindow(enabled);
 	GetDlgItem(IDC_BUTTON_DATETIME_SYNC)->EnableWindow(enabled);
 	GetDlgItem(IDC_BUTTON_TERMINAL_DISPLAY)->EnableWindow(enabled);	
+	GetDlgItem(IDC_BUTTON_ED_EVENT_REPORT)->EnableWindow(enabled);
 }
 
 void CEAPSimulatorDlg::OnBnClickedButtonConnect()
@@ -287,3 +290,9 @@
 	CTerminalDisplayDlg dlg;
 	dlg.DoModal();
 }
+
+void CEAPSimulatorDlg::OnBnClickedButtonEdEventReport()
+{
+	CEDEventReportDlg dlg;
+	dlg.DoModal();
+}
diff --git a/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.h b/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.h
index 5bd3972..bd6b3a0 100644
--- a/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.h
+++ b/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.h
@@ -49,4 +49,5 @@
 	afx_msg void OnBnClickedButtonAreYouThere();
 	afx_msg void OnBnClickedButtonDatetimeSync();
 	afx_msg void OnBnClickedButtonTerminalDisplay();
+	afx_msg void OnBnClickedButtonEdEventReport();
 };
diff --git a/SourceCode/Bond/EAPSimulator/Resource.h b/SourceCode/Bond/EAPSimulator/Resource.h
index 5197bdc..088e427 100644
--- a/SourceCode/Bond/EAPSimulator/Resource.h
+++ b/SourceCode/Bond/EAPSimulator/Resource.h
@@ -8,6 +8,7 @@
 #define IDD_EAPSIMULATOR_DIALOG         102
 #define IDR_MAINFRAME                   128
 #define IDD_DIALOG_TERMINAL_DISPLAY     129
+#define IDD_DIALOG_ED_EVENT_REPORT      131
 #define IDC_EDIT_LOG                    1000
 #define IDC_EDIT_IP                     1001
 #define IDC_EDIT_PORT                   1002
@@ -17,16 +18,21 @@
 #define IDC_BUTTON_DATETIME_SYNC        1006
 #define IDC_BUTTON_TERMINAL_DISPLAY     1007
 #define IDC_COMBO_TID                   1008
+#define IDC_BUTTON_ED_EVENT_REPORT      1008
 #define IDC_EDIT_TEXT                   1009
 #define IDC_BUTTON_SEND                 1010
+#define IDC_RADIO_ENABLE                1012
+#define IDC_RADIO_DISABLE               1013
+#define IDC_EDIT1                       1014
+#define IDC_EDIT_CEID                   1014
 
 // Next default values for new objects
 // 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        131
+#define _APS_NEXT_RESOURCE_VALUE        133
 #define _APS_NEXT_COMMAND_VALUE         32771
-#define _APS_NEXT_CONTROL_VALUE         1011
+#define _APS_NEXT_CONTROL_VALUE         1015
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 11c7cc2..14bfb6c 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -51,6 +51,8 @@
 		m_state = MASTERSTATE::READY;
 		m_pActiveRobotTask = nullptr;
 		m_nLastError = 0;
+		m_bEnableEventReport = true;
+		m_bEnableAlarmReport = true;
 		InitializeCriticalSection(&m_criticalSection);
 	}
 
@@ -1585,4 +1587,14 @@
 				time.wHour, time.wMinute, time.wSecond);
 		}
 	}
+
+	void CMaster::enableEventReport(bool bEnable)
+	{
+		m_bEnableEventReport = bEnable;
+	}
+
+	void CMaster::enableAlarmReport(bool bEnable)
+	{
+		m_bEnableAlarmReport = bEnable;
+	}
 }
diff --git a/SourceCode/Bond/Servo/CMaster.h b/SourceCode/Bond/Servo/CMaster.h
index f005d7c..e8a381e 100644
--- a/SourceCode/Bond/Servo/CMaster.h
+++ b/SourceCode/Bond/Servo/CMaster.h
@@ -70,6 +70,8 @@
         void setPortType(unsigned int index, BOOL enable, int type, int mode,
             int cassetteType, int transferMode, BOOL autoChangeEnable);
         void datetimeSync(SYSTEMTIME& time);
+        void enableEventReport(bool bEnable);
+        void enableAlarmReport(bool bEnable);
 
     private:
         inline void lock() { EnterCriticalSection(&m_criticalSection); }
@@ -131,6 +133,10 @@
         // 错误代码
         int m_nLastError;
         std::string m_strLastError;
+
+    private:
+        bool m_bEnableEventReport;
+        bool m_bEnableAlarmReport;
     };
 }
 
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index 832f6d3..07ee9a9 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -754,15 +754,15 @@
 			}
 		}
 		bCheckData = TRUE;
-		LOGI("EanbleDisableAlarm bEnable:%s", bEnable ? _T("YES") : _T("NO"));
-		for (auto item : ids) {
-			LOGI("ID:%u", item);
+		if (m_listener.onEnableDisableEventReport != nullptr) {
+			m_listener.onEnableDisableEventReport(this, bEnable, ids);
 		}
 	}
 
 
 MYREPLY:
-	replyAck(2, 38, pRecv->getHeader()->systemBytes, BYTE(0), "ERACK");
+	replyAck(2, 38, pRecv->getHeader()->systemBytes, 
+		bCheckData ? BYTE(0) : BYTE(1), "ERACK");
 	return 0;
 }
 
diff --git a/SourceCode/Bond/Servo/HsmsPassive.h b/SourceCode/Bond/Servo/HsmsPassive.h
index 38ba909..dbabb8a 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.h
+++ b/SourceCode/Bond/Servo/HsmsPassive.h
@@ -61,6 +61,7 @@
 typedef std::function<void(void* pFrom, std::vector<EQConstant>&)> SECSEQCONSTANTREQUEST;
 typedef std::function<void(void* pFrom, const char*, std::vector<CommandParameter>&)> SECSCommand;
 typedef std::function<void(void* pFrom, SYSTEMTIME& time)> DATETIMESYNC;
+typedef std::function<void(void* pFrom, bool bEnable, std::vector<unsigned int>& ids)> EDEVENTREPORT;
 typedef struct _SECSListener
 {
 	SECSEQOFFLINE				onEQOffLine;
@@ -69,6 +70,7 @@
 	SECSEQCONSTANTREQUEST		onEQConstantSend;
 	SECSCommand					onCommand;
 	DATETIMESYNC				onDatetimeSync;
+	EDEVENTREPORT				onEnableDisableEventReport;
 } SECSListener;
 
 
diff --git a/SourceCode/Bond/Servo/Model.cpp b/SourceCode/Bond/Servo/Model.cpp
index 5d39e14..476ca44 100644
--- a/SourceCode/Bond/Servo/Model.cpp
+++ b/SourceCode/Bond/Servo/Model.cpp
@@ -113,7 +113,12 @@
 			time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond);
 		m_master.datetimeSync(time);
 	};
-
+	listener.onEnableDisableEventReport = [&](void* pFrom, bool bEnable, std::vector<unsigned int> ids) -> void {
+		LOGI("EanbleDisableEventReport bEnable:%s", bEnable ? _T("YES") : _T("NO"));
+		if (ids.empty()) {
+			m_master.enableEventReport(bEnable);
+		}
+	};
 	m_hsmsPassive.setListener(listener);
 	m_hsmsPassive.setEquipmentModelType((LPTSTR)(LPCTSTR)strModeType);
 	m_hsmsPassive.setSoftRev((LPTSTR)(LPCTSTR)strSoftRev);

--
Gitblit v1.9.3