Commit c7c2306d authored by captainwong's avatar captainwong

init

parents
.vscode/
.vs/
packages/
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Dev partner files
*.DPbcd
# vs
*.sdf
#*.sln
*.suo
*.ipch
*.ilk
*.pdb
*.map
#*.vcxproj
#*.filters
*.log
*.tlog
*.nlb
*.DPbcd
*.pd_
*.opensdf
Debug/Maps/
Debug/config/
Debug/
Release/
ReleaseD/
# vc6
#*.dsp
#*.dsw
*.ncb
*.opt
*.plg
*.clw
*.aps
*.log
*.pch
*.idb
*.pdb
*.ilk
*.sbr
*.bsc
*.map
# graph
#*.bmp
*.jpg
*.jpeg
*.jpe
*.jifi
*.gif
#*.ico
#*.png
*.dib
*.tif
*.tiff
# video
*.mp4
/video_record
/video_capture
# Compiled Dynamic libraries
*.so
*.dylib
#*.dll
# Compiled Static libraries
*.lai
*.la
*.a
#*.lib
# Executables
#*.exe
#AlarmCenter_Setup.exe
*.out
*.app
# Database files
#*.mdb
*.ldb
*.db
# Resource files
*.manifest
#*.rc
#*.rc2
*.cur
*.avi
*.wav
# AlarmCenter files
*.bak
*.log
# Mindjet map files
*.mmap.~$lock
#baiduyun files
*.baiduyun.uploading.cfg
# Compressed files
*.rar
*.7z
*.zip
*.tar
*.gz
*.bz
*.bz2
MIT License
Copyright (c) 2019 HENGBO
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
# Hengbo Protocal Library
恒博协议库
## 各头文件说明
* `ademco_event.h`
定义了安定宝事件码及所需的结构体
* `ademco_detail.h`
定义了各种辅助函数
* `ademco_packet.h`
定义了可用于安定宝协议封包、解包的结构体与相应函数

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29306.81
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo", "demo\demo.vcxproj", "{36640D95-55AB-4DCF-9062-91A53203E6A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|x64.ActiveCfg = Debug|x64
{36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|x64.Build.0 = Debug|x64
{36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|x86.ActiveCfg = Debug|Win32
{36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|x86.Build.0 = Debug|Win32
{36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|x64.ActiveCfg = Release|x64
{36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|x64.Build.0 = Release|x64
{36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|x86.ActiveCfg = Release|Win32
{36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A7C808AC-B572-4B53-A2B5-B50905BE6550}
EndGlobalSection
EndGlobal
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#define DISABLE_JLIB_LOG2
#include <ademco_packet.h>
#include <ademco_detail.h>
using namespace ademco;
#define EXPECT_EQ(a, b) assert((a) == (b))
#define EXPECT_TRUE(a) assert(a)
#define EXPECT_STREQ(a, b) assert(strcmp((a), (b)) == 0)
void test()
{
char pack[1024] = { 0 };
AdemcoPacket ap = {};
// parse data from self made
{
auto size = ap.make(pack, sizeof(pack));
size_t cb_commited = 0;
EXPECT_EQ(ap.parse(pack, size, cb_commited), ParseResult::RESULT_OK);
EXPECT_EQ(cb_commited, size);
}
// parse data from production
{
char raw[] = "\nC5C30053\"HENG-BO\"0000R000000L000000#90219125916578[#000000|1737 00 000]_09:11:19,08-05-2019\r";
size_t cb_commited = 0;
EXPECT_EQ(ap.parse(raw, strlen(raw), cb_commited), ParseResult::RESULT_OK);
EXPECT_EQ(cb_commited, strlen(raw));
EXPECT_EQ(ap.crc_.value_, 0xC5C3);
EXPECT_EQ(ap.len_.value_, 0x0053);
EXPECT_EQ(ap.id_.eid_, AdemcoId::Enum::id_hb);
EXPECT_EQ(ap.seq_.value_, 0); // 0 is not a valid seq, but...
EXPECT_TRUE(strncmp("R000000", ap.rrcvr_.data_.data(), 7) == 0);
EXPECT_TRUE(strncmp("L000000", ap.lpref_.data_.data(), 7) == 0);
EXPECT_STREQ(ap.acct_.acct(), "90219125916578");
EXPECT_EQ(ap.ademcoData_.ademco_id_, 0);
EXPECT_EQ(ap.ademcoData_.ademco_event_, ADEMCO_EVENT::EVENT_I_AM_WIRE_MACHINE);
EXPECT_EQ(ap.ademcoData_.gg_, 0);
EXPECT_EQ(ap.ademcoData_.zone_, 0);
EXPECT_STREQ(ap.timestamp_.data_, "_09:11:19,08-05-2019");
}
}
void generate_network_data()
{
char pack[1024];
AdemcoPacket ap;
ap.make_hb(pack, sizeof(pack), 1, "861234567890", 666666, 0, ademco::EVENT_ARM, 0);
printf("generate_network_data:%s\n", ap.toString().data());
}
void handle_network_data(const char* data_from_network)
{
AdemcoPacket ap;
size_t cb_commited = 0;
auto result = ap.parse(data_from_network, strlen(data_from_network), cb_commited);
switch (result) {
case ademco::ParseResult::RESULT_OK:
{
printf("id=%s\n", ap.id_.data());
switch (ap.id_.eid_) {
case AdemcoId::id_ack:
// success
break;
case AdemcoId::id_hb:
// event report
printf("%s\n", ap.ademcoData_.toString().data());
break;
default:
break;
}
break;
}
case ademco::ParseResult::RESULT_NOT_ENOUGH:
// do nothing
break;
case ademco::ParseResult::RESULT_DATA_ERROR:
default:
// error handle, e.g. clear buff
break;
}
}
int main()
{
test();
generate_network_data();
char data_from_network[] = "\nC5C30053\"HENG-BO\"0000R000000L000000#90219125916578[#000000|1737 00 000]_09:11:19,08-05-2019\r";
handle_network_data(data_from_network);
char buff[1024];
AdemcoPacket ap;
ap.make(buff, sizeof(buff));
handle_network_data(buff);
ap.make_ack(buff, sizeof(buff), 1, "861234567890", 123321);
handle_network_data(buff);
size_t ademco_id = 123456; // 主机标识
size_t zone = 123; // 防区标识
auto evnt = EVENT_FIRE; // 事件码
ap.make_hb(buff, sizeof(buff), 1, nullptr, ademco_id, 0, evnt, zone);
handle_network_data(buff);
}
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{36640D95-55AB-4DCF-9062-91A53203E6A9}</ProjectGuid>
<RootNamespace>demo</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</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 />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="demo.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\ademco_detail.h" />
<ClInclude Include="..\include\ademco_event.h" />
<ClInclude Include="..\include\ademco_packet.h" />
<ClInclude Include="..\include\hb.h" />
<ClInclude Include="..\include\hb_detail.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<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>
<Filter Include="include">
<UniqueIdentifier>{9cddb4df-0c1d-4f36-a814-5412a486e938}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="demo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\ademco_detail.h">
<Filter>include</Filter>
</ClInclude>
<ClInclude Include="..\include\ademco_event.h">
<Filter>include</Filter>
</ClInclude>
<ClInclude Include="..\include\ademco_packet.h">
<Filter>include</Filter>
</ClInclude>
<ClInclude Include="..\include\hb.h">
<Filter>include</Filter>
</ClInclude>
<ClInclude Include="..\include\hb_detail.h">
<Filter>include</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment