Browse Source

静态初版232

lijinwen 4 months ago
commit
2ff338b055

+ 257 - 0
BaseEnums/Channels.h

@@ -0,0 +1,257 @@
+// // ******************************************************************
+// //       /\ /|       @File         Channels.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+namespace Protocol
+{
+    // 24.5弃用
+    // enum class ChannelId
+    // {
+    //     C1 = 0,
+    //     C2,
+    //     C3,
+    //     C4,
+    //     C5,
+    //     C6,
+    //     C7,
+    //     C8,
+    //     M1 = 100,
+    //     M2,
+    //     M3,
+    //     M4,
+    //     M5,
+    //     M6,
+    //     M7,
+    //     M8,
+    //     M9,
+    //     M10,
+    //     M11,
+    //     M12,
+    //     M13,
+    //     M14,
+    //     M15,
+    //     M16,
+    //     M17,
+    //     M18,
+    //     M19,
+    //     M20,
+    //     M21,
+    //     M22,
+    //     M23,
+    //     M24,
+    //     M25,
+    //     M26,
+    //     M27,
+    //     M28,
+    //     M29,
+    //     M30,
+    //     M31,
+    //     M32,
+    //     M33,
+    //     M34,
+    //     M35,
+    //     M36,
+    //     M37,
+    //     M38,
+    //     M39,
+    //     M40,
+    //     M41,
+    //     M42,
+    //     M43,
+    //     M44,
+    //     M45,
+    //     M46,
+    //     M47,
+    //     M48,
+    //     R1 = 200,
+    //     R2,
+    //     R3,
+    //     R4,
+    //     R5,
+    //     R6,
+    //     R7,
+    //     R8,
+    //     R9,
+    //     R10,
+    //     R11,
+    //     R12,
+    //     R13,
+    //     R14,
+    //     R15,
+    //     R16,
+    //     B1 = 300,
+    //     B2,
+    //     D0 = 400,
+    //     D1,
+    //     D2,
+    //     D3,
+    //     D4,
+    //     D5,
+    //     D6,
+    //     D7,
+    //     D8,
+    //     D9,
+    //     D10,
+    //     D11,
+    //     D12,
+    //     D13,
+    //     D14,
+    //     D15,
+    //     D16,
+    //     D17,
+    //     D18,
+    //     D19,
+    //     D20,
+    //     D21,
+    //     D22,
+    //     D23,
+    //     D24,
+    //     D25,
+    //     D26,
+    //     D27,
+    //     D28,
+    //     D29,
+    //     D30,
+    //     D31,
+    //     D32,
+    //     D33,
+    //     D34,
+    //     D35,
+    //     D36,
+    //     D37,
+    //     D38,
+    //     D39,
+    //     D40,
+    //     D41,
+    //     D42,
+    //     D43,
+    //     D44,
+    //     D45,
+    //     D46,
+    //     D47,
+    //     D48,
+    //     D49,
+    //     D50,
+    //     D51,
+    //     D52,
+    //     D53,
+    //     D54,
+    //     D55,
+    //     D56,
+    //     D57,
+    //     D58,
+    //     D59,
+    //     D60,
+    //     D61,
+    //     D62,
+    //     D63,
+    //     // D64,
+    //     P1 = 1100,
+    //     P2,
+    //     P3,
+    //     P4,
+    //     P5,
+    //     P6,
+    //     P7,
+    //     P8,
+    //     P9,
+    //     P10,
+    //     P11,
+    //     P12,
+    //     P13,
+    //     P14,
+    //     P15,
+    //     P16,
+    //     AWG1 = 1200,
+    //     AWG2,
+    //     AWG3,
+    //     AWG4,
+    //     DVM = 1240,
+    //     CYM = 1245,
+    //     Ext = 1250,
+    //
+    //     Ext5,
+    //     AC,
+    //     AuxIn,
+    //     //Assign them to logical RF channel like math
+    //     RF1 = 1300,
+    //     RF2,
+    //     RF3,
+    //     RF4,
+    //     RF5,
+    //     RF6,
+    //     RF7,
+    //     RF8,
+    //     //Assign 'RF' to independent phisical RF channel
+    //     RF,
+    //     AVT1 = 1400,
+    //     AVT2,
+    //     AVT3,
+    //     AVT4,
+    //     AVT5,
+    //     AVT6,
+    //     AVT7,
+    //     AVT8,
+    //     AVT,
+    //     PVT1 = 1500,
+    //     PVT2,
+    //     PVT3,
+    //     PVT4,
+    //     PVT5,
+    //     PVT6,
+    //     PVT7,
+    //     PVT8,
+    //     PVT,
+    //     PVF1 = 1600,
+    //     PVF2,
+    //     PVF3,
+    //     PVF4,
+    //     PVF5,
+    //     PVF6,
+    //     PVF7,
+    //     PVF8,
+    //     PVF,
+    //     PGD1 = 1700,
+    //     PGD2,
+    //     PGD3,
+    //     PGD4,
+    //     PGD5,
+    //     PGD6,
+    //     PGD7,
+    //     PGD8,
+    //     PGD,
+    //     TVF1 = 1800,
+    //     TVF2,
+    //     TVF3,
+    //     TVF4,
+    //     TVF5,
+    //     TVF6,
+    //     TVF7,
+    //     TVF8,
+    //     TVF,
+    //     FVT1 = 1900,
+    //     FVT2,
+    //     FVT3,
+    //     FVT4,
+    //     FVT5,
+    //     FVT6,
+    //     FVT7,
+    //     FVT8,
+    //     FVT,
+    //     USER = 2000,
+    //     POWER1 = 2100,
+    //     POWER2,
+    //     POWER3,
+    //     POWER4,
+    //     POWER5,
+    //     POWER6,
+    //     POWER7,
+    //     POWER8,
+    // };
+}

+ 20 - 0
BaseEnums/DataCheckEnums.h

@@ -0,0 +1,20 @@
+// // ******************************************************************
+// //       /\ /|       @File         DataCheckEnums.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+
+namespace Protocol
+{
+    enum class OddEvenCheck:int32_t
+    {
+        None = 0,
+        Odd,
+        Even
+    };
+}

+ 35 - 0
BaseEnums/EdgePulseEnums.h

@@ -0,0 +1,35 @@
+// // ******************************************************************
+// //       /\ /|       @File         EdgePulseEnums.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <cstdint>
+
+namespace Protocol
+{
+    enum class ThreeLevelEdgePulseStatusType : uint8_t
+    {
+        High = 0b11,
+        Middle = 0b01,
+        Low = 0b00,
+        None = 0b10,
+    };
+
+    enum class TwoLevelEdgePulseStatusType
+    {
+        Low,
+        High,
+        None,
+    };
+
+    enum class SignType
+    {
+        SingleEnded,
+        Diff
+    };
+}

+ 28 - 0
BaseEnums/LogerEnums.h

@@ -0,0 +1,28 @@
+// // ******************************************************************
+// //       /\ /|       @File         LogerEnums.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <cstdint>
+
+namespace Protocol
+{
+    enum class LogLevel : int32_t
+    {
+        //关闭所有日志
+        Close = 0,
+        //日常-少
+        Level1,
+        //日常-多
+        Level2,
+        //调试日志
+        LevelDebug,
+        //开启所有日志
+        All,
+    };
+};

+ 149 - 0
BaseEnums/ProtocolEnums.h

@@ -0,0 +1,149 @@
+// // ******************************************************************
+// //       /\ /|       @File         ProtocolEnums.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <iostream>
+#include <unordered_map>
+
+namespace Protocol
+{
+    // 公共枚举,表示解码的状态
+    enum class ProtocolStatus: int32_t
+    {
+        Success,
+        QuantizeFailure,
+        QuantizeInProgress,
+        DecodeFailure,
+        DecodeInProgress,
+        Canceled
+    };
+
+    enum class Edge: int32_t
+    {
+        None,
+        Falling,
+        Rise,
+    };
+
+    enum class ProtocolClass: int32_t
+    {
+        Other,
+        Serial,
+        Parallel,
+    };
+
+    enum class SignalType: int32_t
+    {
+        SingleEnded,
+        Diff
+    };
+
+    enum class MSBOrLSB: int32_t
+    {
+        MSB,
+        LSB
+    };
+
+    enum class Polarity: int32_t
+    {
+        None,
+        Pos,
+        Neg
+    };
+
+    // 枚举类,定义了支持的串行通信协议类型。
+    enum class SerialProtocolType : int32_t
+    {
+        Close = 0,
+        // 表示没有协议
+        RS232,
+        // RS232 协议
+        I2C,
+        // I2C 协议
+        SPI,
+        // SPI 协议
+        CAN,
+        // CAN 协议
+        CAN_FD,
+        // CAN with Flexible Data-Rate 协议
+        LIN,
+        // LIN 协议
+        FlexRay,
+        // FlexRay 通信协议
+        AudioBus,
+        // 音频总线协议
+        MIL,
+        // MIL-STD-1553 协议
+        ARINC429,
+        // ARINC429 航空电子协议
+        USB,
+        // USB 通用串行总线协议
+        SENT,
+        // 单边电流传输协议
+        SPMI,
+        // 串行外围设备多路传输接口
+        Ethernet,
+        // 以太网协议
+        CXPI,
+        // CXPI 协议
+        NFC,
+        // 近场通信协议
+        PD,
+        // 电力传输协议
+        NRZ,
+        // 非归零编码
+        Manchester,
+        // 曼彻斯特编码
+        DigRF_3G,
+        // 数字射频3G协议
+        DigRF_V4,
+        // 数字射频V4协议
+        Common_8b10b,
+        // 8b/10b编码
+        JTAG,
+        // 联合测试行动组协议
+        SATA,
+        // 串行ATA接口
+        PCIe,
+        // 外围设备互连高速扩展协议
+        // 如果有新的协议类型,可以继续添加如下:
+        // NewProtocolTypeX, // 新的协议类型X
+        // ...
+    };
+
+    //
+    // std::unordered_map<SerialProtocolType, std::string> protocolTypeAliases = {
+    //     {SerialProtocolType::Close, "Close"},
+    //     {SerialProtocolType::RS232, "RS232"},
+    //     {SerialProtocolType::I2C, "I2C"},
+    //     {SerialProtocolType::SPI, "SPI"},
+    //     {SerialProtocolType::CAN, "CAN"},
+    //     {SerialProtocolType::CAN_FD, "CAN-FD"},
+    //     {SerialProtocolType::LIN, "LIN"},
+    //     {SerialProtocolType::FlexRay, "FlexRay"},
+    //     {SerialProtocolType::AudioBus, "AudioBus"},
+    //     {SerialProtocolType::MIL, "MIL-STD-1553"},
+    //     {SerialProtocolType::ARINC429, "ARINC429"},
+    //     {SerialProtocolType::USB, "USB"},
+    //     {SerialProtocolType::SENT, "SENT"},
+    //     {SerialProtocolType::SPMI, "SPMI"},
+    //     {SerialProtocolType::Ethernet, "Ethernet"},
+    //     {SerialProtocolType::CXPI, "CXPI"},
+    //     {SerialProtocolType::NFC, "NFC"},
+    //     {SerialProtocolType::PD, "PD"},
+    //     {SerialProtocolType::NRZ, "NRZ"},
+    //     {SerialProtocolType::Manchester, "Manchester"},
+    //     {SerialProtocolType::DigRF_3G, "DigRF-3G"},
+    //     {SerialProtocolType::DigRF_V4, "DigRF-V4"},
+    //     {SerialProtocolType::Common_8b10b, "Common-8b10b"},
+    //     {SerialProtocolType::JTAG, "JTAG"},
+    //     {SerialProtocolType::SATA, "SATA"},
+    //     {SerialProtocolType::PCIe, "PCIe"}
+    // };
+}

+ 22 - 0
BaseEnums/QuantizedEnums.h

@@ -0,0 +1,22 @@
+// // ******************************************************************
+// //       /\ /|       @File         QuantizedEnums.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include "../QuantizeParams.h"
+
+namespace Protocol
+{
+    enum class QuantizedLevelOption:byte
+    {
+        Two = 2,
+        Three = 3,
+        Four = 4,
+        Five = 5
+    };
+}

+ 35 - 0
BaseHelper/CommonHelper.h

@@ -0,0 +1,35 @@
+// // ******************************************************************
+// //       /\ /|       @File         CommonHelper.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <type_traits>
+#include <typeinfo>
+
+namespace Protocol
+{
+    class CommonHelper
+    {
+    public:
+        template <typename EnumType>
+        static bool EnumIsDefined(int value)
+        {
+            static_assert(std::is_enum_v<EnumType>, "EnumType must be an enumeration type");
+            return std::underlying_type_t<EnumType>(value) >= 0;
+        }
+
+        template <typename EnumType>
+        struct EnumTypeInfo
+        {
+            static const std::type_info& GetTypeInfo()
+            {
+                return typeid(EnumType);
+            }
+        };
+    };
+}

+ 30 - 0
BaseHelper/DataCheckHelper.cpp

@@ -0,0 +1,30 @@
+// // ******************************************************************
+// //       /\ /|       @File         DataCheckHelper.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "DataCheckHelper.h"
+
+namespace Protocol
+{
+    bool DataCheckHelper::CheckDataByOddEven(uint8_t data, int32_t dataBitCount,
+                                             const OddEvenCheck checkType)
+    {
+        if (checkType == OddEvenCheck::None) return true;
+        bool temp = false;
+
+        while (dataBitCount > 0)
+        {
+            temp ^= ((data & 0b01) == 1);
+            data >>= 1;
+            dataBitCount--;
+        }
+
+        if (checkType == OddEvenCheck::Odd) temp = !temp;
+        return temp;
+    }
+}

+ 24 - 0
BaseHelper/DataCheckHelper.h

@@ -0,0 +1,24 @@
+// // ******************************************************************
+// //       /\ /|       @File         DataCheckHelper.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+
+#include <cstdint>
+
+#include "../BaseEnums/DataCheckEnums.h"
+
+#pragma once
+namespace Protocol
+{
+    class DataCheckHelper
+    {
+    public:
+        static bool CheckDataByOddEven(uint8_t data, int32_t dataBitCount, OddEvenCheck checkType);
+    };
+}

+ 19 - 0
BaseHelper/DecodeDataHelper.cpp

@@ -0,0 +1,19 @@
+// // ******************************************************************
+// //       /\ /|       @File         DecodeDataHelper.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "DecodeDataHelper.h"
+
+#include <cstdint>
+
+#include "CommonHelper.h"
+// "BaseEnums/Channels.h"
+
+namespace ProtocolBase
+{
+}

+ 13 - 0
BaseHelper/DecodeDataHelper.h

@@ -0,0 +1,13 @@
+// // ******************************************************************
+// //       /\ /|       @File         DecodeDataHelper.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+namespace ProtocolBase
+{
+}

+ 78 - 0
BaseHelper/Logger.cpp

@@ -0,0 +1,78 @@
+// // ******************************************************************
+// //       /\ /|       @File         Logger.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "Logger.h"
+
+namespace Protocol
+{
+    std::mutex Logger::InstanceMutex_ = std::mutex();
+    Logger Logger::Instance_ = Logger();
+
+    Logger::Logger()
+    {
+        LogPath_ = "./DecoderLogs/";
+        if (!Fs::exists(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 nowTm;
+        localtime_s(&nowTm, &now); // 使用线程安全的localtime_s
+        std::stringstream logFileNameStream;
+        logFileNameStream << LogPath_ << "2024." << std::put_time(&nowTm, "%m.%d") << ".log";
+        LogFileName_ = logFileNameStream.str();
+
+        LogFile_.open(LogFileName_, std::ios::out | std::ios::app);
+    }
+
+    void Logger::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());
+        tm nowTm;
+        localtime_s(&nowTm, &now); // 使用线程安全的localtime_s
+
+        std::stringstream timeStream;
+        timeStream << std::put_time(&nowTm, "%Y-%m-%d %X");
+
+        std::ofstream& logFile = Instance_.LogFile_;
+        if (logFile.is_open())
+        {
+            logFile << "[" << timeStream.str() << "] - " << message << std::endl;
+            logFile.flush(); // 确保立即写入文件
+        }
+    }
+
+    Logger::~Logger()
+    {
+        if (LogFile_.is_open())
+        {
+            LogFile_.close();
+        }
+    }
+
+    void WriteLog(LogLevel level, const char* format, ...)
+    {
+        if (Logger::LogLevel != LogLevel::All
+            && (Logger::LogLevel == LogLevel::Close || level > Logger::LogLevel))
+        {
+            return;
+        }
+
+        va_list args;
+        va_start(args, format);
+
+        char buffer[1024];
+        vsnprintf(buffer, sizeof(buffer), format, args);
+        va_end(args);
+
+        Logger::Log(buffer);
+    }
+}

+ 53 - 0
BaseHelper/Logger.h

@@ -0,0 +1,53 @@
+// // ******************************************************************
+// //       /\ /|       @File         Logger.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#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/LogerEnums.h"
+
+namespace Fs = std::filesystem;
+
+namespace Protocol
+{
+    class Logger
+    {
+    public:
+        Logger();
+
+        static void Log(const std::string& message);
+
+        ~Logger();
+
+        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 Logger Instance_;
+
+        Logger(const Logger&) = delete;
+        Logger& operator=(const Logger&) = delete;
+    };
+
+    void WriteLog(LogLevel level, const char* format, ...);
+}

+ 10 - 0
DecodeEvent.cpp

@@ -0,0 +1,10 @@
+// // ******************************************************************
+// //       /\ /|       @File         DecodeEvent.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "DecodeEvent.h"

+ 23 - 0
DecodeEvent.h

@@ -0,0 +1,23 @@
+// // ******************************************************************
+// //       /\ /|       @File         DecodeEvent.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <cstdint>
+#include <string>
+
+namespace Protocol
+{
+    struct DecodeBaseEvent
+    {
+        int64_t EventIndex = -1; //事件序号
+        int64_t StartIndex = 0; //事件时域起始帧序号
+        int64_t EndIndex = 0; //事件时域结束帧序号
+        char* Name; //string 事件名称
+    };
+}

+ 21 - 0
DecodeResult.cpp

@@ -0,0 +1,21 @@
+// // ******************************************************************
+// //       /\ /|       @File         DecodeResult.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "DecodeResult.h"
+
+namespace Protocol
+{
+    // DecodeResult::~DecodeResult()
+    // = default;
+    //
+    // SerialProtocolType DecodeResult::GetProtocolType()
+    // {
+    //     return SerialProtocolType::Close;
+    // }
+}

+ 38 - 0
DecodeResult.h

@@ -0,0 +1,38 @@
+// // ******************************************************************
+// //       /\ /|       @File         DecodeResult.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <cstdint>
+#include <vector>
+//#include "Channels.h"
+#include "BaseEnums/ProtocolEnums.h"
+
+namespace Protocol
+{
+    struct DecodeResultCell
+    {
+        int64_t StartIndex = -1; //结果时域起始帧
+        int64_t Length = -1; //结果时域帧长度
+        uint8_t* Data = {}; //结果数据数组
+        int64_t DataCount; //数据数组长度
+        bool IsEventInfo = false; //是否是事件帧
+    };
+
+
+    struct DecodeResult
+    {
+        //协议类型
+        //virtual SerialProtocolType GetProtocolType();
+        SerialProtocolType ProtocolType;
+        //结果有效
+        bool ResultValid = false;
+        //结果数据 子协议实现扩展
+        void* ResultDataPtr;
+    };
+}

+ 33 - 0
EdgePulse.cpp

@@ -0,0 +1,33 @@
+// // ******************************************************************
+// //       /\ /|       @File         EdgePulse.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "EdgePulse.h"
+
+namespace Protocol
+{
+    // int32_t EdgePulse::GetLength() const
+    // {
+    //     return EndIndex > StartIndex && StartIndex > 0 ? EndIndex - StartIndex : 0;
+    // }
+
+    // TwoLevelEdgePulse::TwoLevelEdgePulse(TwoLevelEdgePulseStatusType current)
+    // {
+    //     CurrentLevel = current;
+    // }
+
+    ThreeLevelEdgePulseStatusType ThreeLevelEdgePulse::ConvertToStatus(const bool highLevel, const bool lowLoglevel)
+    {
+        return static_cast<ThreeLevelEdgePulseStatusType>((highLevel ? 1 : 0) << 1 | (lowLoglevel ? 1 : 0));
+    }
+
+    ThreeLevelEdgePulse::ThreeLevelEdgePulse(ThreeLevelEdgePulseStatusType current)
+    {
+        CurrentLevel = current;
+    }
+}

+ 62 - 0
EdgePulse.h

@@ -0,0 +1,62 @@
+// // ******************************************************************
+// //       /\ /|       @File         EdgePulse.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <cstdint>
+#include "BaseEnums/ProtocolEnums.h"
+#include "BaseEnums/EdgePulseEnums.h"
+
+namespace Protocol
+{
+    //基结构体,仅用于继承,不会实际使用
+    struct EdgePulse
+    {
+        int32_t StartIndex = -1; //时域起始帧号
+        int32_t EndIndex = -1; //时域结束帧号
+        Edge Edge = Edge::None; //边沿类型 上升 or 下降
+        // virtual uint32_t LevelCount() const { return 0; } //电平数量 2or3
+        // virtual int32_t GetLength() const; //时域长度
+        // virtual ~EdgePulse() = default;
+    };
+
+    //双电平边沿脉宽
+    struct TwoLevelEdgePulse final : EdgePulse
+    {
+        //电平类型    Low, High, None,
+        TwoLevelEdgePulseStatusType CurrentLevel = TwoLevelEdgePulseStatusType::None;
+        static uint32_t LevelCount() { return 2; }
+
+        int32_t GetLength() const
+        {
+            return EndIndex > StartIndex && StartIndex > 0 ? EndIndex - StartIndex : 0;
+        }
+
+        // uint32_t LevelCount() const override { return 2; }
+        //
+        // int32_t GetLength() const override
+        // {
+        //     return EndIndex > StartIndex && StartIndex > 0 ? EndIndex - StartIndex : 0;
+        // }
+        //
+        // explicit TwoLevelEdgePulse(TwoLevelEdgePulseStatusType current);
+    };
+
+    //三电平边沿脉宽
+    struct ThreeLevelEdgePulse final : EdgePulse
+    {
+        //电平类型  High = 0b11,Middle = 0b01,Low = 0b00,None = 0b10,
+        static ThreeLevelEdgePulseStatusType ConvertToStatus(bool highLevel, bool lowLoglevel);
+
+        //uint32_t LevelCount() const override { return 3; }
+        static uint32_t LevelCount() { return 3; }
+        explicit ThreeLevelEdgePulse(ThreeLevelEdgePulseStatusType current);
+
+        ThreeLevelEdgePulseStatusType CurrentLevel = ThreeLevelEdgePulseStatusType::None;
+    };
+}

+ 28 - 0
EdgePulseData.cpp

@@ -0,0 +1,28 @@
+// // ******************************************************************
+// //       /\ /|       @File         EdgePulseData.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "EdgePulseData.h"
+
+namespace ProtocolBase
+{
+}
+
+Protocol::EdgePulseDataTwoLevels::EdgePulseDataTwoLevels(uint64_t edgePulsesCount, uint64_t dataCount,
+                                                         double sampleRate,
+                                                         EdgePulse* edgePulsesPtr): EdgePulseData(
+    edgePulsesCount, dataCount, sampleRate, edgePulsesPtr)
+{
+}
+
+Protocol::EdgePulseDataThreeLevels::EdgePulseDataThreeLevels(uint64_t edgePulsesCount, uint64_t dataCount,
+                                                             double sampleRate,
+                                                             EdgePulse* edgePulsesPtr): EdgePulseData(edgePulsesCount,
+    dataCount, sampleRate, edgePulsesPtr)
+{
+}

+ 75 - 0
EdgePulseData.h

@@ -0,0 +1,75 @@
+// // ******************************************************************
+// //       /\ /|       @File         EdgePulseData.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include "EdgePulse.h"
+//#include "BaseEnums/Channels.h"
+
+namespace Protocol
+{
+    struct EdgePulseData
+    {
+        /**
+        * \brief 波形数据长度
+        */
+        uint64_t WaveformDataCount;
+        /**
+        * \brief 边沿脉宽个数
+        */
+        uint64_t EdgePulsesCount;
+        /**
+         * \brief 采样率
+         */
+        double SampleRate;
+
+        EdgePulseData(uint64_t edgePulsesCount, uint64_t dataCount, double sampleRate,
+                      EdgePulse* edgePulsesPtr)
+            : WaveformDataCount(dataCount),
+              EdgePulsesCount(edgePulsesCount),
+              SampleRate(sampleRate),
+              EdgePulsesPtr_(edgePulsesPtr)
+        {
+        }
+
+        EdgePulse* GetDataAddrPtr() const
+        {
+            return EdgePulsesPtr_;
+            //return edgePulsesPtr;
+        }
+
+    protected:
+        EdgePulse* EdgePulsesPtr_; //边沿脉宽数据指针
+    };
+
+    struct EdgePulseDataTwoLevels : EdgePulseData
+    {
+        EdgePulseDataTwoLevels(uint64_t edgePulsesCount, uint64_t dataCount, double sampleRate,
+                               EdgePulse* edgePulsesPtr);
+
+        __override TwoLevelEdgePulse* GetDataAddrPtr() const
+        {
+            return reinterpret_cast<TwoLevelEdgePulse*>(EdgePulsesPtr_);
+        }
+
+        __readonly int32_t LevelCount = 2;
+    };
+
+    struct EdgePulseDataThreeLevels : EdgePulseData
+    {
+        EdgePulseDataThreeLevels(uint64_t edgePulsesCount, uint64_t dataCount, double sampleRate,
+                                 EdgePulse* edgePulsesPtr);
+
+        __override TwoLevelEdgePulse* GetDataAddrPtr() const
+        {
+            return reinterpret_cast<TwoLevelEdgePulse*>(EdgePulsesPtr_);
+        }
+
+        __readonly int32_t LevelCount = 3;
+    };
+}

+ 43 - 0
ProtocolDecodeBase.cpp

@@ -0,0 +1,43 @@
+// // ******************************************************************
+// //       /\ /|       @File         ProtocolDecodeBase.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "ProtocolDecodeBase.h"
+//#include "DecodeParams.h"
+#include "QuantizeParams.h"
+#include "BaseHelper/Logger.h"
+//#include "ProtocolUSB/UsbDecode.h"
+#include "ProtocolRS232/RS232Decode.h"
+
+namespace Protocol
+{
+
+    void cancel()
+    {
+        canceled = true;
+    }
+
+}
+
+void getVersionExport(uint8_t* version)
+{
+#ifdef  DLL_VERSION
+    // 将字符串转换为字符数组
+    constexpr char versionString[] = DLL_VERSION;
+
+    // 遍历字符串,将其转换为字节数组
+    for (size_t i = 0; i < sizeof(versionString); ++i)
+    {
+        version[i] = static_cast<unsigned char>(versionString[i]);
+    }
+#else
+    version[0] = 0;
+    version[1] = 0;
+    version[2] = 0;
+#endif
+}

+ 52 - 0
ProtocolDecodeBase.h

@@ -0,0 +1,52 @@
+// // ******************************************************************
+// //       /\ /|       @File         ProtocolDecodeBase.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <iostream>
+#include <memory>
+#include <thread>
+#include <atomic>
+#include <vector>
+#include <string>
+#include <stdexcept>
+
+#include "DecodeResult.h"
+#include "BaseEnums/ProtocolEnums.h"
+#include "BaseHelper/Logger.h"
+
+#define DLL_VERSION "0.1.0"
+
+#ifdef LIBMATH_EXPORTS
+#define LIBMATH_API __declspec(dllexport)
+#else
+#define LIBMATH_API __declspec(dllimport)
+#endif
+
+namespace Protocol
+{
+    class QuantizeParams;
+    struct DecodeParams;
+
+    // 取消解码
+    void cancel();
+
+    inline auto status = ProtocolStatus::Canceled; // 解码状态
+
+};
+
+//外部调用
+extern "C" {
+inline std::atomic<bool> canceled(false);// 取消标志
+inline LIBMATH_API void setCancellationSignal(bool value)
+{
+    canceled = value;
+}
+    
+LIBMATH_API void getVersionExport(uint8_t* version);
+}

+ 22 - 0
ProtocolDecoder.sln

@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProtocolDecoder", "ProtocolDecoder.vcxproj", "{452B01D0-9E45-432F-904B-A81BB6C5B9C4}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Debug|x64 = Debug|x64
+		Release|Win32 = Release|Win32
+		Release|x64 = Release|x64
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{452B01D0-9E45-432F-904B-A81BB6C5B9C4}.Debug|Win32.ActiveCfg = Debug|Win32
+		{452B01D0-9E45-432F-904B-A81BB6C5B9C4}.Debug|Win32.Build.0 = Debug|Win32
+		{452B01D0-9E45-432F-904B-A81BB6C5B9C4}.Debug|x64.ActiveCfg = Debug|x64
+		{452B01D0-9E45-432F-904B-A81BB6C5B9C4}.Debug|x64.Build.0 = Debug|x64
+		{452B01D0-9E45-432F-904B-A81BB6C5B9C4}.Release|Win32.ActiveCfg = Release|Win32
+		{452B01D0-9E45-432F-904B-A81BB6C5B9C4}.Release|Win32.Build.0 = Release|Win32
+		{452B01D0-9E45-432F-904B-A81BB6C5B9C4}.Release|x64.ActiveCfg = Release|x64
+		{452B01D0-9E45-432F-904B-A81BB6C5B9C4}.Release|x64.Build.0 = Release|x64
+	EndGlobalSection
+EndGlobal

+ 353 - 0
ProtocolDecoder.vcxproj

@@ -0,0 +1,353 @@
+<?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>
+        <ClCompile Include="BaseHelper\DataCheckHelper.cpp">
+            <RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
+            <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+            <Optimization>Disabled</Optimization>
+            <SupportJustMyCode>true</SupportJustMyCode>
+            <AssemblerOutput>NoListing</AssemblerOutput>
+            <AssemblerListingLocation>x64\Debug\</AssemblerListingLocation>
+            <UndefineAllPreprocessorDefinitions>false</UndefineAllPreprocessorDefinitions>
+            <BrowseInformation>false</BrowseInformation>
+            <BrowseInformationFile>x64\Debug\</BrowseInformationFile>
+            <CompileAs>Default</CompileAs>
+            <ConformanceMode>true</ConformanceMode>
+            <DiagnosticsFormat>Column</DiagnosticsFormat>
+            <DisableLanguageExtensions>false</DisableLanguageExtensions>
+            <ErrorReporting>Prompt</ErrorReporting>
+            <ExpandAttributedSource>false</ExpandAttributedSource>
+            <ExceptionHandling>Sync</ExceptionHandling>
+            <EnableASAN>false</EnableASAN>
+            <EnableFuzzer>false</EnableFuzzer>
+            <EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
+            <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
+            <FloatingPointModel>Precise</FloatingPointModel>
+            <ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
+            <GenerateModuleDependencies>false</GenerateModuleDependencies>
+            <GenerateSourceDependencies>false</GenerateSourceDependencies>
+            <GenerateXMLDocumentationFiles>false</GenerateXMLDocumentationFiles>
+            <InlineFunctionExpansion>Default</InlineFunctionExpansion>
+            <IntrinsicFunctions>false</IntrinsicFunctions>
+            <IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
+            <LanguageStandard>stdcpp17</LanguageStandard>
+            <LanguageStandard_C>stdc17</LanguageStandard_C>
+            <MinimalRebuild>false</MinimalRebuild>
+            <ModuleDependenciesFile>x64\Debug\</ModuleDependenciesFile>
+            <ModuleOutputFile>x64\Debug\</ModuleOutputFile>
+            <OmitDefaultLibName>false</OmitDefaultLibName>
+            <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
+            <WholeProgramOptimization>false</WholeProgramOptimization>
+            <ObjectFileName>x64\Debug\</ObjectFileName>
+            <CallingConvention>Cdecl</CallingConvention>
+            <ProgramDataBaseFileName>x64\Debug\vc143.pdb</ProgramDataBaseFileName>
+            <PrecompiledHeader>NotUsing</PrecompiledHeader>
+            <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+            <PrecompiledHeaderOutputFile>x64\Debug\ProtocolDecoder.pch</PrecompiledHeaderOutputFile>
+            <PreprocessToFile>false</PreprocessToFile>
+            <PreprocessKeepComments>false</PreprocessKeepComments>
+            <PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
+            <RemoveUnreferencedCodeData>true</RemoveUnreferencedCodeData>
+            <ScanSourceForModuleDependencies>false</ScanSourceForModuleDependencies>
+            <ShowIncludes>false</ShowIncludes>
+            <SourceDependenciesFile>x64\Debug\</SourceDependenciesFile>
+            <SuppressStartupBanner>true</SuppressStartupBanner>
+            <BufferSecurityCheck>true</BufferSecurityCheck>
+            <SmallerTypeCheck>false</SmallerTypeCheck>
+            <SpectreMitigation>false</SpectreMitigation>
+            <StructMemberAlignment>Default</StructMemberAlignment>
+            <TrackerLogDirectory>x64\Debug\ProtocolDecoder.tlog\</TrackerLogDirectory>
+            <TranslateIncludes>false</TranslateIncludes>
+            <MinimalRebuildFromTracking>true</MinimalRebuildFromTracking>
+            <TreatWarningAsError>false</TreatWarningAsError>
+            <TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
+            <UseFullPaths>true</UseFullPaths>
+            <WarningLevel>Level3</WarningLevel>
+            <XMLDocumentationFileName>x64\Debug\</XMLDocumentationFileName>
+            <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+            <IntelJCCErratum>false</IntelJCCErratum>
+            <BuildStlModules>false</BuildStlModules>
+            <TreatAngleIncludeAsExternal>false</TreatAngleIncludeAsExternal>
+            <ExternalWarningLevel>InheritWarningLevel</ExternalWarningLevel>
+            <TreatExternalTemplatesAsInternal>true</TreatExternalTemplatesAsInternal>
+            <DisableAnalyzeExternal>false</DisableAnalyzeExternal>
+            <PreprocessorDefinitions>_DEBUG;CPPDYNAMICLIBRARYTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;_WINDLL;_UNICODE;UNICODE;</PreprocessorDefinitions>
+            <SDLCheck>true</SDLCheck>
+            <LinkCompiled>true</LinkCompiled>
+        </ClCompile>
+        <ClCompile Include="BaseHelper\DecodeDataHelper.cpp">
+            <RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
+            <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+            <Optimization>Disabled</Optimization>
+            <SupportJustMyCode>true</SupportJustMyCode>
+            <AssemblerOutput>NoListing</AssemblerOutput>
+            <AssemblerListingLocation>x64\Debug\</AssemblerListingLocation>
+            <UndefineAllPreprocessorDefinitions>false</UndefineAllPreprocessorDefinitions>
+            <BrowseInformation>false</BrowseInformation>
+            <BrowseInformationFile>x64\Debug\</BrowseInformationFile>
+            <CompileAs>Default</CompileAs>
+            <ConformanceMode>true</ConformanceMode>
+            <DiagnosticsFormat>Column</DiagnosticsFormat>
+            <DisableLanguageExtensions>false</DisableLanguageExtensions>
+            <ErrorReporting>Prompt</ErrorReporting>
+            <ExpandAttributedSource>false</ExpandAttributedSource>
+            <ExceptionHandling>Sync</ExceptionHandling>
+            <EnableASAN>false</EnableASAN>
+            <EnableFuzzer>false</EnableFuzzer>
+            <EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
+            <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
+            <FloatingPointModel>Precise</FloatingPointModel>
+            <ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
+            <GenerateModuleDependencies>false</GenerateModuleDependencies>
+            <GenerateSourceDependencies>false</GenerateSourceDependencies>
+            <GenerateXMLDocumentationFiles>false</GenerateXMLDocumentationFiles>
+            <InlineFunctionExpansion>Default</InlineFunctionExpansion>
+            <IntrinsicFunctions>false</IntrinsicFunctions>
+            <IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
+            <LanguageStandard>stdcpp17</LanguageStandard>
+            <LanguageStandard_C>stdc17</LanguageStandard_C>
+            <MinimalRebuild>false</MinimalRebuild>
+            <ModuleDependenciesFile>x64\Debug\</ModuleDependenciesFile>
+            <ModuleOutputFile>x64\Debug\</ModuleOutputFile>
+            <OmitDefaultLibName>false</OmitDefaultLibName>
+            <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
+            <WholeProgramOptimization>false</WholeProgramOptimization>
+            <ObjectFileName>x64\Debug\</ObjectFileName>
+            <CallingConvention>Cdecl</CallingConvention>
+            <ProgramDataBaseFileName>x64\Debug\vc143.pdb</ProgramDataBaseFileName>
+            <PrecompiledHeader>NotUsing</PrecompiledHeader>
+            <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+            <PrecompiledHeaderOutputFile>x64\Debug\ProtocolDecoder.pch</PrecompiledHeaderOutputFile>
+            <PreprocessToFile>false</PreprocessToFile>
+            <PreprocessKeepComments>false</PreprocessKeepComments>
+            <PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
+            <RemoveUnreferencedCodeData>true</RemoveUnreferencedCodeData>
+            <ScanSourceForModuleDependencies>false</ScanSourceForModuleDependencies>
+            <ShowIncludes>false</ShowIncludes>
+            <SourceDependenciesFile>x64\Debug\</SourceDependenciesFile>
+            <SuppressStartupBanner>true</SuppressStartupBanner>
+            <BufferSecurityCheck>true</BufferSecurityCheck>
+            <SmallerTypeCheck>false</SmallerTypeCheck>
+            <SpectreMitigation>false</SpectreMitigation>
+            <StructMemberAlignment>Default</StructMemberAlignment>
+            <TrackerLogDirectory>x64\Debug\ProtocolDecoder.tlog\</TrackerLogDirectory>
+            <TranslateIncludes>false</TranslateIncludes>
+            <MinimalRebuildFromTracking>true</MinimalRebuildFromTracking>
+            <TreatWarningAsError>false</TreatWarningAsError>
+            <TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
+            <UseFullPaths>true</UseFullPaths>
+            <WarningLevel>Level3</WarningLevel>
+            <XMLDocumentationFileName>x64\Debug\</XMLDocumentationFileName>
+            <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+            <IntelJCCErratum>false</IntelJCCErratum>
+            <BuildStlModules>false</BuildStlModules>
+            <TreatAngleIncludeAsExternal>false</TreatAngleIncludeAsExternal>
+            <ExternalWarningLevel>InheritWarningLevel</ExternalWarningLevel>
+            <TreatExternalTemplatesAsInternal>true</TreatExternalTemplatesAsInternal>
+            <DisableAnalyzeExternal>false</DisableAnalyzeExternal>
+            <PreprocessorDefinitions>_DEBUG;CPPDYNAMICLIBRARYTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;_WINDLL;_UNICODE;UNICODE;</PreprocessorDefinitions>
+            <SDLCheck>true</SDLCheck>
+            <LinkCompiled>true</LinkCompiled>
+        </ClCompile>
+        <ClCompile Include="BaseHelper\Logger.cpp"/>
+        <ClCompile Include="DecodeEvent.cpp"/>
+        <ClCompile Include="DecodeResult.cpp"/>
+        <ClCompile Include="dllmain.cpp"/>
+        <ClCompile Include="EdgePulse.cpp"/>
+        <ClCompile Include="EdgePulseData.cpp"/>
+        <ClCompile Include="ProtocolDecodeBase.cpp"/>
+        <ClCompile Include="ProtocolRS232\RS232Decode.cpp"/>
+        <ClCompile Include="ProtocolRS232\RS232DecodeEvent.cpp"/>
+        <ClCompile Include="ProtocolRS232\RS232DecodeResult.cpp"/>
+        <ClCompile Include="ProtocolRS232\RS232Packet.cpp"/>
+        <ClCompile Include="QuantizeParams.cpp"/>
+    </ItemGroup>
+    <ItemGroup>
+        <ClInclude Include="BaseEnums\Channels.h"/>
+        <ClInclude Include="BaseEnums\DataCheckEnums.h"/>
+        <ClInclude Include="BaseEnums\EdgePulseEnums.h"/>
+        <ClInclude Include="BaseEnums\LogerEnums.h"/>
+        <ClInclude Include="BaseEnums\ProtocolEnums.h"/>
+        <ClInclude Include="BaseEnums\QuantizedEnums.h"/>
+        <ClInclude Include="BaseHelper\CommonHelper.h"/>
+        <ClInclude Include="BaseHelper\DataCheckHelper.h"/>
+        <ClInclude Include="BaseHelper\DecodeDataHelper.h"/>
+        <ClInclude Include="BaseHelper\Logger.h"/>
+        <ClInclude Include="DecodeEvent.h"/>
+        <ClInclude Include="DecodeResult.h"/>
+        <ClInclude Include="EdgePulse.h"/>
+        <ClInclude Include="EdgePulseData.h"/>
+        <ClInclude Include="ProtocolDecodeBase.h"/>
+        <ClInclude Include="ProtocolRS232\Constants.h"/>
+        <ClInclude Include="ProtocolRS232\Protocol.RS232.Options.h"/>
+        <ClInclude Include="ProtocolRS232\RS232Params.h"/>
+        <ClInclude Include="ProtocolRS232\ProtocolRS232Enums.h"/>
+        <ClInclude Include="ProtocolRS232\RS232Decode.h"/>
+        <ClInclude Include="ProtocolRS232\RS232DecodeEvent.h"/>
+        <ClInclude Include="ProtocolRS232\RS232DecodeResult.h"/>
+        <ClInclude Include="ProtocolRS232\RS232Packet.h"/>
+        <ClInclude Include="QuantizeParams.h"/>
+    </ItemGroup>
+    <ItemGroup>
+        <Folder Include="ProtocolUSB\"/>
+    </ItemGroup>
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/>
+    <ImportGroup Label="ExtensionTargets">
+    </ImportGroup>
+</Project>

+ 14 - 0
ProtocolRS232/Constants.h

@@ -0,0 +1,14 @@
+// // ******************************************************************
+// //       /\ /|       @File         Constants.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+
+namespace Protocol
+{
+}

+ 31 - 0
ProtocolRS232/Protocol.RS232.Options.h

@@ -0,0 +1,31 @@
+// // ******************************************************************
+// //       /\ /|       @File         Protocol.RS232.Options.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+
+//#include "../CommonBase/Enums/Channels.h"
+#include "ProtocolRS232Enums.h"
+
+namespace Protocol
+{
+    struct ProtocolRS232Options
+    {
+        unsigned int BaudRate; //波特率
+        Protocol::OddEvenCheck OddEvenCheckType; //奇偶检验类型  None,Odd,Even
+
+        Protocol::Polarity Polarity; //电平极性  None, Pos,  Neg
+        Protocol::SignalType SignalType; //信号类型   SingleEnded单端,Diff差分
+        //Protocol::ChannelId Source; //信源号
+        Protocol::MSBOrLSB MSBOrLSB; //大小端
+
+        Protocol::RS232Enums::DataBitWidth DataBitWidth; //数据位宽
+        Protocol::RS232Enums::StopBit StopBit; //停止位
+        float Threshold; //电平阈值
+    };
+}

+ 54 - 0
ProtocolRS232/ProtocolRS232Enums.h

@@ -0,0 +1,54 @@
+// // ******************************************************************
+// //       /\ /|       @File         ProtocolRS232Enums.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include "../EdgePulse.h"
+#include "../BaseEnums/DataCheckEnums.h"
+
+namespace Protocol
+{
+    class RS232Enums
+    {
+    public:
+        enum class RS232DecodeEventType: int32_t
+        {
+            None,
+            Start,
+            Data,
+            Parity,
+        };
+
+        enum class DataBitWidth: int32_t
+        {
+            DataBitWidth_5Bit = 5,
+            DataBitWidth_6Bit,
+            DataBitWidth_7Bit,
+            DataBitWidth_8Bit
+        };
+
+
+        enum class StopBit: int32_t
+        {
+            StopBit_1bit,
+            StopBit_2bit
+        };
+
+        enum class BPSList: int32_t
+        {
+            BPSList_2400,
+            BPSList_4800,
+            BPSList_9600,
+            BPSList_19200,
+            BPSList_38400,
+            BPSList_57600,
+            BPSList_115200,
+            BPSList_Custom
+        };
+    };
+}

+ 453 - 0
ProtocolRS232/RS232Decode.cpp

@@ -0,0 +1,453 @@
+// // ******************************************************************
+// //       /\ /|       @File         RS232Decode.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "RS232Decode.h"
+
+#include "../BaseEnums/DataCheckEnums.h"
+#include "../BaseHelper/DataCheckHelper.h"
+#include "../BaseHelper/Logger.h"
+
+namespace Protocol
+{
+	
+	std::vector<RS232DecodeResultCell> decodeResultUnits;
+	std::vector<RS232DecodeEventUnit> decodeEventUnitsStorage;
+	std::vector<RS232DecodeEvent> decodeEvents;
+	
+
+	int32_t getStartIndex(const ProtocolRS232Options& options, TwoLevelEdgePulse*& node,
+		double count,
+		double& realCount,
+		const int32_t startIndex,
+		TwoLevelEdgePulseStatusType& startStatus)
+	{
+		startStatus = options.Polarity == Polarity::Pos
+			? TwoLevelEdgePulseStatusType::High
+			: TwoLevelEdgePulseStatusType::Low;
+
+		while (node != nullptr)
+		{
+			if (node->CurrentLevel != startStatus && node->StartIndex >= startIndex)
+			{
+				//计算该脉宽中,最大包括几个bit信息宽度
+				const double bitCount = std::round(node->GetLength() / count);
+				if (bitCount > 0 && bitCount < static_cast<int32_t>(options.DataBitWidth) + 4)
+				{
+					realCount = node->GetLength() / bitCount;
+				}
+				if (bitCount > 0) break;
+			}
+
+			node++;
+		}
+		return node == nullptr ? -1 : node->StartIndex;
+	}
+
+	bool pauseDataRS232(const ProtocolRS232Options& options, TwoLevelEdgePulse* edgePulses,
+		const uint64_t edgePulseCount,
+		const uint64_t waveformDataCount, const double sampleRate,
+		RS232DecodeResult& decodeResult)
+
+	{
+		canceled = false;
+		WriteLog(LogLevel::LevelDebug, " SignalType:%d, DataBitWidth:%d"
+			, static_cast<int>(options.SignalType), static_cast<int>(options.DataBitWidth));
+		if (canceled)
+		{
+			WriteLog(LogLevel::Level2, "  ParsingData canceled.\n");
+
+			return false;
+		}
+
+		//栈上 初始化内存
+		std::vector<RS232Packet> rs232Packets;
+		rs232Packets = {};
+		decodeEvents = {};
+		decodeResultUnits = {};
+ 
+		auto decodeResultUnitsPtr = &decodeResultUnits;
+		auto decodeEventsPtr = &decodeEvents;
+		WriteLog(LogLevel::LevelDebug, "  decodeResultUnitsPtr:0x%X\n", static_cast<void*>(decodeResultUnitsPtr));
+		WriteLog(LogLevel::LevelDebug, "  decodeEventsPtr:0x%X\n", static_cast<void*>(decodeEventsPtr));
+		canceled = false;
+
+		if (canceled)
+		{
+			WriteLog(LogLevel::Level2, "  ParsingData canceled.\n");
+			return false;
+		}
+		if (edgePulses == nullptr)
+		{
+			WriteLog(LogLevel::Level2, " EdgePulseDataPtr is nullptr\n");
+			return false;
+		}
+		//if (edgePulseData.edgePulses.empty())
+		if (waveformDataCount == 0)
+		{
+			std::cout << "  DataCount is 0 or sampleRate error\n";
+			WriteLog(LogLevel::Level2, " DataCount is 0 or sampleRate error\n");
+			return false;
+		}
+
+		int32_t dataBitCount = 0;
+		switch (options.DataBitWidth)
+		{
+		case RS232Enums::DataBitWidth::DataBitWidth_5Bit:
+			dataBitCount = 5;
+			break;
+		case RS232Enums::DataBitWidth::DataBitWidth_6Bit:
+			dataBitCount = 6;
+			break;
+		case RS232Enums::DataBitWidth::DataBitWidth_7Bit:
+			dataBitCount = 7;
+			break;
+		case RS232Enums::DataBitWidth::DataBitWidth_8Bit:
+			dataBitCount = 8;
+			break;
+		}
+
+
+		uint64_t edgePulseIndex = 0;
+
+		//每bit理论长度
+		const double count = 1.0 / options.BaudRate * sampleRate;
+		WriteLog(LogLevel::LevelDebug, "  bit count:%f", count);
+		//const double count = static_cast<double>(dataCount);
+		//每bit实际长度
+		double realCount = count;
+
+		const int32_t stopBitCount = options.StopBit == RS232Enums::StopBit::StopBit_1bit
+			? 1
+			: options.StopBit == RS232Enums::StopBit::StopBit_2bit
+			? 2
+			: 1;
+
+		WriteLog(LogLevel::LevelDebug, "  realCount:%f", realCount);
+		WriteLog(LogLevel::LevelDebug, "  edgePulsePointer:0x%x", reinterpret_cast<void*>(edgePulses));
+		//WriteLog("  edgePulsePointer:0x%x", edgePulses);
+		WriteLog(LogLevel::LevelDebug, "  edgePulse StartIndex:%d", edgePulses->StartIndex);
+		WriteLog(LogLevel::LevelDebug, "  edgePulse EndIndex:%d", edgePulses->EndIndex);
+		WriteLog(LogLevel::LevelDebug, "  edgePulseCount:%d", edgePulseCount);
+
+		try
+		{
+			int32_t startIndex = 0;
+
+			while (edgePulses != nullptr && edgePulseIndex < edgePulseCount)
+			{
+				if (count <= 2) break;
+				TwoLevelEdgePulseStatusType levelState;
+				//找到帧头 根据帧头得到实际bit宽度realCount  帧头起始位置startIndex 电平状态levelState
+				int32_t packetStartIndex =
+					getStartIndex(options, edgePulses, count, realCount, startIndex, levelState);
+				//WriteLog("  GetStartIndex PacketStartIndex:%d\n", packetStartIndex);
+				if (canceled)
+				{
+					WriteLog(LogLevel::Level2, "  ParsingData canceled.\n");
+					return false;
+				}
+
+				if (packetStartIndex == -1) break;
+				//std::cout << " packetStartIndex:" << packetStartIndex << " ,realCount:" << realCount << "\n";
+				//构造帧
+				RS232Packet packet = {};
+				packetStartIndex += static_cast<int32_t>(std::round(realCount / 2));
+
+				if (edgePulses->StartIndex >= edgePulses->EndIndex || !CommonHelper::EnumIsDefined<
+					TwoLevelEdgePulseStatusType>(static_cast<int>(edgePulses->CurrentLevel)))
+				{
+					std::ostringstream msg;
+					msg << " =>178 loop break Index:" << packetStartIndex << " ,dataCount:" <<
+						waveformDataCount << "\n";
+					WriteLog(LogLevel::LevelDebug, msg.str().c_str());
+					break;
+				}
+				if (packetStartIndex >= static_cast<int32_t>(waveformDataCount))
+				{
+					std::ostringstream msg;
+					msg << " =>186 loop break Index:" << packetStartIndex << " ,dataCount:" <<
+						waveformDataCount << "\n";
+					WriteLog(LogLevel::LevelDebug, msg.str().c_str());
+					break;
+				}
+
+				if (startIndex == static_cast<int32_t>(waveformDataCount)) break;
+
+				packet.StartBit = levelState == TwoLevelEdgePulseStatusType::High;
+				packet.StartIndex = packetStartIndex - static_cast<int32_t>(std::round(realCount / 2));
+				packet.DataIndex = packetStartIndex + static_cast<int32_t>(std::round(realCount / 2));
+				packet.PerBitLenght = realCount;
+
+				WriteLog(LogLevel::LevelDebug, "=> Tst  StartIndex:%d,dataBitCount:%d", packet.StartIndex, dataBitCount);
+				for (int32_t dataBitIndex = 0; dataBitIndex < dataBitCount; dataBitIndex++)
+				{
+					if (canceled)
+					{
+						WriteLog(LogLevel::Level2, "  ParsingData canceled.\n");
+						return false;
+					}
+
+					packetStartIndex += static_cast<int32_t>(std::round(realCount));
+
+					//std::cout << "  P150 Test" << "\n";
+					if (packetStartIndex >= static_cast<int32_t>(waveformDataCount))
+					{
+						startIndex = static_cast<int32_t>(waveformDataCount);
+						WriteLog(LogLevel::LevelDebug, "  =>%d break \n", __LINE__);
+						break;
+					}
+					//std::cout << "  P157 Test" << "\n";
+					TwoLevelEdgePulseStatusType bitStatus;
+					if (!getRS232Bit(edgePulses, packetStartIndex, bitStatus))
+					{
+						//gMutex.unlock(); // 执行完操作后手动释放锁
+						return false;
+					}
+					//按位构造数据
+					if (options.MSBOrLSB == MSBOrLSB::MSB)
+					{
+						packet.Data = static_cast<uint8_t>(packet.Data << 1);
+						packet.Data |= bitStatus == TwoLevelEdgePulseStatusType::High ? 1 : 0;
+					}
+					else
+					{
+						packet.Data |= static_cast<uint8_t>((bitStatus ==
+							TwoLevelEdgePulseStatusType::High
+							? 1
+							: 0) << dataBitIndex);
+					}
+					WriteLog(LogLevel::LevelDebug, "Tst CurrentLevel:%d, bitStatus:%d", edgePulses->CurrentLevel, bitStatus);
+				}
+				//std::cout << "  P177 Test" << "\n";
+				if (startIndex == static_cast<int32_t>(waveformDataCount)) break;
+				//校验位
+				if (options.OddEvenCheckType != OddEvenCheck::None)
+				{
+					packetStartIndex += static_cast<int32_t>(std::round(realCount));
+
+					if (packetStartIndex >= static_cast<int32_t>(waveformDataCount))
+					{
+						//startIndex = static_cast<int32_t>(bufferLength);
+						rs232Packets.push_back(packet);
+						WriteLog(LogLevel::LevelDebug, "  =>%d break \n", __LINE__);
+						break;
+					}
+					TwoLevelEdgePulseStatusType bitStatus;
+					if (!getRS232Bit(edgePulses, packetStartIndex, bitStatus))
+					{
+						//gMutex.unlock(); // 执行完操作后手动释放锁
+						return false;
+					}
+					packet.ParityFind = true;
+					packet.ParityBit = bitStatus == TwoLevelEdgePulseStatusType::High;
+					packet.ParityResult = DataCheckHelper::CheckDataByOddEven(
+						packet.Data, dataBitCount, options.OddEvenCheckType);
+					packet.ParityIndex = packet.DataIndex + static_cast<int32_t>(
+						std::round(realCount * dataBitCount));
+				}
+				//std::cout << "  P203 Test" << "\n";
+				rs232Packets.push_back(packet);
+
+				packetStartIndex += static_cast<int32_t>(realCount * stopBitCount);
+				startIndex = packetStartIndex;
+				edgePulseIndex++;
+			}
+		}
+		catch (const char* ex)
+		{
+			WriteLog(LogLevel::LevelDebug, "  ParsingData L%d catch :%s", __LINE__, ex);
+			return false;
+		}
+
+		{
+			std::ostringstream msg;
+			msg << "  edgePulseIndex:" << edgePulseIndex << ",";
+			msg << "  rs232Packets count:" << rs232Packets.size() << ",";
+			msg << "  get events && results";
+			WriteLog(LogLevel::Level2, msg.str().c_str());
+		}
+		//get events && results
+		//std::cout << "  P218 Test rs232Packets Count:" << rs232Packets.size() << "\n";
+		if (!rs232Packets.empty())
+		{
+			decodeEventUnitsStorage = {};
+			//for (int64_t i = 0; i < static_cast<int64_t>(rs232Packets.size()); i++)
+			for (auto packet : rs232Packets)
+			{
+				if (canceled)
+				{
+					WriteLog(LogLevel::Level2, "  ParsingData canceled.\n");
+					//gMutex.unlock(); // 执行完操作后手动释放锁
+					return false;
+				}
+				RS232DecodeResultCell resultUnit;
+				RS232DecodeEvent decodeEvent = {};
+				auto eventPtr = &decodeEvent;
+				RS232DecodeEventUnit eventStart;
+				RS232DecodeEventUnit eventData;
+				int64_t eventStartIndex = packet.StartIndex;
+				int64_t oneBitLength = static_cast<int64_t>(packet.PerBitLenght);
+
+				eventPtr->StartIndex = packet.StartIndex;
+
+				eventStart.StartIndex = packet.StartIndex;
+				eventStart.Length = oneBitLength;
+				eventStartIndex += 1;
+				eventStart.EventType = RS232Enums::RS232DecodeEventType::Start;
+
+				eventData.StartIndex = eventStart.StartIndex;
+				eventData.Length = oneBitLength * dataBitCount;
+				eventData.Data = packet.Data;
+				eventData.EventType = RS232Enums::RS232DecodeEventType::Data;
+				eventStartIndex += 8;
+
+
+				//std::cout << "  P249 Test I:" << i << "\n";
+				if (packet.ParityFind)
+				{
+					RS232DecodeEventUnit eventUints[3];
+					eventUints[0] = eventStart;
+					eventUints[1] = eventData;
+					RS232DecodeEventUnit eventParity;
+					//std::cout << "  P253 Test I:" << i << "\n";
+					eventParity.Data = packet.ParityResult ? 1 : 0;
+					eventParity.StartIndex = eventStartIndex;
+					eventParity.Length = oneBitLength;
+					eventParity.EventType = RS232Enums::RS232DecodeEventType::Parity;
+					eventPtr->ParityResult = packet.ParityResult ? 1 : 0;
+					eventUints[2] = eventParity;
+					//eventPtr->EventData = eventUints;
+					eventStartIndex += 8;
+					eventPtr->EventDataCount = 3;
+					eventPtr->EndIndex = packet.StartIndex + oneBitLength * (dataBitCount + 1);
+					// 将eventUints复制到decodeEventUnitsStorage中
+					decodeEventUnitsStorage.insert(decodeEventUnitsStorage.end(), std::begin(eventUints),
+						std::end(eventUints));
+					//最后来赋值
+					//decodeEvent.EventData = decodeEventUnitsStorage.data() + decodeEventUnitsStorage.size() - 3;
+				}
+				else
+				{
+					RS232DecodeEventUnit eventUints[2];
+					eventUints[0] = eventStart;
+					eventUints[1] = eventData;
+					eventPtr->EventDataCount = 2;
+
+					//eventPtr->EventData = eventUints;
+					//std::cout << "  P263 Test I:" << i << "\n";
+					eventPtr->ParityResult = 0;
+					eventPtr->EndIndex = packet.StartIndex + oneBitLength * (dataBitCount);
+					// 将eventUints复制到decodeEventUnitsStorage中
+					decodeEventUnitsStorage.insert(decodeEventUnitsStorage.end(), std::begin(eventUints),
+						std::end(eventUints));
+					//最后来赋值
+					//decodeEvent.EventData = decodeEventUnitsStorage.data() + decodeEventUnitsStorage.size() - 2;
+				}
+
+				//std::cout << "  P266 Test I:" << i << "\n";
+				resultUnit.StartIndex = packet.StartIndex;
+				//最后来赋值
+				//resultUnit.Data = &packet.Data;
+				WriteLog(LogLevel::LevelDebug, "  Tst Data Ptr:0x%x , Data:%d", static_cast<void*>(resultUnit.Data),
+					packet.Data);
+				resultUnit.DataCount = 1;
+				resultUnit.Length = eventStartIndex - packet.StartIndex;
+
+				eventPtr->EventIndex = static_cast<int64_t>(decodeEventsPtr->size());
+
+				decodeEvents.push_back(decodeEvent);
+				decodeResultUnits.push_back(resultUnit);
+
+				decodeResult.DecodeEventNeedUpdate = true;
+				decodeResult.DecodeResultNeedUpdate = true;
+			}
+		}
+
+		/////////////////////////// 指针赋值 /////////////////////////////////
+		int64_t eventDataIndex = 0;
+		for (int i = 0; i < decodeEvents.size(); i++) // NOLINT(modernize-loop-convert, clang-diagnostic-sign-compare)
+		{
+			decodeEvents[i].EventData = decodeEventUnitsStorage.data() + eventDataIndex;
+			eventDataIndex += decodeEvents[i].EventDataCount;
+		}
+
+		for (int i = 0; i < decodeResultUnits.size(); i++)  // NOLINT(clang-diagnostic-sign-compare)
+		{
+			int64_t startIndex = decodeResultUnits[i].StartIndex;
+			for (int x = 0; i < rs232Packets.size(); x++) // NOLINT(clang-diagnostic-sign-compare)
+			{
+				if (rs232Packets[x].StartIndex == startIndex)
+				{
+					decodeResultUnits[i].Data = &(rs232Packets[x].Data);
+					break;
+				}
+			}
+		}
+		
+		decodeResult.DecodeEventsPtr = decodeEventsPtr->data();
+		decodeResult.DecodeResultUnitsPtr = decodeResultUnitsPtr->data();
+		decodeResult.DecodeEventCount = decodeEventsPtr->size();
+		decodeResult.DecodeResultCount = decodeResultUnitsPtr->size();
+		  
+		WriteLog(LogLevel::Level1, "  Cpp ParsingData Done,return True \n\n");
+
+		return true;
+	}
+
+
+
+	std::vector<const char*> getEventInfoTitles()
+	{
+		return eventInfoTitles;
+	}
+
+	bool getRS232Bit(TwoLevelEdgePulse*& edgePulse,
+		int32_t targetIndex, TwoLevelEdgePulseStatusType& status)
+	{
+		status = TwoLevelEdgePulseStatusType::None;
+		if (edgePulse == nullptr)
+		{
+			return false;
+		}
+		if (targetIndex <= 0 || edgePulse->StartIndex > targetIndex)
+		{
+			return false;
+		}
+		while (edgePulse != nullptr)
+		{
+			if (edgePulse->StartIndex <= targetIndex && edgePulse->EndIndex > targetIndex)
+			{
+				status = edgePulse->CurrentLevel;
+				//test
+				WriteLog(LogLevel::Level2, "StartIndex:%d , status:%d", edgePulse->StartIndex, status);
+				return true;
+			}
+			edgePulse++;
+		}
+		return false;
+	}
+
+	bool quantizeParamsDecodeRS232(const QuantizeParams& quantizeParams, const ProtocolRS232Options& options,
+		RS232DecodeResult& decodeResult)
+	{
+		canceled = false;
+		//todo
+		return false;
+	}
+
+	bool decodeRS232(const ProtocolRS232Options& options,
+		const EdgePulseDataTwoLevels& edgePulseData,
+		RS232DecodeResult& decodeResult)
+	{
+		return pauseDataRS232(options, edgePulseData.GetDataAddrPtr(),
+			edgePulseData.EdgePulsesCount,
+			edgePulseData.WaveformDataCount, edgePulseData.SampleRate,
+			decodeResult);
+	}
+}

+ 47 - 0
ProtocolRS232/RS232Decode.h

@@ -0,0 +1,47 @@
+// // ******************************************************************
+// //       /\ /|       @File         RS232Decode.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <cstdint>
+#include <future>
+
+#include "../BaseHelper/CommonHelper.h"
+// #include "../CommonBase/EnumTypeInfo.h"
+#include "../EdgePulseData.h"
+// #include "Constants.h"
+#include "ProtocolRS232Enums.h"
+#include "RS232Params.h"
+#include "RS232DecodeResult.h"
+//#include "RS232Packet.h"
+#include "../ProtocolDecodeBase.h"
+#include "Protocol.RS232.Options.h"
+#include "../BaseHelper/Logger.h"
+
+namespace Protocol
+{
+    static bool getRS232Bit(TwoLevelEdgePulse*& edgePulse,
+                            int32_t targetIndex, TwoLevelEdgePulseStatusType& status);
+    inline std::vector<const char*> eventInfoTitles = {
+        "Index", "Start Time", "Data", "Parity", "Error"
+    };
+
+    std::vector<const char*> getEventInfoTitles();
+     
+    extern "C" {
+
+    LIBMATH_API bool decodeRS232(const ProtocolRS232Options& options,
+                                 const EdgePulseDataTwoLevels& edgePulseData,
+                                 RS232DecodeResult& decodeResult);
+
+    LIBMATH_API bool quantizeParamsDecodeRS232(const QuantizeParams& quantizeParams,
+                                               const ProtocolRS232Options& options,
+                                               RS232DecodeResult& decodeResult);
+
+    }
+}

+ 10 - 0
ProtocolRS232/RS232DecodeEvent.cpp

@@ -0,0 +1,10 @@
+// // ******************************************************************
+// //       /\ /|       @File         RS232DecodeEvent.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "RS232DecodeEvent.h"

+ 57 - 0
ProtocolRS232/RS232DecodeEvent.h

@@ -0,0 +1,57 @@
+// // ******************************************************************
+// //       /\ /|       @File         RS232DecodeEvent.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <vector>
+#include "ProtocolRS232Enums.h"
+#include "../DecodeEvent.h"
+
+namespace Protocol
+{
+    struct RS232DecodeEventUnit
+    {
+        int64_t StartIndex; //开始帧
+        int64_t Length; //长度
+        uint8_t Data; //数据
+
+        RS232Enums::RS232DecodeEventType EventType; //事件类型   None, Start, Data,Parity,
+
+        // //事件相等判断
+        // bool Equals(const RS232DecodeEventUint eventData) const
+        // {
+        //     return Data == eventData.Data;
+        // }
+    };
+
+
+    struct RS232DecodeEvent : DecodeBaseEvent
+    {
+        int8_t ParityResult; //校验结果
+        RS232DecodeEventUnit* EventData; //事件数据指针
+        int64_t EventDataCount; //事件数据长度
+
+        //事件相等判断
+        // bool Equals(const RS232DecodeEvent decodeEvent)
+        // {
+        //     if (decodeEvent.EventDataCount != EventDataCount)
+        //     {
+        //         return false;
+        //     }
+        //     const int64_t size = decodeEvent.EventDataCount;
+        //     for (int64_t i = 0; i < size; i++)
+        //     {
+        //         if (!decodeEvent.EventData[i].Equals(EventData[i]))
+        //         {
+        //             return false;
+        //         }
+        //     }
+        //     return true;
+        // }
+    };
+}

+ 18 - 0
ProtocolRS232/RS232DecodeResult.cpp

@@ -0,0 +1,18 @@
+// // ******************************************************************
+// //       /\ /|       @File         RS232DecodeResult.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "RS232DecodeResult.h"
+
+namespace Protocol
+{
+    // void RS232DecodeResult::ClearData()
+    // {
+    //      
+    // }
+}

+ 38 - 0
ProtocolRS232/RS232DecodeResult.h

@@ -0,0 +1,38 @@
+// // ******************************************************************
+// //       /\ /|       @File         RS232DecodeResult.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <cstdint>
+#include "ProtocolRS232Enums.h"
+#include "../DecodeResult.h"
+#include "RS232Packet.h"
+#include "RS232DecodeEvent.h"
+
+namespace Protocol
+{
+    struct RS232DecodeResultCell : DecodeResultCell
+    {
+    };
+
+    struct RS232DecodeResult // : DecodeResult
+    {
+        // SerialProtocolType GetProtocolType() override
+        // {
+        //     return SerialProtocolType::RS232;
+        // }
+        //
+        // void ClearData();
+        bool DecodeResultNeedUpdate = false;
+        bool DecodeEventNeedUpdate = false;
+        RS232DecodeResultCell* DecodeResultUnitsPtr; //解码数据结果指针
+        RS232DecodeEvent* DecodeEventsPtr; //解码结果事件指针
+        uint64_t DecodeResultCount; //结果数量
+        uint64_t DecodeEventCount; //事件数量
+    };
+}

+ 18 - 0
ProtocolRS232/RS232Packet.cpp

@@ -0,0 +1,18 @@
+// // ******************************************************************
+// //       /\ /|       @File         RS232Packet.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "RS232Packet.h"
+
+namespace Protocol
+{
+    // Enums::RS232DecodePacketType RS232Packet::GetPacketType()
+    // {
+    //     return Enums::RS232DecodePacketType::None;
+    // }
+}

+ 34 - 0
ProtocolRS232/RS232Packet.h

@@ -0,0 +1,34 @@
+// // ******************************************************************
+// //       /\ /|       @File         RS232Packet.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <cstdint>
+#include "ProtocolRS232Enums.h"
+
+namespace Protocol
+{
+    //内部使用数据结构 数据帧
+    struct RS232Packet
+    {
+        bool StartBit; //起始位
+        bool ParityBit; //校验位数据 High or Low
+        bool ParityFind; //是否存在校验位
+        bool ParityResult; //校验结果 有效 or 无效
+
+        uint8_t Data; //解码数据
+        int32_t DataIndex; //数据开始帧序号
+        int32_t ParityIndex; //校准开始帧序号
+        int32_t StartIndex; //数据开始序号
+
+        double PerBitLenght; //单字节数据时域占比长度
+
+        //virtual Enums::RS232DecodePacketType GetPacketType();
+        //virtual ~RS232Packet() = default;
+    };
+}

+ 43 - 0
ProtocolRS232/RS232Params.h

@@ -0,0 +1,43 @@
+// // ******************************************************************
+// //       /\ /|       @File         RS232Params.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+
+#include "../BaseEnums/Channels.h"
+#include "ProtocolRS232Enums.h"
+#include "../QuantizeParams.h"
+//#include "../DecodeParams.h"
+
+namespace Protocol
+{
+    struct RS232DecodeParams //:public DecodeParams
+    {
+        //=============== 配置参数 ==============//
+        uint32_t BaudRate; //波特率
+        OddEvenCheck OddEvenCheckType; //奇偶检验类型  None,Odd,Even
+
+        Polarity Polarity; //电平极性  None, Pos,  Neg
+        SignalType SignalType; //信号类型   SingleEnded单端,Diff差分
+        //ChannelId Source; //信源号
+        MSBOrLSB MSBOrLSB; //大小端
+
+        RS232Enums::DataBitWidth DataBitWidth; //数据位宽
+        RS232Enums::StopBit StopBit; //停止位
+        float Threshold; //电平阈值
+
+        //=============== 双电平数据 ==============//
+        EdgePulseDataTwoLevels* EdgePulseData;
+    };
+
+    //整型输入参数
+    class UsbQuantizedParams : QuantizeParams
+    {
+        //todo 整形参数
+    };
+}

+ 26 - 0
QuantizeParams.cpp

@@ -0,0 +1,26 @@
+// // ******************************************************************
+// //       /\ /|       @File         QuantizeParams.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include "QuantizeParams.h"
+
+namespace Protocol
+{
+    QuantizeParams::QuantizeParams(): LevelOption(), BitDepth(0)
+    {
+        // 初始化默认参数...
+    }
+
+    QuantizeParams::QuantizeParams(const QuantizeParams& quantizeParams): LevelOption(quantizeParams.LevelOption),
+                                                                          BitDepth(quantizeParams.BitDepth)
+
+    {
+    }
+
+    QuantizeParams::~QuantizeParams() = default;
+}

+ 44 - 0
QuantizeParams.h

@@ -0,0 +1,44 @@
+// // ******************************************************************
+// //       /\ /|       @File         QuantizeParams.h
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#pragma once
+#include <memory>
+//#include <string>
+#include <windows.h>
+
+#include "EdgePulse.h"
+#include "BaseEnums/QuantizedEnums.h"
+
+namespace Protocol
+{
+    class QuantizeParams
+    {
+    public:
+        //电平数量  目前第一步支持2、3电平2种
+        QuantizedLevelOption LevelOption;
+
+        // 电平阈值数组,用于存储多电平量化的阈值。
+        // 数组的大小取决于所需的电平数量,例如,如果需要4个电平,则需要3个阈值。
+        //单位 V
+        std::vector<double> LevelThresholdsByV;
+
+        // 量化位数
+        int BitDepth;
+
+        // 原始数据对象
+        std::unique_ptr<byte> OriginalData;
+
+        QuantizeParams();
+
+        //拷贝构造函数  ljw 24.5
+        QuantizeParams(const QuantizeParams& quantizeParams);
+
+        ~QuantizeParams();
+    };
+}

+ 37 - 0
dllmain.cpp

@@ -0,0 +1,37 @@
+// // ******************************************************************
+// //       /\ /|       @File         dllmain.cpp
+// //       \ V/        @Brief
+// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
+// //       /  |        @Creation      2024-05-16
+// //      /  \\        @Modified      2024-05-16
+// //    *(__\_\
+// // ******************************************************************
+
+#include <windows.h>
+
+//核心的入口函数,动态链接库入口函数
+BOOL APIENTRY DllMain(HMODULE hModule, //APIENTRY可以换成WINAPI、__stdcall和CALLBACK,是一种调用约定
+                      DWORD ul_reason_for_call,
+                      LPVOID lpReserved
+)
+//hModule:DLL模块的句柄	   ul_reason_for_call:DLL模块被调用的原因	lpReserved:保留参数,没有意义,windows不想让我们知道的参数	
+{
+    switch (ul_reason_for_call)
+    {
+    case DLL_PROCESS_ATTACH:
+        //当DLL被进程加载时DLLMain被调用
+        break;
+    case DLL_THREAD_ATTACH:
+        //有线程被创建时,DLLmain被调用
+        break;
+    case DLL_THREAD_DETACH:
+        //有线程结束时,DLLmain被调用
+        break;
+    case DLL_PROCESS_DETACH:
+        //当DLL被进程卸载时,DLLmain被调用
+        break;
+    default:
+        break;
+    }
+    return TRUE;
+}