lijinwen il y a 2 mois
Parent
commit
8141008f96

+ 218 - 218
ProtocolDecoder.vcxproj

@@ -1,221 +1,221 @@
 <?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>15.0</VCProjectVersion>
-    <ProjectGuid>{452B01D0-9E45-432F-904B-A81BB6C5B9C4}</ProjectGuid>
-    <Keyword>Win32Proj</Keyword>
-    <RootNamespace>ProtocolDecoder</RootNamespace>
-    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup>
-    <PreferredToolArchitecture>x64</PreferredToolArchitecture>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v143</PlatformToolset>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v143</PlatformToolset>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v143</PlatformToolset>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v143</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)'=='Debug|x64'">
-    <LinkIncremental>true</LinkIncremental>
-    <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\lib\x64</LibraryPath>
-  </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>NotUsing</PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <SDLCheck>true</SDLCheck>
-      <PreprocessorDefinitions>WIN32;_DEBUG;CPPDYNAMICLIBRARYTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <ConformanceMode>true</ConformanceMode>
-      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <SDLCheck>true</SDLCheck>
-      <PreprocessorDefinitions>_DEBUG;CPPDYNAMICLIBRARYTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;LIBMATH_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <ConformanceMode>true</ConformanceMode>
-      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
-      <LanguageStandard>stdcpp17</LanguageStandard>
-      <LanguageStandard_C>stdc17</LanguageStandard_C>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <SDLCheck>true</SDLCheck>
-      <PreprocessorDefinitions>WIN32;NDEBUG;CPPDYNAMICLIBRARYTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <ConformanceMode>true</ConformanceMode>
-      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <SDLCheck>true</SDLCheck>
-      <PreprocessorDefinitions>NDEBUG;CPPDYNAMICLIBRARYTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <ConformanceMode>true</ConformanceMode>
-      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClInclude Include="BaseEnums\channels.h" />
-    <ClInclude Include="BaseEnums\data_check_enums.h" />
-    <ClInclude Include="BaseEnums\edge_pulse_enums.h" />
-    <ClInclude Include="BaseEnums\loger_enums.h" />
-    <ClInclude Include="BaseEnums\protocol_enums.h" />
-    <ClInclude Include="BaseEnums\quantized_enums.h" />
-    <ClInclude Include="BaseHelper\common_helper.h" />
-    <ClInclude Include="BaseHelper\constants.h" />
-    <ClInclude Include="BaseHelper\data_check_helper.h" />
-    <ClInclude Include="BaseHelper\decode_data_helper.h" />
-    <ClInclude Include="BaseHelper\Loger.h" />
-    <ClInclude Include="decode_event.h" />
-    <ClInclude Include="decode_result.h" />
-    <ClInclude Include="edge_pulse.h" />
-    <ClInclude Include="edge_pulse_data.h" />
-    <ClInclude Include="export_method.h" />
-    <ClInclude Include="ProtocolRS232\constants.h" />
-    <ClInclude Include="ProtocolRS232\protocol_rs232_enums.h" />
-    <ClInclude Include="ProtocolRS232\protocol_rs232_options.h" />
-    <ClInclude Include="ProtocolRS232\rs232_decode.h" />
-    <ClInclude Include="ProtocolRS232\rs232_decode_event.h" />
-    <ClInclude Include="ProtocolRS232\rs232_decode_result.h" />
-    <ClInclude Include="ProtocolRS232\rs232_packet.h" />
-    <ClInclude Include="ProtocolRS232\rs232_params.h" />
-    <ClInclude Include="ProtocolUSB\constants.h" />
-    <ClInclude Include="ProtocolUSB\protocol_usb_enums.h" />
-    <ClInclude Include="ProtocolUSB\SYNC.h" />
-    <ClInclude Include="ProtocolUSB\usb_decoder.h" />
-    <ClInclude Include="ProtocolUSB\usb_decode_event.h" />
-    <ClInclude Include="ProtocolUSB\usb_decode_options.h" />
-    <ClInclude Include="ProtocolUSB\usb_decode_result.h" />
-    <ClInclude Include="ProtocolUSB\usb_packet.h" />
-    <ClInclude Include="protocol_decode_base.h" />
-    <ClInclude Include="quantize_params.h" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="BaseHelper\common_helper.cpp" />
-    <ClCompile Include="BaseHelper\datacheckhelper.cpp" />
-    <ClCompile Include="BaseHelper\decode_data_helper.cpp" />
-    <ClCompile Include="BaseHelper\loger.cpp" />
-    <ClCompile Include="decode_event.cpp" />
-    <ClCompile Include="decode_result.cpp" />
-    <ClCompile Include="dllmain.cpp" />
-    <ClCompile Include="edge_pulse.cpp" />
-    <ClCompile Include="edge_pulse_data.cpp" />
-    <ClCompile Include="export_method.cpp" />
-    <ClCompile Include="ProtocolRS232\rs232_decode.cpp" />
-    <ClCompile Include="ProtocolRS232\rs232_decodeevent.cpp" />
-    <ClCompile Include="ProtocolRS232\rs232_decoderesult.cpp" />
-    <ClCompile Include="ProtocolRS232\rs232_packet.cpp" />
-    <ClCompile Include="ProtocolUSB\constants.cpp" />
-    <ClCompile Include="ProtocolUSB\usb_decoder.cpp" />
-    <ClCompile Include="ProtocolUSB\usb_decode_event.cpp" />
-    <ClCompile Include="ProtocolUSB\usb_decode_result.cpp" />
-    <ClCompile Include="ProtocolUSB\usb_packet.cpp" />
-    <ClCompile Include="protocol_decode_base.cpp" />
-    <ClCompile Include="quantize_params.cpp" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+    <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>15.0</VCProjectVersion>
+        <ProjectGuid>{452B01D0-9E45-432F-904B-A81BB6C5B9C4}</ProjectGuid>
+        <Keyword>Win32Proj</Keyword>
+        <RootNamespace>ProtocolDecoder</RootNamespace>
+        <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+    </PropertyGroup>
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props"/>
+    <PropertyGroup>
+        <PreferredToolArchitecture>x64</PreferredToolArchitecture>
+    </PropertyGroup>
+    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+        <ConfigurationType>DynamicLibrary</ConfigurationType>
+        <UseDebugLibraries>true</UseDebugLibraries>
+        <PlatformToolset>v143</PlatformToolset>
+        <CharacterSet>Unicode</CharacterSet>
+    </PropertyGroup>
+    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+        <ConfigurationType>DynamicLibrary</ConfigurationType>
+        <UseDebugLibraries>false</UseDebugLibraries>
+        <PlatformToolset>v143</PlatformToolset>
+        <WholeProgramOptimization>true</WholeProgramOptimization>
+        <CharacterSet>Unicode</CharacterSet>
+    </PropertyGroup>
+    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+        <ConfigurationType>DynamicLibrary</ConfigurationType>
+        <UseDebugLibraries>true</UseDebugLibraries>
+        <PlatformToolset>v143</PlatformToolset>
+        <CharacterSet>Unicode</CharacterSet>
+    </PropertyGroup>
+    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+        <ConfigurationType>DynamicLibrary</ConfigurationType>
+        <UseDebugLibraries>false</UseDebugLibraries>
+        <PlatformToolset>v143</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)'=='Debug|x64'">
+        <LinkIncremental>true</LinkIncremental>
+        <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\lib\x64</LibraryPath>
+    </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>NotUsing</PrecompiledHeader>
+            <WarningLevel>Level3</WarningLevel>
+            <Optimization>Disabled</Optimization>
+            <SDLCheck>true</SDLCheck>
+            <PreprocessorDefinitions>WIN32;_DEBUG;CPPDYNAMICLIBRARYTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+            <ConformanceMode>true</ConformanceMode>
+            <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+        </ClCompile>
+        <Link>
+            <SubSystem>Windows</SubSystem>
+            <GenerateDebugInformation>true</GenerateDebugInformation>
+        </Link>
+    </ItemDefinitionGroup>
+    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+        <ClCompile>
+            <PrecompiledHeader>NotUsing</PrecompiledHeader>
+            <WarningLevel>Level3</WarningLevel>
+            <Optimization>Disabled</Optimization>
+            <SDLCheck>true</SDLCheck>
+            <PreprocessorDefinitions>_DEBUG;CPPDYNAMICLIBRARYTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;LIBMATH_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+            <ConformanceMode>true</ConformanceMode>
+            <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+            <LanguageStandard>stdcpp17</LanguageStandard>
+            <LanguageStandard_C>stdc17</LanguageStandard_C>
+        </ClCompile>
+        <Link>
+            <SubSystem>Windows</SubSystem>
+            <GenerateDebugInformation>true</GenerateDebugInformation>
+        </Link>
+    </ItemDefinitionGroup>
+    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+        <ClCompile>
+            <PrecompiledHeader>NotUsing</PrecompiledHeader>
+            <WarningLevel>Level3</WarningLevel>
+            <Optimization>MaxSpeed</Optimization>
+            <FunctionLevelLinking>true</FunctionLevelLinking>
+            <IntrinsicFunctions>true</IntrinsicFunctions>
+            <SDLCheck>true</SDLCheck>
+            <PreprocessorDefinitions>WIN32;NDEBUG;CPPDYNAMICLIBRARYTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+            <ConformanceMode>true</ConformanceMode>
+            <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+        </ClCompile>
+        <Link>
+            <SubSystem>Windows</SubSystem>
+            <EnableCOMDATFolding>true</EnableCOMDATFolding>
+            <OptimizeReferences>true</OptimizeReferences>
+            <GenerateDebugInformation>true</GenerateDebugInformation>
+        </Link>
+    </ItemDefinitionGroup>
+    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+        <ClCompile>
+            <PrecompiledHeader>NotUsing</PrecompiledHeader>
+            <WarningLevel>Level3</WarningLevel>
+            <Optimization>MaxSpeed</Optimization>
+            <FunctionLevelLinking>true</FunctionLevelLinking>
+            <IntrinsicFunctions>true</IntrinsicFunctions>
+            <SDLCheck>true</SDLCheck>
+            <PreprocessorDefinitions>NDEBUG;CPPDYNAMICLIBRARYTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+            <ConformanceMode>true</ConformanceMode>
+            <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+        </ClCompile>
+        <Link>
+            <SubSystem>Windows</SubSystem>
+            <EnableCOMDATFolding>true</EnableCOMDATFolding>
+            <OptimizeReferences>true</OptimizeReferences>
+            <GenerateDebugInformation>true</GenerateDebugInformation>
+        </Link>
+    </ItemDefinitionGroup>
+    <ItemGroup>
+        <ClInclude Include="BaseEnums\channels.h"/>
+        <ClInclude Include="BaseEnums\data_check_enums.h"/>
+        <ClInclude Include="BaseEnums\edge_pulse_enums.h"/>
+        <ClInclude Include="BaseEnums\loger_enums.h"/>
+        <ClInclude Include="BaseEnums\protocol_enums.h"/>
+        <ClInclude Include="BaseEnums\quantized_enums.h"/>
+        <ClInclude Include="BaseHelper\common_helper.h"/>
+        <ClInclude Include="BaseHelper\constants.h"/>
+        <ClInclude Include="BaseHelper\data_check_helper.h"/>
+        <ClInclude Include="BaseHelper\decode_data_helper.h"/>
+        <ClInclude Include="BaseHelper\Loger.h"/>
+        <ClInclude Include="decode_event.h"/>
+        <ClInclude Include="decode_result.h"/>
+        <ClInclude Include="edge_pulse.h"/>
+        <ClInclude Include="edge_pulse_data.h"/>
+        <ClInclude Include="export_method.h"/>
+        <ClInclude Include="ProtocolRS232\constants.h"/>
+        <ClInclude Include="ProtocolRS232\protocol_rs232_enums.h"/>
+        <ClInclude Include="ProtocolRS232\protocol_rs232_options.h"/>
+        <ClInclude Include="ProtocolRS232\rs232_decode.h"/>
+        <ClInclude Include="ProtocolRS232\rs232_decode_event.h"/>
+        <ClInclude Include="ProtocolRS232\rs232_decode_result.h"/>
+        <ClInclude Include="ProtocolRS232\rs232_packet.h"/>
+        <ClInclude Include="ProtocolRS232\rs232_params.h"/>
+        <ClInclude Include="ProtocolUSB\constants.h"/>
+        <ClInclude Include="ProtocolUSB\protocol_usb_enums.h"/>
+        <ClInclude Include="ProtocolUSB\SYNC.h"/>
+        <ClInclude Include="ProtocolUSB\usb_decoder.h"/>
+        <ClInclude Include="ProtocolUSB\usb_decode_event.h"/>
+        <ClInclude Include="ProtocolUSB\usb_decode_options.h"/>
+        <ClInclude Include="ProtocolUSB\usb_decode_result.h"/>
+        <ClInclude Include="ProtocolUSB\usb_packet.h"/>
+        <ClInclude Include="protocol_decode_base.h"/>
+        <ClInclude Include="quantize_params.h"/>
+    </ItemGroup>
+    <ItemGroup>
+        <ClCompile Include="BaseHelper\common_helper.cpp"/>
+        <ClCompile Include="BaseHelper\datacheckhelper.cpp"/>
+        <ClCompile Include="BaseHelper\decode_data_helper.cpp"/>
+        <ClCompile Include="BaseHelper\loger.cpp"/>
+        <ClCompile Include="decode_event.cpp"/>
+        <ClCompile Include="decode_result.cpp"/>
+        <ClCompile Include="dllmain.cpp"/>
+        <ClCompile Include="edge_pulse.cpp"/>
+        <ClCompile Include="edge_pulse_data.cpp"/>
+        <ClCompile Include="export_method.cpp"/>
+        <ClCompile Include="ProtocolRS232\rs232_decode.cpp"/>
+        <ClCompile Include="ProtocolRS232\rs232_decodeevent.cpp"/>
+        <ClCompile Include="ProtocolRS232\rs232_decoderesult.cpp"/>
+        <ClCompile Include="ProtocolRS232\rs232_packet.cpp"/>
+        <ClCompile Include="ProtocolUSB\constants.cpp"/>
+        <ClCompile Include="ProtocolUSB\usb_decoder.cpp"/>
+        <ClCompile Include="ProtocolUSB\usb_decode_event.cpp"/>
+        <ClCompile Include="ProtocolUSB\usb_decode_result.cpp"/>
+        <ClCompile Include="ProtocolUSB\usb_packet.cpp"/>
+        <ClCompile Include="protocol_decode_base.cpp"/>
+        <ClCompile Include="quantize_params.cpp"/>
+    </ItemGroup>
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/>
+    <ImportGroup Label="ExtensionTargets">
+    </ImportGroup>
 </Project>

+ 63 - 63
ProtocolUSB/usb_decode_result.h

@@ -18,74 +18,74 @@
 
 namespace Protocol
 {
-	class UsbDecodeResultCell : DecodeResultCell
-	{
+    class UsbDecodeResultCell : DecodeResultCell
+    {
 
 
-	};
+    };
 
-	struct UsbDecodeResult //: DecodeResult
-	{
-		bool decodeResultNeedUpdate = false;
-		bool decodeEventNeedUpdate = false;
-		UsbDecodeResultCell* decodeResultCellsPtr; //解码数据结果指针
-		UsbDecodeEvent* decodeEventsPtr; //解码结果事件指针
-		uint64_t decodeResultCount; //结果数量
-		uint64_t decodeEventCount; //事件数量
-		USBEnums::USBSpeed usbSpeed; //真实速率
-		//std::vector<UsbDecodeResultCell> DecodeResultCells;
-		//std::vector<UsbDecodeEvent> DecodeEventCells;  
-		UsbDecodeResult() : decodeResultCellsPtr(nullptr), decodeEventsPtr(nullptr), decodeResultCount(0), decodeEventCount(0),
-			usbSpeed(USBEnums::USBSpeed::FULL_SPEED)
-		{
-			//ProtocolType = SerialProtocolType::USB;
-			//DecodeResultCells = {};
-		}
-		UsbDecodeResult(const UsbDecodeResult& result) : usbSpeed(USBEnums::USBSpeed::FULL_SPEED)
-		{
-			decodeResultNeedUpdate = result.decodeResultNeedUpdate;
-			decodeEventNeedUpdate = result.decodeEventNeedUpdate;
-			decodeResultCellsPtr = result.decodeResultCellsPtr;
-			decodeEventsPtr = result.decodeEventsPtr;
+    struct UsbDecodeResult //: DecodeResult
+    {
+        bool decodeResultNeedUpdate = false;
+        bool decodeEventNeedUpdate = false;
+        UsbDecodeResultCell* decodeResultCellsPtr; //解码数据结果指针
+        UsbDecodeEvent* decodeEventsPtr; //解码结果事件指针
+        uint64_t decodeResultCount; //结果数量
+        uint64_t decodeEventCount; //事件数量
+        USBEnums::USBSpeed usbSpeed; //真实速率
+        //std::vector<UsbDecodeResultCell> DecodeResultCells;
+        //std::vector<UsbDecodeEvent> DecodeEventCells;  
+        UsbDecodeResult() : decodeResultCellsPtr(nullptr), decodeEventsPtr(nullptr), decodeResultCount(0), decodeEventCount(0),
+                            usbSpeed(USBEnums::USBSpeed::FULL_SPEED)
+        {
+            //ProtocolType = SerialProtocolType::USB;
+            //DecodeResultCells = {};
+        }
+        UsbDecodeResult(const UsbDecodeResult& result) : usbSpeed(USBEnums::USBSpeed::FULL_SPEED)
+        {
+            decodeResultNeedUpdate = result.decodeResultNeedUpdate;
+            decodeEventNeedUpdate = result.decodeEventNeedUpdate;
+            decodeResultCellsPtr = result.decodeResultCellsPtr;
+            decodeEventsPtr = result.decodeEventsPtr;
 
-			decodeResultCount = result.decodeResultCount;
-			decodeEventCount = result.decodeEventCount;
-		}
-		~UsbDecodeResult() = default;
+            decodeResultCount = result.decodeResultCount;
+            decodeEventCount = result.decodeEventCount;
+        }
+        ~UsbDecodeResult() = default;
 
-		UsbDecodeResult(UsbDecodeResult&& other) noexcept
-			: decodeResultNeedUpdate(other.decodeResultNeedUpdate),
-			decodeEventNeedUpdate(other.decodeEventNeedUpdate),
-			decodeResultCellsPtr(other.decodeResultCellsPtr),
-			decodeEventsPtr(other.decodeEventsPtr),
-			decodeResultCount(other.decodeResultCount),
-			decodeEventCount(other.decodeEventCount), usbSpeed(USBEnums::USBSpeed::FULL_SPEED)
+        UsbDecodeResult(UsbDecodeResult&& other) noexcept
+            : decodeResultNeedUpdate(other.decodeResultNeedUpdate),
+              decodeEventNeedUpdate(other.decodeEventNeedUpdate),
+              decodeResultCellsPtr(other.decodeResultCellsPtr),
+              decodeEventsPtr(other.decodeEventsPtr),
+              decodeResultCount(other.decodeResultCount),
+              decodeEventCount(other.decodeEventCount), usbSpeed(USBEnums::USBSpeed::FULL_SPEED)
 
-		{
-		}
-		UsbDecodeResult& operator=(const UsbDecodeResult& other)
-		{
-			if (this == &other) return *this;
-			decodeResultNeedUpdate = other.decodeResultNeedUpdate;
-			decodeEventNeedUpdate = other.decodeEventNeedUpdate;
-			decodeResultCellsPtr = other.decodeResultCellsPtr;
-			decodeEventsPtr = other.decodeEventsPtr;
-			decodeResultCount = other.decodeResultCount;
-			decodeEventCount = other.decodeEventCount;
-			return *this;
-		}
-		UsbDecodeResult& operator=(UsbDecodeResult&& other) noexcept
-		{
-			if (this == &other) return *this;
-			decodeResultNeedUpdate = other.decodeResultNeedUpdate;
-			decodeEventNeedUpdate = other.decodeEventNeedUpdate;
-			decodeResultCellsPtr = other.decodeResultCellsPtr;
-			decodeEventsPtr = other.decodeEventsPtr;
-			decodeResultCount = other.decodeResultCount;
-			decodeEventCount = other.decodeEventCount;
-			return *this;
-		}
-		//void Add(const UsbDecodeResultCell* cell);
-	};
+        {
+        }
+        UsbDecodeResult& operator=(const UsbDecodeResult& other)
+        {
+            if (this == &other) return *this;
+            decodeResultNeedUpdate = other.decodeResultNeedUpdate;
+            decodeEventNeedUpdate = other.decodeEventNeedUpdate;
+            decodeResultCellsPtr = other.decodeResultCellsPtr;
+            decodeEventsPtr = other.decodeEventsPtr;
+            decodeResultCount = other.decodeResultCount;
+            decodeEventCount = other.decodeEventCount;
+            return *this;
+        }
+        UsbDecodeResult& operator=(UsbDecodeResult&& other) noexcept
+        {
+            if (this == &other) return *this;
+            decodeResultNeedUpdate = other.decodeResultNeedUpdate;
+            decodeEventNeedUpdate = other.decodeEventNeedUpdate;
+            decodeResultCellsPtr = other.decodeResultCellsPtr;
+            decodeEventsPtr = other.decodeEventsPtr;
+            decodeResultCount = other.decodeResultCount;
+            decodeEventCount = other.decodeEventCount;
+            return *this;
+        }
+        //void Add(const UsbDecodeResultCell* cell);
+    };
 
 }

+ 485 - 487
ProtocolUSB/usb_decoder.cpp

@@ -19,491 +19,489 @@
 
 namespace Protocol
 {
-	std::vector<std::string> USBDecoder::EventInfoTitles()
-	{
-		return { "Index", "Start Time", "Sync", "PID", "Data", "Addr", "FNUM", "CRC5", "CRC16", "EOP", "Error" };
-	}
-
-	//主解码函数入口
-	bool USBDecoder::DecodeUSB(const UsbDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_dp,
-		const EdgePulseDataTwoLevels& edge_pulses_dm, UsbDecodeResult& result)
-	{
-		std::vector<TwoLevelEdgePulse> edge_pulses1 = {};
-
-		if (&edge_pulses_dp != nullptr && edge_pulses_dp.waveformDataCount > 0)
-		{
-			edge_pulses1 =
-				CommonHelper::ConvertPointerArrayToVector<TwoLevelEdgePulse>(
-					edge_pulses_dp.GetDataAddrPtr(), edge_pulses_dp.edgePulsesCount);
-		}
-		std::vector<TwoLevelEdgePulse> edge_pulses2 = {};
-		if (&edge_pulses_dm != nullptr && edge_pulses_dm.waveformDataCount > 0)
-		{
-			edge_pulses2 = CommonHelper::ConvertPointerArrayToVector<TwoLevelEdgePulse>(
-				edge_pulses_dm.GetDataAddrPtr(), edge_pulses_dm.edgePulsesCount);
-		}
-
-
-		differenceEopIndexs_ = {};
-		double set_bit_time_span = 0;
-		//////参数判断
-		if (!CheckOptions(option, edge_pulses1, edge_pulses2, set_bit_time_span))
-		{
-			return false;
-		}
-		resultCells_ = {};
-		resultEvents_ = {};
-		usbDiffUnalignedFramesIndex_ = {};
-
-		//////处理差分逻辑
-		if (option.signType == SignType::Diff)
-		{
-			if (!ParseDiffSignalData(edge_pulses1, edge_pulses2))
-			{
-				return false;
-			}
-		}
-		else
-		{
-			if (edge_pulses1.size() < edge_pulses2.size())
-			{
-				signEdgePulse_ = std::move(edge_pulses2);
-			}
-			else
-			{
-				signEdgePulse_ = std::move(edge_pulses1);
-			}
-		}
-		waveMaxTimeIndexLen_ = signEdgePulse_[signEdgePulse_.size() - 1].endIndex;
-		//////处理单端逻辑
-		if (option.autoClock) set_bit_time_span = -1;
-		if (ParseSingleData(set_bit_time_span, option.autoClock))
-		{
-			result = {};
-			result.decodeEventsPtr = resultEvents_.data();
-			result.decodeResultCellsPtr = resultCells_.data();
-			result.decodeEventCount = resultEvents_.size();
-			result.decodeResultCount = resultCells_.size();
-			result.decodeResultNeedUpdate = !resultCells_.empty();
-			result.decodeEventNeedUpdate = !resultEvents_.empty();
-			result.usbSpeed = usbSpeed_;
-			// WriteLog(LogLevel::LevelDebug, "Offset 1: %d" , offsetof(UsbDecodeEvent, PacketTitle));
-			// WriteLog(LogLevel::LevelDebug, "Offset 2: %d" , offsetof(UsbDecodeEvent, FrameId));
-			// WriteLog(LogLevel::LevelDebug, "Offset 2.5: %d" , offsetof(UsbDecodeEvent, EndPoint));
-			// WriteLog(LogLevel::LevelDebug, "Offset 3: %d" , offsetof(UsbDecodeEvent, CrcSignNum));
-			// WriteLog(LogLevel::LevelDebug, "Offset 3.5: %d" , offsetof(UsbDecodeEvent, CrcData));
-			// WriteLog(LogLevel::LevelDebug, "Offset 4: %d" , offsetof(UsbDecodeEvent, DataCount));
-			// WriteLog(LogLevel::LevelDebug, "Offset 5: %d" , offsetof(UsbDecodeEvent, DecodeDatasPtr));
-			return true;
-		}
-		return false;
-	}
-
-	bool USBDecoder::ParseSingleData(double set_bit_time_span, bool auto_clock)
-	{
-		if (signEdgePulse_.empty()) return false;
-		WriteLog(LogLevel::Level2, "ParseSingleData start");
-
-		// 检查是否取消
-		if (canceled)
-		{
-			WriteLog(LogLevel::Level2, "AsyncFunction canceled");
-			return false;
-		}
-		int32_t left_data_size = static_cast<int32_t>(signEdgePulse_.size());
-		//找数据包
-		if (FindPackets(left_data_size, usb_packets_, set_bit_time_span))
-		{
-			if (usb_packets_.empty())
-			{
-				if (auto_clock)
-				{
-					syncBitLen_ = USB_USB_SYNC_BIT_NORMAL_SPEED_LEN;
-					usbSpeed_ = USBEnums::USBSpeed::FULL_SPEED;
-					left_data_size = static_cast<int32_t>(signEdgePulse_.size());
-					set_bit_time_span = -1;
-					FindPackets(left_data_size, usb_packets_, set_bit_time_span);
-				}
-				if (usb_packets_.empty())
-				{
-					WriteLog(LogLevel::Level2, "ParseSingleData false - usb_packets is empty");
-					return false;
-				}
-			}
-
-			for (auto&& element : usb_packets_)
-			{
-				//resultData.Add(new UsbDecodeResultCell(element));
-				resultEvents_.emplace_back(element);
-				resultEvents_[resultEvents_.size() - 1].eventIndex = static_cast<int64_t>(resultEvents_.size());
-			}
-		}
-		WriteLog(LogLevel::Level2, "ParseSingleData done");
-		return true;
-	}
-	bool USBDecoder::CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, double threshold)
-	{
-		for (int i = 2; i < size; i++)
-		{
-			double difference = std::abs(array[i] - array[i - 1]);
-			double percentage_difference = difference / array[i - 1];
-			if (difference < 50)
-			{
-				if (isAutoClk_ || usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED)
-				{
-					threshold = USB_TIME_DIFFERENCE_THRESHOLD_HIGH_SPEED;
-				}
-				else
-				{
-					threshold = USB_TIME_DIFFERENCE_THRESHOLD;
-				}
-
-			}
-		
-			if (percentage_difference > threshold )
-			{
-				return false; // 如果差异大于阈值,则返回 false
-			}
-		}
-
-		return true; // 所有元素之间的差异都小于阈值
-	}
-	bool USBDecoder::CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, int32_t avg_span, double threshold)
-
-	{
-		for (int i = 2; i < size; i++)
-		{
-			//double absolute_difference = array[i] / avg_span;
-
-			double difference1 = std::abs(array[i] - avg_span);
-			double percentage_difference1 = difference1 / avg_span;
-
-			double difference2 = std::abs(array[i] - array[i - 1]);
-			double percentage_difference2 = difference2 / array[i - 1];
-			if (difference2 < 50)
-			{
-				if (isAutoClk_ || usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED)
-				{
-					threshold = USB_TIME_DIFFERENCE_THRESHOLD_HIGH_SPEED;
-				}
-				else
-				{
-					threshold = USB_TIME_DIFFERENCE_THRESHOLD;
-				}
-
-			}
-		 
-			if (percentage_difference1 > threshold && percentage_difference2 > threshold)
-			{
-				return false; // 如果差异大于阈值,则返回 false
-			}
-		}
-
-		return true; // 所有元素之间的差异都小于阈值
-	}
-
-	void USBDecoder::ClearEdgeArray(Edge* edges, int32_t size)
-	{
-		for (int i = 0; i < size; ++i)
-		{
-			edges[i] = Edge::None;
-		}
-	}
-
-	//检查同步域边沿
-	bool USBDecoder::CheckSyncEdges(Edge start_edge, const Edge* edges)
-	{
-		return edges[0] != edges[1] && edges[0] == start_edge && edges[0] == edges[6];
-	}
-
-	//检查同步域在时域间隔
-	bool USBDecoder::CheckSyncSpans(const TwoLevelEdgePulse* node, const int32_t count, int32_t& avg_spans)
-	{
-		if (count < 1)
-		{
-			return false;
-		}
-		auto start_indexs = new int32_t[count + 1];
-		avg_spans = 0;
-		if ((node - 1) != nullptr)
-		{
-			node--;
-		}
-
-		for (int i = count - 1; i >= 0; i--)
-		{
-			node--;
-			if (node == nullptr)
-			{
-				return false;
-			}
-			start_indexs[i] = node->startIndex;
-		}
-		return CheckSyncSpansByArray(start_indexs, count, avg_spans);
-	}
-
-
-	bool USBDecoder::CheckSyncSpansByArray(const int32_t* start_indexs, const int32_t count,
-		int32_t& avg_span)
-	{
-		if (count < 1)
-		{
-			return false;
-		}
-
-		auto tmp_spans = new double[count - 1];
-		for (int i = 1; i < count; i++)
-		{
-			tmp_spans[i - 1] = static_cast<double>(start_indexs[i] - start_indexs[i - 1]);
-		}
-
-		double total_spans = 0;
-		for (int i = 0; i < count - 1; i++)
-		{
-			total_spans += std::abs(tmp_spans[2 + (i / 2)]);
-		}
-		avg_span = static_cast<int>(total_spans / (count - 1));
-		//return CheckTimeDifferenceWithinThreshold(tmp_spans, count - 1, avg_span);
-		return CheckTimeDifferenceWithinThreshold(tmp_spans, count - 1);
-	}
-
-	// bool USBDecoder::FindAllSyncs(TwoLevelEdgePulse* node, std::vector<SYNC>& all_sync
-	//                               , double set_bit_time_span,bool force_normal_speed, bool polarity)
-	bool USBDecoder::FindAllSyncs(TwoLevelEdgePulse* node, std::vector<SYNC>& all_sync
-		, double set_bit_time_span, bool polarity)
-	{
-		all_sync.clear();
-		int first_avg_span = 0;
-
-		if (node == nullptr || node - 1 == nullptr)
-		{
-			return false;
-		}
-		// if (force_normal_speed)
-		// {
-		//     syncBitLen_ = USB_USB_SYNC_BIT_NORMAL_SPEED_LEN;
-		// }
-		Edge next_edge = polarity ? Edge::Rise : Edge::Falling;
-		Edge start_edge = next_edge;
-
-		TwoLevelEdgePulse* start_info_node = nullptr;
-		Edge tmp_edges[USB_USB_SYNC_BIT_MAX_LEN];
-		TwoLevelEdgePulse* tmp_edges_ptr[USB_USB_SYNC_BIT_MAX_LEN];
-		int32_t tmp_edges_len[USB_USB_SYNC_BIT_MAX_LEN];
-		ClearEdgeArray(tmp_edges, syncBitLen_);
-
-		int tmp_edge_count = 0;
-		TwoLevelEdgePulse* tmp_node = node;
-
-		while (tmp_node != nullptr)
-		{
-			if (canceled)
-			{
-				WriteLog(LogLevel::Level2, "AsyncFunction canceled");
-				return false;
-			}
-			if (tmp_node->startIndex < 0 || tmp_node->endIndex < 0
-				|| tmp_node->startIndex > tmp_node->endIndex || tmp_node->LevelCount() <= 0)
-			{
-				WriteLog(LogLevel::Level2, "FindAllSyncs break,SYNC count:%d", all_sync.size());
-				break;
-			}
-			//可能找到目标头
-			if (first_avg_span != 0 && tmp_node->GetLength() > first_avg_span * 8)
-			{
-				tmp_edge_count = 0;
-			}
-
-			if (tmp_edge_count <= syncBitLen_ - 1)
-			{
-				if (tmp_edge_count == 0)
-				{
-					start_info_node = tmp_node;
-				}
-
-				tmp_edges[tmp_edge_count] = tmp_node->edge;
-				tmp_edges_ptr[tmp_edge_count] = tmp_node;
-				tmp_edges_len[tmp_edge_count] = tmp_node->GetLength();
-				tmp_edge_count++;
-			}
-			else
-			{
-				if (CheckSyncEdges(start_edge, tmp_edges))
-				{
-					int avg_spans;
-					if (CheckSyncSpans(tmp_node, syncBitLen_ - 1, avg_spans))
-					{
-						if (all_sync.empty())
-						{
-							int32_t set_bit_span = static_cast<int>(set_bit_time_span);
-
-							first_avg_span = set_bit_span >= 0 ? set_bit_span : avg_spans;
-							all_sync.emplace_back(start_info_node, (tmp_node - 2)->startIndex + first_avg_span,
-								first_avg_span, usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED);
-						}
-						else if (start_info_node != nullptr && (start_info_node - 1) != nullptr && (start_info_node - 1)->
-							GetLength() > first_avg_span * syncBitLen_)
-						{
-							int32_t set_bit_span = static_cast<int>(set_bit_time_span);
-							avg_spans = set_bit_span >= 0 ? set_bit_span : avg_spans;
-							all_sync.emplace_back(start_info_node, (tmp_node - 2)->startIndex + avg_spans,
-								avg_spans, usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED);
-						}
-
-						ClearEdgeArray(tmp_edges, syncBitLen_);
-						tmp_edge_count = 0;
-						tmp_node++;
-						//left_over_size--;
-						continue;
-					}
-				}
-
-				for (int i = 0; i < syncBitLen_ - 1; i++)
-				{
-					tmp_edges[i] = tmp_edges[i + 1];
-					tmp_edges_ptr[i] = tmp_edges_ptr[i + 1];
-					tmp_edges_len[i] = tmp_edges_len[i + 1];
-				}
-
-				tmp_edges[syncBitLen_ - 1] = tmp_node->edge;
-				tmp_edges_ptr[syncBitLen_ - 1] = tmp_node;
-				tmp_edges_len[syncBitLen_ - 1] = tmp_node->GetLength();
-				start_info_node++;
-			}
-
-			tmp_node++;
-			//left_over_size--;
-		}
-
-		return !all_sync.empty();
-	}
-
-	bool USBDecoder::FindPackets(int32_t& left_over_size,
-		std::vector<USBPacket>& all_packet, double set_bit_time_span,
-		bool polarity)
-	{
-		TwoLevelEdgePulse* node = signEdgePulse_.data();
-		all_packet.clear();
-		std::vector<SYNC> all_sync;
-
-		//找的全部同步帧
-		if (!FindAllSyncs(node, all_sync, set_bit_time_span, polarity) || all_sync.empty())
-		{
-			return false;
-		}
-
-		for (const auto& sync : all_sync)
-		{
-			if (sync.nodePtr == nullptr)
-			{
-				continue;
-			}
-			if (canceled)
-			{
-				WriteLog(LogLevel::Level2, "AsyncFunction canceled");
-				return false;
-			}
-			TwoLevelEdgePulse* tmp_node = sync.nodePtr;
-
-			int32_t eop_index = -1;
-			//有差分Eop情况
-			if (!differenceEopIndexs_.empty() && differenceEopIndexs_.size() > all_packet.size())
-			{
-				eop_index = differenceEopIndexs_[all_packet.size()];
-			}
-			if (eop_index <= 0)
-			{
-				//如果存在后续同步帧,用下个同步帧头-1的起始做可能结束 
-				if (static_cast<int32_t>(all_sync.size()) > static_cast<int32_t>(all_packet.size() + 2))
-				{
-					eop_index = (all_sync[all_packet.size() + 2].nodePtr - 1)->startIndex;
-				}
-				else
-				{
-					eop_index = waveMaxTimeIndexLen_;
-				}
-			}
-			int32_t packetMaxTimeLen = eop_index - sync.nodePtr->startIndex;
-			if (packetMaxTimeLen <= 0)
-			{
-				WriteLog(LogLevel::Level2, "FindPackets Warning: packetMaxTimeLen <= 0");
-			}
-			USBPacket packet(tmp_node, left_over_size, sync, polarity, packetMaxTimeLen);
-			if (packet.IsValid())
-			{
-				all_packet.push_back(packet);
-			}
-		}
-
-		return true;
-	}
-	bool USBDecoder::CheckOptions(UsbDecodeOptions option, const std::vector<TwoLevelEdgePulse>& edge_pulses_dp,
-		const std::vector<TwoLevelEdgePulse>& edge_pulses_dm, double& set_bit_time_span)
-	{
-		double usb_speed;
-		usbSpeed_ = option.usbSpeed;
-		switch (option.usbSpeed)
-		{
-		case USBEnums::USBSpeed::LOW_SPEED:
-			usb_speed = USB_LOW_SPEED_MHZ;
-			syncBitLen_ = USB_USB_SYNC_BIT_NORMAL_SPEED_LEN;
-			break;
-		case USBEnums::USBSpeed::FULL_SPEED:
-			usb_speed = USB_FULL_SPEED_MHZ;
-			syncBitLen_ = USB_USB_SYNC_BIT_NORMAL_SPEED_LEN;
-			break;
-		case USBEnums::USBSpeed::HIGH_SPEED:
-			usb_speed = USB_HIGH_SPEED_MHZ;
-			syncBitLen_ = USB_USB_SYNC_BIT_HIGH_SPEED_LEN;
-			break;
-		default:
-			WriteLog(LogLevel::Level2, "CheckOptions Failed, usbSpeed error");
-			return false;
-		}
-		isAutoClk_ = option.autoClock;
-		if (!isAutoClk_ && option.samplingFrequency < usb_speed * 2)
-		{
-			WriteLog(LogLevel::Level2, "CheckOptions Failed, samplingFrequency error");
-			return false;
-		}
-
-		if (!isAutoClk_)
-		{
-			syncBitLen_ = USB_USB_SYNC_BIT_MAX_LEN;
-		}
-		if (option.signType == SignType::SingleEnded)
-		{
-			WriteLog(LogLevel::Level2, "CheckOptions SignType:%d", static_cast<int>(option.signType));
-			if (edge_pulses_dp.size() < USB_MINIMUM_SEQUENCE_LENGTH && edge_pulses_dm.size() < USB_MINIMUM_SEQUENCE_LENGTH)
-			{
-				WriteLog(LogLevel::Level2, "CheckOptions Failed, edgePulses.size too short");
-				return false;
-			}
-		}
-		else
-		{
-			auto edge_pulses_size1 = static_cast<double>(edge_pulses_dp.size());
-			auto edge_pulses_size2 = static_cast<double>(edge_pulses_dm.size());
-			//// 差分长度判断
-			if (!DataCheckHelper::CheckDoubleIsEqual(edge_pulses_size1, edge_pulses_size2)
-				&& ((USB_DIFF_LEN_DIFFERENCE_THRESHOLD * edge_pulses_size1) > edge_pulses_size2
-					|| (USB_DIFF_LEN_DIFFERENCE_THRESHOLD * edge_pulses_size2) > edge_pulses_size1))
-			{
-				WriteLog(LogLevel::Level2, "CheckOptions Failed,diff edgePulses size is not equal");
-				return false;
-			}
-
-			if (edge_pulses_dp.size() < USB_MINIMUM_SEQUENCE_LENGTH)
-			{
-				WriteLog(LogLevel::Level2, "CheckOptions Failed, edgePulses size too short");
-				return false;
-			}
-
-			usbDiffSignalRealEdgesCount_ = static_cast<int32_t>(edge_pulses_dp.size() > edge_pulses_dm.size()
-				? edge_pulses_dm.size()
-				: edge_pulses_dp.size());
-		}
-		set_bit_time_span = option.samplingFrequency / (usb_speed * 1000000);
-		return true;
-	}
+    std::vector<std::string> USBDecoder::EventInfoTitles()
+    {
+        return {"Index", "Start Time", "Sync", "PID", "Data", "Addr", "FNUM", "CRC5", "CRC16", "EOP", "Error"};
+    }
+
+    //主解码函数入口
+    bool USBDecoder::DecodeUSB(const UsbDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_dp,
+                               const EdgePulseDataTwoLevels& edge_pulses_dm, UsbDecodeResult& result)
+    {
+        std::vector<TwoLevelEdgePulse> edge_pulses1 = {};
+
+        if (&edge_pulses_dp != nullptr && edge_pulses_dp.waveformDataCount > 0)
+        {
+            edge_pulses1 =
+                CommonHelper::ConvertPointerArrayToVector<TwoLevelEdgePulse>(
+                    edge_pulses_dp.GetDataAddrPtr(), edge_pulses_dp.edgePulsesCount);
+        }
+        std::vector<TwoLevelEdgePulse> edge_pulses2 = {};
+        if (&edge_pulses_dm != nullptr && edge_pulses_dm.waveformDataCount > 0)
+        {
+            edge_pulses2 = CommonHelper::ConvertPointerArrayToVector<TwoLevelEdgePulse>(
+                edge_pulses_dm.GetDataAddrPtr(), edge_pulses_dm.edgePulsesCount);
+        }
+
+
+        differenceEopIndexs_ = {};
+        double set_bit_time_span = 0;
+        //////参数判断
+        if (!CheckOptions(option, edge_pulses1, edge_pulses2, set_bit_time_span))
+        {
+            return false;
+        }
+        resultCells_ = {};
+        resultEvents_ = {};
+        usbDiffUnalignedFramesIndex_ = {};
+
+        //////处理差分逻辑
+        if (option.signType == SignType::Diff)
+        {
+            if (!ParseDiffSignalData(edge_pulses1, edge_pulses2))
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if (edge_pulses1.size() < edge_pulses2.size())
+            {
+                signEdgePulse_ = std::move(edge_pulses2);
+            }
+            else
+            {
+                signEdgePulse_ = std::move(edge_pulses1);
+            }
+        }
+        waveMaxTimeIndexLen_ = signEdgePulse_[signEdgePulse_.size() - 1].endIndex;
+        //////处理单端逻辑
+        if (option.autoClock) set_bit_time_span = -1;
+        if (ParseSingleData(set_bit_time_span, option.autoClock))
+        {
+            result = {};
+            result.decodeEventsPtr = resultEvents_.data();
+            result.decodeResultCellsPtr = resultCells_.data();
+            result.decodeEventCount = resultEvents_.size();
+            result.decodeResultCount = resultCells_.size();
+            result.decodeResultNeedUpdate = !resultCells_.empty();
+            result.decodeEventNeedUpdate = !resultEvents_.empty();
+            result.usbSpeed = usbSpeed_;
+            // WriteLog(LogLevel::LevelDebug, "Offset 1: %d" , offsetof(UsbDecodeEvent, PacketTitle));
+            // WriteLog(LogLevel::LevelDebug, "Offset 2: %d" , offsetof(UsbDecodeEvent, FrameId));
+            // WriteLog(LogLevel::LevelDebug, "Offset 2.5: %d" , offsetof(UsbDecodeEvent, EndPoint));
+            // WriteLog(LogLevel::LevelDebug, "Offset 3: %d" , offsetof(UsbDecodeEvent, CrcSignNum));
+            // WriteLog(LogLevel::LevelDebug, "Offset 3.5: %d" , offsetof(UsbDecodeEvent, CrcData));
+            // WriteLog(LogLevel::LevelDebug, "Offset 4: %d" , offsetof(UsbDecodeEvent, DataCount));
+            // WriteLog(LogLevel::LevelDebug, "Offset 5: %d" , offsetof(UsbDecodeEvent, DecodeDatasPtr));
+            return true;
+        }
+        return false;
+    }
+
+    bool USBDecoder::ParseSingleData(double set_bit_time_span, bool auto_clock)
+    {
+        if (signEdgePulse_.empty()) return false;
+        WriteLog(LogLevel::Level2, "ParseSingleData start");
+
+        // 检查是否取消
+        if (canceled)
+        {
+            WriteLog(LogLevel::Level2, "AsyncFunction canceled");
+            return false;
+        }
+        int32_t left_data_size = static_cast<int32_t>(signEdgePulse_.size());
+        //找数据包
+        if (FindPackets(left_data_size, usb_packets_, set_bit_time_span))
+        {
+            if (usb_packets_.empty())
+            {
+                if (auto_clock)
+                {
+                    syncBitLen_ = USB_USB_SYNC_BIT_NORMAL_SPEED_LEN;
+                    usbSpeed_ = USBEnums::USBSpeed::FULL_SPEED;
+                    left_data_size = static_cast<int32_t>(signEdgePulse_.size());
+                    set_bit_time_span = -1;
+                    FindPackets(left_data_size, usb_packets_, set_bit_time_span);
+                }
+                if (usb_packets_.empty())
+                {
+                    WriteLog(LogLevel::Level2, "ParseSingleData false - usb_packets is empty");
+                    return false;
+                }
+            }
+
+            for (auto&& element : usb_packets_)
+            {
+                //resultData.Add(new UsbDecodeResultCell(element));
+                resultEvents_.emplace_back(element);
+                resultEvents_[resultEvents_.size() - 1].eventIndex = static_cast<int64_t>(resultEvents_.size());
+            }
+        }
+        WriteLog(LogLevel::Level2, "ParseSingleData done");
+        return true;
+    }
+    bool USBDecoder::CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, double threshold)
+    {
+        for (int i = 2; i < size; i++)
+        {
+            double difference = std::abs(array[i] - array[i - 1]);
+            double percentage_difference = difference / array[i - 1];
+            if (difference < 50)
+            {
+                if (isAutoClk_ || usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED)
+                {
+                    threshold = USB_TIME_DIFFERENCE_THRESHOLD_HIGH_SPEED;
+                }
+                else
+                {
+                    threshold = USB_TIME_DIFFERENCE_THRESHOLD;
+                }
+            }
+
+            if (percentage_difference > threshold)
+            {
+                return false; // 如果差异大于阈值,则返回 false
+            }
+        }
+
+        return true; // 所有元素之间的差异都小于阈值
+    }
+    bool USBDecoder::CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, int32_t avg_span, double threshold)
+
+    {
+        for (int i = 2; i < size; i++)
+        {
+            //double absolute_difference = array[i] / avg_span;
+
+            double difference1 = std::abs(array[i] - avg_span);
+            double percentage_difference1 = difference1 / avg_span;
+
+            double difference2 = std::abs(array[i] - array[i - 1]);
+            double percentage_difference2 = difference2 / array[i - 1];
+            if (difference2 < 50)
+            {
+                if (isAutoClk_ || usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED)
+                {
+                    threshold = USB_TIME_DIFFERENCE_THRESHOLD_HIGH_SPEED;
+                }
+                else
+                {
+                    threshold = USB_TIME_DIFFERENCE_THRESHOLD;
+                }
+            }
+
+            if (percentage_difference1 > threshold && percentage_difference2 > threshold)
+            {
+                return false; // 如果差异大于阈值,则返回 false
+            }
+        }
+
+        return true; // 所有元素之间的差异都小于阈值
+    }
+
+    void USBDecoder::ClearEdgeArray(Edge* edges, int32_t size)
+    {
+        for (int i = 0; i < size; ++i)
+        {
+            edges[i] = Edge::None;
+        }
+    }
+
+    //检查同步域边沿
+    bool USBDecoder::CheckSyncEdges(Edge start_edge, const Edge* edges)
+    {
+        return edges[0] != edges[1] && edges[0] == start_edge && edges[0] == edges[6];
+    }
+
+    //检查同步域在时域间隔
+    bool USBDecoder::CheckSyncSpans(const TwoLevelEdgePulse* node, const int32_t count, int32_t& avg_spans)
+    {
+        if (count < 1)
+        {
+            return false;
+        }
+        auto start_indexs = new int32_t[count + 1];
+        avg_spans = 0;
+        if ((node - 1) != nullptr)
+        {
+            node--;
+        }
+
+        for (int i = count - 1; i >= 0; i--)
+        {
+            node--;
+            if (node == nullptr)
+            {
+                return false;
+            }
+            start_indexs[i] = node->startIndex;
+        }
+        return CheckSyncSpansByArray(start_indexs, count, avg_spans);
+    }
+
+
+    bool USBDecoder::CheckSyncSpansByArray(const int32_t* start_indexs, const int32_t count,
+                                           int32_t& avg_span)
+    {
+        if (count < 1)
+        {
+            return false;
+        }
+
+        auto tmp_spans = new double[count - 1];
+        for (int i = 1; i < count; i++)
+        {
+            tmp_spans[i - 1] = static_cast<double>(start_indexs[i] - start_indexs[i - 1]);
+        }
+
+        double total_spans = 0;
+        for (int i = 0; i < count - 1; i++)
+        {
+            total_spans += std::abs(tmp_spans[2 + (i / 2)]);
+        }
+        avg_span = static_cast<int>(total_spans / (count - 1));
+        //return CheckTimeDifferenceWithinThreshold(tmp_spans, count - 1, avg_span);
+        return CheckTimeDifferenceWithinThreshold(tmp_spans, count - 1);
+    }
+
+    // bool USBDecoder::FindAllSyncs(TwoLevelEdgePulse* node, std::vector<SYNC>& all_sync
+    //                               , double set_bit_time_span,bool force_normal_speed, bool polarity)
+    bool USBDecoder::FindAllSyncs(TwoLevelEdgePulse* node, std::vector<SYNC>& all_sync
+                                  , double set_bit_time_span, bool polarity)
+    {
+        all_sync.clear();
+        int first_avg_span = 0;
+
+        if (node == nullptr || node - 1 == nullptr)
+        {
+            return false;
+        }
+        // if (force_normal_speed)
+        // {
+        //     syncBitLen_ = USB_USB_SYNC_BIT_NORMAL_SPEED_LEN;
+        // }
+        Edge next_edge = polarity ? Edge::Rise : Edge::Falling;
+        Edge start_edge = next_edge;
+
+        TwoLevelEdgePulse* start_info_node = nullptr;
+        Edge tmp_edges[USB_USB_SYNC_BIT_MAX_LEN];
+        TwoLevelEdgePulse* tmp_edges_ptr[USB_USB_SYNC_BIT_MAX_LEN];
+        int32_t tmp_edges_len[USB_USB_SYNC_BIT_MAX_LEN];
+        ClearEdgeArray(tmp_edges, syncBitLen_);
+
+        int tmp_edge_count = 0;
+        TwoLevelEdgePulse* tmp_node = node;
+
+        while (tmp_node != nullptr)
+        {
+            if (canceled)
+            {
+                WriteLog(LogLevel::Level2, "AsyncFunction canceled");
+                return false;
+            }
+            if (tmp_node->startIndex < 0 || tmp_node->endIndex < 0
+                || tmp_node->startIndex > tmp_node->endIndex || tmp_node->LevelCount() <= 0)
+            {
+                WriteLog(LogLevel::Level2, "FindAllSyncs break,SYNC count:%d", all_sync.size());
+                break;
+            }
+            //可能找到目标头
+            if (first_avg_span != 0 && tmp_node->GetLength() > first_avg_span * 8)
+            {
+                tmp_edge_count = 0;
+            }
+
+            if (tmp_edge_count <= syncBitLen_ - 1)
+            {
+                if (tmp_edge_count == 0)
+                {
+                    start_info_node = tmp_node;
+                }
+
+                tmp_edges[tmp_edge_count] = tmp_node->edge;
+                tmp_edges_ptr[tmp_edge_count] = tmp_node;
+                tmp_edges_len[tmp_edge_count] = tmp_node->GetLength();
+                tmp_edge_count++;
+            }
+            else
+            {
+                if (CheckSyncEdges(start_edge, tmp_edges))
+                {
+                    int avg_spans;
+                    if (CheckSyncSpans(tmp_node, syncBitLen_ - 1, avg_spans))
+                    {
+                        if (all_sync.empty())
+                        {
+                            int32_t set_bit_span = static_cast<int>(set_bit_time_span);
+
+                            first_avg_span = set_bit_span >= 0 ? set_bit_span : avg_spans;
+                            all_sync.emplace_back(start_info_node, (tmp_node - 2)->startIndex + first_avg_span,
+                                                  first_avg_span, usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED);
+                        }
+                        else if (start_info_node != nullptr && (start_info_node - 1) != nullptr && (start_info_node - 1)->
+                            GetLength() > first_avg_span * syncBitLen_)
+                        {
+                            int32_t set_bit_span = static_cast<int>(set_bit_time_span);
+                            avg_spans = set_bit_span >= 0 ? set_bit_span : avg_spans;
+                            all_sync.emplace_back(start_info_node, (tmp_node - 2)->startIndex + avg_spans,
+                                                  avg_spans, usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED);
+                        }
+
+                        ClearEdgeArray(tmp_edges, syncBitLen_);
+                        tmp_edge_count = 0;
+                        tmp_node++;
+                        //left_over_size--;
+                        continue;
+                    }
+                }
+
+                for (int i = 0; i < syncBitLen_ - 1; i++)
+                {
+                    tmp_edges[i] = tmp_edges[i + 1];
+                    tmp_edges_ptr[i] = tmp_edges_ptr[i + 1];
+                    tmp_edges_len[i] = tmp_edges_len[i + 1];
+                }
+
+                tmp_edges[syncBitLen_ - 1] = tmp_node->edge;
+                tmp_edges_ptr[syncBitLen_ - 1] = tmp_node;
+                tmp_edges_len[syncBitLen_ - 1] = tmp_node->GetLength();
+                start_info_node++;
+            }
+
+            tmp_node++;
+            //left_over_size--;
+        }
+
+        return !all_sync.empty();
+    }
+
+    bool USBDecoder::FindPackets(int32_t& left_over_size,
+                                 std::vector<USBPacket>& all_packet, double set_bit_time_span,
+                                 bool polarity)
+    {
+        TwoLevelEdgePulse* node = signEdgePulse_.data();
+        all_packet.clear();
+        std::vector<SYNC> all_sync;
+
+        //找的全部同步帧
+        if (!FindAllSyncs(node, all_sync, set_bit_time_span, polarity) || all_sync.empty())
+        {
+            return false;
+        }
+
+        for (const auto& sync : all_sync)
+        {
+            if (sync.nodePtr == nullptr)
+            {
+                continue;
+            }
+            if (canceled)
+            {
+                WriteLog(LogLevel::Level2, "AsyncFunction canceled");
+                return false;
+            }
+            TwoLevelEdgePulse* tmp_node = sync.nodePtr;
+
+            int32_t eop_index = -1;
+            //有差分Eop情况
+            if (!differenceEopIndexs_.empty() && differenceEopIndexs_.size() > all_packet.size())
+            {
+                eop_index = differenceEopIndexs_[all_packet.size()];
+            }
+            if (eop_index <= 0)
+            {
+                //如果存在后续同步帧,用下个同步帧头-1的起始做可能结束 
+                if (static_cast<int32_t>(all_sync.size()) > static_cast<int32_t>(all_packet.size() + 2))
+                {
+                    eop_index = (all_sync[all_packet.size() + 2].nodePtr - 1)->startIndex;
+                }
+                else
+                {
+                    eop_index = waveMaxTimeIndexLen_;
+                }
+            }
+            int32_t packetMaxTimeLen = eop_index - sync.nodePtr->startIndex;
+            if (packetMaxTimeLen <= 0)
+            {
+                WriteLog(LogLevel::Level2, "FindPackets Warning: packetMaxTimeLen <= 0");
+            }
+            USBPacket packet(tmp_node, left_over_size, sync, polarity, packetMaxTimeLen);
+            if (packet.IsValid())
+            {
+                all_packet.push_back(packet);
+            }
+        }
+
+        return true;
+    }
+    bool USBDecoder::CheckOptions(UsbDecodeOptions option, const std::vector<TwoLevelEdgePulse>& edge_pulses_dp,
+                                  const std::vector<TwoLevelEdgePulse>& edge_pulses_dm, double& set_bit_time_span)
+    {
+        double usb_speed;
+        usbSpeed_ = option.usbSpeed;
+        switch (option.usbSpeed)
+        {
+        case USBEnums::USBSpeed::LOW_SPEED:
+            usb_speed = USB_LOW_SPEED_MHZ;
+            syncBitLen_ = USB_USB_SYNC_BIT_NORMAL_SPEED_LEN;
+            break;
+        case USBEnums::USBSpeed::FULL_SPEED:
+            usb_speed = USB_FULL_SPEED_MHZ;
+            syncBitLen_ = USB_USB_SYNC_BIT_NORMAL_SPEED_LEN;
+            break;
+        case USBEnums::USBSpeed::HIGH_SPEED:
+            usb_speed = USB_HIGH_SPEED_MHZ;
+            syncBitLen_ = USB_USB_SYNC_BIT_HIGH_SPEED_LEN;
+            break;
+        default:
+            WriteLog(LogLevel::Level2, "CheckOptions Failed, usbSpeed error");
+            return false;
+        }
+        isAutoClk_ = option.autoClock;
+        if (!isAutoClk_ && option.samplingFrequency < usb_speed * 2)
+        {
+            WriteLog(LogLevel::Level2, "CheckOptions Failed, samplingFrequency error");
+            return false;
+        }
+
+        if (!isAutoClk_)
+        {
+            syncBitLen_ = USB_USB_SYNC_BIT_MAX_LEN;
+        }
+        if (option.signType == SignType::SingleEnded)
+        {
+            WriteLog(LogLevel::Level2, "CheckOptions SignType:%d", static_cast<int>(option.signType));
+            if (edge_pulses_dp.size() < USB_MINIMUM_SEQUENCE_LENGTH && edge_pulses_dm.size() < USB_MINIMUM_SEQUENCE_LENGTH)
+            {
+                WriteLog(LogLevel::Level2, "CheckOptions Failed, edgePulses.size too short");
+                return false;
+            }
+        }
+        else
+        {
+            auto edge_pulses_size1 = static_cast<double>(edge_pulses_dp.size());
+            auto edge_pulses_size2 = static_cast<double>(edge_pulses_dm.size());
+            //// 差分长度判断
+            if (!DataCheckHelper::CheckDoubleIsEqual(edge_pulses_size1, edge_pulses_size2)
+                && ((USB_DIFF_LEN_DIFFERENCE_THRESHOLD * edge_pulses_size1) > edge_pulses_size2
+                    || (USB_DIFF_LEN_DIFFERENCE_THRESHOLD * edge_pulses_size2) > edge_pulses_size1))
+            {
+                WriteLog(LogLevel::Level2, "CheckOptions Failed,diff edgePulses size is not equal");
+                return false;
+            }
+
+            if (edge_pulses_dp.size() < USB_MINIMUM_SEQUENCE_LENGTH)
+            {
+                WriteLog(LogLevel::Level2, "CheckOptions Failed, edgePulses size too short");
+                return false;
+            }
+
+            usbDiffSignalRealEdgesCount_ = static_cast<int32_t>(edge_pulses_dp.size() > edge_pulses_dm.size()
+                                                                    ? edge_pulses_dm.size()
+                                                                    : edge_pulses_dp.size());
+        }
+        set_bit_time_span = option.samplingFrequency / (usb_speed * 1000000);
+        return true;
+    }
 }

+ 77 - 75
ProtocolUSB/usb_decoder.h

@@ -27,79 +27,81 @@
 
 namespace Protocol
 {
-	class USBDecoder
-	{
-	public:
-		USBDecoder() : usbDiffSignalRealEdgesCount_(0), waveMaxTimeIndexLen_(0)
-		{
-			differenceEopIndexs_ = {};
-			resultCells_ = {};
-			resultEvents_ = {};
-			usb_packets_ = {};
-			signEdgePulse_ = {};
-		}
-
-		static std::vector<std::string> EventInfoTitles();
-
-		bool DecodeUSB(const UsbDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_dp,
-			const EdgePulseDataTwoLevels& edge_pulses_dm, UsbDecodeResult& result);
-
-	private:
-		USBEnums::USBSpeed usbSpeed_;
-		bool isAutoClk_;
-		std::vector<UsbDecodeResultCell> resultCells_;
-		std::vector<UsbDecodeEvent> resultEvents_;
-		std::vector<USBPacket> usb_packets_;
-		std::vector<int32_t> differenceEopIndexs_;
-
-		std::vector<TwoLevelEdgePulse> signEdgePulse_;
-
-		//usb差分信号非对齐位置
-		std::vector<int32_t> usbDiffUnalignedFramesIndex_;
-
-		//差分信号可用长度
-		int32_t usbDiffSignalRealEdgesCount_;
-		//传入波形最大时域长度
-		int32_t waveMaxTimeIndexLen_;
-		//同步帧长度
-		int32_t syncBitLen_ = USB_USB_SYNC_BIT_MAX_LEN;
-		bool ParseDiffSignalData(std::vector<TwoLevelEdgePulse> edge_pulses_dp,
-			std::vector<TwoLevelEdgePulse> edge_pulses_dm)
-		{
-			//找出非对称边沿
-			//todo  add  differenceEopIndexs
-			//temp
-			signEdgePulse_ = std::move(edge_pulses_dp);
-
-			return true;
-		}
-
-		bool CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, int32_t avg_span, double threshold = USB_TIME_DIFFERENCE_THRESHOLD);
-		bool CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, double threshold = USB_TIME_DIFFERENCE_THRESHOLD);
-
-		static void ClearEdgeArray(Edge* edges, int32_t size);
-
-		static bool CheckSyncEdges(Edge start_edge, const Edge* edges);
-
-		//检查同步域在时域间隔
-		bool CheckSyncSpans(const TwoLevelEdgePulse* node, int32_t count,
-			int32_t& avg_spans);
-
-		bool CheckSyncSpansByArray(const int32_t* start_indexs, int32_t count, int32_t& avg_span);
-
-		// bool FindAllSyncs(TwoLevelEdgePulse* node, std::vector<SYNC>& all_sync
-		//                   , double set_bit_time_span, bool force_normal_speed, bool polarity = false);
-		bool FindAllSyncs(TwoLevelEdgePulse* node, std::vector<SYNC>& all_sync
-			, double set_bit_time_span, bool polarity = false);
-
-		// static bool FindAllSyncs(Protocol::TwoLevelEdgePulse* node, int32_t left_over_size,
-		//                          std::vector<SYNC>& all_sync, bool polarity = false);
-
-		bool FindPackets(int32_t& left_over_size,
-			std::vector<USBPacket>& all_packet, double set_bit_time_span,
-			bool polarity = false);
-		bool CheckOptions(UsbDecodeOptions option, const std::vector<TwoLevelEdgePulse>& edge_pulses_dp,
-			const std::vector<TwoLevelEdgePulse>& edge_pulses_dm, double& set_bit_time_span);
-		bool ParseSingleData(double set_bit_time_span, bool auto_clock);
-	};
+    class USBDecoder
+    {
+    public:
+        USBDecoder() : usbDiffSignalRealEdgesCount_(0), waveMaxTimeIndexLen_(0)
+        {
+            differenceEopIndexs_ = {};
+            resultCells_ = {};
+            resultEvents_ = {};
+            usb_packets_ = {};
+            signEdgePulse_ = {};
+        }
+
+        static std::vector<std::string> EventInfoTitles();
+
+        bool DecodeUSB(const UsbDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_dp,
+                       const EdgePulseDataTwoLevels& edge_pulses_dm, UsbDecodeResult& result);
+
+    private:
+        USBEnums::USBSpeed usbSpeed_;
+        bool isAutoClk_;
+        std::vector<UsbDecodeResultCell> resultCells_;
+        std::vector<UsbDecodeEvent> resultEvents_;
+        std::vector<USBPacket> usb_packets_;
+        std::vector<int32_t> differenceEopIndexs_;
+
+        std::vector<TwoLevelEdgePulse> signEdgePulse_;
+
+        //usb差分信号非对齐位置
+        std::vector<int32_t> usbDiffUnalignedFramesIndex_;
+
+        //差分信号可用长度
+        int32_t usbDiffSignalRealEdgesCount_;
+        //传入波形最大时域长度
+        int32_t waveMaxTimeIndexLen_;
+        //同步帧长度
+        int32_t syncBitLen_ = USB_USB_SYNC_BIT_MAX_LEN;
+        bool ParseDiffSignalData(std::vector<TwoLevelEdgePulse> edge_pulses_dp,
+                                 std::vector<TwoLevelEdgePulse> edge_pulses_dm)
+        {
+            //找出非对称边沿
+            //todo  add  differenceEopIndexs
+            //temp
+            signEdgePulse_ = std::move(edge_pulses_dp);
+
+            return true;
+        }
+
+        bool CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, int32_t avg_span,
+                                                double threshold = USB_TIME_DIFFERENCE_THRESHOLD);
+        bool CheckTimeDifferenceWithinThreshold(const double* array, int32_t size,
+                                                double threshold = USB_TIME_DIFFERENCE_THRESHOLD);
+
+        static void ClearEdgeArray(Edge* edges, int32_t size);
+
+        static bool CheckSyncEdges(Edge start_edge, const Edge* edges);
+
+        //检查同步域在时域间隔
+        bool CheckSyncSpans(const TwoLevelEdgePulse* node, int32_t count,
+                            int32_t& avg_spans);
+
+        bool CheckSyncSpansByArray(const int32_t* start_indexs, int32_t count, int32_t& avg_span);
+
+        // bool FindAllSyncs(TwoLevelEdgePulse* node, std::vector<SYNC>& all_sync
+        //                   , double set_bit_time_span, bool force_normal_speed, bool polarity = false);
+        bool FindAllSyncs(TwoLevelEdgePulse* node, std::vector<SYNC>& all_sync
+                          , double set_bit_time_span, bool polarity = false);
+
+        // static bool FindAllSyncs(Protocol::TwoLevelEdgePulse* node, int32_t left_over_size,
+        //                          std::vector<SYNC>& all_sync, bool polarity = false);
+
+        bool FindPackets(int32_t& left_over_size,
+                         std::vector<USBPacket>& all_packet, double set_bit_time_span,
+                         bool polarity = false);
+        bool CheckOptions(UsbDecodeOptions option, const std::vector<TwoLevelEdgePulse>& edge_pulses_dp,
+                          const std::vector<TwoLevelEdgePulse>& edge_pulses_dm, double& set_bit_time_span);
+        bool ParseSingleData(double set_bit_time_span, bool auto_clock);
+    };
 }

+ 576 - 576
ProtocolUSB/usb_packet.cpp

@@ -13,580 +13,580 @@
 
 namespace Protocol
 {
-	USBPacket::USBPacket() : PacketTitle(), pid_(0), last_nrbz_data_bit_(false), polarity_(false), end_point_(0),
-		crc_sign_num_(0),
-		crc16_(0), is_valid_(false),
-		is_crc_checked_(false),
-		to_extracted_next_data_start_index_(-1),
-		to_nrzi_decode_next_data_start_index_(-1),
-		max_possible_data_length_(-1)
-
-
-	{
-	}
-
-	USBPacket::USBPacket(TwoLevelEdgePulse* pid_node, int32_t& left_over_size, const SYNC& sync
-		, bool polarity, int32_t max_data_length)
-	{
-		this->polarity_ = polarity;
-		packet_sync_ = sync;
-		if (max_data_length >= 0)
-		{
-			max_possible_data_length_ = max_data_length;
-		}
-
-		//this->pidType = nullptr;
-		TwoLevelEdgePulse* tmp_pid_node = pid_node;
-		/*if (tmp_pid_node->startIndex < sync.endIndex && tmp_pid_node->startIndex < sync.nodePtr->startIndex + sync.Length())
-		{
-			while (tmp_pid_node->startIndex < sync.endIndex && tmp_pid_node->startIndex < sync.nodePtr->startIndex + sync.Length())
-			{
-				tmp_pid_node += 1;
-			}
-			tmp_pid_node -= 2;
-		}*/
-		 
-		if (!GetPID(tmp_pid_node))
-		{
-			return;
-		}
-
-		is_valid_ = true;
-
-		if (this->packet_type_ == USBEnums::USBPacketType::NO_DEFINE)
-		{
-			return;
-		}
-		//解码域内容
-		DecodeFields(tmp_pid_node);
-	}
-
-	bool USBPacket::CheckNibblesInverse(uint8_t value)
-	{
-		const uint8_t high_nibble = static_cast<uint8_t>(value >> 4);
-		const uint8_t low_nibble = static_cast<uint8_t>(value & 0x0F);
-		return high_nibble == (~low_nibble & 0x0F);
-	}
-
-	bool USBPacket::GetPID(TwoLevelEdgePulse*& pid_node)
-	{
-		if (!CheckNodeValid(static_cast<EdgePulse>(*pid_node)))
-		{
-			WriteLog(LogLevel::Level2, "node check fail");
-			return false;
-		}
-		if (packet_sync_.singleBitTimingLength <= 0)
-		{
-			return false;
-		}
-		last_nrbz_data_bit_ = false;
-		uint8_t data;
-		int32_t pid_start_index = packet_sync_.endIndex + 2;
-
-		if (!DecodeNextByte(pid_node, pid_start_index, data))
-		{
-			return false;
-		}
-
-		pid_ = data;
-		auto handshake_type = USBEnums::HandshakePackageType::NAK;
-		if (IsTokenPackageType())
-		{
-			packet_type_ = USBEnums::USBPacketType::TOKEN;
-		}
-		else if (IsDataPackageType())
-		{
-			packet_type_ = USBEnums::USBPacketType::DATA;
-		}
-		else if (IsHandshakePackageType(handshake_type))
-		{
-			packet_type_ = USBEnums::USBPacketType::HAND_SHAKE;
-			switch (handshake_type)
-			{
-			case USBEnums::HandshakePackageType::ACK:
-				PacketTitle = USBEnums::EventInfoTitles::ACK;
-				break;
-			case USBEnums::HandshakePackageType::NAK:
-				PacketTitle = USBEnums::EventInfoTitles::NAK;
-				break;
-			case USBEnums::HandshakePackageType::STALL:
-				PacketTitle = USBEnums::EventInfoTitles::STALL;
-				break;
-			case USBEnums::HandshakePackageType::NYET:
-				PacketTitle = USBEnums::EventInfoTitles::NYET;
-				break;
-			default:  // NOLINT(clang-diagnostic-covered-switch-default)
-				return false;
-			}
-		}
-		else if (IsSpecialPacketType())
-		{
-			packet_type_ = USBEnums::USBPacketType::SPECIAL;
-		}
-		else
-		{
-			return false;
-		}
-		return true;
-	}
-
-	bool USBPacket::GetNRZIData(TwoLevelEdgePulse*& node, int32_t need_bit_count, int32_t start_index,
-		std::vector<bool>& out_data)
-	{
-		if (!CheckNodeValid(node))
-		{
-			WriteLog(LogLevel::Level2, "node check fail");
-			return false;
-		}
-		const int32_t get_data_start_index = start_index;
-		//const int32_t get_data_start_index = node->StartIndex;
-		const bool high_polarity_edge = packet_sync_.nodePtr->edge == Edge::Falling;
-		const double single_bit_timing_length_threshold = packet_sync_.singleBitTimingLength * USB_SYNC_BIT_TOL;
-		out_data = {};
-		//nrzi  补位个数
-		const int32_t pre_complement_number = need_bit_count / USB_NRZI_COMPLEMENT_PER_NUM;
-		const int32_t pre_complement_need_bit_count = need_bit_count + pre_complement_number;
-		std::vector<bool> nrzi_data(pre_complement_need_bit_count, false);
-		int32_t getbit_count = 0;
-		bool get_last_nrzi_bit_polarity = false;
-		while (getbit_count < pre_complement_need_bit_count)
-		{
-			if (!CheckNodeValid(node))
-			{
-				WriteLog(LogLevel::Level2, "GetNRZIData node check fail");
-				return false;
-			}
-			if (node->endIndex < start_index)
-			{
-				node++;
-				continue;
-			}
-
-			////fix
-			if (node->endIndex - start_index < packet_sync_.singleBitTimingLength / 2)
-			{
-				node++;
-				if (!CheckNodeValid(node))
-				{
-					WriteLog(LogLevel::Level2, "GetNRZIData node check fail");
-					return false;
-				}
-			}
-			if (!get_last_nrzi_bit_polarity && CheckNodeValid(node - 1))
-			{
-				if (start_index - node->startIndex > single_bit_timing_length_threshold)
-				{
-					last_nrbz_data_bit_ = node->CurrentLevel == TwoLevelEdgePulseStatusType::High;
-				}
-				else
-				{
-					//不用改
-					//last_NRBZ_data_bit = (node - 1)->CurrentLevel == TwoLevelEdgePulseStatusType::High;
-				}
-
-				get_last_nrzi_bit_polarity = true;
-			}
-			if (node->endIndex - start_index >= single_bit_timing_length_threshold)
-			{
-				const int bits_count = static_cast<int>((node->endIndex - start_index) /
-					single_bit_timing_length_threshold);
-
-				const int last_gotbit_count = getbit_count;
-
-				for (int i = 0; i < bits_count; i++)
-				{
-					if (last_gotbit_count + i >= pre_complement_need_bit_count)
-					{
-						break;
-					}
-					if ((last_gotbit_count + i) >= static_cast<int32_t>(nrzi_data.size()))
-					{
-						WriteLog(LogLevel::Level2, "GetNRZIData error: last_gotbit_count + i > nrzi_data.size()");
-						break;
-					}
-					nrzi_data[last_gotbit_count + i] = high_polarity_edge == (node->edge ==
-						Edge::Rise);
-					getbit_count++;
-					start_index += packet_sync_.singleBitTimingLength;
-				}
-			}
-			else
-			{
-				nrzi_data[getbit_count] = node->edge == Edge::Rise;
-				getbit_count++;
-			}
-			if (getbit_count == pre_complement_need_bit_count)
-			{
-				break;
-			}
-			node++;
-			if (start_index < node->startIndex)
-			{
-				start_index = node->startIndex;
-			}
-		}
-		//待提取下个位标_位移数
-		int32_t move_bit_count = 0;
-
-		//lastNRBZDataBit = node->Edge == Edge::Rise;
-		//处理连续 输出结果
-
-		int32_t continuous_count = 0;
-		bool last_value = false;
-		for (bool data : nrzi_data)
-		{
-			move_bit_count++;
-
-			//6个连续下一个翻转,必然是插入的bit
-			if (continuous_count == USB_NRZI_COMPLEMENT_PER_NUM && data != last_value)
-			{
-				continuous_count = 0;
-				continue;
-			}
-			if (last_value == data)
-			{
-				continuous_count++;
-			}
-			else
-			{
-				last_value = data;
-				continuous_count = 0;
-			}
-
-			out_data.push_back(data);
-			if (static_cast<int32_t>(out_data.size()) == need_bit_count)
-			{
-				// if (get_data_start_index == packetSYNC.NodePtr->StartIndex)
-				// {
-				// 	to_extracted_next_data_start_index = packetSYNC.EndIndex;
-				// }
-				// else
-				// {
-				to_extracted_next_data_start_index_ = get_data_start_index + (move_bit_count * packet_sync_.
-					singleBitTimingLength);
-				//}
-				//while (pre_complement_number > 0 && to_extracted_next_data_start_index > 0 && to_extracted_next_data_start_index
-				//    < node->StartIndex)
-				//{
-				//    //退回多抽的点位标
-				//    pre_complement_number--;
-				//    node--;
-				//}
-				while (to_extracted_next_data_start_index_ > 0 && to_extracted_next_data_start_index_
-					< node->startIndex)
-				{
-					//退回多抽的点位标
-					node--;
-				}
-				return true;
-			}
-		}
-
-		WriteLog(LogLevel::LevelDebug, "GetNRZIData return fail");
-		return false;
-	}
-	//NRZI解码下个字节
-	bool USBPacket::DecodeNextByteByDataField(TwoLevelEdgePulse*& node, uint8_t& out_data)
-	{
-		return DecodeNextByte(node, to_extracted_next_data_start_index_, out_data);
-	}
-
-	void USBPacket::NRBZToNormalData(const TwoLevelEdgePulse* node,
-		int32_t need_bit_count, std::vector<bool> nrzi_data, uint8_t& out_data)
-	{
-		//lastNRBZDataBit = node->Edge == Edge::Rise;
-		for (int i = 0; i < need_bit_count; i++)
-		{
-			//信号不变,就是数据1
-			if (last_nrbz_data_bit_ == nrzi_data[i])
-			{
-				out_data |= (1 << i);
-			}
-			else
-			{
-				//信号变了就是数据0
-			}
-			last_nrbz_data_bit_ = nrzi_data[i];
-		}
-		//out_data = CommonHelper::ReverseOrderBits(out_data);
-	}
-	//NRZI解码下个字节
-	bool USBPacket::DecodeNextByte(TwoLevelEdgePulse*& node, int32_t start_index, uint8_t& out_data)
-	{
-		out_data = 0;
-		constexpr int32_t need_bit_count = 8;
-		std::vector<bool> nrzi_data = {};
-		if (!GetNRZIData(node, need_bit_count, start_index, nrzi_data))
-		{
-			WriteLog(LogLevel::Level2, "DecodeNextByte GetNRZIData fail");
-			return false;
-		}
-		NRBZToNormalData(node, need_bit_count, nrzi_data, out_data);
-		return true;
-	}
-	bool USBPacket::DecodeTokenBytes(TwoLevelEdgePulse*& node, USBEnums::TokenPackageType type)
-	{
-		bool is_sof_type = type == USBEnums::TokenPackageType::SOF;
-		bool result;
-		if (!is_sof_type)
-		{
-			//7addr-4enp-5crc bit
-			//////////////////////////// addr ////////////////////////////
-			std::vector<bool> addr_data = {};
-			uint8_t addr = 0;
-			result = GetNRZIData(node, USB_ADDR_BIT_COUNT, to_extracted_next_data_start_index_,
-				addr_data);
-			if (!result)
-			{
-				return false;
-			}
-			NRBZToNormalData(node, USB_ADDR_BIT_COUNT, addr_data
-				, addr);
-			address_.push_back(addr);
-			//////////////////////////// endpoint ////////////////////////////
-			std::vector<bool> endpoint_data = {};
-
-			result = GetNRZIData(node, USB_ENDPOINT_BIT_COUNT, to_extracted_next_data_start_index_,
-				endpoint_data);
-			if (!result)
-			{
-				return false;
-			}
-			NRBZToNormalData(node, USB_ENDPOINT_BIT_COUNT, endpoint_data
-				, end_point_);
-		}
-		else
-		{
-			//11frame-5bitcrc
-			//////////////////////////// frame ////////////////////////////
-			std::vector<bool> frame_data = {};
-			uint8_t frame_id_tmp = 0;
-			datas_ = {};
-			result = GetNRZIData(node, USB_FRAMEID_BIT_COUNT, to_extracted_next_data_start_index_,
-				frame_data);
-			if (!result)
-			{
-				return false;
-			}
-
-			NRBZToNormalData(node, USB_FRAMEID_BIT_COUNT, frame_data
-				, frame_id_tmp);
-			datas_.push_back(frame_id_tmp);
-			frame_id_tmp = 0;
-			for (int i = 8; i < USB_FRAMEID_BIT_COUNT - 8; i++)
-			{
-				if (last_nrbz_data_bit_ != frame_data[i])
-				{
-					last_nrbz_data_bit_ = frame_data[i];
-				}
-				else
-				{
-					frame_id_tmp |= (1 << i);
-				}
-			}
-			datas_.push_back(frame_id_tmp);
-		}
-
-		//////////////////////////// CRC5 ////////////////////////////
-		std::vector<bool> crc_data = {};
-		uint8_t crc = 0;
-		result = GetNRZIData(node, USB_CRC5_BIT_COUNT, to_extracted_next_data_start_index_,
-			crc_data);
-		if (!result)
-		{
-			return false;
-		}
-
-		NRBZToNormalData(node, USB_CRC5_BIT_COUNT, crc_data
-			, crc);
-		crc_sign_num_ = USB_CRC5_BIT_COUNT;
-		crc16_ = crc;
-		WriteLog(LogLevel::LevelDebug, "DecodeTokenBytes = true,crc_sign_num=%d,crc=0x%x"
-			, crc_sign_num_, crc16_);
-		return true;
-	}
-
-	void USBPacket::DecodeFields(TwoLevelEdgePulse*& node)
-	{
-		switch (packet_type_)  // NOLINT(clang-diagnostic-switch-enum)
-		{
-		case USBEnums::USBPacketType::TOKEN:
-			DecodeFieldsByToken(node);
-			break;
-		case USBEnums::USBPacketType::DATA:
-
-			DecodeFieldsByData(node);
-			break;
-		case USBEnums::USBPacketType::HAND_SHAKE:
-			break;
-		case USBEnums::USBPacketType::SPECIAL:
-			DecodeFieldsBySpecial(node);
-			break;
-		default:
-			break;
-		}
-	}
-
-	void USBPacket::DecodeFieldsByToken(TwoLevelEdgePulse*& node)
-	{
-		if (packet_type_ == USBEnums::USBPacketType::NO_DEFINE)
-		{
-			WriteLog(LogLevel::Level2, "DecodeFieldsByToken error:packetType is NO_DEFINE");
-			return;
-		}
-
-		switch (static_cast<
-			USBEnums::TokenPackageType>(RealPID()))
-		{
-		case USBEnums::TokenPackageType::SOF:
-			PacketTitle = USBEnums::EventInfoTitles::SOF;
-			DecodeTokenBytes(node, USBEnums::TokenPackageType::SOF);
-			break;
-		case USBEnums::TokenPackageType::SETUP:
-			PacketTitle = USBEnums::EventInfoTitles::SETUP;
-			DecodeTokenBytes(node, USBEnums::TokenPackageType::SETUP);
-			break;
-		case USBEnums::TokenPackageType::IN_TYPE:
-			PacketTitle = USBEnums::EventInfoTitles::TIN;
-			DecodeTokenBytes(node, USBEnums::TokenPackageType::IN_TYPE);
-			break;
-		case USBEnums::TokenPackageType::OUT_TYPE:
-			PacketTitle = USBEnums::EventInfoTitles::TOUT;
-			DecodeTokenBytes(node, USBEnums::TokenPackageType::OUT_TYPE);
-			break;
-			// default:
-			//     return;
-		}
-	}
-
-	void USBPacket::DecodeFieldsByData(TwoLevelEdgePulse*& node)
-	{
-		if (packet_type_ == USBEnums::USBPacketType::NO_DEFINE)
-		{
-			WriteLog(LogLevel::Level2, "DecodeFieldsByToken error:packetType is NO_DEFINE");
-			return;
-		}
-		int32_t end_index = packet_sync_.nodePtr->endIndex;
-		std::vector<uint8_t> get_data_tmp = {};
-		switch (auto package_type = static_cast<USBEnums::DataPackageType>(RealPID()))
-		{
-		case USBEnums::DataPackageType::DATA0:
-		case USBEnums::DataPackageType::DATA1:
-			PacketTitle = package_type == USBEnums::DataPackageType::DATA0
-				? USBEnums::EventInfoTitles::DATA0
-				: USBEnums::EventInfoTitles::DATA1;
-			datas_.clear();
-
-			if (max_possible_data_length_ >= 0 && max_possible_data_length_
-			> packet_sync_.Length())
-			{
-				end_index = max_possible_data_length_ + packet_sync_.nodePtr->startIndex;
-			}
-			while (CheckNodeValid(node) && node->startIndex < end_index)
-			{
-				uint8_t data;
-				bool result = DecodeNextByteByDataField(node, data);
-				if (!result)
-				{
-					WriteLog(LogLevel::Level2, "DecodeFieldsByData DecodeNextByte fail:StartIndex:%d", node->startIndex);
-					break;
-				}
-				get_data_tmp.push_back(data);
-			}
-			if (get_data_tmp.size() > 2)
-			{
-				//data
-				for (uint64_t i = 0; i < get_data_tmp.size() - 2; i++)
-				{
-					datas_.push_back(get_data_tmp[i]);
-				}
-				//crc16
-				/* for (uint64_t i = (get_data_tmp.size() - 2); i < get_data_tmp.size(); i++)
-				 {
-				 }*/
-				uint8_t crc16_h = CommonHelper::ReverseOrderBits(get_data_tmp[get_data_tmp.size() - 2]);
-				uint8_t crc16_l = CommonHelper::ReverseOrderBits(get_data_tmp[get_data_tmp.size() - 1]);
-				crc16_ = (static_cast<uint16_t>(crc16_h) << 8) + static_cast<uint16_t>(crc16_l);
-
-				crc_sign_num_ = 16;
-			}
-			else
-			{
-				WriteLog(LogLevel::Level2, "Waring:DecodeFieldsByData Decode DataSize < 2 (%d)", get_data_tmp.size());
-				datas_ = std::move(get_data_tmp);
-			}
-			get_data_tmp.clear();
-			break;
-		case USBEnums::DataPackageType::DATA2:
-			PacketTitle = USBEnums::EventInfoTitles::DATA2;
-			break;
-		case USBEnums::DataPackageType::M_DATA:
-			PacketTitle = USBEnums::EventInfoTitles::MDATA;
-			break;
-			// default:
-			//     break;
-		}
-	}
-
-	void USBPacket::DecodeFieldsBySpecial(TwoLevelEdgePulse*& node) const
-	{
-		//todo
-		if (packet_type_ != USBEnums::USBPacketType::SPECIAL)
-		{
-		}
-	}
-	bool USBPacket::IsTokenPackageType() const
-	{
-		int32_t real_pid = RealPID();
-		if (static_cast<int32_t>(USBEnums::TokenPackageType::IN_TYPE) == real_pid
-			|| static_cast<int32_t>(USBEnums::TokenPackageType::OUT_TYPE) == real_pid
-			|| static_cast<int32_t>(USBEnums::TokenPackageType::SETUP) == real_pid
-			|| static_cast<int32_t>(USBEnums::TokenPackageType::SOF) == real_pid
-			)
-		{
-			return true;
-		}
-		return false;
-	}
-	bool USBPacket::IsSpecialPacketType() const
-	{
-		int32_t real_pid = RealPID();
-		if (static_cast<int32_t>(USBEnums::SpecialPacketType::ERR) == real_pid
-			|| static_cast<int32_t>(USBEnums::SpecialPacketType::PING) == real_pid
-			|| static_cast<int32_t>(USBEnums::SpecialPacketType::REMAIN) == real_pid
-			|| static_cast<int32_t>(USBEnums::SpecialPacketType::SPLIT) == real_pid
-			)
-		{
-			return true;
-		}
-		return false;
-	}
-	bool USBPacket::IsHandshakePackageType(USBEnums::HandshakePackageType& type) const
-	{
-		int32_t real_pid = RealPID();
-		if (static_cast<int32_t>(USBEnums::HandshakePackageType::NYET) == real_pid
-			|| static_cast<int32_t>(USBEnums::HandshakePackageType::STALL) == real_pid
-			|| static_cast<int32_t>(USBEnums::HandshakePackageType::ACK) == real_pid
-			|| static_cast<int32_t>(USBEnums::HandshakePackageType::NAK) == real_pid
-			)
-		{
-			type = static_cast<USBEnums::HandshakePackageType>(real_pid);
-			return true;
-		}
-		return false;
-	}
-	bool USBPacket::IsDataPackageType()
-	{
-		int32_t real_pid = RealPID();
-		if (static_cast<int32_t>(USBEnums::DataPackageType::DATA0) == real_pid
-			|| static_cast<int32_t>(USBEnums::DataPackageType::DATA1) == real_pid
-			|| static_cast<int32_t>(USBEnums::DataPackageType::DATA2) == real_pid
-			|| static_cast<int32_t>(USBEnums::DataPackageType::M_DATA) == real_pid
-			)
-		{
-			to_nrzi_decode_next_data_start_index_ = packet_sync_.endIndex + (packet_sync_.oneByteTimingLength);
-			return true;
-		}
-		return false;
-	}
+    USBPacket::USBPacket() : PacketTitle(), pid_(0), last_nrbz_data_bit_(false), polarity_(false), end_point_(0),
+                             crc_sign_num_(0),
+                             crc16_(0), is_valid_(false),
+                             is_crc_checked_(false),
+                             to_extracted_next_data_start_index_(-1),
+                             to_nrzi_decode_next_data_start_index_(-1),
+                             max_possible_data_length_(-1)
+
+
+    {
+    }
+
+    USBPacket::USBPacket(TwoLevelEdgePulse* pid_node, int32_t& left_over_size, const SYNC& sync
+                         , bool polarity, int32_t max_data_length)
+    {
+        this->polarity_ = polarity;
+        packet_sync_ = sync;
+        if (max_data_length >= 0)
+        {
+            max_possible_data_length_ = max_data_length;
+        }
+
+        //this->pidType = nullptr;
+        TwoLevelEdgePulse* tmp_pid_node = pid_node;
+        /*if (tmp_pid_node->startIndex < sync.endIndex && tmp_pid_node->startIndex < sync.nodePtr->startIndex + sync.Length())
+        {
+            while (tmp_pid_node->startIndex < sync.endIndex && tmp_pid_node->startIndex < sync.nodePtr->startIndex + sync.Length())
+            {
+                tmp_pid_node += 1;
+            }
+            tmp_pid_node -= 2;
+        }*/
+
+        if (!GetPID(tmp_pid_node))
+        {
+            return;
+        }
+
+        is_valid_ = true;
+
+        if (this->packet_type_ == USBEnums::USBPacketType::NO_DEFINE)
+        {
+            return;
+        }
+        //解码域内容
+        DecodeFields(tmp_pid_node);
+    }
+
+    bool USBPacket::CheckNibblesInverse(uint8_t value)
+    {
+        const uint8_t high_nibble = static_cast<uint8_t>(value >> 4);
+        const uint8_t low_nibble = static_cast<uint8_t>(value & 0x0F);
+        return high_nibble == (~low_nibble & 0x0F);
+    }
+
+    bool USBPacket::GetPID(TwoLevelEdgePulse*& pid_node)
+    {
+        if (!CheckNodeValid(static_cast<EdgePulse>(*pid_node)))
+        {
+            WriteLog(LogLevel::Level2, "node check fail");
+            return false;
+        }
+        if (packet_sync_.singleBitTimingLength <= 0)
+        {
+            return false;
+        }
+        last_nrbz_data_bit_ = false;
+        uint8_t data;
+        int32_t pid_start_index = packet_sync_.endIndex + 2;
+
+        if (!DecodeNextByte(pid_node, pid_start_index, data))
+        {
+            return false;
+        }
+
+        pid_ = data;
+        auto handshake_type = USBEnums::HandshakePackageType::NAK;
+        if (IsTokenPackageType())
+        {
+            packet_type_ = USBEnums::USBPacketType::TOKEN;
+        }
+        else if (IsDataPackageType())
+        {
+            packet_type_ = USBEnums::USBPacketType::DATA;
+        }
+        else if (IsHandshakePackageType(handshake_type))
+        {
+            packet_type_ = USBEnums::USBPacketType::HAND_SHAKE;
+            switch (handshake_type)
+            {
+            case USBEnums::HandshakePackageType::ACK:
+                PacketTitle = USBEnums::EventInfoTitles::ACK;
+                break;
+            case USBEnums::HandshakePackageType::NAK:
+                PacketTitle = USBEnums::EventInfoTitles::NAK;
+                break;
+            case USBEnums::HandshakePackageType::STALL:
+                PacketTitle = USBEnums::EventInfoTitles::STALL;
+                break;
+            case USBEnums::HandshakePackageType::NYET:
+                PacketTitle = USBEnums::EventInfoTitles::NYET;
+                break;
+            default:  // NOLINT(clang-diagnostic-covered-switch-default)
+                return false;
+            }
+        }
+        else if (IsSpecialPacketType())
+        {
+            packet_type_ = USBEnums::USBPacketType::SPECIAL;
+        }
+        else
+        {
+            return false;
+        }
+        return true;
+    }
+
+    bool USBPacket::GetNRZIData(TwoLevelEdgePulse*& node, int32_t need_bit_count, int32_t start_index,
+                                std::vector<bool>& out_data)
+    {
+        if (!CheckNodeValid(node))
+        {
+            WriteLog(LogLevel::Level2, "node check fail");
+            return false;
+        }
+        const int32_t get_data_start_index = start_index;
+        //const int32_t get_data_start_index = node->StartIndex;
+        const bool high_polarity_edge = packet_sync_.nodePtr->edge == Edge::Falling;
+        const double single_bit_timing_length_threshold = packet_sync_.singleBitTimingLength * USB_SYNC_BIT_TOL;
+        out_data = {};
+        //nrzi  补位个数
+        const int32_t pre_complement_number = need_bit_count / USB_NRZI_COMPLEMENT_PER_NUM;
+        const int32_t pre_complement_need_bit_count = need_bit_count + pre_complement_number;
+        std::vector<bool> nrzi_data(pre_complement_need_bit_count, false);
+        int32_t getbit_count = 0;
+        bool get_last_nrzi_bit_polarity = false;
+        while (getbit_count < pre_complement_need_bit_count)
+        {
+            if (!CheckNodeValid(node))
+            {
+                WriteLog(LogLevel::Level2, "GetNRZIData node check fail");
+                return false;
+            }
+            if (node->endIndex < start_index)
+            {
+                node++;
+                continue;
+            }
+
+            ////fix
+            if (node->endIndex - start_index < packet_sync_.singleBitTimingLength / 2)
+            {
+                node++;
+                if (!CheckNodeValid(node))
+                {
+                    WriteLog(LogLevel::Level2, "GetNRZIData node check fail");
+                    return false;
+                }
+            }
+            if (!get_last_nrzi_bit_polarity && CheckNodeValid(node - 1))
+            {
+                if (start_index - node->startIndex > single_bit_timing_length_threshold)
+                {
+                    last_nrbz_data_bit_ = node->CurrentLevel == TwoLevelEdgePulseStatusType::High;
+                }
+                else
+                {
+                    //不用改
+                    //last_NRBZ_data_bit = (node - 1)->CurrentLevel == TwoLevelEdgePulseStatusType::High;
+                }
+
+                get_last_nrzi_bit_polarity = true;
+            }
+            if (node->endIndex - start_index >= single_bit_timing_length_threshold)
+            {
+                const int bits_count = static_cast<int>((node->endIndex - start_index) /
+                    single_bit_timing_length_threshold);
+
+                const int last_gotbit_count = getbit_count;
+
+                for (int i = 0; i < bits_count; i++)
+                {
+                    if (last_gotbit_count + i >= pre_complement_need_bit_count)
+                    {
+                        break;
+                    }
+                    if ((last_gotbit_count + i) >= static_cast<int32_t>(nrzi_data.size()))
+                    {
+                        WriteLog(LogLevel::Level2, "GetNRZIData error: last_gotbit_count + i > nrzi_data.size()");
+                        break;
+                    }
+                    nrzi_data[last_gotbit_count + i] = high_polarity_edge == (node->edge ==
+                        Edge::Rise);
+                    getbit_count++;
+                    start_index += packet_sync_.singleBitTimingLength;
+                }
+            }
+            else
+            {
+                nrzi_data[getbit_count] = node->edge == Edge::Rise;
+                getbit_count++;
+            }
+            if (getbit_count == pre_complement_need_bit_count)
+            {
+                break;
+            }
+            node++;
+            if (start_index < node->startIndex)
+            {
+                start_index = node->startIndex;
+            }
+        }
+        //待提取下个位标_位移数
+        int32_t move_bit_count = 0;
+
+        //lastNRBZDataBit = node->Edge == Edge::Rise;
+        //处理连续 输出结果
+
+        int32_t continuous_count = 0;
+        bool last_value = false;
+        for (bool data : nrzi_data)
+        {
+            move_bit_count++;
+
+            //6个连续下一个翻转,必然是插入的bit
+            if (continuous_count == USB_NRZI_COMPLEMENT_PER_NUM && data != last_value)
+            {
+                continuous_count = 0;
+                continue;
+            }
+            if (last_value == data)
+            {
+                continuous_count++;
+            }
+            else
+            {
+                last_value = data;
+                continuous_count = 0;
+            }
+
+            out_data.push_back(data);
+            if (static_cast<int32_t>(out_data.size()) == need_bit_count)
+            {
+                // if (get_data_start_index == packetSYNC.NodePtr->StartIndex)
+                // {
+                // 	to_extracted_next_data_start_index = packetSYNC.EndIndex;
+                // }
+                // else
+                // {
+                to_extracted_next_data_start_index_ = get_data_start_index + (move_bit_count * packet_sync_.
+                    singleBitTimingLength);
+                //}
+                //while (pre_complement_number > 0 && to_extracted_next_data_start_index > 0 && to_extracted_next_data_start_index
+                //    < node->StartIndex)
+                //{
+                //    //退回多抽的点位标
+                //    pre_complement_number--;
+                //    node--;
+                //}
+                while (to_extracted_next_data_start_index_ > 0 && to_extracted_next_data_start_index_
+                    < node->startIndex)
+                {
+                    //退回多抽的点位标
+                    node--;
+                }
+                return true;
+            }
+        }
+
+        WriteLog(LogLevel::LevelDebug, "GetNRZIData return fail");
+        return false;
+    }
+    //NRZI解码下个字节
+    bool USBPacket::DecodeNextByteByDataField(TwoLevelEdgePulse*& node, uint8_t& out_data)
+    {
+        return DecodeNextByte(node, to_extracted_next_data_start_index_, out_data);
+    }
+
+    void USBPacket::NRBZToNormalData(const TwoLevelEdgePulse* node,
+                                     int32_t need_bit_count, std::vector<bool> nrzi_data, uint8_t& out_data)
+    {
+        //lastNRBZDataBit = node->Edge == Edge::Rise;
+        for (int i = 0; i < need_bit_count; i++)
+        {
+            //信号不变,就是数据1
+            if (last_nrbz_data_bit_ == nrzi_data[i])
+            {
+                out_data |= (1 << i);
+            }
+            else
+            {
+                //信号变了就是数据0
+            }
+            last_nrbz_data_bit_ = nrzi_data[i];
+        }
+        //out_data = CommonHelper::ReverseOrderBits(out_data);
+    }
+    //NRZI解码下个字节
+    bool USBPacket::DecodeNextByte(TwoLevelEdgePulse*& node, int32_t start_index, uint8_t& out_data)
+    {
+        out_data = 0;
+        constexpr int32_t need_bit_count = 8;
+        std::vector<bool> nrzi_data = {};
+        if (!GetNRZIData(node, need_bit_count, start_index, nrzi_data))
+        {
+            WriteLog(LogLevel::Level2, "DecodeNextByte GetNRZIData fail");
+            return false;
+        }
+        NRBZToNormalData(node, need_bit_count, nrzi_data, out_data);
+        return true;
+    }
+    bool USBPacket::DecodeTokenBytes(TwoLevelEdgePulse*& node, USBEnums::TokenPackageType type)
+    {
+        bool is_sof_type = type == USBEnums::TokenPackageType::SOF;
+        bool result;
+        if (!is_sof_type)
+        {
+            //7addr-4enp-5crc bit
+            //////////////////////////// addr ////////////////////////////
+            std::vector<bool> addr_data = {};
+            uint8_t addr = 0;
+            result = GetNRZIData(node, USB_ADDR_BIT_COUNT, to_extracted_next_data_start_index_,
+                                 addr_data);
+            if (!result)
+            {
+                return false;
+            }
+            NRBZToNormalData(node, USB_ADDR_BIT_COUNT, addr_data
+                             , addr);
+            address_.push_back(addr);
+            //////////////////////////// endpoint ////////////////////////////
+            std::vector<bool> endpoint_data = {};
+
+            result = GetNRZIData(node, USB_ENDPOINT_BIT_COUNT, to_extracted_next_data_start_index_,
+                                 endpoint_data);
+            if (!result)
+            {
+                return false;
+            }
+            NRBZToNormalData(node, USB_ENDPOINT_BIT_COUNT, endpoint_data
+                             , end_point_);
+        }
+        else
+        {
+            //11frame-5bitcrc
+            //////////////////////////// frame ////////////////////////////
+            std::vector<bool> frame_data = {};
+            uint8_t frame_id_tmp = 0;
+            datas_ = {};
+            result = GetNRZIData(node, USB_FRAMEID_BIT_COUNT, to_extracted_next_data_start_index_,
+                                 frame_data);
+            if (!result)
+            {
+                return false;
+            }
+
+            NRBZToNormalData(node, USB_FRAMEID_BIT_COUNT, frame_data
+                             , frame_id_tmp);
+            datas_.push_back(frame_id_tmp);
+            frame_id_tmp = 0;
+            for (int i = 8; i < USB_FRAMEID_BIT_COUNT - 8; i++)
+            {
+                if (last_nrbz_data_bit_ != frame_data[i])
+                {
+                    last_nrbz_data_bit_ = frame_data[i];
+                }
+                else
+                {
+                    frame_id_tmp |= (1 << i);
+                }
+            }
+            datas_.push_back(frame_id_tmp);
+        }
+
+        //////////////////////////// CRC5 ////////////////////////////
+        std::vector<bool> crc_data = {};
+        uint8_t crc = 0;
+        result = GetNRZIData(node, USB_CRC5_BIT_COUNT, to_extracted_next_data_start_index_,
+                             crc_data);
+        if (!result)
+        {
+            return false;
+        }
+
+        NRBZToNormalData(node, USB_CRC5_BIT_COUNT, crc_data
+                         , crc);
+        crc_sign_num_ = USB_CRC5_BIT_COUNT;
+        crc16_ = crc;
+        WriteLog(LogLevel::LevelDebug, "DecodeTokenBytes = true,crc_sign_num=%d,crc=0x%x"
+                 , crc_sign_num_, crc16_);
+        return true;
+    }
+
+    void USBPacket::DecodeFields(TwoLevelEdgePulse*& node)
+    {
+        switch (packet_type_)  // NOLINT(clang-diagnostic-switch-enum)
+        {
+        case USBEnums::USBPacketType::TOKEN:
+            DecodeFieldsByToken(node);
+            break;
+        case USBEnums::USBPacketType::DATA:
+
+            DecodeFieldsByData(node);
+            break;
+        case USBEnums::USBPacketType::HAND_SHAKE:
+            break;
+        case USBEnums::USBPacketType::SPECIAL:
+            DecodeFieldsBySpecial(node);
+            break;
+        default:
+            break;
+        }
+    }
+
+    void USBPacket::DecodeFieldsByToken(TwoLevelEdgePulse*& node)
+    {
+        if (packet_type_ == USBEnums::USBPacketType::NO_DEFINE)
+        {
+            WriteLog(LogLevel::Level2, "DecodeFieldsByToken error:packetType is NO_DEFINE");
+            return;
+        }
+
+        switch (static_cast<
+            USBEnums::TokenPackageType>(RealPID()))
+        {
+        case USBEnums::TokenPackageType::SOF:
+            PacketTitle = USBEnums::EventInfoTitles::SOF;
+            DecodeTokenBytes(node, USBEnums::TokenPackageType::SOF);
+            break;
+        case USBEnums::TokenPackageType::SETUP:
+            PacketTitle = USBEnums::EventInfoTitles::SETUP;
+            DecodeTokenBytes(node, USBEnums::TokenPackageType::SETUP);
+            break;
+        case USBEnums::TokenPackageType::IN_TYPE:
+            PacketTitle = USBEnums::EventInfoTitles::TIN;
+            DecodeTokenBytes(node, USBEnums::TokenPackageType::IN_TYPE);
+            break;
+        case USBEnums::TokenPackageType::OUT_TYPE:
+            PacketTitle = USBEnums::EventInfoTitles::TOUT;
+            DecodeTokenBytes(node, USBEnums::TokenPackageType::OUT_TYPE);
+            break;
+        // default:
+        //     return;
+        }
+    }
+
+    void USBPacket::DecodeFieldsByData(TwoLevelEdgePulse*& node)
+    {
+        if (packet_type_ == USBEnums::USBPacketType::NO_DEFINE)
+        {
+            WriteLog(LogLevel::Level2, "DecodeFieldsByToken error:packetType is NO_DEFINE");
+            return;
+        }
+        int32_t end_index = packet_sync_.nodePtr->endIndex;
+        std::vector<uint8_t> get_data_tmp = {};
+        switch (auto package_type = static_cast<USBEnums::DataPackageType>(RealPID()))
+        {
+        case USBEnums::DataPackageType::DATA0:
+        case USBEnums::DataPackageType::DATA1:
+            PacketTitle = package_type == USBEnums::DataPackageType::DATA0
+                              ? USBEnums::EventInfoTitles::DATA0
+                              : USBEnums::EventInfoTitles::DATA1;
+            datas_.clear();
+
+            if (max_possible_data_length_ >= 0 && max_possible_data_length_
+                > packet_sync_.Length())
+            {
+                end_index = max_possible_data_length_ + packet_sync_.nodePtr->startIndex;
+            }
+            while (CheckNodeValid(node) && node->startIndex < end_index)
+            {
+                uint8_t data;
+                bool result = DecodeNextByteByDataField(node, data);
+                if (!result)
+                {
+                    WriteLog(LogLevel::Level2, "DecodeFieldsByData DecodeNextByte fail:StartIndex:%d", node->startIndex);
+                    break;
+                }
+                get_data_tmp.push_back(data);
+            }
+            if (get_data_tmp.size() > 2)
+            {
+                //data
+                for (uint64_t i = 0; i < get_data_tmp.size() - 2; i++)
+                {
+                    datas_.push_back(get_data_tmp[i]);
+                }
+                //crc16
+                /* for (uint64_t i = (get_data_tmp.size() - 2); i < get_data_tmp.size(); i++)
+                 {
+                 }*/
+                uint8_t crc16_h = CommonHelper::ReverseOrderBits(get_data_tmp[get_data_tmp.size() - 2]);
+                uint8_t crc16_l = CommonHelper::ReverseOrderBits(get_data_tmp[get_data_tmp.size() - 1]);
+                crc16_ = (static_cast<uint16_t>(crc16_h) << 8) + static_cast<uint16_t>(crc16_l);
+
+                crc_sign_num_ = 16;
+            }
+            else
+            {
+                WriteLog(LogLevel::Level2, "Waring:DecodeFieldsByData Decode DataSize < 2 (%d)", get_data_tmp.size());
+                datas_ = std::move(get_data_tmp);
+            }
+            get_data_tmp.clear();
+            break;
+        case USBEnums::DataPackageType::DATA2:
+            PacketTitle = USBEnums::EventInfoTitles::DATA2;
+            break;
+        case USBEnums::DataPackageType::M_DATA:
+            PacketTitle = USBEnums::EventInfoTitles::MDATA;
+            break;
+        // default:
+        //     break;
+        }
+    }
+
+    void USBPacket::DecodeFieldsBySpecial(TwoLevelEdgePulse*& node) const
+    {
+        //todo
+        if (packet_type_ != USBEnums::USBPacketType::SPECIAL)
+        {
+        }
+    }
+    bool USBPacket::IsTokenPackageType() const
+    {
+        int32_t real_pid = RealPID();
+        if (static_cast<int32_t>(USBEnums::TokenPackageType::IN_TYPE) == real_pid
+            || static_cast<int32_t>(USBEnums::TokenPackageType::OUT_TYPE) == real_pid
+            || static_cast<int32_t>(USBEnums::TokenPackageType::SETUP) == real_pid
+            || static_cast<int32_t>(USBEnums::TokenPackageType::SOF) == real_pid
+        )
+        {
+            return true;
+        }
+        return false;
+    }
+    bool USBPacket::IsSpecialPacketType() const
+    {
+        int32_t real_pid = RealPID();
+        if (static_cast<int32_t>(USBEnums::SpecialPacketType::ERR) == real_pid
+            || static_cast<int32_t>(USBEnums::SpecialPacketType::PING) == real_pid
+            || static_cast<int32_t>(USBEnums::SpecialPacketType::REMAIN) == real_pid
+            || static_cast<int32_t>(USBEnums::SpecialPacketType::SPLIT) == real_pid
+        )
+        {
+            return true;
+        }
+        return false;
+    }
+    bool USBPacket::IsHandshakePackageType(USBEnums::HandshakePackageType& type) const
+    {
+        int32_t real_pid = RealPID();
+        if (static_cast<int32_t>(USBEnums::HandshakePackageType::NYET) == real_pid
+            || static_cast<int32_t>(USBEnums::HandshakePackageType::STALL) == real_pid
+            || static_cast<int32_t>(USBEnums::HandshakePackageType::ACK) == real_pid
+            || static_cast<int32_t>(USBEnums::HandshakePackageType::NAK) == real_pid
+        )
+        {
+            type = static_cast<USBEnums::HandshakePackageType>(real_pid);
+            return true;
+        }
+        return false;
+    }
+    bool USBPacket::IsDataPackageType()
+    {
+        int32_t real_pid = RealPID();
+        if (static_cast<int32_t>(USBEnums::DataPackageType::DATA0) == real_pid
+            || static_cast<int32_t>(USBEnums::DataPackageType::DATA1) == real_pid
+            || static_cast<int32_t>(USBEnums::DataPackageType::DATA2) == real_pid
+            || static_cast<int32_t>(USBEnums::DataPackageType::M_DATA) == real_pid
+        )
+        {
+            to_nrzi_decode_next_data_start_index_ = packet_sync_.endIndex + (packet_sync_.oneByteTimingLength);
+            return true;
+        }
+        return false;
+    }
 }

+ 1 - 1
ProtocolUSB/usb_packet.h

@@ -26,7 +26,7 @@ namespace Protocol
     public:
         USBPacket();
         USBPacket(TwoLevelEdgePulse* pid_node, int32_t& left_over_size, const SYNC& sync, bool polarity,
-                   int32_t max_data_length);
+                  int32_t max_data_length);
 
         USBEnums::USBPacketType Type() const { return packet_type_; }
         uint8_t PID() const { return pid_; }

+ 1 - 1
quantize_params.cpp

@@ -17,7 +17,7 @@ namespace Protocol
     }
 
     QuantizeParams::QuantizeParams(const QuantizeParams& quantize_params): levelOption(quantize_params.levelOption),
-                                                                          BitDepth(quantize_params.BitDepth)
+                                                                           BitDepth(quantize_params.BitDepth)
 
     {
     }