Bläddra i källkod

USB更新 0.1.6

lijinwen 2 månader sedan
förälder
incheckning
d23c063e73

+ 5 - 5
BaseHelper/common_helper.cpp → BaseHelper/common_helper.cc

@@ -18,7 +18,7 @@ namespace Protocol
         {
             throw std::invalid_argument("Array must contain at least two elements.");
         }
-        int32_t first_value = array[0];
+        const int32_t first_value = array[0];
         int32_t max_difference = 0;
         int32_t most_different_index = 0;
 
@@ -42,14 +42,14 @@ namespace Protocol
         return array; // 如果第一个元素不是差异最大的,则返回原数组
     }
 
-    uint8_t CommonHelper::SwapHighLowBits(uint8_t value)
+    uint8_t CommonHelper::SwapHighLowBits(const uint8_t value)
     {
         // 获取低4位
-        uint8_t lowerNibble = value & 0x0F;
+        const uint8_t lower_nibble = value & 0x0F;
         // 获取高4位
-        uint8_t higherNibble = (value >> 4) & 0x0F;
+        const uint8_t higher_nibble = (value >> 4) & 0x0F;
         // 交换高低4位
-        return static_cast<uint8_t>(higherNibble | lowerNibble << 4);
+        return static_cast<uint8_t>(higher_nibble | lower_nibble << 4);
     }
     uint8_t CommonHelper::ReverseOrderBits(uint8_t value)
     {

+ 1 - 1
BaseHelper/data_check_helper.h

@@ -19,7 +19,7 @@ namespace Protocol
     class DataCheckHelper
     {
     public:
-        static bool CheckDataByOddEven(uint8_t data, int32_t dataBitCount, OddEvenCheck checkType);
+        static bool CheckDataByOddEven(uint8_t data, int32_t data_bit_count, OddEvenCheck check_type);
         //比较浮点数是否相等
         static bool CheckDoubleIsEqual(double a, double b);
     };

+ 7 - 7
BaseHelper/datacheckhelper.cpp → BaseHelper/datacheckhelper.cc

@@ -15,23 +15,23 @@
 
 namespace Protocol
 {
-    bool DataCheckHelper::CheckDataByOddEven(uint8_t data, int32_t dataBitCount,
-                                             const OddEvenCheck checkType)
+    bool DataCheckHelper::CheckDataByOddEven(uint8_t data, int32_t data_bit_count,
+                                             const OddEvenCheck check_type)
     {
-        if (checkType == OddEvenCheck::None) return true;
+        if (check_type == OddEvenCheck::None) return true;
         bool temp = false;
 
-        while (dataBitCount > 0)
+        while (data_bit_count > 0)
         {
             temp ^= ((data & 0b01) == 1);
             data >>= 1;
-            dataBitCount--;
+            data_bit_count--;
         }
 
-        if (checkType == OddEvenCheck::Odd) temp = !temp;
+        if (check_type == OddEvenCheck::Odd) temp = !temp;
         return temp;
     }
-    bool DataCheckHelper::CheckDoubleIsEqual(double a, double b)
+    bool DataCheckHelper::CheckDoubleIsEqual(const double a, const double b)
     {
         return fabs(a - b) < FLOAT_EQUAL_EPSILON;
     }

+ 0 - 0
BaseHelper/decode_data_helper.cpp → BaseHelper/decode_data_helper.cc


+ 13 - 13
BaseHelper/loger.cpp → BaseHelper/loger.cc

@@ -16,33 +16,33 @@ namespace Protocol
 
     Loger::Loger()
     {
-        LogPath_ = "./DecoderLogs/";
-        if (!Fs::exists(LogPath_))
+        logPath_ = "./DecoderLogs/";
+        if (!Fs::exists(logPath_))
         {
-            Fs::create_directories(LogPath_);
+            Fs::create_directories(logPath_);
         }
         // Generate the log file name with the current date.
         time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
         tm now_tm;
         localtime_s(&now_tm, &now); // 使用线程安全的localtime_s
         std::stringstream log_file_name_stream;
-        log_file_name_stream << LogPath_ << "2024." << std::put_time(&now_tm, "%m.%d") << ".log";
-        LogFileName_ = log_file_name_stream.str();
+        log_file_name_stream << logPath_ << "2024." << std::put_time(&now_tm, "%m.%d") << ".log";
+        logFileName_ = log_file_name_stream.str();
 
-        LogFile_.open(LogFileName_, std::ios::out | std::ios::app);
+        logFile_.open(logFileName_, std::ios::out | std::ios::app);
     }
 
     void Loger::Log(const std::string& message)
     {
         std::lock_guard<std::mutex> lock(instanceMutex_); // 锁定以保证线程安全
-        time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
+        const time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
         tm now_tm;
         localtime_s(&now_tm, &now); // 使用线程安全的localtime_s
 
         std::stringstream time_stream;
         time_stream << std::put_time(&now_tm, "%Y-%m-%d %X");
 
-        std::ofstream& logFile = instance_.LogFile_;
+        std::ofstream& logFile = instance_.logFile_;
         if (logFile.is_open())
         {
             logFile << "[" << time_stream.str() << "] - " << message << std::endl;
@@ -52,16 +52,16 @@ namespace Protocol
 
     Loger::~Loger()
     {
-        if (LogFile_.is_open())
+        if (logFile_.is_open())
         {
-            LogFile_.close();
+            logFile_.close();
         }
     }
 
-    void WriteLog(LogLevel level, const char* format, ...)
+    void WriteLog(const LogLevel level, const char* format, ...)
     {
-        if (Loger::LogLevel != LogLevel::All
-            && (Loger::LogLevel == LogLevel::Close || level > Loger::LogLevel))
+        if (Loger::logLevel != LogLevel::All
+            && (Loger::logLevel == LogLevel::Close || level > Loger::logLevel))
         {
             return;
         }

+ 53 - 0
BaseHelper/loger.h

@@ -0,0 +1,53 @@
+// // ******************************************************************
+// //       /\ /|       @File         Loger.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-06-24
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+
+#include <iostream>
+#include <fstream>
+#include <mutex>
+#include <filesystem>
+#include <string>
+
+#include <chrono>
+#include <cstdarg>
+#include <iomanip>
+#include <sstream>
+#include <cstdlib> // 对于std::put_time的tm结构体定义
+
+#include "../BaseEnums/loger_enums.h"
+
+namespace Fs = std::filesystem;
+
+namespace Protocol
+{
+    class Loger
+    {
+    public:
+        Loger();
+
+        static void Log(const std::string& message);
+
+        ~Loger();
+
+        inline static auto logLevel = LogLevel::All;
+
+    private:
+        std::string logPath_;
+        std::string logFileName_; // The full path and filename of the log file.
+        std::ofstream logFile_;
+        static std::mutex instanceMutex_;
+        static Loger instance_;
+
+        Loger(const Loger&) = delete;
+        Loger& operator=(const Loger&) = delete;
+    };
+
+    void WriteLog(LogLevel level, const char* format, ...);
+}

+ 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.cc" />
+    <ClCompile Include="BaseHelper\datacheckhelper.cc" />
+    <ClCompile Include="BaseHelper\decode_data_helper.cc" />
+    <ClCompile Include="BaseHelper\loger.cc" />
+    <ClCompile Include="decode_event.cc" />
+    <ClCompile Include="decode_result.cc" />
+    <ClCompile Include="dllmain.cc" />
+    <ClCompile Include="edge_pulse.cc" />
+    <ClCompile Include="edge_pulse_data.cc" />
+    <ClCompile Include="export_method.cc" />
+    <ClCompile Include="ProtocolRS232\rs232_decode.cc" />
+    <ClCompile Include="ProtocolRS232\rs232_decodeevent.cc" />
+    <ClCompile Include="ProtocolRS232\rs232_decoderesult.cc" />
+    <ClCompile Include="ProtocolRS232\rs232_packet.cc" />
+    <ClCompile Include="ProtocolUSB\constants.cc" />
+    <ClCompile Include="ProtocolUSB\usb_decoder.cc" />
+    <ClCompile Include="ProtocolUSB\usb_decode_event.cc" />
+    <ClCompile Include="ProtocolUSB\usb_decode_result.cc" />
+    <ClCompile Include="ProtocolUSB\usb_packet.cc" />
+    <ClCompile Include="protocol_decode_base.cc" />
+    <ClCompile Include="quantize_params.cc" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
 </Project>

+ 2 - 2
ProtocolRS232/rs232_decode.cpp → ProtocolRS232/rs232_decode.cc

@@ -22,7 +22,7 @@ namespace Protocol
 
 
     int32_t getStartIndex(const ProtocolRS232Options& options, TwoLevelEdgePulse*& node,
-                          double count,
+                          const double count,
                           double& realCount,
                           const int32_t startIndex,
                           TwoLevelEdgePulseStatusType& startStatus)
@@ -406,7 +406,7 @@ namespace Protocol
     }
 
     bool getRS232Bit(TwoLevelEdgePulse*& edge_pulse,
-                     int32_t targetIndex, TwoLevelEdgePulseStatusType& status)
+                     const int32_t targetIndex, TwoLevelEdgePulseStatusType& status)
     {
         status = TwoLevelEdgePulseStatusType::None;
         if (edge_pulse == nullptr)

+ 0 - 0
ProtocolRS232/rs232_decodeevent.cpp → ProtocolRS232/rs232_decodeevent.cc


+ 0 - 0
ProtocolRS232/rs232_decoderesult.cpp → ProtocolRS232/rs232_decoderesult.cc


+ 0 - 0
ProtocolRS232/rs232_packet.cpp → ProtocolRS232/rs232_packet.cc


+ 6 - 6
ProtocolUSB/SYNC.h

@@ -34,7 +34,7 @@ namespace Protocol
             return packetEndIndex;
         }
 
-        void SetPacketEndIndex(int value)
+        void SetPacketEndIndex(const int value)
         {
             packetEndIndex = value;
         }
@@ -43,11 +43,11 @@ namespace Protocol
         {
         }
 
-        SYNC(TwoLevelEdgePulse* node_ptr, int end_index, int single_bit_timing_length,bool is_high_speed) : nodePtr(node_ptr),
-            endIndex(end_index),
-            singleBitTimingLength(single_bit_timing_length),
-            oneByteTimingLength(single_bit_timing_length * USB_BYTE_BIT_COUNT),
-            packetEndIndex(0)
+        SYNC(TwoLevelEdgePulse* node_ptr, const int end_index, const int single_bit_timing_length, const bool is_high_speed) : nodePtr(node_ptr),
+                                                                                                                               endIndex(end_index),
+                                                                                                                               singleBitTimingLength(single_bit_timing_length),
+                                                                                                                               oneByteTimingLength(single_bit_timing_length * USB_BYTE_BIT_COUNT),
+                                                                                                                               packetEndIndex(0)
         {
             int32_t sync_byte_len = is_high_speed ? USB_USB_SYNC_BIT_MAX_LEN : USB_BYTE_BIT_COUNT;
             int32_t fix_sync_end_index = node_ptr->startIndex + static_cast<int32_t>(single_bit_timing_length * sync_byte_len

+ 0 - 0
ProtocolUSB/constants.cpp → ProtocolUSB/constants.cc


+ 1 - 0
ProtocolUSB/constants.h

@@ -28,6 +28,7 @@ namespace Protocol
     //NRZI 连续补位/个数
     constexpr int32_t USB_NRZI_COMPLEMENT_PER_NUM = 6;
 
+    constexpr int32_t USB_IDLE_MIN_BIT_LEN = 8;
     constexpr int32_t USB_BYTE_BIT_COUNT = 8;
     constexpr double USB_LOW_SPEED_MHZ = 1.5;
     constexpr double USB_FULL_SPEED_MHZ = 12;

+ 0 - 0
ProtocolUSB/usb_decode_event.cpp → ProtocolUSB/usb_decode_event.cc


+ 0 - 0
ProtocolUSB/usb_decode_result.cpp → ProtocolUSB/usb_decode_result.cc


+ 138 - 47
ProtocolUSB/usb_decoder.cpp → ProtocolUSB/usb_decoder.cc

@@ -99,7 +99,7 @@ namespace Protocol
         return false;
     }
 
-    bool USBDecoder::ParseSingleData(double set_bit_time_span, bool auto_clock)
+    bool USBDecoder::ParseSingleData(double set_bit_time_span, const bool auto_clock)
     {
         if (signEdgePulse_.empty()) return false;
         WriteLog(LogLevel::Level2, "ParseSingleData start");
@@ -112,41 +112,52 @@ namespace Protocol
         }
         int32_t left_data_size = static_cast<int32_t>(signEdgePulse_.size());
         //找数据包
-        if (FindPackets(left_data_size, usb_packets_, set_bit_time_span))
+        if (FindPackets(left_data_size, usb_packets_, set_bit_time_span) && !usb_packets_.empty())
         {
-            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;
         }
-        WriteLog(LogLevel::Level2, "ParseSingleData done");
-        return true;
+        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;
+            }
+            else
+            {
+                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;
+            }
+        }
+        return false;
     }
-    bool USBDecoder::CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, double threshold)
+    bool USBDecoder::CheckTimeDifferenceWithinThreshold(const double* array, const 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];
+            const double difference = std::abs(array[i] - array[i - 1]);
+            const double percentage_difference = difference / array[i - 1];
             if (difference < 50)
             {
                 if (isAutoClk_ || usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED)
@@ -167,18 +178,19 @@ namespace Protocol
 
         return true; // 所有元素之间的差异都小于阈值
     }
-    bool USBDecoder::CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, int32_t avg_span, double threshold)
+    bool USBDecoder::CheckTimeDifferenceWithinThreshold(const double* array, const int32_t size, const 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;
+            const double difference1 = std::abs(array[i] - avg_span);
+            const double percentage_difference1 = difference1 / avg_span;
 
-            double difference2 = std::abs(array[i] - array[i - 1]);
-            double percentage_difference2 = difference2 / array[i - 1];
+            const double difference2 = std::abs(array[i] - array[i - 1]);
+            const double percentage_difference2 = difference2 / array[i - 1];
             if (difference2 < 50)
             {
                 if (isAutoClk_ || usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED)
@@ -200,7 +212,7 @@ namespace Protocol
         return true; // 所有元素之间的差异都小于阈值
     }
 
-    void USBDecoder::ClearEdgeArray(Edge* edges, int32_t size)
+    void USBDecoder::ClearEdgeArray(Edge* edges, const int32_t size)
     {
         for (int i = 0; i < size; ++i)
         {
@@ -209,7 +221,7 @@ namespace Protocol
     }
 
     //检查同步域边沿
-    bool USBDecoder::CheckSyncEdges(Edge start_edge, const Edge* edges)
+    bool USBDecoder::CheckSyncEdges(const Edge start_edge, const Edge* edges)
     {
         return edges[0] != edges[1] && edges[0] == start_edge && edges[0] == edges[6];
     }
@@ -221,7 +233,7 @@ namespace Protocol
         {
             return false;
         }
-        auto start_indexs = new int32_t[count + 1];
+        const auto start_indexs = new int32_t[count + 1];
         avg_spans = 0;
         if ((node - 1) != nullptr)
         {
@@ -249,7 +261,7 @@ namespace Protocol
             return false;
         }
 
-        auto tmp_spans = new double[count - 1];
+        const 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]);
@@ -265,14 +277,71 @@ namespace Protocol
         return CheckTimeDifferenceWithinThreshold(tmp_spans, count - 1);
     }
 
+    //bool USBDecoder::GetPolarty(TwoLevelEdgePulse* node, double set_bit_time_span, int& last_valid_data_index)
+    bool USBDecoder::GetPolarty(TwoLevelEdgePulse* node, const double set_bit_time_span)
+    {
+        TwoLevelEdgePulse* max_length_node = new TwoLevelEdgePulse();
+        double time_length_threshold = 0;
+        //last_valid_data_index = -1;
+
+        if (node->startIndex > 0)
+        {
+            max_length_node->startIndex = 0;
+            max_length_node->endIndex = node->startIndex;
+            max_length_node->CurrentLevel = node->CurrentLevel == TwoLevelEdgePulseStatusType::Low
+                                                ? TwoLevelEdgePulseStatusType::High
+                                                : TwoLevelEdgePulseStatusType::Low;
+        }
+        else
+        {
+            max_length_node = node;
+        }
+
+        if (set_bit_time_span > 0)
+        {
+            time_length_threshold = USB_USB_SYNC_BIT_MAX_LEN * set_bit_time_span;
+        }
+        while (node != nullptr)
+        {
+            if (canceled)
+            {
+                WriteLog(LogLevel::Level2, "AsyncFunction canceled");
+                return false;
+            }
+            const int32_t node_len = node->GetLength();
+            if ((max_length_node->GetLength() < node_len) || (time_length_threshold > 0 && node_len > time_length_threshold))
+            {
+                max_length_node = node;
+            }
+            /*if ((time_length_threshold > 0 && node_len > time_length_threshold) || node_len >= max_length_node->GetLength())
+            {
+                last_valid_data_index = node->startIndex;
+            }
+            else
+            {
+                last_valid_data_index = node->endIndex;
+            }*/
+
+            node++;
+            if (node->startIndex < 0 || node->endIndex < 0
+                || node->startIndex > node->endIndex || node->LevelCount() <= 0)
+            {
+                WriteLog(LogLevel::LevelDebug, "GetPolarty break");
+                break;
+            }
+        }
+
+        return max_length_node->CurrentLevel == TwoLevelEdgePulseStatusType::Low;
+    }
+
     // 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)
+                                  , const double set_bit_time_span, const bool polarity, int32_t& last_valid_data_index)
     {
         all_sync.clear();
         int first_avg_span = 0;
-
+        last_valid_data_index = -1;
         if (node == nullptr || node - 1 == nullptr)
         {
             return false;
@@ -281,8 +350,8 @@ namespace Protocol
         // {
         //     syncBitLen_ = USB_USB_SYNC_BIT_NORMAL_SPEED_LEN;
         // }
-        Edge next_edge = polarity ? Edge::Rise : Edge::Falling;
-        Edge start_edge = next_edge;
+        const Edge next_edge = polarity ? Edge::Rise : Edge::Falling;
+        const Edge start_edge = next_edge;
 
         TwoLevelEdgePulse* start_info_node = nullptr;
         Edge tmp_edges[USB_USB_SYNC_BIT_MAX_LEN];
@@ -307,9 +376,13 @@ namespace Protocol
                 break;
             }
             //可能找到目标头
-            if (first_avg_span != 0 && tmp_node->GetLength() > first_avg_span * 8)
+            if (first_avg_span != 0 && tmp_node->GetLength() > first_avg_span * USB_IDLE_MIN_BIT_LEN)
             {
                 tmp_edge_count = 0;
+                if (tmp_node->startIndex > 0)
+                {
+                    last_valid_data_index = tmp_node->startIndex;
+                }
             }
 
             if (tmp_edge_count <= syncBitLen_ - 1)
@@ -376,16 +449,19 @@ namespace Protocol
         return !all_sync.empty();
     }
 
+
     bool USBDecoder::FindPackets(int32_t& left_over_size,
-                                 std::vector<USBPacket>& all_packet, double set_bit_time_span,
-                                 bool polarity)
+                                 std::vector<USBPacket>& all_packet, const double set_bit_time_span)
     {
         TwoLevelEdgePulse* node = signEdgePulse_.data();
         all_packet.clear();
         std::vector<SYNC> all_sync;
-
+        //int last_valid_data_index = -1;
+        //bool polarity = GetPolarty(node, set_bit_time_span, last_valid_data_index);
+        const bool polarity = GetPolarty(node, set_bit_time_span);
+        int32_t last_valid_data_index = -1;
         //找的全部同步帧
-        if (!FindAllSyncs(node, all_sync, set_bit_time_span, polarity) || all_sync.empty())
+        if (!FindAllSyncs(node, all_sync, set_bit_time_span, polarity, last_valid_data_index) || all_sync.empty())
         {
             return false;
         }
@@ -414,14 +490,29 @@ namespace Protocol
                 //如果存在后续同步帧,用下个同步帧头-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;
+                    const TwoLevelEdgePulse* tmp_node = (all_sync[all_packet.size() + 1].nodePtr - 1);
+                    if (set_bit_time_span > 0 && tmp_node->GetLength() > USB_BYTE_BIT_COUNT * set_bit_time_span)
+                    {
+                        eop_index = tmp_node->startIndex;
+                    }
+                    else
+                    {
+                        eop_index = (all_sync[all_packet.size() + 2].nodePtr - 1)->startIndex;
+                    }
                 }
                 else
                 {
-                    eop_index = waveMaxTimeIndexLen_;
+                    if (last_valid_data_index > 0 && last_valid_data_index < waveMaxTimeIndexLen_)
+                    {
+                        eop_index = last_valid_data_index;
+                    }
+                    else
+                    {
+                        eop_index = waveMaxTimeIndexLen_;
+                    }
                 }
             }
-            int32_t packetMaxTimeLen = eop_index - sync.nodePtr->startIndex;
+            const int32_t packetMaxTimeLen = eop_index - sync.nodePtr->startIndex;
             if (packetMaxTimeLen <= 0)
             {
                 WriteLog(LogLevel::Level2, "FindPackets Warning: packetMaxTimeLen <= 0");
@@ -480,8 +571,8 @@ namespace Protocol
         }
         else
         {
-            auto edge_pulses_size1 = static_cast<double>(edge_pulses_dp.size());
-            auto edge_pulses_size2 = static_cast<double>(edge_pulses_dm.size());
+            const auto edge_pulses_size1 = static_cast<double>(edge_pulses_dp.size());
+            const 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

+ 6 - 4
ProtocolUSB/usb_decoder.h

@@ -79,6 +79,9 @@ namespace Protocol
         bool CheckTimeDifferenceWithinThreshold(const double* array, int32_t size,
                                                 double threshold = USB_TIME_DIFFERENCE_THRESHOLD);
 
+        //bool GetPolarty(TwoLevelEdgePulse* node, double set_bit_time_span, int& last_valid_data_index);
+        bool GetPolarty(TwoLevelEdgePulse* node, double set_bit_time_span);
+
         static void ClearEdgeArray(Edge* edges, int32_t size);
 
         static bool CheckSyncEdges(Edge start_edge, const Edge* edges);
@@ -92,14 +95,13 @@ namespace Protocol
         // 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);
+                          , double set_bit_time_span, bool polarity, int32_t& last_valid_data_index);
 
         // 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);
+                         std::vector<USBPacket>& all_packet, double set_bit_time_span);
         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);

+ 11 - 11
ProtocolUSB/usb_packet.cpp → ProtocolUSB/usb_packet.cc

@@ -26,7 +26,7 @@ namespace Protocol
     }
 
     USBPacket::USBPacket(TwoLevelEdgePulse* pid_node, int32_t& left_over_size, const SYNC& sync
-                         , bool polarity, int32_t max_data_length)
+                         , const bool polarity, const int32_t max_data_length)
     {
         this->polarity_ = polarity;
         packet_sync_ = sync;
@@ -61,7 +61,7 @@ namespace Protocol
         DecodeFields(tmp_pid_node);
     }
 
-    bool USBPacket::CheckNibblesInverse(uint8_t value)
+    bool USBPacket::CheckNibblesInverse(const 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);
@@ -130,7 +130,7 @@ namespace Protocol
         return true;
     }
 
-    bool USBPacket::GetNRZIData(TwoLevelEdgePulse*& node, int32_t need_bit_count, int32_t start_index,
+    bool USBPacket::GetNRZIData(TwoLevelEdgePulse*& node, const int32_t need_bit_count, int32_t start_index,
                                 std::vector<bool>& out_data)
     {
         if (!CheckNodeValid(node))
@@ -292,7 +292,7 @@ namespace Protocol
     }
 
     void USBPacket::NRBZToNormalData(const TwoLevelEdgePulse* node,
-                                     int32_t need_bit_count, std::vector<bool> nrzi_data, uint8_t& out_data)
+                                     const 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++)
@@ -311,7 +311,7 @@ namespace Protocol
         //out_data = CommonHelper::ReverseOrderBits(out_data);
     }
     //NRZI解码下个字节
-    bool USBPacket::DecodeNextByte(TwoLevelEdgePulse*& node, int32_t start_index, uint8_t& out_data)
+    bool USBPacket::DecodeNextByte(TwoLevelEdgePulse*& node, const int32_t start_index, uint8_t& out_data)
     {
         out_data = 0;
         constexpr int32_t need_bit_count = 8;
@@ -324,7 +324,7 @@ namespace Protocol
         NRBZToNormalData(node, need_bit_count, nrzi_data, out_data);
         return true;
     }
-    bool USBPacket::DecodeTokenBytes(TwoLevelEdgePulse*& node, USBEnums::TokenPackageType type)
+    bool USBPacket::DecodeTokenBytes(TwoLevelEdgePulse*& node, const USBEnums::TokenPackageType type)
     {
         bool is_sof_type = type == USBEnums::TokenPackageType::SOF;
         bool result;
@@ -480,7 +480,7 @@ namespace Protocol
             if (max_possible_data_length_ >= 0 && max_possible_data_length_
                 > packet_sync_.Length())
             {
-                end_index = max_possible_data_length_ + packet_sync_.nodePtr->startIndex;
+                end_index = max_possible_data_length_ + packet_sync_.nodePtr->startIndex - packet_sync_.singleBitTimingLength /2;
             }
             while (CheckNodeValid(node) && node->startIndex < end_index)
             {
@@ -493,10 +493,10 @@ namespace Protocol
                 }
                 get_data_tmp.push_back(data);
             }
-            if (get_data_tmp.size() > 2)
+            if (get_data_tmp.size() > 3)
             {
                 //data
-                for (uint64_t i = 0; i < get_data_tmp.size() - 2; i++)
+                for (uint64_t i = 0; i < get_data_tmp.size() - 3; i++)
                 {
                     datas_.push_back(get_data_tmp[i]);
                 }
@@ -504,8 +504,8 @@ namespace Protocol
                 /* 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]);
+                uint8_t crc16_h = CommonHelper::ReverseOrderBits(get_data_tmp[get_data_tmp.size() - 3]);
+                uint8_t crc16_l = CommonHelper::ReverseOrderBits(get_data_tmp[get_data_tmp.size() - 2]);
                 crc16_ = (static_cast<uint16_t>(crc16_h) << 8) + static_cast<uint16_t>(crc16_l);
 
                 crc_sign_num_ = 16;

+ 1 - 1
ProtocolUSB/usb_packet.h

@@ -30,7 +30,7 @@ namespace Protocol
 
         USBEnums::USBPacketType Type() const { return packet_type_; }
         uint8_t PID() const { return pid_; }
-        void SetPID(uint8_t value) { pid_ = value; }
+        void SetPID(const uint8_t value) { pid_ = value; }
         bool LastNRBZDataBit() const { return last_nrbz_data_bit_; }
         uint8_t RealPID() const { return static_cast<uint8_t>(pid_ & 0xF); }
         //const std::type_info& PIDType() const { return pidType; }

+ 0 - 0
decode_event.cpp → decode_event.cc


+ 0 - 0
decode_result.cpp → decode_result.cc


+ 1 - 1
dllmain.cpp → dllmain.cc

@@ -11,7 +11,7 @@
 
 //核心的入口函数,动态链接库入口函数
 BOOL APIENTRY DllMain(HMODULE hModule, //APIENTRY可以换成WINAPI、__stdcall和CALLBACK,是一种调用约定
-                      DWORD ul_reason_for_call,
+                      const DWORD ul_reason_for_call,
                       LPVOID lpReserved
 )
 //hModule:DLL模块的句柄	   ul_reason_for_call:DLL模块被调用的原因	lpReserved:保留参数,没有意义,windows不想让我们知道的参数	

+ 2 - 2
edge_pulse.cpp → edge_pulse.cc

@@ -26,7 +26,7 @@ namespace Protocol
         return static_cast<ThreeLevelEdgePulseStatusType>((high_level ? 1 : 0) << 1 | (low_loglevel ? 1 : 0));
     }
 
-    ThreeLevelEdgePulse::ThreeLevelEdgePulse(ThreeLevelEdgePulseStatusType current)
+    ThreeLevelEdgePulse::ThreeLevelEdgePulse(const ThreeLevelEdgePulseStatusType current)
     {
         CurrentLevel = current;
     }
@@ -39,7 +39,7 @@ namespace Protocol
         }
         return CheckNodeValid(edge[0]);
     }
-    bool CheckNodeValid(EdgePulse edge)
+    bool CheckNodeValid(const EdgePulse edge)
     {
         if (edge.startIndex < 0 || edge.endIndex < 0 || edge.endIndex <= edge.startIndex
             || edge.edge == Edge::None)

+ 5 - 5
edge_pulse_data.cpp → edge_pulse_data.cc

@@ -13,16 +13,16 @@ namespace ProtocolBase
 {
 }
 
-Protocol::EdgePulseDataTwoLevels::EdgePulseDataTwoLevels(uint64_t edge_pulses_count, uint64_t data_count,
-                                                         double sample_rate,
+Protocol::EdgePulseDataTwoLevels::EdgePulseDataTwoLevels(const uint64_t edge_pulses_count, const uint64_t data_count,
+                                                         const double sample_rate,
                                                          EdgePulse* edge_pulses_ptr): EdgePulseData(
     edge_pulses_count, data_count, sample_rate, edge_pulses_ptr)
 {
 }
 
-Protocol::EdgePulseDataThreeLevels::EdgePulseDataThreeLevels(uint64_t edge_pulses_count, uint64_t data_count,
-                                                             double sample_rate,
+Protocol::EdgePulseDataThreeLevels::EdgePulseDataThreeLevels(const uint64_t edge_pulses_count, const uint64_t data_count,
+                                                             const double sample_rate,
                                                              EdgePulse* edge_pulses_ptr): EdgePulseData(edge_pulses_count,
-    data_count, sample_rate, edge_pulses_ptr)
+                                                                                                        data_count, sample_rate, edge_pulses_ptr)
 {
 }

+ 1 - 1
edge_pulse_data.h

@@ -29,7 +29,7 @@ namespace Protocol
          */
         double sampleRate;
 
-        EdgePulseData(uint64_t edge_pulses_count, uint64_t data_count, double sample_rate,
+        EdgePulseData(const uint64_t edge_pulses_count, const uint64_t data_count, const double sample_rate,
                       EdgePulse* edge_pulses_ptr)
             : waveformDataCount(data_count),
               edgePulsesCount(edge_pulses_count),

+ 1 - 1
export_method.cpp → export_method.cc

@@ -15,7 +15,7 @@ namespace Protocol
 {
     //静态方式 对象只有放在全局
     USBDecoder usb_decode = {};
-    bool Parse_USB(UsbDecodeOptions option, const EdgePulseDataTwoLevels& edge_pluses_data1,
+    bool ParseUSB(UsbDecodeOptions option, const EdgePulseDataTwoLevels& edge_pluses_data1,
                    const EdgePulseDataTwoLevels& edge_pluses_data2, UsbDecodeResult& result)
     {
         return usb_decode.DecodeUSB(option, edge_pluses_data1, edge_pluses_data2, result);

+ 2 - 2
export_method.h

@@ -26,7 +26,7 @@
 namespace Protocol
 {
     extern "C" {
-    LIBMATH_API bool Parse_USB(UsbDecodeOptions option, const EdgePulseDataTwoLevels& edge_pluses_data1,
+    LIBMATH_API bool ParseUSB(UsbDecodeOptions option, const EdgePulseDataTwoLevels& edge_pluses_data1,
                                const EdgePulseDataTwoLevels& edge_pluses_data2, UsbDecodeResult& result);
 
 
@@ -39,7 +39,7 @@ namespace Protocol
     //                                            rs232_decode_result& decodeResult);
 
 
-    inline LIBMATH_API void SetCancellationSignal(bool value)
+    inline LIBMATH_API void SetCancellationSignal(const bool value)
     {
         canceled = value;
     }

+ 4 - 4
protocol_decode_base.cpp → protocol_decode_base.cc

@@ -20,16 +20,16 @@ namespace Protocol
 
 }
 
-void getVersionExport(uint8_t* version)
+void GetVersionExport(uint8_t* version)
 {
 #ifdef  DLL_VERSION
     // 将字符串转换为字符数组
-    constexpr char versionString[] = DLL_VERSION;
+    constexpr char version_string[] = DLL_VERSION;
 
     // 遍历字符串,将其转换为字节数组
-    for (size_t i = 0; i < sizeof(versionString); ++i)
+    for (size_t i = 0; i < sizeof(version_string); ++i)
     {
-        version[i] = static_cast<unsigned char>(versionString[i]);
+        version[i] = static_cast<unsigned char>(version_string[i]);
     }
 #else
     version[0] = 0;

+ 1 - 1
protocol_decode_base.h

@@ -20,7 +20,7 @@
 #include "BaseEnums/protocol_enums.h"
 #include "BaseHelper/Loger.h"
 
-#define DLL_VERSION "0.1.5"
+#define DLL_VERSION "0.1.6"
 
 namespace Protocol
 {

+ 0 - 0
quantize_params.cpp → quantize_params.cc


BIN
x64/Debug/ProtocolDecoder.dll


BIN
x64/Debug/ProtocolDecoder.pdb