Commit f9e16e88 authored by captainwong's avatar captainwong

verified & benched

parent 575fa5dd
This diff is collapsed.
This diff is collapsed.
<?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>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{d0015e82-053e-431e-95d6-41e9ac9c1342}</ProjectGuid>
<RootNamespace>ademco</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</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 Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;ADEMCO_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;ADEMCO_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;ADEMCO_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;ADEMCO_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\c\ademco.c" />
<ClCompile Include="dllmain.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\c\ademco.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;c++;cppm;ixx;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;h++;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>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\c\ademco.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\c\ademco.h">
<Filter>Source Files</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
// dllmain.cpp : Defines the entry point for the DLL application.
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <windows.h>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
<?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>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{a06eee58-8005-49fd-976f-79bf9ad8feac}</ProjectGuid>
<RootNamespace>ademcodemo</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>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</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 Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.c" />
</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;c++;cppm;ixx;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;h++;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>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c">
<Filter>Source Files</Filter>
</ClCompile>
</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
#include "../../c/ademco.h"
#include <assert.h>
#include <string.h>
#ifdef _WIN64
#ifdef _DEBUG
#pragma comment(lib, "../x64/Debug/ademco.lib")
#else
#pragma comment(lib, "../x64/Release/ademco.lib")
#endif
#else // WIN32
#ifdef _DEBUG
#pragma comment(lib, "../Win32/Debug/ademco.lib")
#else
#pragma comment(lib, "../Win32/Release/ademco.lib")
#endif
#endif
int main()
{
int cb_commited = 0;
AdemcoPacket pkt;
// 解析完整数据包
{
char raw[] = "\nC5C30053\"HENG-BO\"0000R000000L000000#90219125916578[#000000|1737 00 000]_09:11:19,08-05-2019\r";
AdemcoParseResult res = ademcoPacketParse(raw, (int)strlen(raw), &pkt, &cb_commited);
assert(res == RESULT_OK);
}
// 解析长度不足的数据包
{
char raw_not_enough[] = "\nC5C30053\"HENG-BO\"0000R000000L000000";
AdemcoParseResult res = ademcoPacketParse(raw_not_enough, (int)strlen(raw_not_enough), &pkt, &cb_commited);
assert(res == RESULT_NOT_ENOUGH);
}
// 解析到错误数据包
{
char raw_error[] = "abcdeadfasdfasdfasd";
AdemcoParseResult res = ademcoPacketParse(raw_error, (int)strlen(raw_error), &pkt, &cb_commited);
assert(res == RESULT_ERROR);
}
// 打包示例
{
char buff[1024];
// 对安定宝ID为666666的主机进行撤防
int len = ademcoMakeHbPacket(buff, sizeof(buff), 1, "861234567890", 666666, 1400, 0, 0, NULL);
assert(len > 0);
AdemcoParseResult res = ademcoPacketParse(buff, len, &pkt, &cb_commited);
assert(res == RESULT_OK);
assert(cb_commited == len);
}
// ACK 示例
{
char buff[1024];
// 对安定宝ID为666666的主机回应ACK
int len = ademcoMakeAckPacket(buff, sizeof(buff), 1, "861234567890", 666666);
assert(len > 0);
AdemcoParseResult res = ademcoPacketParse(buff, len, &pkt, &cb_commited);
assert(res == RESULT_OK);
assert(cb_commited == len);
}
}
#define DISABLE_JLIB_LOG2
#include "../../include/ademco_packet.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
using namespace ademco;
using namespace std::chrono;
#ifdef _DEBUG
constexpr int TIMES = 10000;
#if 0
#include "bench_old.h"
#else
constexpr int TIMES = 100000;
#include "bench.h"
#endif
char data[TIMES * 256];
void ademcoPacketBench()
{
printf("\nademcoPacketBench...\n");
printf("generating data...\n");
//std::vector<char> data; data.reserve(TIMES * 100);
AdemcoPacket ap;
//char tmp[256];
size_t total_len = 0;
for (int i = 0; i < TIMES; i++) {
auto len = ap.make_hb(data + total_len, sizeof(data) - total_len, (i + 1) % 10000, std::to_string(i), (i + 1) % AdemcoIdSentinel, 0, EVENT_ARM, 0);
assert(len > 0);
total_len += len;
if ((i + 1) % 1000 == 0) {
printf("\r%d/%d %s", i + 1, TIMES, ap.timestamp_.data_);
std::this_thread::sleep_for(milliseconds(15));
}
}
printf("\ndone\ntesting parse...\n");
auto start = steady_clock::now();
size_t cb = 0;
auto res = ap.parse(&data[0], total_len, cb);
assert(res == ParseResult::RESULT_OK);
size_t pos = 0;
int packets = 0;
while (res == ParseResult::RESULT_OK) {
packets++;
if (packets % 500 == 0) {
printf("\r%d/%d %s", packets, TIMES, ap.timestamp_.data_);
}
pos += cb;
if (total_len > pos) {
res = ap.parse(&data[pos], total_len - pos, cb);
} else { break; }
}
assert(res == ParseResult::RESULT_OK);
assert(packets == TIMES);
auto duration = steady_clock::now() - start;
auto ms = duration_cast<milliseconds>(duration).count();
auto us = duration_cast<microseconds>(duration).count();
double avg = us * 1.0 / TIMES;
printf("\ndone\nduration=%ldms\navg parse time=%.2lfus\n", (long)ms, avg);
double avgpps = 1000.0 * TIMES / ms;
printf("average packets per second=%.2lf\n", avgpps);
double avgbps = total_len * 1000.0 / ms;
printf("average bytes per second=%.2lfB/s, %.2lfKB/s\n", avgbps, avgbps / 1024.0);
}
int main()
{
ademcoPacketBench();
......
#pragma once
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <assert.h>
using namespace std::chrono;
#include "../../c/ademco.h"
#ifdef _WIN64
#ifdef _DEBUG
#pragma comment(lib, "../x64/Debug/ademco.lib")
#else
#pragma comment(lib, "../x64/Release/ademco.lib")
#endif
#else // WIN32
#ifdef _DEBUG
#pragma comment(lib, "../Win32/Debug/ademco.lib")
#else
#pragma comment(lib, "../Win32/Release/ademco.lib")
#endif
#endif
#ifdef _DEBUG
constexpr int TIMES = 10000;
#else
constexpr int TIMES = 100000;
#endif
uint8_t data[TIMES * 256];
void ademcoPacketBench()
{
printf("\nademcoPacketBench...\n");
printf("generating data...\n");
//std::vector<char> data; data.reserve(TIMES * 100);
//char tmp[256];
size_t total_len = 0;
for (int i = 0; i < TIMES; i++) {
auto len = ademcoMakeHbPacket((data + total_len), sizeof(data) - total_len,
(i + 1) % 10000, std::to_string(i).c_str(), (i + 1) % ADEMCO_ID_SENTINEL, EVENT_ARM, 0, 0, NULL);
assert(len > 0);
total_len += len;
if ((i + 1) % 1000 == 0) {
printf("\r%d/%d", i + 1, TIMES);
//std::this_thread::sleep_for(milliseconds(15));
}
}
printf("\ndone\ntesting parse...\n");
auto start = steady_clock::now();
int cb = 0;
AdemcoPacket pkt;
auto res = ademcoPacketParse(&data[0], total_len, &pkt, &cb);
assert(res == AdemcoParseResult::RESULT_OK);
size_t pos = 0;
int packets = 0;
while (res == AdemcoParseResult::RESULT_OK) {
packets++;
if (packets % 500 == 0) {
printf("\r%d/%d", packets, TIMES);
}
pos += cb;
if (total_len > pos) {
res = ademcoPacketParse(&data[pos], total_len - pos, &pkt, &cb);
} else { break; }
}
assert(res == AdemcoParseResult::RESULT_OK);
assert(packets == TIMES);
auto duration = steady_clock::now() - start;
auto ms = duration_cast<milliseconds>(duration).count();
auto us = duration_cast<microseconds>(duration).count();
double avg = us * 1.0 / TIMES;
printf("\ndone\nduration=%ldms\navg parse time=%.2lfus\n", (long)ms, avg);
double avgpps = 1000.0 * TIMES / ms;
printf("average packets per second=%.2lf\n", avgpps);
double avgbps = total_len * 1000.0 / ms;
printf("average bytes per second=%.2lfB/s, %.2lfKB/s\n", avgbps, avgbps / 1024.0);
system("pause");
}
......@@ -75,6 +75,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TargetName>$(ProjectName)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
......@@ -130,6 +133,10 @@
<ItemGroup>
<ClCompile Include="bench.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bench.h" />
<ClInclude Include="bench_old.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
......
......@@ -19,4 +19,12 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="bench.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="bench_old.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
#pragma once
#define DISABLE_JLIB_LOG2
#include "../../include/ademco_packet.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
using namespace std::chrono;
#ifdef _DEBUG
constexpr int TIMES = 10000;
#else
constexpr int TIMES = 100000;
#endif
char data[TIMES * 256];
using namespace ademco;
void ademcoPacketBench()
{
printf("\nademcoPacketBench...\n");
printf("generating data...\n");
//std::vector<char> data; data.reserve(TIMES * 100);
AdemcoPacket ap;
//char tmp[256];
size_t total_len = 0;
for (int i = 0; i < TIMES; i++) {
auto len = ap.make_hb(data + total_len, sizeof(data) - total_len, (i + 1) % 10000, std::to_string(i), (i + 1) % AdemcoIdSentinel, 0, EVENT_ARM, 0);
assert(len > 0);
total_len += len;
if ((i + 1) % 1000 == 0) {
printf("\r%d/%d %s", i + 1, TIMES, ap.timestamp_.data_);
std::this_thread::sleep_for(milliseconds(15));
}
}
printf("\ndone\ntesting parse...\n");
auto start = steady_clock::now();
size_t cb = 0;
auto res = ap.parse(&data[0], total_len, cb);
assert(res == ParseResult::RESULT_OK);
size_t pos = 0;
int packets = 0;
while (res == ParseResult::RESULT_OK) {
packets++;
if (packets % 500 == 0) {
printf("\r%d/%d %s", packets, TIMES, ap.timestamp_.data_);
}
pos += cb;
if (total_len > pos) {
res = ap.parse(&data[pos], total_len - pos, cb);
} else { break; }
}
assert(res == ParseResult::RESULT_OK);
assert(packets == TIMES);
auto duration = steady_clock::now() - start;
auto ms = duration_cast<milliseconds>(duration).count();
auto us = duration_cast<microseconds>(duration).count();
double avg = us * 1.0 / TIMES;
printf("\ndone\nduration=%ldms\navg parse time=%.2lfus\n", (long)ms, avg);
double avgpps = 1000.0 * TIMES / ms;
printf("average packets per second=%.2lf\n", avgpps);
double avgbps = total_len * 1000.0 / ms;
printf("average bytes per second=%.2lfB/s, %.2lfKB/s\n", avgbps, avgbps / 1024.0);
system("pause");
}
\ No newline at end of file
......@@ -42,6 +42,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server_demo_libevent_linux"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bench_client_ex", "bench_client_ex\bench_client_ex.vcxproj", "{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ademco", "ademco\ademco.vcxproj", "{D0015E82-053E-431E-95D6-41E9AC9C1342}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ademco_demo", "ademco_demo\ademco_demo.vcxproj", "{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -242,6 +246,34 @@ Global
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Release|x64.Build.0 = Release|x64
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Release|x86.ActiveCfg = Release|Win32
{12E806BE-BA3E-452A-AB9D-09F4B379DEB2}.Release|x86.Build.0 = Release|Win32
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Debug|Any CPU.ActiveCfg = Debug|Win32
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Debug|ARM.ActiveCfg = Debug|Win32
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Debug|ARM64.ActiveCfg = Debug|Win32
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Debug|x64.ActiveCfg = Debug|x64
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Debug|x64.Build.0 = Debug|x64
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Debug|x86.ActiveCfg = Debug|Win32
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Debug|x86.Build.0 = Debug|Win32
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Release|Any CPU.ActiveCfg = Release|Win32
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Release|ARM.ActiveCfg = Release|Win32
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Release|ARM64.ActiveCfg = Release|Win32
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Release|x64.ActiveCfg = Release|x64
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Release|x64.Build.0 = Release|x64
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Release|x86.ActiveCfg = Release|Win32
{D0015E82-053E-431E-95D6-41E9AC9C1342}.Release|x86.Build.0 = Release|Win32
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Debug|Any CPU.ActiveCfg = Debug|Win32
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Debug|ARM.ActiveCfg = Debug|Win32
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Debug|ARM64.ActiveCfg = Debug|Win32
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Debug|x64.ActiveCfg = Debug|x64
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Debug|x64.Build.0 = Debug|x64
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Debug|x86.ActiveCfg = Debug|Win32
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Debug|x86.Build.0 = Debug|Win32
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Release|Any CPU.ActiveCfg = Release|Win32
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Release|ARM.ActiveCfg = Release|Win32
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Release|ARM64.ActiveCfg = Release|Win32
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Release|x64.ActiveCfg = Release|x64
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Release|x64.Build.0 = Release|x64
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Release|x86.ActiveCfg = Release|Win32
{A06EEE58-8005-49FD-976F-79BF9AD8FEAC}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
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