From 702b614519289b33aee26c456dc22ffde0c09dda Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 16 一月 2025 11:32:15 +0800
Subject: [PATCH] 1.终端信息显示;
---
SourceCode/Bond/Servo/Servo.vcxproj | 16 +++
SourceCode/Bond/Servo/HsmsPassive.h | 3
SourceCode/Bond/Servo/Servo.vcxproj.filters | 7 +
SourceCode/Bond/Servo/resource.h | 0
SourceCode/Bond/Servo/HsmsPassive.cpp | 80 +++++++++++--------
SourceCode/Bond/Servo/Servo.rc | 0
SourceCode/Bond/Servo/ServoDlg.cpp | 71 +++++++++++++++++
SourceCode/Bond/Servo/Common.h | 1
SourceCode/Bond/Servo/ServoDlg.h | 17 +++-
9 files changed, 156 insertions(+), 39 deletions(-)
diff --git a/SourceCode/Bond/Servo/Common.h b/SourceCode/Bond/Servo/Common.h
index 3761f38..50370d7 100644
--- a/SourceCode/Bond/Servo/Common.h
+++ b/SourceCode/Bond/Servo/Common.h
@@ -6,6 +6,7 @@
#define RX_CODE_LOG 1000
#define RX_CODE_PASSIVE_STATUS_CHANGED 1001
#define RX_CODE_MES_MESSAGE 1002
+#define RX_HSMS_TERMINAL_TEXT 1003
/* Channel Name */
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index ab08dae..5a62733 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -191,6 +191,9 @@
else if (nStream == 5 && pHeader->function == 3) {
replyEanbleDisableAlarmReport(pMessage);
}
+ else if (nStream == 10 && pHeader->function == 3) {
+ replyTerminalDisplay(pMessage);
+ }
};
PassiveListener listener;
@@ -292,6 +295,19 @@
return 0;
}
+// 通用的reply ack函数
+void CHsmsPassive::replyAck(int s, int f, unsigned int systemBytes, BYTE ack, const char* pszAckName)
+{
+ IMessage* pMessage = NULL;
+ HSMS_Create1Message(pMessage, m_nSessionId, s, f, systemBytes);
+ ASSERT(pMessage);
+ ISECS2Item* pItem = pMessage->getBody();
+ pItem->setBinary(ack, pszAckName);
+ m_pPassive->sendMessage(pMessage);
+ LOGI("<HSMS>[SECS Msg SEND]S%dF%d (SysByte=%u)", s, f, systemBytes);
+ HSMS_Destroy1Message(pMessage);
+}
+
// S1F1
int CHsmsPassive::requestAreYouThere()
{
@@ -387,17 +403,7 @@
SetLocalTime(&time);
}
-
- IMessage* pMessage = NULL;
- HSMS_Create1Message(pMessage, m_nSessionId, 2, 32, pRecv->getHeader()->systemBytes);
- ASSERT(pMessage);
-
- ISECS2Item* pItem = pMessage->getBody();
- pItem->setBinary(BYTE(0), "TIACK");
- m_pPassive->sendMessage(pMessage);
- LOGI("<HSMS>[SECS Msg SEND]S2F32 (SysByte=%u)", pRecv->getHeader()->systemBytes);
- HSMS_Destroy1Message(pMessage);
-
+ replyAck(2, 32, pRecv->getHeader()->systemBytes, BYTE(0), "TIACK");
return 0;
}
@@ -437,18 +443,7 @@
MYREPLY:
- int s = 2;
- int f = 38;
- IMessage* pMessage = NULL;
- HSMS_Create1Message(pMessage, m_nSessionId, s, f, pRecv->getHeader()->systemBytes);
- ASSERT(pMessage);
- ISECS2Item* pItem = pMessage->getBody();
- pItem->setBinary(BYTE(0), "ERACK");
- m_pPassive->sendMessage(pMessage);
- LOGI("<HSMS>[SECS Msg SEND]S%dF%d (SysByte=%u)", s, f, pRecv->getHeader()->systemBytes);
- HSMS_Destroy1Message(pMessage);
-
-
+ replyAck(2, 38, pRecv->getHeader()->systemBytes, BYTE(0), "ERACK");
return 0;
}
@@ -477,18 +472,37 @@
MYREPLY:
- int s = 5;
- int f = 4;
- IMessage* pMessage = NULL;
- HSMS_Create1Message(pMessage, m_nSessionId, s, f, pRecv->getHeader()->systemBytes);
- ASSERT(pMessage);
- ISECS2Item* pItem = pMessage->getBody();
- pItem->setBinary(BYTE(0), "ACKC5");
- m_pPassive->sendMessage(pMessage);
- LOGI("<HSMS>[SECS Msg SEND]S%dF%d (SysByte=%u)", s, f, pRecv->getHeader()->systemBytes);
- HSMS_Destroy1Message(pMessage);
+ replyAck(5, 4, pRecv->getHeader()->systemBytes, BYTE(0), "ACKC5");
+ return 0;
+}
+
+// S10F3
+int CHsmsPassive::replyTerminalDisplay(IMessage* pRecv)
+{
+ if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
+ return ER_NOTSELECT;
+ }
+ ISECS2Item* pBody = pRecv->getBody();
+ if (pBody == nullptr || pBody->getType() != SITYPE::A) ER_PARAM_ERROR;
+
+ BOOL bCheckData = FALSE;
+ BYTE tid;
+ char* pszText = nullptr;;
+ {
+ ISECS2Item* pItem = pRecv->getBody();
+ if (pItem->getSubItemSize() < 2) goto MYREPLY;
+ if (!pItem->getSubItemBinary(0, tid)) goto MYREPLY;
+ if (!pItem->getSubItemString(1, pszText)) goto MYREPLY;
+ bCheckData = TRUE;
+ LOGI("TerminalDisplay tid:%d, pszText:%s", tid, pszText);
+ m_pModel->notifyText(RX_HSMS_TERMINAL_TEXT, pszText);
+ }
+
+
+MYREPLY:
+ replyAck(10, 4, pRecv->getHeader()->systemBytes, BYTE(0), "ACKC10");
return 0;
}
diff --git a/SourceCode/Bond/Servo/HsmsPassive.h b/SourceCode/Bond/Servo/HsmsPassive.h
index ac820bb..42bef1c 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.h
+++ b/SourceCode/Bond/Servo/HsmsPassive.h
@@ -35,12 +35,15 @@
int requestAlarmReport(int ALCD, int ALID, const char* ALTX);
private:
+ void replyAck(int s, int f, unsigned int systemBytes, BYTE ack, const char* pszAckName);
+
/* reply开头的函数为回复函数 */
int replyAreYouThere(unsigned int systemBytes);
int replyEstablishCommunications(unsigned int systemBytes);
int replyDatetime(IMessage* pRecv);
int replyEanbleDisableEventReport(IMessage* pRecv);
int replyEanbleDisableAlarmReport(IMessage* pRecv);
+ int replyTerminalDisplay(IMessage* pRecv);
private:
inline void Lock() { EnterCriticalSection(&m_criticalSection); }
diff --git a/SourceCode/Bond/Servo/Servo.rc b/SourceCode/Bond/Servo/Servo.rc
index 3fcb2f2..91a49f9 100644
--- a/SourceCode/Bond/Servo/Servo.rc
+++ b/SourceCode/Bond/Servo/Servo.rc
Binary files differ
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj b/SourceCode/Bond/Servo/Servo.vcxproj
index d0153cb..e049e84 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj
+++ b/SourceCode/Bond/Servo/Servo.vcxproj
@@ -21,7 +21,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{66ADACE5-3166-4D1F-B30B-DE5E01FB01A2}</ProjectGuid>
<RootNamespace>Servo</RootNamespace>
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion>
<Keyword>MFCProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@@ -43,7 +43,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
@@ -207,6 +207,7 @@
<ClInclude Include="ServoGraph.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
+ <ClInclude Include="TerminalDisplayDlg.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="BlButton.cpp" />
@@ -228,11 +229,13 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
+ <ClCompile Include="TerminalDisplayDlg.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Servo.rc" />
</ItemGroup>
<ItemGroup>
+ <None Include="packages.config" />
<None Include="res\Servo.rc2" />
</ItemGroup>
<ItemGroup>
@@ -243,10 +246,19 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
+ <Import Project="..\packages\Microsoft.Web.WebView2.1.0.2903.40\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2903.40\build\native\Microsoft.Web.WebView2.targets')" />
+ <Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties RESOURCE_FILE="Servo.rc" />
</VisualStudio>
</ProjectExtensions>
+ <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+ <PropertyGroup>
+ <ErrorText>杩欏彴璁$畻鏈轰笂缂哄皯姝ら」鐩紩鐢ㄧ殑 NuGet 绋嬪簭鍖呫�備娇鐢ㄢ�淣uGet 绋嬪簭鍖呰繕鍘熲�濆彲涓嬭浇杩欎簺绋嬪簭鍖呫�傛湁鍏虫洿澶氫俊鎭紝璇峰弬瑙� http://go.microsoft.com/fwlink/?LinkID=322105銆傜己灏戠殑鏂囦欢鏄� {0}銆�</ErrorText>
+ </PropertyGroup>
+ <Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2903.40\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2903.40\build\native\Microsoft.Web.WebView2.targets'))" />
+ <Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
+ </Target>
</Project>
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj.filters b/SourceCode/Bond/Servo/Servo.vcxproj.filters
index 1f263f5..9d77c23 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj.filters
+++ b/SourceCode/Bond/Servo/Servo.vcxproj.filters
@@ -69,6 +69,9 @@
<ClInclude Include="SecsTestDlg.h">
<Filter>澶存枃浠�</Filter>
</ClInclude>
+ <ClInclude Include="TerminalDisplayDlg.h">
+ <Filter>澶存枃浠�</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Servo.cpp">
@@ -113,6 +116,9 @@
<ClCompile Include="SecsTestDlg.cpp">
<Filter>婧愭枃浠�</Filter>
</ClCompile>
+ <ClCompile Include="TerminalDisplayDlg.cpp">
+ <Filter>婧愭枃浠�</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Servo.rc">
@@ -123,6 +129,7 @@
<None Include="res\Servo.rc2">
<Filter>璧勬簮鏂囦欢</Filter>
</None>
+ <None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Image Include="res\Servo.ico">
diff --git a/SourceCode/Bond/Servo/ServoDlg.cpp b/SourceCode/Bond/Servo/ServoDlg.cpp
index 7d7b5ad..bea9cf1 100644
--- a/SourceCode/Bond/Servo/ServoDlg.cpp
+++ b/SourceCode/Bond/Servo/ServoDlg.cpp
@@ -31,6 +31,10 @@
#define INDICATE_MEASUREMENT 13
+/* 创建终端的定时器 */
+#define TIMER_ID_CREATE_TERMINAL 1
+
+
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
@@ -76,6 +80,8 @@
m_hbrBkgnd = nullptr;
m_bShowLogWnd = FALSE;
m_pLogDlg = nullptr;
+ m_pTerminalDisplayDlg = nullptr;
+ m_pObserver = nullptr;
}
void CServoDlg::DoDataExchange(CDataExchange* pDX)
@@ -108,10 +114,41 @@
ON_UPDATE_COMMAND_UI(ID_MENU_WND_LOG, &CServoDlg::OnUpdateMenuWndLog)
ON_COMMAND(ID_MENU_HELP_ABOUT, &CServoDlg::OnMenuHelpAbout)
ON_WM_INITMENUPOPUP()
+ ON_WM_TIMER()
END_MESSAGE_MAP()
// CServoDlg 消息处理程序
+
+void CServoDlg::InitRxWindows()
+{
+ /* 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_HSMS_TERMINAL_TEXT == code) {
+ const char* pszText;
+ if (pAny->getStringValue("text", pszText)) {
+ ShowTerminalText(pszText);
+ }
+ }
+ pAny->release();
+ }, [&]() -> void {
+ // onComplete
+ }, [&](IThrowable* pThrowable) -> void {
+ // onErrorm
+ pThrowable->printf();
+ });
+
+ theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread())
+ ->subscribe(m_pObserver);
+ }
+}
BOOL CServoDlg::OnInitDialog()
{
@@ -242,6 +279,8 @@
theApp.m_model.init();
+ SetTimer(TIMER_ID_CREATE_TERMINAL, 3000, nullptr);
+ InitRxWindows();
UpdateLogBtn();
Resize();
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
@@ -452,10 +491,21 @@
delete m_pLogDlg;
m_pLogDlg = nullptr;
}
+ if (m_pTerminalDisplayDlg != nullptr) {
+ m_pTerminalDisplayDlg->DestroyWindow();
+ delete m_pTerminalDisplayDlg;
+ m_pTerminalDisplayDlg = nullptr;
+ }
if (m_hbrBkgnd != nullptr) {
::DeleteObject(m_hbrBkgnd);
}
+
+ if (m_pObserver != nullptr) {
+ m_pObserver->unsubscribe();
+ m_pObserver = NULL;
+ }
+
}
void CServoDlg::OnBnClickedButtonLog()
@@ -544,3 +594,24 @@
CDialogEx::OnMove(x, y);
}
+
+void CServoDlg::ShowTerminalText(const char* pszText, unsigned int duration/* = -1*/)
+{
+ ASSERT(m_pTerminalDisplayDlg);
+ m_pTerminalDisplayDlg->ShowText(pszText, duration);
+}
+
+void CServoDlg::OnTimer(UINT_PTR nIDEvent)
+{
+ if (TIMER_ID_CREATE_TERMINAL == nIDEvent) {
+ // 预先创建终端窗口
+ KillTimer(TIMER_ID_CREATE_TERMINAL);
+ char szBuffer[MAX_PATH];
+ sprintf_s(szBuffer, MAX_PATH, "%s\\RES\\TeminalMsg.html", (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ m_pTerminalDisplayDlg = new CTerminalDisplayDlg();
+ m_pTerminalDisplayDlg->SetTemplateHtml(szBuffer);
+ m_pTerminalDisplayDlg->Create(IDD_DIALOG_TERMINAL_DISPLAY, this);
+ }
+
+ CDialogEx::OnTimer(nIDEvent);
+}
diff --git a/SourceCode/Bond/Servo/ServoDlg.h b/SourceCode/Bond/Servo/ServoDlg.h
index 3b1cd3b..2681c75 100644
--- a/SourceCode/Bond/Servo/ServoDlg.h
+++ b/SourceCode/Bond/Servo/ServoDlg.h
@@ -6,6 +6,7 @@
#include "ServoGraph.h"
#include "BlButton.h"
#include "LogDlg.h"
+#include "TerminalDisplayDlg.h"
// CServoDlg 对话框
@@ -16,9 +17,20 @@
CServoDlg(CWnd* pParent = NULL); // 标准构造函数
+public:
+ void ShowTerminalText(const char* pszText, unsigned int duration = -1);
+
private:
+ void InitRxWindows();
void Resize();
void UpdateLogBtn();
+
+
+private:
+ IObserver* m_pObserver;
+ BOOL m_bShowLogWnd;
+ CLogDlg* m_pLogDlg;
+ CTerminalDisplayDlg* m_pTerminalDisplayDlg;
// 对话框数据
@@ -29,10 +41,6 @@
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
-
-private:
- BOOL m_bShowLogWnd;
- CLogDlg* m_pLogDlg;
// 实现
protected:
@@ -70,4 +78,5 @@
afx_msg void OnMenuFileExit();
afx_msg void OnUpdateMenuFileExit(CCmdUI* pCmdUI);
afx_msg void OnMenuHelpAbout();
+ afx_msg void OnTimer(UINT_PTR nIDEvent);
};
diff --git a/SourceCode/Bond/Servo/resource.h b/SourceCode/Bond/Servo/resource.h
index 7126e89..d2f26d9 100644
--- a/SourceCode/Bond/Servo/resource.h
+++ b/SourceCode/Bond/Servo/resource.h
Binary files differ
--
Gitblit v1.9.3