From a9e9f76d23ee7206ea0080a8f5a94e312c9d90f1 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期二, 08 七月 2025 19:41:08 +0800
Subject: [PATCH] 1.UI分组启用和禁用,方便增加更多测试功能时代码整洁简单; 2.增加Are You There测试;
---
SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 119 insertions(+), 1 deletions(-)
diff --git a/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp b/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp
index 7f01939..e37d164 100644
--- a/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp
+++ b/SourceCode/Bond/EAPSimulator/EAPSimulatorDlg.cpp
@@ -7,6 +7,9 @@
#include "EAPSimulator.h"
#include "EAPSimulatorDlg.h"
#include "afxdialogex.h"
+#include "Common.h"
+#include <regex>
+
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -54,21 +57,76 @@
: CDialogEx(IDD_EAPSIMULATOR_DIALOG, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
+ m_pObserver = nullptr;
}
void CEAPSimulatorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
+ DDX_Control(pDX, IDC_EDIT_LOG, m_logEdit);
}
BEGIN_MESSAGE_MAP(CEAPSimulatorDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
+ ON_WM_DESTROY()
+ ON_BN_CLICKED(IDC_BUTTON_CONNECT, &CEAPSimulatorDlg::OnBnClickedButtonConnect)
+ ON_BN_CLICKED(IDC_BUTTON_DISCONNECT, &CEAPSimulatorDlg::OnBnClickedButtonDisconnect)
+ ON_BN_CLICKED(IDC_BUTTON_ARE_YOU_THERE, &CEAPSimulatorDlg::OnBnClickedButtonAreYouThere)
END_MESSAGE_MAP()
// CEAPSimulatorDlg 娑堟伅澶勭悊绋嬪簭
+
+void CEAPSimulatorDlg::InitRxWindow()
+{
+ /* code */
+ // 璁㈤槄鏁版嵁
+ IRxWindows* pRxWindows = RX_GetRxWindows();
+ pRxWindows->enableLog(5);
+ if (m_pObserver == NULL) {
+ m_pObserver = pRxWindows->allocObserver([&](IAny* pAny) -> void {
+ // onNext
+ pAny->addRef();
+ int code = pAny->getCode();
+ if (RX_CODE_LOG == code && ::IsWindow(m_hWnd)) {
+ const char* pszLogMsg;
+ int level;
+ if (pAny->getStringValue("text", pszLogMsg)
+ && pAny->getIntValue("exCode", level)) {
+ CString strText = pszLogMsg;
+ strText.Replace("\n", "\r\n");
+ AppendLog(level, (LPTSTR)(LPCTSTR)strText);
+ }
+ }
+ else if (RX_CODE_ACTIVE_STATUS_CHANGED == code) {
+ int state;
+ if (pAny->getIntValue("exCode", state)) {
+ if ((ACTIVESTATE)state == ACTIVESTATE::SELECTED) {
+ SetGroup2Enabled(TRUE);
+ }
+ if ((ACTIVESTATE)state == ACTIVESTATE::NOT_CONNECTED) {
+ SetGroup2Enabled(FALSE);
+ SetGroup1Enabled(TRUE);
+ }
+ }
+ }
+
+ pAny->release();
+ }, [&]() -> void {
+ // onComplete
+ }, [&](IThrowable* pThrowable) -> void {
+ // onErrorm
+ pThrowable->printf();
+ });
+
+ theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread())
+ ->subscribe(m_pObserver);
+ }
+
+ theApp.m_model.init();
+}
BOOL CEAPSimulatorDlg::OnInitDialog()
{
@@ -99,7 +157,16 @@
SetIcon(m_hIcon, TRUE); // 璁剧疆澶у浘鏍�
SetIcon(m_hIcon, FALSE); // 璁剧疆灏忓浘鏍�
- // TODO: 鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲浠g爜
+ SetDlgItemText(IDC_EDIT_IP, _T("127.0.0.1"));
+ SetDlgItemInt(IDC_EDIT_PORT, 7000);
+ SetGroup2Enabled(FALSE);
+ SetGroup1Enabled(TRUE);
+
+
+ // log edit
+ m_logEdit.SetMaxLineCount(8000);
+ m_logEdit.SetLimitText(-1);
+ InitRxWindow();
return TRUE; // 闄ら潪灏嗙劍鐐硅缃埌鎺т欢锛屽惁鍒欒繑鍥� TRUE
}
@@ -153,3 +220,54 @@
return static_cast<HCURSOR>(m_hIcon);
}
+void CEAPSimulatorDlg::AppendLog(int level, const char* pszText)
+{
+ if (!::IsWindow(m_logEdit.m_hWnd)) {
+ return;
+ }
+ m_logEdit.AppendText(pszText);
+}
+
+
+
+void CEAPSimulatorDlg::OnDestroy()
+{
+ CDialogEx::OnDestroy();
+
+ ASSERT(m_pObserver != NULL);
+ m_pObserver->unsubscribe();
+ m_pObserver = NULL;
+}
+
+void CEAPSimulatorDlg::SetGroup1Enabled(bool enabled)
+{
+ GetDlgItem(IDC_EDIT_IP)->EnableWindow(enabled);
+ GetDlgItem(IDC_EDIT_PORT)->EnableWindow(enabled);
+ GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(enabled);
+}
+
+void CEAPSimulatorDlg::SetGroup2Enabled(bool enabled)
+{
+ GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(enabled);
+ GetDlgItem(IDC_BUTTON_ARE_YOU_THERE)->EnableWindow(enabled);
+}
+
+void CEAPSimulatorDlg::OnBnClickedButtonConnect()
+{
+ CString strIp;
+ UINT port;
+ GetDlgItemText(IDC_EDIT_IP, strIp);
+ port = GetDlgItemInt(IDC_EDIT_PORT);
+ theApp.m_model.connectEq((LPTSTR)(LPCTSTR)strIp, port);
+ SetGroup1Enabled(FALSE);
+}
+
+void CEAPSimulatorDlg::OnBnClickedButtonDisconnect()
+{
+ theApp.m_model.disconnect();
+}
+
+void CEAPSimulatorDlg::OnBnClickedButtonAreYouThere()
+{
+ theApp.m_model.m_pHsmsActive->hsmsAreYouThere();
+}
--
Gitblit v1.9.3