| SourceCode/Bond/BoounionPLC/BoounionPLC.vcxproj | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/BoounionPLC/BoounionPLC.vcxproj.filters | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/BoounionPLC/Common.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/BoounionPLC/Model.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/BoounionPLC/Model.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/BoounionPLC/PLC.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/BoounionPLC/PLC.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/BoounionPLC/PagePlcList.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| SourceCode/Bond/BoounionPLC/PagePlcList.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
SourceCode/Bond/BoounionPLC/BoounionPLC.vcxproj
@@ -200,6 +200,7 @@ <ClInclude Include="Log.h" /> <ClInclude Include="Model.h" /> <ClInclude Include="PagePlcList.h" /> <ClInclude Include="PLC.h" /> <ClInclude Include="Resource.h" /> <ClInclude Include="stdafx.h" /> <ClInclude Include="targetver.h" /> @@ -216,6 +217,7 @@ <ClCompile Include="Log.cpp" /> <ClCompile Include="Model.cpp" /> <ClCompile Include="PagePlcList.cpp" /> <ClCompile Include="PLC.cpp" /> <ClCompile Include="stdafx.cpp"> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> SourceCode/Bond/BoounionPLC/BoounionPLC.vcxproj.filters
@@ -63,6 +63,9 @@ <ClInclude Include="ApredTreeCtrl.h"> <Filter>头æä»¶</Filter> </ClInclude> <ClInclude Include="PLC.h"> <Filter>头æä»¶</Filter> </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="BoounionPLC.cpp"> @@ -101,6 +104,9 @@ <ClCompile Include="ApredTreeCtrl.cpp"> <Filter>æºæä»¶</Filter> </ClCompile> <ClCompile Include="PLC.cpp"> <Filter>æºæä»¶</Filter> </ClCompile> </ItemGroup> <ItemGroup> <ResourceCompile Include="BoounionPLC.rc"> SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
@@ -111,6 +111,7 @@ // æ§è¡æ¤æä½ SetIcon(m_hIcon, TRUE); // è®¾ç½®å¤§å¾æ SetIcon(m_hIcon, FALSE); // 设置å°å¾æ theApp.m_model.init(); // toolbar @@ -353,10 +354,17 @@ { int id = (int)lParam; if (id == IDC_BUTTON_ADD) { AfxMessageBox("IDC_BUTTON_ADD"); static int i = 0; char szName[256]; sprintf_s(szName, 256, "PLC%d", ++i); theApp.m_model.addPlc(szName, "192.168.1.188", 1001); } else if (id == IDC_BUTTON_DELETE) { AfxMessageBox("IDC_BUTTON_DELETE"); static int i = 0; i += 2; char szName[256]; sprintf_s(szName, 256, "PLC%d", i); theApp.m_model.removePlc(szName); } else if (id == IDC_BUTTON_SETTINGS) { SourceCode/Bond/BoounionPLC/Common.h
@@ -4,6 +4,9 @@ /* Rx Code */ #define RX_CODE_TEST 0 #define RX_CODE_LOG 1000 #define RX_CODE_ADD_PLC 1001 #define RX_CODE_REMOVE_PLC 1002 /* å®å¶é¢è² */ #define APP_MAIN_DLG_BACKGROUND RGB(255, 255, 255) SourceCode/Bond/BoounionPLC/Model.cpp
@@ -23,6 +23,10 @@ CModel::~CModel() { for (auto item : m_mapPlc) { delete item.second; } m_mapPlc.clear(); } IObservable* CModel::getObservable() @@ -286,3 +290,30 @@ { } std::map<std::string, CPLC*>& CModel::gtPlcMap() { return m_mapPlc; } int CModel::addPlc(const char* pszName, const char* pszIp, const unsigned int port) { auto iter = m_mapPlc.find(pszName); if (iter != m_mapPlc.end()) return -1; CPLC* pPLC = new CPLC(pszName, pszIp, port); m_mapPlc[pszName] = pPLC; notifyPtr(RX_CODE_ADD_PLC, pPLC); return 0; } int CModel::removePlc(const char* pszName) { auto iter = m_mapPlc.find(pszName); if (iter == m_mapPlc.end()) return -1; notifyPtr(RX_CODE_REMOVE_PLC, iter->second); delete iter->second; m_mapPlc.erase(iter); return 0; } SourceCode/Bond/BoounionPLC/Model.h
@@ -1,5 +1,7 @@ #pragma once #include "Configuration.h" #include "PLC.h" #include <map> class CModel @@ -14,6 +16,9 @@ int init(); int term(); void onTimer(UINT nTimerid); std::map<std::string, CPLC*>& gtPlcMap(); int addPlc(const char* pszName, const char* pszIp, const unsigned int port); int removePlc(const char* pszName); public: int notify(int code); @@ -37,6 +42,7 @@ IObservable* m_pObservable; IObservableEmitter* m_pObservableEmitter; CString m_strWorkDir; std::map<std::string, CPLC*> m_mapPlc; private: int m_nTimerID; SourceCode/Bond/BoounionPLC/PLC.cpp
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,33 @@ #include "stdafx.h" #include "PLC.h" CPLC::CPLC() { } CPLC::CPLC(const char* pszName, const char* pszIp, const unsigned int port) { m_strName = pszName; m_strIp = pszIp; m_nPort = port; } CPLC::~CPLC() { } std::string& CPLC::getName() { return m_strName; } std::string& CPLC::getIp() { return m_strIp; } unsigned int CPLC::getPort() { return m_nPort; } SourceCode/Bond/BoounionPLC/PLC.h
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,21 @@ #pragma once #include <string> class CPLC { public: CPLC(); CPLC(const char* pszName, const char* pszIp, const unsigned int port); ~CPLC(); public: std::string& getName(); std::string& getIp(); unsigned int getPort(); private: std::string m_strName; std::string m_strIp; unsigned int m_nPort; }; SourceCode/Bond/BoounionPLC/PagePlcList.cpp
@@ -17,6 +17,7 @@ { m_crBkgnd = PAGE_PLC_LIST_BACKGROUND; m_hbrBkgnd = nullptr; m_pObserver = nullptr; } CPagePlcList::~CPagePlcList() @@ -40,9 +41,51 @@ // CPagePlcList æ¶æ¯å¤çç¨åº void CPagePlcList::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_CODE_ADD_PLC == code) { CPLC* pPlc; if (pAny->getPtrValue("ptr", (void*&)pPlc)) { HTREEITEM hItem = m_treeCtrl.InsertItem(pPlc->getName().c_str(), nullptr, nullptr); m_treeCtrl.SetItemData(hItem, (DWORD_PTR)pPlc); } } else if (RX_CODE_REMOVE_PLC == code) { CPLC* pPlc; if (pAny->getPtrValue("ptr", (void*&)pPlc)) { HTREEITEM hItem = FindItem(pPlc); if (hItem != nullptr) { m_treeCtrl.DeleteItem(hItem); } } } pAny->release(); }, [&]() -> void { // onComplete }, [&](IThrowable* pThrowable) -> void { // onErrorm pThrowable->printf(); }); theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread()) ->subscribe(m_pObserver); } } BOOL CPagePlcList::OnInitDialog() { CDialogEx::OnInitDialog(); InitRxWindows(); m_treeCtrl.SetBkColor(PAGE_PLC_LIST_BACKGROUND); @@ -74,7 +117,10 @@ { CDialogEx::OnDestroy(); // TODO: 卿¤å¤æ·»å æ¶æ¯å¤çç¨åºä»£ç if (m_pObserver != nullptr) { m_pObserver->unsubscribe(); m_pObserver = NULL; } } void CPagePlcList::OnSize(UINT nType, int cx, int cy) @@ -92,8 +138,8 @@ void CPagePlcList::ReadPLCList() { m_treeCtrl.InsertItem("PLC1", nullptr, nullptr); m_treeCtrl.InsertItem("PLC2", nullptr, nullptr); //m_treeCtrl.InsertItem("PLC1", nullptr, nullptr); //m_treeCtrl.InsertItem("PLC2", nullptr, nullptr); } BOOL CPagePlcList::PreTranslateMessage(MSG* pMsg) @@ -104,3 +150,17 @@ return CDialogEx::PreTranslateMessage(pMsg); } HTREEITEM CPagePlcList::FindItem(CPLC* pPlc) { HTREEITEM item = m_treeCtrl.GetChildItem(nullptr); while (item != nullptr) { item = m_treeCtrl.GetNextItem(item, TVGN_NEXT); if (m_treeCtrl.GetItemData(item) == (DWORD_PTR)pPlc) { return item; } } return nullptr; } SourceCode/Bond/BoounionPLC/PagePlcList.h
@@ -14,10 +14,13 @@ private: void InitRxWindows(); void ReadPLCList(); HTREEITEM FindItem(CPLC* pPlc); private: IObserver* m_pObserver; CApredTreeCtrl m_treeCtrl; COLORREF m_crBkgnd; HBRUSH m_hbrBkgnd;