LAPTOP-SNT8I5JK\Boounion
2025-01-06 353400e7e6a1b68944b76ac086e626c83ce914d2
1.初步将PLC调机功能驳离为独立App.
已添加21个文件
已修改2个文件
1603 ■■■■■ 文件已修改
.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/BoounionPLC.cpp 143 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/BoounionPLC.h 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/BoounionPLC.rc 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/BoounionPLC.vcxproj 227 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/BoounionPLC.vcxproj.filters 84 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp 154 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/BoounionPLCDlg.h 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/Common.h 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/Configuration.cpp 105 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/Configuration.h 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/Log.cpp 214 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/Log.h 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/Model.cpp 288 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/Model.h 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/ReadMe.txt 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/Resource.h 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/res/BoounionPLC.ico 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/res/BoounionPLC.rc2 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/stdafx.cpp 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/stdafx.h 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/targetver.h 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/GangBond2860.sln 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -38,3 +38,4 @@
SourceCode/Bond/x64/Release/BEQ.exp
SourceCode/Bond/x64/Release/Bonder.dat
SourceCode/Bond/Servo/x64/
SourceCode/Bond/BoounionPLC/x64/
SourceCode/Bond/BoounionPLC/BoounionPLC.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,143 @@
// BoounionPLC.cpp : å®šä¹‰åº”用程序的类行为。
//
#include "stdafx.h"
#include "BoounionPLC.h"
#include "BoounionPLCDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CBoounionPLCApp
BEGIN_MESSAGE_MAP(CBoounionPLCApp, CWinApp)
    ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CBoounionPLCApp æž„造
CBoounionPLCApp::CBoounionPLCApp()
{
    // æ”¯æŒé‡æ–°å¯åŠ¨ç®¡ç†å™¨
    m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
    // TODO: åœ¨æ­¤å¤„添加构造代码,
    // å°†æ‰€æœ‰é‡è¦çš„初始化放置在 InitInstance ä¸­
}
// å”¯ä¸€çš„一个 CBoounionPLCApp å¯¹è±¡
CBoounionPLCApp theApp;
// CBoounionPLCApp åˆå§‹åŒ–
BOOL CBoounionPLCApp::InitInstance()
{
    // å¦‚果一个运行在 Windows XP ä¸Šçš„应用程序清单指定要
    // ä½¿ç”¨ ComCtl32.dll ç‰ˆæœ¬ 6 æˆ–更高版本来启用可视化方式,
    //则需要 InitCommonControlsEx()。  å¦åˆ™ï¼Œå°†æ— æ³•创建窗口。
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // å°†å®ƒè®¾ç½®ä¸ºåŒ…括所有要在应用程序中使用的
    // å…¬å…±æŽ§ä»¶ç±»ã€‚
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);
    CWinApp::InitInstance();
    AfxEnableControlContainer();
    // åˆ›å»º shell ç®¡ç†å™¨ï¼Œä»¥é˜²å¯¹è¯æ¡†åŒ…含
    // ä»»ä½• shell æ ‘视图控件或 shell åˆ—表视图控件。
    CShellManager *pShellManager = new CShellManager;
    // æ¿€æ´»â€œWindows Native”视觉管理器,以便在 MFC æŽ§ä»¶ä¸­å¯ç”¨ä¸»é¢˜
    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
    // æ ‡å‡†åˆå§‹åŒ–
    // å¦‚果未使用这些功能并希望减小
    // æœ€ç»ˆå¯æ‰§è¡Œæ–‡ä»¶çš„大小,则应移除下列
    // ä¸éœ€è¦çš„特定初始化例程
    // æ›´æ”¹ç”¨äºŽå­˜å‚¨è®¾ç½®çš„æ³¨å†Œè¡¨é¡¹
    // TODO: åº”适当修改该字符串,
    // ä¾‹å¦‚修改为公司或组织名
    SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
    // æœ¬ç¨‹åºæ–‡ä»¶ç›®å½•
    TCHAR sDrive[_MAX_DRIVE];
    TCHAR sDir[_MAX_DIR];
    TCHAR sFilename[_MAX_FNAME], sAppFilename[_MAX_FNAME];
    TCHAR sExt[_MAX_EXT];
    GetModuleFileName(AfxGetInstanceHandle(), sAppFilename, _MAX_FNAME);
    _tsplitpath_s(sAppFilename, sDrive, sDir, sFilename, sExt);
    m_strAppDir = CString(sDrive) + CString(sDir);
    m_strAppFile = CString(sFilename);
    m_model.setWorkDir((LPTSTR)(LPCTSTR)m_strAppDir);
    CString strIniFile;
    strIniFile.Format(_T("%s\\BoounionPLCconfiguration.ini"), (LPTSTR)(LPCTSTR)m_strAppDir);
    int plcTimeout = GetPrivateProfileInt("PLC", "Timeout", 700, strIniFile);
    int plcBufSize = GetPrivateProfileInt("PLC", "BufSize", 20, strIniFile);
    int plcPacketSize = GetPrivateProfileInt("PLC", "PacketSize", 80, strIniFile);
    MCL_Initialize();
    MCL_SetTimeout(plcTimeout);
    MCL_SetMaxActionSize(plcBufSize);
    MCL_SetPacketSize(plcPacketSize);
    RX_Init();
    m_hAppMutex = CreateMutexA(NULL, FALSE, _T("BoounionPLC"));
    if (GetLastError() == ERROR_ALREADY_EXISTS) {
        AfxMessageBox(_T("已经运行了一个实例,启动失败!"));
        return FALSE;
    }
    CBoounionPLCDlg dlg;
    m_pMainWnd = &dlg;
    INT_PTR nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        // TODO: åœ¨æ­¤æ”¾ç½®å¤„理何时用
        //  â€œç¡®å®šâ€æ¥å…³é—­å¯¹è¯æ¡†çš„代码
    }
    else if (nResponse == IDCANCEL)
    {
        // TODO: åœ¨æ­¤æ”¾ç½®å¤„理何时用
        //  â€œå–消”来关闭对话框的代码
    }
    else if (nResponse == -1)
    {
        TRACE(traceAppMsg, 0, "警告: å¯¹è¯æ¡†åˆ›å»ºå¤±è´¥ï¼Œåº”用程序将意外终止。\n");
        TRACE(traceAppMsg, 0, "警告: å¦‚果您在对话框上使用 MFC æŽ§ä»¶ï¼Œåˆ™æ— æ³• #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
    }
    // åˆ é™¤ä¸Šé¢åˆ›å»ºçš„ shell ç®¡ç†å™¨ã€‚
    if (pShellManager != NULL)
    {
        delete pShellManager;
    }
    // ç”±äºŽå¯¹è¯æ¡†å·²å…³é—­ï¼Œæ‰€ä»¥å°†è¿”回 FALSE ä»¥ä¾¿é€€å‡ºåº”用程序,
    //  è€Œä¸æ˜¯å¯åŠ¨åº”ç”¨ç¨‹åºçš„æ¶ˆæ¯æ³µã€‚
    return FALSE;
}
int CBoounionPLCApp::ExitInstance()
{
    m_model.term();
    RX_Term();
    MCL_Term();
    CloseHandle(m_hAppMutex);
    return CWinApp::ExitInstance();
}
SourceCode/Bond/BoounionPLC/BoounionPLC.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,42 @@
// BoounionPLC.h : PROJECT_NAME åº”用程序的主头文件
//
#pragma once
#ifndef __AFXWIN_H__
    #error "在包含此文件之前包含“stdafx.h”以生成 PCH æ–‡ä»¶"
#endif
#include "resource.h"        // ä¸»ç¬¦å·
#include "Model.h"
// CBoounionPLCApp:
// æœ‰å…³æ­¤ç±»çš„实现,请参阅 BoounionPLC.cpp
//
class CBoounionPLCApp : public CWinApp
{
public:
    CBoounionPLCApp();
public:
    CModel m_model;
    HANDLE m_hAppMutex;
    CString m_strAppDir;
    CString m_strAppFile;
    int m_nVersionNumber;
    CString m_strVersionName;
// é‡å†™
public:
    virtual BOOL InitInstance();
// å®žçް
    DECLARE_MESSAGE_MAP()
    virtual int ExitInstance();
};
extern CBoounionPLCApp theApp;
SourceCode/Bond/BoounionPLC/BoounionPLC.rc
Binary files differ
SourceCode/Bond/BoounionPLC/BoounionPLC.vcxproj
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,227 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{6DC0600E-5588-4033-A281-3626A4F74B67}</ProjectGuid>
    <RootNamespace>BoounionPLC</RootNamespace>
    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
    <Keyword>MFCProj</Keyword>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <CharacterSet>MultiByte</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemGroup>
    <Text Include="ReadMe.txt" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="BoounionPLC.h" />
    <ClInclude Include="BoounionPLCDlg.h" />
    <ClInclude Include="Common.h" />
    <ClInclude Include="Configuration.h" />
    <ClInclude Include="Log.h" />
    <ClInclude Include="Model.h" />
    <ClInclude Include="Resource.h" />
    <ClInclude Include="stdafx.h" />
    <ClInclude Include="targetver.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="BoounionPLC.cpp" />
    <ClCompile Include="BoounionPLCDlg.cpp" />
    <ClCompile Include="Configuration.cpp" />
    <ClCompile Include="Log.cpp" />
    <ClCompile Include="Model.cpp" />
    <ClCompile Include="stdafx.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="BoounionPLC.rc" />
  </ItemGroup>
  <ItemGroup>
    <None Include="res\BoounionPLC.rc2" />
  </ItemGroup>
  <ItemGroup>
    <Image Include="res\BoounionPLC.ico" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
SourceCode/Bond/BoounionPLC/BoounionPLC.vcxproj.filters
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="源文件">
      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    </Filter>
    <Filter Include="头文件">
      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
      <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
    </Filter>
    <Filter Include="资源文件">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <Text Include="ReadMe.txt" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="BoounionPLC.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="BoounionPLCDlg.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="stdafx.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="targetver.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="Resource.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="Model.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="Common.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="Configuration.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="Log.h">
      <Filter>头文件</Filter>
    </ClInclude>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="BoounionPLC.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="BoounionPLCDlg.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="stdafx.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="Model.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="Configuration.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="Log.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="BoounionPLC.rc">
      <Filter>资源文件</Filter>
    </ResourceCompile>
  </ItemGroup>
  <ItemGroup>
    <None Include="res\BoounionPLC.rc2">
      <Filter>资源文件</Filter>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Image Include="res\BoounionPLC.ico">
      <Filter>资源文件</Filter>
    </Image>
  </ItemGroup>
</Project>
SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,154 @@
// BoounionPLCDlg.cpp : å®žçŽ°æ–‡ä»¶
//
#include "stdafx.h"
#include "BoounionPLC.h"
#include "BoounionPLCDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// ç”¨äºŽåº”用程序“关于”菜单项的 CAboutDlg å¯¹è¯æ¡†
class CAboutDlg : public CDialogEx
{
public:
    CAboutDlg();
// å¯¹è¯æ¡†æ•°æ®
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_ABOUTBOX };
#endif
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV æ”¯æŒ
// å®žçް
protected:
    DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CBoounionPLCDlg å¯¹è¯æ¡†
CBoounionPLCDlg::CBoounionPLCDlg(CWnd* pParent /*=NULL*/)
    : CDialogEx(IDD_BOOUNIONPLC_DIALOG, pParent)
{
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CBoounionPLCDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CBoounionPLCDlg, CDialogEx)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()
// CBoounionPLCDlg æ¶ˆæ¯å¤„理程序
BOOL CBoounionPLCDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    // å°†â€œå…³äºŽ...”菜单项添加到系统菜单中。
    // IDM_ABOUTBOX å¿…须在系统命令范围内。
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);
    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        BOOL bNameValid;
        CString strAboutMenu;
        bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
        ASSERT(bNameValid);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }
    // è®¾ç½®æ­¤å¯¹è¯æ¡†çš„图标。  å½“应用程序主窗口不是对话框时,框架将自动
    //  æ‰§è¡Œæ­¤æ“ä½œ
    SetIcon(m_hIcon, TRUE);            // è®¾ç½®å¤§å›¾æ ‡
    SetIcon(m_hIcon, FALSE);        // è®¾ç½®å°å›¾æ ‡
    // TODO: åœ¨æ­¤æ·»åŠ é¢å¤–çš„åˆå§‹åŒ–ä»£ç 
    return TRUE;  // é™¤éžå°†ç„¦ç‚¹è®¾ç½®åˆ°æŽ§ä»¶ï¼Œå¦åˆ™è¿”回 TRUE
}
void CBoounionPLCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialogEx::OnSysCommand(nID, lParam);
    }
}
// å¦‚果向对话框添加最小化按钮,则需要下面的代码
//  æ¥ç»˜åˆ¶è¯¥å›¾æ ‡ã€‚  å¯¹äºŽä½¿ç”¨æ–‡æ¡£/视图模型的 MFC åº”用程序,
//  è¿™å°†ç”±æ¡†æž¶è‡ªåŠ¨å®Œæˆã€‚
void CBoounionPLCDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // ç”¨äºŽç»˜åˆ¶çš„设备上下文
        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
        // ä½¿å›¾æ ‡åœ¨å·¥ä½œåŒºçŸ©å½¢ä¸­å±…中
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;
        // ç»˜åˆ¶å›¾æ ‡
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialogEx::OnPaint();
    }
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CBoounionPLCDlg::OnQueryDragIcon()
{
    return static_cast<HCURSOR>(m_hIcon);
}
SourceCode/Bond/BoounionPLC/BoounionPLCDlg.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,34 @@
// BoounionPLCDlg.h : å¤´æ–‡ä»¶
//
#pragma once
// CBoounionPLCDlg å¯¹è¯æ¡†
class CBoounionPLCDlg : public CDialogEx
{
// æž„造
public:
    CBoounionPLCDlg(CWnd* pParent = NULL);    // æ ‡å‡†æž„造函数
// å¯¹è¯æ¡†æ•°æ®
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_BOOUNIONPLC_DIALOG };
#endif
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV æ”¯æŒ
// å®žçް
protected:
    HICON m_hIcon;
    // ç”Ÿæˆçš„æ¶ˆæ¯æ˜ å°„函数
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()
};
SourceCode/Bond/BoounionPLC/Common.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,6 @@
#pragma once
/* Rx Code */
#define RX_CODE_TEST                    0
#define RX_CODE_LOG                        1000
SourceCode/Bond/BoounionPLC/Configuration.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,105 @@
#include "stdafx.h"
#include "Configuration.h"
CConfiguration::CConfiguration()
{
}
CConfiguration::CConfiguration(const char* pszFilepath)
{
    m_strFilepath = pszFilepath;
}
CConfiguration::~CConfiguration()
{
}
void CConfiguration::setFilepath(const char* pszFilepath)
{
    m_strFilepath = pszFilepath;
}
void CConfiguration::getUnitId(CString& strUnitId)
{
    char szTemp[256];
    GetPrivateProfileString("App", _T("UnitId"), _T(""), szTemp, 256, m_strFilepath);
    strUnitId = szTemp;
}
void CConfiguration::getBond1(CString& strIp, UINT& port, UINT& doorCount)
{
    char szTemp[256];
    // è¯»IP和端口
    GetPrivateProfileString("Bond1", _T("IP"), _T(""), szTemp, 256, m_strFilepath);
    strIp = szTemp;
    port = GetPrivateProfileInt("Bond1", _T("Port"), 0, m_strFilepath);
    doorCount = GetPrivateProfileInt("Bond1", _T("DoorCount"), 0, m_strFilepath);
}
int CConfiguration::getLogcatLevel()
{
    return GetPrivateProfileInt(_T("Logcat"), _T("Level"), 0, m_strFilepath);
}
void CConfiguration::setLogcatLevel(int level)
{
    WritePrivateProfileString(_T("Logcat"), _T("Level"),
        std::to_string(level).c_str(), m_strFilepath);
}
int CConfiguration::setLogcatIncludeText(CString& strInclude)
{
    WritePrivateProfileString(_T("Logcat"), _T("IncludeText"),
        strInclude, m_strFilepath);
    return 0;
}
int CConfiguration::getLogcatIncludeText(CString& strInclude)
{
    char szTemp[256];
    GetPrivateProfileString("Logcat", _T("IncludeText"), _T(""), szTemp, 256, m_strFilepath);
    strInclude = szTemp;
    return 0;
}
void CConfiguration::setLogcatIncludeRegex(BOOL bRegex)
{
    WritePrivateProfileString(_T("Logcat"), _T("IncludeRegex"),
        bRegex ? "1" : "0", m_strFilepath);
}
BOOL CConfiguration::isLogcatIncludeRegex()
{
    return GetPrivateProfileInt(_T("Logcat"), _T("IncludeRegex"), 0, m_strFilepath);
}
int CConfiguration::getCustomLogcatIncludeTexts(std::vector<std::string>& texts)
{
    char szSection[256], szTemp[256];
    for (int i = 0; i < 10; i++) {
        sprintf_s(szSection, 256, "CustomInclude%d", i + 1);
        GetPrivateProfileString("Logcat", szSection, _T(""),
            szTemp, 256, m_strFilepath);
        std::string strInclude(szTemp);
        if (!strInclude.empty()) {
            texts.push_back(strInclude);
        }
    }
    return (int)texts.size();
}
int CConfiguration::getP2RemoteEqReconnectInterval()
{
    return GetPrivateProfileInt(_T("P2"), _T("RemoteEqReconnectInterval"), 20, m_strFilepath);
}
void CConfiguration::setP2RemoteEqReconnectInterval(int second)
{
    WritePrivateProfileString(_T("P2"), _T("RemoteEqReconnectInterval"),
        std::to_string(second).c_str(), m_strFilepath);
}
SourceCode/Bond/BoounionPLC/Configuration.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,31 @@
#pragma once
#include <vector>
#include <string>
class CConfiguration
{
public:
    CConfiguration();
    CConfiguration(const char* pszFilepath);
    ~CConfiguration();
public:
    void setFilepath(const char* pszFilepath);
    void getUnitId(CString& strUnitId);
    void getBond1(CString& strIp, UINT& port, UINT& doorCount);
    int getLogcatLevel();
    void setLogcatLevel(int level);
    int setLogcatIncludeText(CString& strInclude);
    int getLogcatIncludeText(CString& strInclude);
    void setLogcatIncludeRegex(BOOL bRegex);
    BOOL isLogcatIncludeRegex();
    int getCustomLogcatIncludeTexts(std::vector<std::string>& texts);
public:
    void setP2RemoteEqReconnectInterval(int second);
    int getP2RemoteEqReconnectInterval();
private:
    CString m_strFilepath;
};
SourceCode/Bond/BoounionPLC/Log.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,214 @@
#include "stdafx.h"
#include "Log.h"
static const char* pszLevel[] = {" [Debug] ", " [Info] ", " [Warn] ", " [Error] "};
CLog::CLog()
{
    m_nLevel = 0;
    m_nOutputTarget = OT_TRACE;
    m_bAutoAppendTime = TRUE;
    m_strEquipmentId = _T("Unknown");
    m_nDay = 0;
    m_funOnLog = nullptr;
    InitializeCriticalSection(&m_criticalSection);
}
CLog::~CLog()
{
    DeleteCriticalSection(&m_criticalSection);
}
CLog *CLog::GetLog(void)
{
    static CLog* pLog = NULL;
    if (pLog == NULL) {
        static CLog log;
        pLog = &log;
    }
    return pLog;
}
void CLog::SetOnLogCallback(ONLOG funOnLog)
{
    m_funOnLog = funOnLog;
}
void CLog::SetOutputTarget(int flag)
{
    m_nOutputTarget = flag;
}
void CLog::SetEquipmentId(const char* pszEquipmentId)
{
    m_strEquipmentId = pszEquipmentId;
}
void CLog::SetAutoAppendTimeString(BOOL bAutoAppendTime)
{
    m_bAutoAppendTime = bAutoAppendTime;
}
void CLog::Batch()
{
    if (m_file.m_hFile != CFile::hFileNull) {
        m_file.Close();
    }
}
BOOL CLog::BatchAndNew(int& nDay)
{
    Batch();
    if ( (m_nOutputTarget & OT_FILE) && m_file.m_hFile == CFile::hFileNull) {
        CString strFilepath;
        BOOL bRet = m_file.Open(MakeFilepathD(strFilepath, nDay), CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite | CFile::shareDenyWrite);
        if (bRet) {
            m_file.SeekToEnd();
        }
        return bRet;
    }
    return FALSE;
}
#define BUFFERSIZE        1024*10
void CLog::LogFormat(int nLevel, const char* pszTag, char* szMessage, ...)
{
    // æ£€æŸ¥æ—¥æœŸæ˜¯å¦æœ‰å˜åŒ–,有变化则结批
    Lock();
    _SYSTEMTIME sysTime;
    GetLocalTime(&sysTime);
    if(m_nDay != sysTime.wDay) {
        int nDay = 0;
        if (BatchAndNew(nDay)) {
            m_nDay = nDay;
        }
    }
    Unlock();
    if (nLevel < m_nLevel) {
        return;
    }
    char szFullMessage[BUFFERSIZE];
    char szFormatMessage[BUFFERSIZE];
    // format message
    va_list ap;
    va_start(ap, szMessage);
    _vsnprintf_s(szFormatMessage, BUFFERSIZE, szMessage, ap);
    va_end(ap);
    if (m_bAutoAppendTime) {
        CString strTime;
        strcpy_s(szFullMessage, BUFFERSIZE, (LPTSTR)(LPCTSTR)GetCurTime(strTime));
    }
    strcat_s(szFullMessage, BUFFERSIZE, pszLevel[nLevel]);
    strcat_s(szFullMessage, szFormatMessage);
    strcat_s(szFullMessage, BUFFERSIZE, "\n");
    if (m_nOutputTarget & OT_FILE) {
        Lock();
        if (m_file.m_hFile != CFile::hFileNull) {
            m_file.WriteString(szFullMessage);
        }
        Unlock();
    }
    if (m_nOutputTarget & OT_ODSTRING) {
        OutputDebugStringA(szFullMessage);
    }
    else if(m_nOutputTarget & OT_TRACE) {
        TRACE(szFormatMessage);
    }
    if (m_funOnLog != nullptr) {
        m_funOnLog(nLevel, szFullMessage);
    }
}
void CLog::Log(int nLevel, const char* pszTag, const char* szMessage)
{
    // æ£€æŸ¥æ—¥æœŸæ˜¯å¦æœ‰å˜åŒ–,有变化则结批
    Lock();
    _SYSTEMTIME sysTime;
    GetLocalTime(&sysTime);
    if (m_nDay != sysTime.wDay) {
        int nDay = 0;
        if (BatchAndNew(nDay)) {
            m_nDay = nDay;
        }
    }
    Unlock();
    if (nLevel < m_nLevel) {
        return;
    }
    CString strMsg;
    if (m_bAutoAppendTime) {
        CString strTime;
        GetCurTime(strTime);
        strMsg.Append(strTime);
    }
    strMsg.Append(pszTag);
    strMsg.Append(szMessage);
    strMsg.Append("\n");
    if (m_nOutputTarget & OT_FILE) {
        Lock();
        if (m_file.m_hFile != CFile::hFileNull) {
            m_file.WriteString(strMsg);
        }
        Unlock();
    }
    if (m_nOutputTarget & OT_ODSTRING) {
        OutputDebugStringA(strMsg);
    }
    else if (m_nOutputTarget & OT_TRACE) {
        TRACE(strMsg);
    }
    if (m_funOnLog != nullptr) {
        m_funOnLog(nLevel, strMsg);
    }
}
CString& CLog::GetCurTime(CString& strTime)
{
    _SYSTEMTIME sysTime;
    GetLocalTime(&sysTime);
    strTime.Format(_T("%d/%02d/%02d %02d:%02d:%02d.%03d"), sysTime.wYear, sysTime.wMonth, sysTime.wDay,
        sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds);
    return strTime;
}
CString& CLog::MakeFilepath(CString& strFilepath)
{
    _SYSTEMTIME sysTime;
    GetLocalTime(&sysTime);
    strFilepath.Format(_T("%s\\Log(%s)_%d_%02d_%02d.log"), (LPTSTR)(LPCTSTR)m_strLogsDir,
        (LPTSTR)(LPCTSTR)m_strEquipmentId,
        sysTime.wYear, sysTime.wMonth, sysTime.wDay);
    return strFilepath;
}
CString& CLog::MakeFilepathD(CString& strFilepath, int& day)
{
    _SYSTEMTIME sysTime;
    GetLocalTime(&sysTime);
    strFilepath.Format(_T("%s\\Log(%s)_%d_%02d_%02d.log"), (LPTSTR)(LPCTSTR)m_strLogsDir,
        (LPTSTR)(LPCTSTR)m_strEquipmentId,
        sysTime.wYear, sysTime.wMonth, sysTime.wDay);
    day = sysTime.wDay;
    return strFilepath;
}
void CLog::SetLogsDir(CString strDir)
{
    m_strLogsDir = strDir;
}
SourceCode/Bond/BoounionPLC/Log.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,61 @@
#pragma once
#include <functional>
#define LEVEL_DEBUG        0
#define LEVEL_INFO        1
#define LEVEL_WARN        2
#define LEVEL_ERROR        3
#define LOGD(msg, ...)        CLog::GetLog()->LogFormat(LEVEL_DEBUG, "", msg, __VA_ARGS__)
#define LOGI(msg, ...)        CLog::GetLog()->LogFormat(LEVEL_INFO, "", msg, __VA_ARGS__)
#define LOGW(msg, ...)        CLog::GetLog()->LogFormat(LEVEL_WARN, "", msg, __VA_ARGS__)
#define LOGE(msg, ...)        CLog::GetLog()->LogFormat(LEVEL_ERROR, "", msg, __VA_ARGS__)
#define OT_FILE            0x01
#define OT_ODSTRING        0x02
#define OT_TRACE        0x04
#define LOGBATHCH()                CLog::GetLog()->Batch()
#define LOGNEW()                CLog::GetLog()->BatchAndNew()
typedef std::function<void(int level, const char* pszMessage)> ONLOG;
class CLog
{
public:
    CLog();
    ~CLog();
public:
    void SetOnLogCallback(ONLOG funOnLog);
    static CLog *GetLog(void);
    void SetOutputTarget(int flag);
    void SetEquipmentId(const char* pszEquipmentId);
    static CString& GetCurTime(CString& strTime);
    CString& MakeFilepath(CString& strFilepath);
    CString& MakeFilepathD(CString& strFilepath, int& day);
    void LogFormat(int nLevel, const char* pszTag, char* szMessage, ...);
    void Log(int nLevel, const char* pszTag, const char* szMessage);
    void SetAutoAppendTimeString(BOOL bAutoAppendTime);
    void SetLogsDir(CString strDir);
    void Batch();
    BOOL BatchAndNew(int& nDay);
private:
    inline void Lock() { EnterCriticalSection(&m_criticalSection); }
    inline void Unlock() { LeaveCriticalSection(&m_criticalSection); }
private:
    ONLOG m_funOnLog;
    int m_nOutputTarget;
    int m_nLevel;
    BOOL m_bAutoAppendTime;
    CString m_strLogsDir;
    CString m_strEquipmentId;
    CStdioFile m_file;
    int m_nDay;                        // æŒ‰æ—¥ä¿å­˜ä¸€æ¡è®°å½•,比较此数字,以决定是否结批并创建新文件
    CRITICAL_SECTION m_criticalSection;
};
SourceCode/Bond/BoounionPLC/Model.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,288 @@
#include "stdafx.h"
#include "Model.h"
#include "Log.h"
#include "Common.h"
CModel* g_pModel = NULL;
void CALLBACK ModerTimerProc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime)
{
    if (g_pModel != NULL) {
        g_pModel->onTimer(nTimerid);
    }
}
CModel::CModel()
{
    m_pObservableEmitter = nullptr;
    m_pObservable = nullptr;
    m_nTimerID = 0;
}
CModel::~CModel()
{
}
IObservable* CModel::getObservable()
{
    return m_pObservable;
}
void CModel::setWorkDir(const char* pszWorkDir)
{
    m_strWorkDir = pszWorkDir;
}
int CModel::init()
{
    CString strIniFile;
    CString strUnitId;
    strIniFile.Format(_T("%s\\Configuration.ini"), (LPTSTR)(LPCTSTR)m_strWorkDir);
    m_configuration.setFilepath((LPTSTR)(LPCTSTR)strIniFile);
    m_configuration.getUnitId(strUnitId);
    // Log
    CString strLogDir;
    strLogDir.Format(_T("%s\\BoounionPLCLog"), (LPTSTR)(LPCTSTR)m_strWorkDir);
    ::CreateDirectory(strLogDir, NULL);
    CLog::GetLog()->SetOnLogCallback([&](int level, const char* pszMessage) -> void {
        notifyTextAndInt(RX_CODE_LOG, pszMessage, level);
    });
    CLog::GetLog()->SetAutoAppendTimeString(TRUE);
    CLog::GetLog()->SetOutputTarget(OT_FILE);
    CLog::GetLog()->SetLogsDir(strLogDir);
    CLog::GetLog()->SetEquipmentId((LPTSTR)(LPCTSTR)strUnitId);
    LOGI("\r\n\r\n~~~ Prog Start! ~~~");
    m_pObservable = RX_AllocaObservable([&](IObservableEmitter* e) -> void {
        m_pObservableEmitter = e;            // ä¿å­˜å‘射器
    });
    m_nTimerID = (int)SetTimer(NULL, 1, 1000, (TIMERPROC)ModerTimerProc);
    g_pModel = this;
    return 0;
}
int CModel::term()
{
    CLog::GetLog()->SetOnLogCallback(nullptr);
    return 0;
}
int CModel::notify(int code)
{
    /* code */
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 1;
}
int CModel::notifyPtr(int code, void* ptr/* = NULL*/)
{
    /* code */
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            pAny->setPtrValue("ptr", ptr);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 1;
}
int CModel::notifyObj(int code, IRxObject* pObj)
{
    /* code */
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            pAny->setObject("obj", pObj);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 1;
}
int CModel::notifyObjAndPtr(int code, IRxObject* pObj, void* ptr)
{
    /* code */
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            pAny->setObject("obj", pObj);
            pAny->setPtrValue("ptr", ptr);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 1;
}
int CModel::notifyInt(int code, int exCode)
{
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            pAny->setIntValue("exCode", exCode);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 0;
}
int CModel::notifyInt2(int code, int exCode, int exCode2)
{
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            pAny->setIntValue("exCode", exCode);
            pAny->setIntValue("exCode2", exCode2);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 0;
}
int CModel::notifyDouble(int code, double dValue)
{
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            pAny->setDoubleValue("value", dValue);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 0;
}
int CModel::notifyObjAndInt(int code, IRxObject* pObj1, IRxObject* pObj2, int exCode)
{
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            if (pObj1 != nullptr) pAny->setObject("obj", pObj1);
            if (pObj2 != nullptr) pAny->setObject("obj2", pObj2);
            pAny->setIntValue("exCode", exCode);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 0;
}
int CModel::notifyText(int code, const char* pszText)
{
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            pAny->setStringValue("text", pszText);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 0;
}
int CModel::notifyTextAndInt(int code, const char* pszText, int exCode)
{
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            pAny->setStringValue("text", pszText);
            pAny->setIntValue("exCode", exCode);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 0;
}
int CModel::notifyPtrAndInt(int code, void* ptr1, void* ptr2, int exCode)
{
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            pAny->setPtrValue("ptr", ptr1);
            pAny->setPtrValue("ptr1", ptr1);
            pAny->setPtrValue("ptr2", ptr2);
            pAny->setIntValue("exCode", exCode);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 0;
}
int CModel::notifyMesMsg(int code, int stream, int function, const char* pszText)
{
    if (m_pObservableEmitter != NULL) {
        IAny* pAny = RX_AllocaAny();
        if (pAny != NULL) {
            pAny->addRef();
            pAny->setCode(code);
            pAny->setIntValue("stream", stream);
            pAny->setIntValue("function", function);
            pAny->setStringValue("text", pszText);
            m_pObservableEmitter->onNext(pAny);
            pAny->release();
        }
    }
    return 0;
}
void CModel::onTimer(UINT nTimerid)
{
}
SourceCode/Bond/BoounionPLC/Model.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,44 @@
#pragma once
#include "Configuration.h"
class CModel
{
public:
    CModel();
    ~CModel();
public:
    IObservable* getObservable();
    void setWorkDir(const char* pszWorkDir);
    int init();
    int term();
    void onTimer(UINT nTimerid);
public:
    int notify(int code);
    int notifyPtr(int code, void* ptr = NULL);
    int notifyObj(int code, IRxObject* pObj);
    int notifyObjAndPtr(int code, IRxObject* pObj, void* ptr);
    int notifyObjAndInt(int code, IRxObject* pObj1, IRxObject* pObj2, int exCode);
    int notifyInt(int code, int exCode);
    int notifyInt2(int code, int exCode, int exCode2);
    int notifyDouble(int code, double dValue);
    int notifyText(int code, const char* pszText);
    int notifyPtrAndInt(int code, void* ptr1, void* ptr2, int exCode);
    int notifyTextAndInt(int code, const char* pszText, int exCode);
    int notifyMesMsg(int code, int stream, int function, const char* pszText);
public:
    CConfiguration m_configuration;
private:
    IObservable* m_pObservable;
    IObservableEmitter* m_pObservableEmitter;
    CString m_strWorkDir;
private:
    int m_nTimerID;
};
SourceCode/Bond/BoounionPLC/ReadMe.txt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,67 @@
================================================================================
    MICROSOFT åŸºç¡€ç±»åº“ : BoounionPLC é¡¹ç›®æ¦‚è¿°
===============================================================================
应用程序向导已为您创建了此 BoounionPLC åº”用程序。此应用程序不仅演示 Microsoft åŸºç¡€ç±»çš„基本使用方法,还可作为您编写应用程序的起点。
本文件概要介绍组成 BoounionPLC åº”用程序的每个文件的内容。
BoounionPLC.vcxproj
    è¿™æ˜¯ä½¿ç”¨åº”用程序向导生成的 VC++ é¡¹ç›®çš„主项目文件,其中包含生成该文件的 Visual C++ çš„版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。
BoounionPLC.vcxproj.filters
    è¿™æ˜¯ä½¿ç”¨â€œåº”用程序向导”生成的 VC++ é¡¹ç›®ç­›é€‰å™¨æ–‡ä»¶ã€‚它包含有关项目文件与筛选器之间的关联信息。在 IDE ä¸­ï¼Œé€šè¿‡è¿™ç§å…³è”,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。
BoounionPLC.h
    è¿™æ˜¯åº”用程序的主头文件。
    å…¶ä¸­åŒ…括其他项目特定的标头(包括 Resource.h),并声明 CBoounionPLCApp åº”用程序类。
BoounionPLC.cpp
    è¿™æ˜¯åŒ…含应用程序类 CBoounionPLCApp çš„主应用程序源文件。
BoounionPLC.rc
    è¿™æ˜¯ç¨‹åºä½¿ç”¨çš„æ‰€æœ‰ Microsoft Windows èµ„源的列表。它包括 RES å­ç›®å½•中存储的图标、位图和光标。此文件可以直接在 Microsoft Visual C++ ä¸­è¿›è¡Œç¼–辑。项目资源包含在 2052 ä¸­ã€‚
res\BoounionPLC.ico
    è¿™æ˜¯ç”¨ä½œåº”用程序图标的图标文件。此图标包括在主资源文件 BoounionPLC.rc ä¸­ã€‚
res\BoounionPLC.rc2
    æ­¤æ–‡ä»¶åŒ…含不在 Microsoft Visual C++ ä¸­è¿›è¡Œç¼–辑的资源。您应该将不可由资源编辑器编辑的所有资源放在此文件中。
/////////////////////////////////////////////////////////////////////////////
应用程序向导创建一个对话框类:
BoounionPLCDlg.h、BoounionPLCDlg.cpp - å¯¹è¯æ¡†
    è¿™äº›æ–‡ä»¶åŒ…含 CBoounionPLCDlg ç±»ã€‚此类定义应用程序的主对话框的行为。对话框模板包含在 BoounionPLC.rc ä¸­ï¼Œè¯¥æ–‡ä»¶å¯ä»¥åœ¨ Microsoft Visual C++ ä¸­ç¼–辑。
/////////////////////////////////////////////////////////////////////////////
其他功能:
ActiveX æŽ§ä»¶
    è¯¥åº”用程序包含对使用 ActiveX æŽ§ä»¶çš„æ”¯æŒã€‚
/////////////////////////////////////////////////////////////////////////////
其他标准文件:
StdAfx.h, StdAfx.cpp
    è¿™äº›æ–‡ä»¶ç”¨äºŽç”Ÿæˆåä¸º BoounionPLC.pch çš„预编译头 (PCH) æ–‡ä»¶å’Œåä¸º StdAfx.obj çš„预编译类型文件。
Resource.h
    è¿™æ˜¯æ ‡å‡†å¤´æ–‡ä»¶ï¼Œå¯ç”¨äºŽå®šä¹‰æ–°çš„资源 ID。Microsoft Visual C++ å°†è¯»å–并更新此文件。
BoounionPLC.manifest
    Windows XP ä½¿ç”¨åº”用程序清单文件来描述特定版本的并行程序集的应用程序依赖项。加载程序使用这些信息来从程序集缓存中加载相应的程序集,并保护其不被应用程序访问。应用程序清单可能会包含在内,以作为与应用程序可执行文件安装在同一文件夹中的外部 .manifest æ–‡ä»¶è¿›è¡Œé‡æ–°åˆ†å‘,它还可能以资源的形式包含在可执行文件中。
/////////////////////////////////////////////////////////////////////////////
其他注释:
应用程序向导使用“TODO:”来指示应添加或自定义的源代码部分。
如果应用程序使用共享 DLL ä¸­çš„ MFC,您将需要重新分发 MFC DLL。如果应用程序所使用的语言与操作系统的区域设置不同,则还需要重新分发相应的本地化资源 mfc110XXX.DLL。
有关上述话题的更多信息,请参见 MSDN æ–‡æ¡£ä¸­æœ‰å…³é‡æ–°åˆ†å‘ Visual C++ åº”用程序的部分。
/////////////////////////////////////////////////////////////////////////////
SourceCode/Bond/BoounionPLC/Resource.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,21 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ ç”Ÿæˆçš„包含文件。
// ç”± BoounionPLC.rc ä½¿ç”¨
//
#define IDR_MAINFRAME                    128
#define IDM_ABOUTBOX                    0x0010
#define IDD_ABOUTBOX                    100
#define IDS_ABOUTBOX                    101
#define IDD_BOOUNIONPLC_DIALOG                102
// æ–°å¯¹è±¡çš„下一组默认值
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE    129
#define _APS_NEXT_CONTROL_VALUE        1000
#define _APS_NEXT_SYMED_VALUE        101
#define _APS_NEXT_COMMAND_VALUE        32771
#endif
#endif
SourceCode/Bond/BoounionPLC/res/BoounionPLC.ico
SourceCode/Bond/BoounionPLC/res/BoounionPLC.rc2
Binary files differ
SourceCode/Bond/BoounionPLC/stdafx.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,8 @@
// stdafx.cpp : åªåŒ…括标准包含文件的源文件
// BoounionPLC.pch å°†ä½œä¸ºé¢„编译头
// stdafx.obj å°†åŒ…含预编译类型信息
#include "stdafx.h"
SourceCode/Bond/BoounionPLC/stdafx.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,55 @@
// stdafx.h : æ ‡å‡†ç³»ç»ŸåŒ…含文件的包含文件,
// æˆ–是经常使用但不常更改的
// ç‰¹å®šäºŽé¡¹ç›®çš„包含文件
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // ä»Ž Windows å¤´ä¸­æŽ’除极少使用的资料
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // æŸäº› CString æž„造函数将是显式的
// å…³é—­ MFC å¯¹æŸäº›å¸¸è§ä½†ç»å¸¸å¯æ”¾å¿ƒå¿½ç•¥çš„警告消息的隐藏
#define _AFX_ALL_WARNINGS
#include <afxwin.h>         // MFC æ ¸å¿ƒç»„件和标准组件
#include <afxext.h>         // MFC æ‰©å±•
#include <afxdisp.h>        // MFC è‡ªåŠ¨åŒ–ç±»
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC å¯¹ Internet Explorer 4 å…¬å…±æŽ§ä»¶çš„æ”¯æŒ
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>             // MFC å¯¹ Windows å…¬å…±æŽ§ä»¶çš„æ”¯æŒ
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxcontrolbars.h>     // åŠŸèƒ½åŒºå’ŒæŽ§ä»¶æ¡çš„ MFC æ”¯æŒ
#include "..\RxWindows1.0\include\RxWindowsLib.h"
#include "..\McLibrarySDK\include\McLib.h"
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
SourceCode/Bond/BoounionPLC/targetver.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,8 @@
#pragma once
// åŒ…括 SDKDDKVer.h å°†å®šä¹‰å¯ç”¨çš„æœ€é«˜ç‰ˆæœ¬çš„ Windows å¹³å°ã€‚
// å¦‚果要为以前的 Windows å¹³å°ç”Ÿæˆåº”用程序,请包括 WinSDKVer.h,并将
// å°† _WIN32_WINNT å®è®¾ç½®ä¸ºè¦æ”¯æŒçš„平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>
SourceCode/Bond/GangBond2860.sln
@@ -13,6 +13,8 @@
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Servo", "Servo\Servo.vcxproj", "{66ADACE5-3166-4D1F-B30B-DE5E01FB01A2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BoounionPLC", "BoounionPLC\BoounionPLC.vcxproj", "{6DC0600E-5588-4033-A281-3626A4F74B67}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|x64 = Debug|x64
@@ -61,6 +63,14 @@
        {66ADACE5-3166-4D1F-B30B-DE5E01FB01A2}.Release|x64.Build.0 = Release|x64
        {66ADACE5-3166-4D1F-B30B-DE5E01FB01A2}.Release|x86.ActiveCfg = Release|Win32
        {66ADACE5-3166-4D1F-B30B-DE5E01FB01A2}.Release|x86.Build.0 = Release|Win32
        {6DC0600E-5588-4033-A281-3626A4F74B67}.Debug|x64.ActiveCfg = Debug|x64
        {6DC0600E-5588-4033-A281-3626A4F74B67}.Debug|x64.Build.0 = Debug|x64
        {6DC0600E-5588-4033-A281-3626A4F74B67}.Debug|x86.ActiveCfg = Debug|Win32
        {6DC0600E-5588-4033-A281-3626A4F74B67}.Debug|x86.Build.0 = Debug|Win32
        {6DC0600E-5588-4033-A281-3626A4F74B67}.Release|x64.ActiveCfg = Release|x64
        {6DC0600E-5588-4033-A281-3626A4F74B67}.Release|x64.Build.0 = Release|x64
        {6DC0600E-5588-4033-A281-3626A4F74B67}.Release|x86.ActiveCfg = Release|Win32
        {6DC0600E-5588-4033-A281-3626A4F74B67}.Release|x86.Build.0 = Release|Win32
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE