├── .gitignore ├── README.md ├── dll ├── debug │ └── hsms.dll └── release │ └── hsms.dll ├── include └── gem.h ├── lib ├── Debug │ └── hsms.lib └── Release │ └── hsms.lib ├── src ├── HsmsDemo │ ├── CHsmsEquipment.cpp │ ├── CHsmsEquipment.h │ ├── HsmsDemo.cpp │ ├── HsmsDemo.vcxproj │ └── HsmsDemo.vcxproj.filters └── Learn │ └── BlockState.h └── win └── EngGemDemo.sln /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GemDemo 2 | Demo for SECS HSMS communication 3 | 4 | # Example 5 | 6 | 通讯库支持SECS-I与HSMS两种通讯方式。区别在初始化时,使用不同的参数类型。 7 | 其它的函数是一样的。 8 | 9 | ## 创建通讯库对象 10 | GemPtr pGem = CGem::GetInstancePtr(); 11 | ## 初始化连接 12 | ### Secs-I 13 | 14 | SecsSet sset; 15 | sset.sComName = "COM1"; 16 | sset.uBaudrate = 9600; 17 | sset.uDevID = 1; 18 | sset.mode = CSECS_EQUIP; 19 | 20 | pGem->InitLink(sset); 21 | 22 | ### Secs-II (HSMS) 23 | 24 | HsmsSet set; 25 | set.uLocalPort = 5000; 26 | set.mode = CHSMS_PASSIVE; 27 | set.uDevID = 1; 28 | 29 | pGem->InitLink(set); 30 | 31 | ## 设置消息接收处理 32 | 33 | pGem->SetSecsRecvFun([this](const SecsMessage& msg) { 34 | return handleMessage(msg); 35 | }); 36 | 37 | ## 启动连接 38 | 39 | pGem->Connect(); 40 | 41 | ## 发送消息 42 | 43 | ItemPtr iSend = Item::L(); 44 | iSend->Append(Item::B(6)); 45 | iSend->Append(Item::U2(10)); 46 | iSend->Append(Item::A("Fire Alarm")); 47 | 48 | SecsMessage smsg{ 5, 1, iSend }; 49 | mid = pGem->Send(smsg); 50 | 51 | ## 回应消息 52 | 53 | ItemPtr item = Item::L(); 54 | item->Append(Item::A("DemoEquip")); 55 | item->Append(Item::A("Rev 1.0")); 56 | 57 | SecsMessage rmsg{1, 2, item, msg.MID}; 58 | m_pGem->Reply(rmsg); 59 | 60 | ## 联系方式 61 | QQ: 24164068 62 | 63 | 64 | -------------------------------------------------------------------------------- /dll/debug/hsms.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tornadoSemi/HsmsCpp/7a8035dcb113b9422b7d3429c92d17693cab974d/dll/debug/hsms.dll -------------------------------------------------------------------------------- /dll/release/hsms.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tornadoSemi/HsmsCpp/7a8035dcb113b9422b7d3429c92d17693cab974d/dll/release/hsms.dll -------------------------------------------------------------------------------- /include/gem.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tornadoSemi/HsmsCpp/7a8035dcb113b9422b7d3429c92d17693cab974d/include/gem.h -------------------------------------------------------------------------------- /lib/Debug/hsms.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tornadoSemi/HsmsCpp/7a8035dcb113b9422b7d3429c92d17693cab974d/lib/Debug/hsms.lib -------------------------------------------------------------------------------- /lib/Release/hsms.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tornadoSemi/HsmsCpp/7a8035dcb113b9422b7d3429c92d17693cab974d/lib/Release/hsms.lib -------------------------------------------------------------------------------- /src/HsmsDemo/CHsmsEquipment.cpp: -------------------------------------------------------------------------------- 1 | #include "CHsmsEquipment.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | CHsmsEquipment::CHsmsEquipment() 8 | { 9 | m_pGem = CGem::GetInstancePtr(CGem::LinkMode::HSMS_SS); 10 | } 11 | 12 | CHsmsEquipment::~CHsmsEquipment() 13 | { 14 | } 15 | 16 | int CHsmsEquipment::Start() 17 | { 18 | srand(time(nullptr)); 19 | int nRand = rand(); 20 | 21 | HsmsSet set; 22 | set.uLocalPort = 5000; 23 | set.mode = CHSMS_PASSIVE; 24 | set.uDevID = 0; 25 | set.cRemoteIP = "127.0.0.1"; 26 | set.uRemotePort = 5000; 27 | 28 | SecsSet sset; 29 | sset.sComName = "COM1"; 30 | sset.uBaudrate = 9600; 31 | sset.uDevID = 1; 32 | sset.mode = CSECS_EQUIP; 33 | 34 | m_pGem->SetSmlLog("../log", 7); 35 | m_pGem->InitLink(set); 36 | 37 | m_pGem->SetSecsRecvFun([this](const SecsMessage& msg) 38 | { 39 | return handleMessage(msg); 40 | }); 41 | 42 | m_pGem->Connect(); 43 | 44 | ItemTest(); 45 | 46 | return 0; 47 | } 48 | 49 | int CHsmsEquipment::Stop() 50 | { 51 | m_pGem->Disconnect(); 52 | 53 | return 0; 54 | } 55 | 56 | int CHsmsEquipment::handleMessage(const SecsMessage& msg) 57 | { 58 | int nSF = SF(msg.S, msg.F); 59 | 60 | switch (nSF) 61 | { 62 | case 1 << 8 | 1: 63 | { 64 | ItemPtr item = Item::L(); 65 | item->Append(Item::A("DemoEquip")); 66 | item->Append(Item::A("Rev 1.0")); 67 | 68 | SecsMessage rmsg{ 1, 2, item, msg.MID }; 69 | m_pGem->Reply(rmsg); 70 | 71 | std::thread t([this]() 72 | { 73 | SecsMessage smsgHello{ 1, 1, nullptr }; 74 | m_pGem->Send(smsgHello); 75 | 76 | std::this_thread::sleep_for(std::chrono::seconds(1)); 77 | ItemPtr iSend = Item::L(); 78 | iSend->Append(Item::B(6)); 79 | iSend->Append(Item::U2(10)); 80 | iSend->Append(Item::A("Fire Alarm")); 81 | iSend->Append(Item::F4(NAN)); 82 | 83 | SecsMessage smsg{ 5, 1, iSend }; 84 | m_pGem->Send(smsg); 85 | }); 86 | t.detach(); 87 | } 88 | break; 89 | case 1 << 8 | 3: 90 | { 91 | ItemPtr item = Item::L(); 92 | for (int i = 0; i < 1000; i++) 93 | { 94 | item->Append(Item::U4(i)); 95 | } 96 | 97 | SecsMessage rmsg{ 1, 4, item, msg.MID }; 98 | m_pGem->Reply(rmsg); 99 | } 100 | break; 101 | default: 102 | { 103 | if (msg.F % 2 != 0) 104 | { 105 | SecsMessage rmsg{ msg.S, (byte)(msg.F + 1), Item::L(), msg.MID }; 106 | m_pGem->Reply(rmsg); 107 | } 108 | } 109 | break; 110 | } 111 | 112 | string sml = Item::GetSML(msg.item); 113 | cout << "recv" << "S" << (int)msg.S << "F" << (int)msg.F << " MID" << msg.MID << endl; 114 | cout << sml.c_str() << endl; 115 | 116 | return 0; 117 | } 118 | 119 | int CHsmsEquipment::ItemTest() 120 | { 121 | auto item = Item::U4(vector{2, 3, 4}); 122 | auto count = item->getCount(); 123 | auto itemcount = item->getItemCount(); 124 | 125 | return 0; 126 | } -------------------------------------------------------------------------------- /src/HsmsDemo/CHsmsEquipment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "windows.h" 3 | #include "../../include/gem.h" 4 | 5 | class CHsmsEquipment 6 | { 7 | public: 8 | CHsmsEquipment(); 9 | ~CHsmsEquipment(); 10 | 11 | public: 12 | int Start(); 13 | int Stop(); 14 | 15 | private: 16 | int handleMessage(const SecsMessage& msg); 17 | int ItemTest(); 18 | 19 | private: 20 | GemPtr m_pGem; 21 | }; 22 | -------------------------------------------------------------------------------- /src/HsmsDemo/HsmsDemo.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include 3 | #include 4 | #include "CHsmsEquipment.h" 5 | 6 | int main() 7 | { 8 | 9 | 10 | CHsmsEquipment equip; 11 | equip.Start(); 12 | 13 | while (1) 14 | { 15 | Sleep(1000); 16 | } 17 | 18 | equip.Stop(); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/HsmsDemo/HsmsDemo.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {10BB6B7A-FB58-43B2-A5E2-45F264EA4CD1} 24 | Win32Proj 25 | HsmsDemo 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | true 78 | $(SolutionDir)\bin\$(Configuration)\ 79 | $(SolutionDir)\..\lib\$(Configuration)\;$(LibraryPath) 80 | 81 | 82 | false 83 | 84 | 85 | false 86 | $(SolutionDir)\bin\$(Configuration)\ 87 | $(SolutionDir)\..\lib\$(Configuration)\;$(LibraryPath) 88 | 89 | 90 | 91 | 92 | 93 | Level3 94 | true 95 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 96 | true 97 | 98 | 99 | Console 100 | true 101 | 102 | 103 | 104 | 105 | 106 | 107 | Level3 108 | true 109 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 110 | true 111 | 112 | 113 | Console 114 | true 115 | 116 | 117 | 118 | 119 | 120 | 121 | Level3 122 | true 123 | true 124 | true 125 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 126 | true 127 | 128 | 129 | Console 130 | true 131 | true 132 | true 133 | 134 | 135 | 136 | 137 | 138 | 139 | Level3 140 | true 141 | true 142 | true 143 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 144 | true 145 | 146 | 147 | Console 148 | true 149 | true 150 | true 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /src/HsmsDemo/HsmsDemo.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 26 | 27 | 头文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/Learn/BlockState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | //#include 13 | #include 14 | 15 | #include 16 | 17 | namespace sc = boost::statechart; 18 | namespace mpl = boost::mpl; 19 | 20 | namespace SECS_E4 21 | { 22 | // define event of Processing 23 | class EvENQ : public sc::event< EvENQ > {}; // 24 | class EvEOT : public sc::event< EvEOT > {}; // 25 | class EvACK : public sc::event< EvACK > {}; // 26 | class EvNoACK : public sc::event< EvACK > {}; // 27 | class EvSendRequest : public sc::event< EvSendRequest > {}; // 28 | class EvT1 : public sc::event< EvT1 > 29 | { 30 | public: 31 | EvT1(); 32 | }; // 33 | class EvT2 : public sc::event< EvT2 > 34 | { 35 | public: 36 | EvT2(); 37 | }; // 38 | class EvOverRetry : public sc::event< EvOverRetry > {}; // 39 | class EvRetry : public sc::event< EvRetry > {}; // 40 | class EvLenErr : public sc::event< EvLenErr > 41 | { 42 | public: 43 | EvLenErr(); 44 | }; // 45 | class EvCheckSumErr : public sc::event< EvCheckSumErr > 46 | { 47 | public: 48 | EvCheckSumErr(); 49 | }; // 50 | class EvIdle : public sc::event< EvIdle > {}; // 51 | class EvNext : public sc::event< EvNext > {}; // 52 | } 53 | 54 | namespace SECS_E4 55 | { 56 | // define state of Processing 57 | class Idle; 58 | class LineRecv; 59 | class LineSend; 60 | class Retry; 61 | class SendData; 62 | class BlockSended; 63 | class GetLen; 64 | class GetData; 65 | class CheckSum; 66 | class BlockReceived; 67 | class FailedSend; 68 | class TimeOut; 69 | class Eat; 70 | class RecvOK; 71 | } 72 | 73 | namespace SECS_E4 74 | { 75 | enum class ErrorType 76 | { 77 | TmoT1, 78 | TmoT2, 79 | LenErr, 80 | CheckSumErr, 81 | SendFailed, 82 | NoAck, 83 | Contention, 84 | }; 85 | } 86 | 87 | namespace SECS_E4 88 | { 89 | class BlockState 90 | : public sc::state_machine 91 | { 92 | public: 93 | BlockState(void); 94 | ~BlockState(void); 95 | 96 | bool Slave() const { return m_bSlave; } 97 | void Slave(bool val) { m_bSlave = val; } 98 | 99 | bool IsCanRetry(); 100 | void ResetRetry(); 101 | void SetRetryCount(int nRetry) 102 | { 103 | m_nTotalRetry = nRetry; 104 | } 105 | 106 | public: 107 | virtual int OnIdle() = 0; 108 | virtual int OnLineRecv() = 0; 109 | virtual int OnGetLen() = 0; 110 | virtual int OnGetData() = 0; 111 | virtual int OnTimeOut() = 0; 112 | virtual int OnEat() = 0; 113 | virtual int OnCheckSum() = 0; 114 | virtual int OnBlockRecv() = 0; 115 | virtual int OnRecvOK() = 0; 116 | 117 | virtual int OnLineSend() = 0; 118 | virtual int OnSendData() = 0; 119 | virtual int OnBlockSend() = 0; 120 | virtual int OnFailedSend() = 0; 121 | virtual int OnError(ErrorType err) = 0; 122 | 123 | private: 124 | bool m_bSlave; 125 | int m_nRetry; 126 | int m_nTotalRetry; 127 | }; 128 | 129 | // 130 | //----------------------------------------------------------------------------- 131 | // 132 | class Idle 133 | : public sc::state< Idle, BlockState > 134 | { 135 | public: 136 | typedef mpl::list 137 | < 138 | sc::transition< EvENQ, LineRecv >, 139 | sc::transition< EvSendRequest, LineSend > 140 | > reactions; 141 | 142 | Idle(my_context ctx); 143 | ~Idle(); 144 | }; 145 | 146 | // 147 | //----------------------------------------------------------------------------- 148 | // 149 | class LineRecv 150 | : public sc::state< LineRecv, BlockState > 151 | { 152 | public: 153 | typedef sc::transition< EvNext, GetLen > reactions; 154 | 155 | LineRecv(my_context ctx); 156 | ~LineRecv(); 157 | }; 158 | 159 | // 160 | //----------------------------------------------------------------------------- 161 | // 162 | class LineSend 163 | : public sc::state< LineSend, BlockState > 164 | { 165 | public: 166 | typedef mpl::list 167 | < 168 | sc::transition< EvT2, Retry >, 169 | sc::transition< EvEOT, SendData >, 170 | sc::custom_reaction< EvENQ > 171 | > reactions; 172 | 173 | LineSend(my_context ctx); 174 | ~LineSend(); 175 | 176 | sc::result react(const EvENQ& ev); 177 | }; 178 | 179 | // 180 | //----------------------------------------------------------------------------- 181 | // 182 | class Retry 183 | : public sc::state< Retry, BlockState > 184 | { 185 | public: 186 | typedef mpl::list 187 | < 188 | sc::custom_reaction< EvRetry > 189 | > reactions; 190 | 191 | Retry(my_context ctx); 192 | ~Retry(); 193 | 194 | sc::result react(const EvRetry& ev); 195 | }; 196 | 197 | // 198 | //----------------------------------------------------------------------------- 199 | // 200 | class SendData 201 | : public sc::state< SendData, BlockState > 202 | { 203 | public: 204 | typedef mpl::list 205 | < 206 | sc::transition< EvT2, Retry >, 207 | sc::transition< EvACK, BlockSended >, 208 | sc::transition< EvNoACK, Retry > 209 | > reactions; 210 | 211 | SendData(my_context ctx); 212 | ~SendData(); 213 | }; 214 | 215 | // 216 | //----------------------------------------------------------------------------- 217 | // 218 | class BlockSended 219 | : public sc::state< BlockSended, BlockState > 220 | { 221 | public: 222 | typedef sc::transition< EvNext, Idle > reactions; 223 | 224 | BlockSended(my_context ctx); 225 | ~BlockSended(); 226 | }; 227 | 228 | // 229 | //----------------------------------------------------------------------------- 230 | // 231 | class GetLen 232 | : public sc::state< GetLen, BlockState > 233 | { 234 | public: 235 | typedef mpl::list 236 | < 237 | sc::transition< EvT2, TimeOut >, 238 | sc::transition< EvLenErr, Eat >, 239 | sc::transition< EvNext, GetData > 240 | > reactions; 241 | 242 | GetLen(my_context ctx); 243 | ~GetLen(); 244 | }; 245 | 246 | // 247 | //----------------------------------------------------------------------------- 248 | // 249 | class GetData 250 | : public sc::state< GetData, BlockState > 251 | { 252 | public: 253 | typedef mpl::list 254 | < 255 | sc::transition< EvT1, TimeOut >, 256 | sc::transition< EvNext, CheckSum > 257 | > reactions; 258 | 259 | GetData(my_context ctx); 260 | ~GetData(); 261 | }; 262 | 263 | // 264 | //----------------------------------------------------------------------------- 265 | // 266 | class CheckSum 267 | : public sc::state< CheckSum, BlockState > 268 | { 269 | public: 270 | typedef mpl::list 271 | < 272 | sc::transition< EvCheckSumErr, Eat >, 273 | sc::transition< EvNext, BlockReceived > 274 | > reactions; 275 | 276 | CheckSum(my_context ctx); 277 | ~CheckSum(); 278 | }; 279 | 280 | // 281 | //----------------------------------------------------------------------------- 282 | // 283 | class BlockReceived 284 | : public sc::state< BlockReceived, BlockState > 285 | { 286 | public: 287 | typedef sc::transition< EvNext, RecvOK > reactions; 288 | 289 | BlockReceived(my_context ctx); 290 | ~BlockReceived(); 291 | }; 292 | 293 | // 294 | //----------------------------------------------------------------------------- 295 | // 296 | class RecvOK 297 | : public sc::state< RecvOK, BlockState > 298 | { 299 | public: 300 | typedef sc::transition< EvNext, Idle > reactions; 301 | 302 | RecvOK(my_context ctx); 303 | ~RecvOK(); 304 | }; 305 | 306 | // 307 | //----------------------------------------------------------------------------- 308 | // 309 | class FailedSend 310 | : public sc::state< FailedSend, BlockState > 311 | { 312 | public: 313 | typedef sc::transition< EvNext, Idle > reactions; 314 | 315 | FailedSend(my_context ctx); 316 | ~FailedSend(); 317 | }; 318 | 319 | // 320 | //----------------------------------------------------------------------------- 321 | // 322 | class TimeOut 323 | : public sc::state< TimeOut, BlockState > 324 | { 325 | public: 326 | typedef sc::transition< EvNext, Idle > reactions; 327 | 328 | TimeOut(my_context ctx); 329 | ~TimeOut(); 330 | }; 331 | 332 | // 333 | //----------------------------------------------------------------------------- 334 | // 335 | class Eat 336 | : public sc::state< Eat, BlockState > 337 | { 338 | public: 339 | typedef sc::transition< EvT1, TimeOut > reactions; 340 | 341 | Eat(my_context ctx); 342 | ~Eat(); 343 | }; 344 | 345 | 346 | 347 | // 348 | //----------------------------------------------------------------------------- 349 | // 350 | } 351 | 352 | 353 | 354 | 355 | -------------------------------------------------------------------------------- /win/EngGemDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30104.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HsmsDemo", "..\src\HsmsDemo\HsmsDemo.vcxproj", "{10BB6B7A-FB58-43B2-A5E2-45F264EA4CD1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {10BB6B7A-FB58-43B2-A5E2-45F264EA4CD1}.Debug|x64.ActiveCfg = Debug|x64 15 | {10BB6B7A-FB58-43B2-A5E2-45F264EA4CD1}.Debug|x64.Build.0 = Debug|x64 16 | {10BB6B7A-FB58-43B2-A5E2-45F264EA4CD1}.Release|x64.ActiveCfg = Release|x64 17 | {10BB6B7A-FB58-43B2-A5E2-45F264EA4CD1}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {2FC63A05-255F-44B0-A875-4CBD19443D77} 24 | EndGlobalSection 25 | EndGlobal 26 | --------------------------------------------------------------------------------