| | |
| | | #include "EAPSimulator.h" |
| | | #include "EAPSimulatorDlg.h" |
| | | #include "afxdialogex.h" |
| | | #include "Common.h" |
| | | #include <regex> |
| | | #include "CTerminalDisplayDlg.h" |
| | | #include "CEDEventReportDlg.h" |
| | | #include "CDefineReportsDlg.h" |
| | | #include "CLinkReportDlg.h" |
| | | |
| | | |
| | | #ifdef _DEBUG |
| | | #define new DEBUG_NEW |
| | |
| | | : 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) |
| | | 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) |
| | | ON_BN_CLICKED(IDC_BUTTON_ED_ALARM_REPORT, &CEAPSimulatorDlg::OnBnClickedButtonEdAlarmReport) |
| | | ON_BN_CLICKED(IDC_BUTTON_DEFINE_REPORT, &CEAPSimulatorDlg::OnBnClickedButtonDefineReport) |
| | | ON_BN_CLICKED(IDC_BUTTON_LINE_REPORT, &CEAPSimulatorDlg::OnBnClickedButtonLineReport) |
| | | ON_BN_CLICKED(IDC_BUTTON_CONFIGURE_SPOOLING, &CEAPSimulatorDlg::OnBnClickedButtonConfigureSpooling) |
| | | 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() |
| | | { |
| | |
| | | SetIcon(m_hIcon, TRUE); // 设置大图标 |
| | | SetIcon(m_hIcon, FALSE); // 设置小图标 |
| | | |
| | | // TODO: 在此添加额外的初始化代码 |
| | | SetDlgItemText(IDC_EDIT_IP, _T("127.0.0.1")); |
| | | SetDlgItemInt(IDC_EDIT_PORT, 7000); |
| | | SetGroup2Enabled(FALSE); |
| | | SetGroup1Enabled(TRUE); |
| | | ::SetProp(GetDlgItem(IDC_BUTTON_ED_ALARM_REPORT)->m_hWnd, _T("Enable"), (void*)1); |
| | | |
| | | |
| | | // log edit |
| | | m_logEdit.SetMaxLineCount(8000); |
| | | m_logEdit.SetLimitText(-1); |
| | | InitRxWindow(); |
| | | |
| | | return TRUE; // 除非将焦点设置到控件,否则返回 TRUE |
| | | } |
| | |
| | | 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); |
| | | GetDlgItem(IDC_BUTTON_DATETIME_SYNC)->EnableWindow(enabled); |
| | | GetDlgItem(IDC_BUTTON_TERMINAL_DISPLAY)->EnableWindow(enabled); |
| | | GetDlgItem(IDC_BUTTON_ED_EVENT_REPORT)->EnableWindow(enabled); |
| | | GetDlgItem(IDC_BUTTON_ED_ALARM_REPORT)->EnableWindow(enabled); |
| | | GetDlgItem(IDC_BUTTON_DEFINE_REPORT)->EnableWindow(enabled); |
| | | GetDlgItem(IDC_BUTTON_LINE_REPORT)->EnableWindow(enabled); |
| | | GetDlgItem(IDC_BUTTON_CONFIGURE_SPOOLING)->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(); |
| | | } |
| | | |
| | | void CEAPSimulatorDlg::OnBnClickedButtonDatetimeSync() |
| | | { |
| | | theApp.m_model.m_pHsmsActive->hsmsDatetimeSync(); |
| | | } |
| | | |
| | | void CEAPSimulatorDlg::OnBnClickedButtonTerminalDisplay() |
| | | { |
| | | CTerminalDisplayDlg dlg; |
| | | dlg.DoModal(); |
| | | } |
| | | |
| | | void CEAPSimulatorDlg::OnBnClickedButtonEdEventReport() |
| | | { |
| | | CEDEventReportDlg dlg; |
| | | dlg.DoModal(); |
| | | } |
| | | |
| | | void CEAPSimulatorDlg::OnBnClickedButtonEdAlarmReport() |
| | | { |
| | | int enable = (int)::GetProp(GetDlgItem(IDC_BUTTON_ED_ALARM_REPORT)->m_hWnd, _T("Enable")); |
| | | enable = enable == 0 ? 1 : 0; |
| | | theApp.m_model.m_pHsmsActive->hsmsEDAlarmReport(enable == 1, 0); |
| | | |
| | | SetDlgItemText(IDC_BUTTON_ED_ALARM_REPORT, |
| | | enable == 1 ? _T("Disable Alarm Report") : _T("Enable Alarm Report")); |
| | | ::SetProp(GetDlgItem(IDC_BUTTON_ED_ALARM_REPORT)->m_hWnd, _T("Enable"), (void*)enable); |
| | | } |
| | | |
| | | void CEAPSimulatorDlg::OnBnClickedButtonDefineReport() |
| | | { |
| | | CDefineReportsDlg dlg; |
| | | dlg.DoModal(); |
| | | } |
| | | |
| | | void CEAPSimulatorDlg::OnBnClickedButtonLineReport() |
| | | { |
| | | CLinkReportDlg dlg; |
| | | dlg.DoModal(); |
| | | } |
| | | |
| | | void CEAPSimulatorDlg::OnBnClickedButtonConfigureSpooling() |
| | | { |
| | | std::map<unsigned int, std::set<unsigned int>> spoolingConfig; |
| | | |
| | | // test clear all |
| | | // theApp.m_model.m_pHsmsActive->hsmsConfigureSpooling(spoolingConfig); |
| | | |
| | | |
| | | // test add s2[1,3,5]; |
| | | // spoolingConfig[2].insert(1); |
| | | // spoolingConfig[2].insert(3); |
| | | // spoolingConfig[2].insert(5); |
| | | // spoolingConfig[3].insert(2); |
| | | // spoolingConfig[3].insert(4); |
| | | // spoolingConfig[3].insert(6); |
| | | // theApp.m_model.m_pHsmsActive->hsmsConfigureSpooling(spoolingConfig); |
| | | |
| | | // test clear S2 |
| | | // spoolingConfig[2].clear(); |
| | | // theApp.m_model.m_pHsmsActive->hsmsConfigureSpooling(spoolingConfig); |
| | | |
| | | spoolingConfig[5].insert(66); |
| | | theApp.m_model.m_pHsmsActive->hsmsConfigureSpooling(spoolingConfig); |
| | | } |