Browse Source

0.1.9 SPI IIC待测试

lijinwen 2 months ago
parent
commit
50ee57004f

+ 1 - 0
.gitignore

@@ -24,3 +24,4 @@ riderModule.iml
 /*.user
 .idea
 .vs
+/x64/Debug/ProtocolDecoder.tlog

+ 2 - 2
BaseHelper/constants.h

@@ -11,8 +11,8 @@
 
 namespace Protocol
 {
-
     //用于设置比较的容忍度
     constexpr double FLOAT_EQUAL_EPSILON = 1e-6;
-
+    //解码超时时间
+    constexpr int32_t DECODE_OUT_TIME_BY_SEC = 2;
 };

+ 0 - 1
ProtocolDecoder.vcxproj

@@ -189,7 +189,6 @@
     <ClInclude Include="ProtocolSPI\constants.h" />
     <ClInclude Include="ProtocolSPI\protocol_spi_enums.h" />
     <ClInclude Include="ProtocolSPI\spi_decoder.h" />
-    <ClInclude Include="ProtocolSPI\spi_decode_event.h" />
     <ClInclude Include="ProtocolSPI\spi_decode_options.h" />
     <ClInclude Include="ProtocolSPI\spi_decode_result.h" />
     <ClInclude Include="ProtocolSPI\spi_packet.h" />

+ 2 - 2
ProtocolIIC/constants.h

@@ -9,10 +9,10 @@
 
 #pragma once
 #include <cstdint>
-
+#include "../BaseHelper/Constants.h"
 namespace Protocol
 {
     //
     //constexpr double xxx = 0.95;
-    constexpr int32_t DECODE_OUT_TIME_BY_SEC = 2;
+   
 }

+ 1 - 0
ProtocolIIC/iic_decode_options.h

@@ -14,5 +14,6 @@ namespace Protocol
     struct IicDecodeOptions
     {
         IicEnums::DataBitWidth data_bit_width;
+        bool* is_cancel;//取消解码
     };
 }

+ 2 - 1
ProtocolIIC/iic_decoder.cc

@@ -4,10 +4,11 @@
 
 namespace Protocol
 {
-    bool IicDecoder::IicDecode(const IicDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_clk,
+    bool IicDecoder::DecodeIic(const IicDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_clk,
                                const EdgePulseDataTwoLevels& edge_pulses_data, IicDecodeResult& result)
     {
         result = {};
+        is_cancel_ptr_ = option.is_cancel;
         wave_data_len_ = static_cast<int32_t>(
             std::min(edge_pulses_clk.waveform_data_count, edge_pulses_data.waveform_data_count));
         bit_width_ = option.data_bit_width;

+ 1 - 1
ProtocolIIC/iic_decoder.h

@@ -25,7 +25,7 @@ namespace Protocol
     class IicDecoder
     {
     public:
-        bool IicDecode(const IicDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_clk,
+        bool DecodeIic(const IicDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_clk,
                        const EdgePulseDataTwoLevels& edge_pulses_data, IicDecodeResult& result);
 
         std::vector<std::string> event_info_titles = {

+ 6 - 6
ProtocolRS232/protocol_rs232_options.h

@@ -16,16 +16,16 @@ namespace Protocol
 {
     struct ProtocolRs232Options
     {
-        unsigned int baudRate; //波特率
-        OddEvenCheck oddEvenCheckType; //奇偶检验类型  None,Odd,Even
+        unsigned int baud_rate; //波特率
+        OddEvenCheck odd_even_check_type; //奇偶检验类型  None,Odd,Even
 
         Polarity polarity; //电平极性  None, Pos,  Neg
-        SignalType signalType; //信号类型   SingleEnded单端,Diff差分
+        SignalType signal_type; //信号类型   SingleEnded单端,Diff差分
 
-        MSBOrLSB msbOrLsb; //大小端
+        MSBOrLSB msb_or_lsb; //大小端
 
-        Rs232Enums::DataBitWidth dataBitWidth; //数据位宽
-        Rs232Enums::StopBit stopBit; //停止位
+        Rs232Enums::DataBitWidth data_bit_width; //数据位宽
+        Rs232Enums::StopBit stop_bit; //停止位
         float threshold; //电平阈值
         bool* is_cancel;
     };

+ 6 - 5
ProtocolRS232/rs232_decode_event.h

@@ -16,11 +16,11 @@ namespace Protocol
 {
     struct Rs232DecodeEventUnit
     {
-        int64_t startIndex; //开始帧
+        int64_t start_index; //开始帧
         int64_t length; //长度
         uint8_t data; //数据
 
-        Rs232Enums::Rs232DecodeEventType eventType; //事件类型   None, Start, Data,Parity,
+        Rs232Enums::Rs232DecodeEventType event_type; //事件类型   None, Start, Data,Parity,
 
         // //事件相等判断
         // bool Equals(const RS232DecodeEventUint eventData) const
@@ -32,9 +32,10 @@ namespace Protocol
 
     struct Rs232DecodeEvent : DecodeBaseEvent
     {
-        int8_t parityResult; //校验结果
-        Rs232DecodeEventUnit* eventData; //事件数据指针
-        int64_t eventDataCount; //事件数据长度
+        int8_t parity_result; //校验结果
+        
+        Rs232DecodeEventUnit* event_data; //事件数据指针
+        int64_t event_data_count; //事件数据长度
 
         //事件相等判断
         // bool Equals(const RS232DecodeEvent decodeEvent)

+ 6 - 6
ProtocolRS232/rs232_decode_result.h

@@ -28,11 +28,11 @@ namespace Protocol
         // }
         //
         // void ClearData();
-        bool decodeResultNeedUpdate = false;
-        bool decodeEventNeedUpdate = false;
-        Rs232DecodeResultCell* decodeResultCellsPtr; //解码数据结果指针
-        Rs232DecodeEvent* decodeEventsPtr; //解码结果事件指针
-        uint64_t decodeResultCount; //结果数量
-        uint64_t decodeEventCount; //事件数量
+        bool decode_result_need_update = false;
+        bool decode_event_need_update = false;
+        Rs232DecodeResultCell* decode_result_cells_ptr; //解码数据结果指针
+        Rs232DecodeEvent* decode_events_ptr; //解码结果事件指针
+        uint64_t decode_result_count; //结果数量
+        uint64_t decode_event_count; //事件数量
     };
 }

+ 63 - 63
ProtocolRS232/rs232_decoder.cc

@@ -32,7 +32,7 @@ namespace Protocol
             {
                 //计算该脉宽中,最大包括几个bit信息宽度
                 const double bitCount = std::round(node->GetLength() / count);
-                if (bitCount > 0 && bitCount < static_cast<int32_t>(options.dataBitWidth) + 4)
+                if (bitCount > 0 && bitCount < static_cast<int32_t>(options.data_bit_width) + 4)
                 {
                     real_count = node->GetLength() / bitCount;
                 }
@@ -51,7 +51,7 @@ namespace Protocol
 
     {
         WriteLog(LogLevel::LevelDebug, " SignalType:%d, DataBitWidth:%d"
-                 , static_cast<int>(options.signalType), static_cast<int>(options.dataBitWidth));
+                 , static_cast<int>(options.signal_type), static_cast<int>(options.data_bit_width));
         if (options.is_cancel)
         {
             WriteLog(LogLevel::Level2, "  ParsingData canceled.\n");
@@ -62,11 +62,11 @@ namespace Protocol
         //栈上 初始化内存
         std::vector<Rs232Packet> rs232_packets;
         rs232_packets = {};
-        decodeEvents_ = {};
-        decodeResultUnits_ = {};
+        decode_events_ = {};
+        decode_result_units_ = {};
 
-        auto decodeResultUnitsPtr = &decodeResultUnits_;
-        auto decodeEvents_Ptr = &decodeEvents_;
+        auto decodeResultUnitsPtr = &decode_result_units_;
+        auto decodeEvents_Ptr = &decode_events_;
         WriteLog(LogLevel::LevelDebug, "  decodeResultUnitsPtr:0x%X\n", static_cast<void*>(decodeResultUnitsPtr));
         WriteLog(LogLevel::LevelDebug, "  decodeEvents_Ptr:0x%X\n", static_cast<void*>(decodeEvents_Ptr));
 
@@ -89,7 +89,7 @@ namespace Protocol
         }
 
         int32_t dataBitCount = 0;
-        switch (options.dataBitWidth)
+        switch (options.data_bit_width)
         {
         case Rs232Enums::DataBitWidth::DATA_BIT_WIDTH_5_BIT:
             dataBitCount = 5;
@@ -109,15 +109,15 @@ namespace Protocol
         uint64_t edgePulseIndex = 0;
 
         //每bit理论长度
-        const double count = 1.0 / options.baudRate * sample_rate;
+        const double count = 1.0 / options.baud_rate * sample_rate;
         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::STOP_BIT_1_BIT
+        const int32_t stopBitCount = options.stop_bit == Rs232Enums::StopBit::STOP_BIT_1_BIT
                                          ? 1
-                                         : options.stopBit == Rs232Enums::StopBit::STOP_BIT_2_BIT
+                                         : options.stop_bit == Rs232Enums::StopBit::STOP_BIT_2_BIT
                                          ? 2
                                          : 1;
 
@@ -171,12 +171,12 @@ namespace Protocol
 
                 if (startIndex == static_cast<int32_t>(waveform_data_count)) 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.perBitLength = realCount;
+                packet.start_bit = levelState == TwoLevelEdgePulseStatusType::High;
+                packet.start_index = packetStartIndex - static_cast<int32_t>(std::round(realCount / 2));
+                packet.data_index = packetStartIndex + static_cast<int32_t>(std::round(realCount / 2));
+                packet.per_bit_length = realCount;
 
-                WriteLog(LogLevel::LevelDebug, "=> Tst  StartIndex:%d,dataBitCount:%d", packet.startIndex, dataBitCount);
+                WriteLog(LogLevel::LevelDebug, "=> Tst  StartIndex:%d,dataBitCount:%d", packet.start_index, dataBitCount);
                 for (int32_t dataBitIndex = 0; dataBitIndex < dataBitCount; dataBitIndex++)
                 {
                     if (options.is_cancel)
@@ -202,7 +202,7 @@ namespace Protocol
                         return false;
                     }
                     //按位构造数据
-                    if (options.msbOrLsb == MSBOrLSB::MSB)
+                    if (options.msb_or_lsb == MSBOrLSB::MSB)
                     {
                         packet.data = static_cast<uint8_t>(packet.data << 1);
                         packet.data |= bitStatus == TwoLevelEdgePulseStatusType::High ? 1 : 0;
@@ -220,7 +220,7 @@ namespace Protocol
                 //std::cout << "  P177 Test" << "\n";
                 if (startIndex == static_cast<int32_t>(waveform_data_count)) break;
                 //校验位
-                if (options.oddEvenCheckType != OddEvenCheck::None)
+                if (options.odd_even_check_type != OddEvenCheck::None)
                 {
                     packetStartIndex += static_cast<int32_t>(std::round(realCount));
 
@@ -237,11 +237,11 @@ namespace Protocol
                         //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>(
+                    packet.parity_find = true;
+                    packet.parity_bit = bitStatus == TwoLevelEdgePulseStatusType::High;
+                    packet.parity_result = DataCheckHelper::CheckDataByOddEven(
+                        packet.data, dataBitCount, options.odd_even_check_type);
+                    packet.parity_index = packet.data_index + static_cast<int32_t>(
                         std::round(realCount * dataBitCount));
                 }
                 //std::cout << "  P203 Test" << "\n";
@@ -269,7 +269,7 @@ namespace Protocol
         //std::cout << "  P218 Test rs232Packets Count:" << rs232Packets.size() << "\n";
         if (!rs232_packets.empty())
         {
-            decodeEventUnitsStorage_ = {};
+            decode_event_units_storage_ = {};
             //for (int64_t i = 0; i < static_cast<int64_t>(rs232Packets.size()); i++)
             for (auto packet : rs232_packets)
             {
@@ -284,43 +284,43 @@ namespace Protocol
                 auto eventPtr = &decodeEvent;
                 Rs232DecodeEventUnit eventStart;
                 Rs232DecodeEventUnit eventData;
-                int64_t eventStartIndex = packet.startIndex;
-                int64_t oneBitLength = static_cast<int64_t>(packet.perBitLength);
+                int64_t eventStartIndex = packet.start_index;
+                int64_t oneBitLength = static_cast<int64_t>(packet.per_bit_length);
 
-                eventPtr->start_index = packet.startIndex;
+                eventPtr->start_index = packet.start_index;
 
-                eventStart.startIndex = packet.startIndex;
+                eventStart.start_index = packet.start_index;
                 eventStart.length = oneBitLength;
                 eventStartIndex += 1;
-                eventStart.eventType = Rs232Enums::Rs232DecodeEventType::START;
+                eventStart.event_type = Rs232Enums::Rs232DecodeEventType::START;
 
-                eventData.startIndex = eventStart.startIndex;
+                eventData.start_index = eventStart.start_index;
                 eventData.length = oneBitLength * dataBitCount;
                 eventData.data = packet.data;
-                eventData.eventType = Rs232Enums::Rs232DecodeEventType::DATA;
+                eventData.event_type = Rs232Enums::Rs232DecodeEventType::DATA;
                 eventStartIndex += 8;
 
 
                 //std::cout << "  P249 Test I:" << i << "\n";
-                if (packet.parityFind)
+                if (packet.parity_find)
                 {
                     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.data = packet.parity_result ? 1 : 0;
+                    eventParity.start_index = eventStartIndex;
                     eventParity.length = oneBitLength;
-                    eventParity.eventType = Rs232Enums::Rs232DecodeEventType::PARITY;
-                    eventPtr->parityResult = packet.parityResult ? 1 : 0;
+                    eventParity.event_type = Rs232Enums::Rs232DecodeEventType::PARITY;
+                    eventPtr->parity_result = packet.parity_result ? 1 : 0;
                     eventUints[2] = eventParity;
                     //eventPtr->EventData = eventUints;
                     eventStartIndex += 8;
-                    eventPtr->eventDataCount = 3;
-                    eventPtr->end_index = packet.startIndex + oneBitLength * (dataBitCount + 1);
+                    eventPtr->event_data_count = 3;
+                    eventPtr->end_index = packet.start_index + oneBitLength * (dataBitCount + 1);
                     // 将eventUints复制到decodeEventUnitsStorage中
-                    decodeEventUnitsStorage_.insert(decodeEventUnitsStorage_.end(), std::begin(eventUints),
+                    decode_event_units_storage_.insert(decode_event_units_storage_.end(), std::begin(eventUints),
                                                    std::end(eventUints));
                     //最后来赋值
                     //decodeEvent.EventData = decodeEventUnitsStorage_.data() + decodeEventUnitsStorage_.size() - 3;
@@ -330,63 +330,63 @@ namespace Protocol
                     Rs232DecodeEventUnit eventUints[2];
                     eventUints[0] = eventStart;
                     eventUints[1] = eventData;
-                    eventPtr->eventDataCount = 2;
+                    eventPtr->event_data_count = 2;
 
                     //eventPtr->EventData = eventUints;
                     //std::cout << "  P263 Test I:" << i << "\n";
-                    eventPtr->parityResult = 0;
-                    eventPtr->end_index = packet.startIndex + oneBitLength * (dataBitCount);
+                    eventPtr->parity_result = 0;
+                    eventPtr->end_index = packet.start_index + oneBitLength * (dataBitCount);
                     // 将eventUints复制到decodeEventUnitsStorage中
-                    decodeEventUnitsStorage_.insert(decodeEventUnitsStorage_.end(), std::begin(eventUints),
+                    decode_event_units_storage_.insert(decode_event_units_storage_.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.startIndex = packet.start_index;
                 //最后来赋值
                 //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;
+                resultUnit.length = eventStartIndex - packet.start_index;
 
                 eventPtr->event_index = static_cast<int64_t>(decodeEvents_Ptr->size());
 
-                decodeEvents_.push_back(decodeEvent);
-                decodeResultUnits_.push_back(resultUnit);
+                decode_events_.push_back(decodeEvent);
+                decode_result_units_.push_back(resultUnit);
 
-                decode_result.decodeEventNeedUpdate = true;
-                decode_result.decodeResultNeedUpdate = true;
+                decode_result.decode_event_need_update = true;
+                decode_result.decode_result_need_update = true;
             }
         }
 
         /////////////////////////// 指针赋值 /////////////////////////////////
         int64_t eventDataIndex = 0;
-        for (int i = 0; i < decodeEvents_.size(); i++) // NOLINT(modernize-loop-convert, clang-diagnostic-sign-compare)
+        for (int i = 0; i < decode_events_.size(); i++) // NOLINT(modernize-loop-convert, clang-diagnostic-sign-compare)
         {
-            decodeEvents_[i].eventData = decodeEventUnitsStorage_.data() + eventDataIndex;
-            eventDataIndex += decodeEvents_[i].eventDataCount;
+            decode_events_[i].event_data = decode_event_units_storage_.data() + eventDataIndex;
+            eventDataIndex += decode_events_[i].event_data_count;
         }
 
-        for (int i = 0; i < decodeResultUnits_.size(); i++)  // NOLINT(clang-diagnostic-sign-compare)
+        for (int i = 0; i < decode_result_units_.size(); i++)  // NOLINT(clang-diagnostic-sign-compare)
         {
-            int64_t startIndex = decodeResultUnits_[i].startIndex;
+            int64_t startIndex = decode_result_units_[i].startIndex;
             for (int x = 0; i < rs232_packets.size(); x++) // NOLINT(clang-diagnostic-sign-compare)
             {
-                if (rs232_packets[x].startIndex == startIndex)
+                if (rs232_packets[x].start_index == startIndex)
                 {
-                    decodeResultUnits_[i].data = &(rs232_packets[x].data);
+                    decode_result_units_[i].data = &(rs232_packets[x].data);
                     break;
                 }
             }
         }
 
-        decode_result.decodeEventsPtr = decodeEvents_Ptr->data();
-        decode_result.decodeResultCellsPtr = decodeResultUnitsPtr->data();
-        decode_result.decodeEventCount = decodeEvents_Ptr->size();
-        decode_result.decodeResultCount = decodeResultUnitsPtr->size();
+        decode_result.decode_events_ptr = decodeEvents_Ptr->data();
+        decode_result.decode_result_cells_ptr = decodeResultUnitsPtr->data();
+        decode_result.decode_event_count = decodeEvents_Ptr->size();
+        decode_result.decode_result_count = decodeResultUnitsPtr->size();
 
         WriteLog(LogLevel::Level1, "  Cpp ParsingData Done,return True \n\n");
 
@@ -396,24 +396,24 @@ namespace Protocol
 
     std::vector<const char*> Rs232Decoder::GetEventInfoTitles()
     {
-        return eventInfoTitles_;
+        return event_info_titles_;
     }
 
     bool Rs232Decoder::GetRs232Bit(TwoLevelEdgePulse*& edge_pulse,
-                     const int32_t targetIndex, TwoLevelEdgePulseStatusType& status)
+                     const int32_t target_index, TwoLevelEdgePulseStatusType& status)
     {
         status = TwoLevelEdgePulseStatusType::None;
         if (edge_pulse == nullptr)
         {
             return false;
         }
-        if (targetIndex <= 0 || edge_pulse->start_index > targetIndex)
+        if (target_index <= 0 || edge_pulse->start_index > target_index)
         {
             return false;
         }
         while (edge_pulse != nullptr)
         {
-            if (edge_pulse->start_index <= targetIndex && edge_pulse->end_index > targetIndex)
+            if (edge_pulse->start_index <= target_index && edge_pulse->end_index > target_index)
             {
                 status = edge_pulse->current_level;
 

+ 9 - 9
ProtocolRS232/rs232_decoder.h

@@ -32,27 +32,27 @@ namespace Protocol
         std::vector<const char*> GetEventInfoTitles();
 
         bool DecodeRs232(const ProtocolRs232Options& options, TwoLevelEdgePulse* edge_pulses,
-                        const uint64_t edge_pulse_count,
-                        const uint64_t waveform_data_count, const double sample_rate,
+                         uint64_t edge_pulse_count,
+                         uint64_t waveform_data_count, double sample_rate,
                         Rs232DecodeResult& decode_result);
         bool QuantizeParamsDecodeRs232(const QuantizeParams& quantize_params, const ProtocolRs232Options& options,
                                    Rs232DecodeResult& decode_result);
     private:
-        bool* is_cancel_ptr_;
-        std::vector<const char*> eventInfoTitles_ = {
+        bool* is_cancel_ptr_ = nullptr;
+        std::vector<const char*> event_info_titles_ = {
             "Index", "Start Time", "Data", "Parity", "Error"
         };
-        std::vector<Rs232DecodeResultCell> decodeResultUnits_;
-        std::vector<Rs232DecodeEventUnit> decodeEventUnitsStorage_;
-        std::vector<Rs232DecodeEvent> decodeEvents_;
+        std::vector<Rs232DecodeResultCell> decode_result_units_;
+        std::vector<Rs232DecodeEventUnit> decode_event_units_storage_;
+        std::vector<Rs232DecodeEvent> decode_events_;
 
         static bool GetRs232Bit(TwoLevelEdgePulse*& edge_pulse,
                                 int32_t target_index, TwoLevelEdgePulseStatusType& status);
        
         static int32_t GetStartIndex(const ProtocolRs232Options& options, TwoLevelEdgePulse*& node,
-                                     const double count,
+                                     double count,
                                      double& real_count,
-                                     const int32_t start_index,
+                                     int32_t start_index,
                                      TwoLevelEdgePulseStatusType& start_status);
         bool ParseRs232(const ProtocolRs232Options& options,
                         const EdgePulseDataTwoLevels& edge_pulse_data,

+ 8 - 8
ProtocolRS232/rs232_packet.h

@@ -16,17 +16,17 @@ namespace Protocol
     //内部使用数据结构 数据帧
     struct Rs232Packet
     {
-        bool startBit; //起始位
-        bool parityBit; //校验位数据 High or Low
-        bool parityFind; //是否存在校验位
-        bool parityResult; //校验结果 有效 or 无效
+        bool start_bit; //起始位
+        bool parity_bit; //校验位数据 High or Low
+        bool parity_find; //是否存在校验位
+        bool parity_result; //校验结果 有效 or 无效
 
         uint8_t data; //解码数据
-        int32_t dataIndex; //数据开始帧序号
-        int32_t parityIndex; //校准开始帧序号
-        int32_t startIndex; //数据开始序号
+        int32_t data_index; //数据开始帧序号
+        int32_t parity_index; //校准开始帧序号
+        int32_t start_index; //数据开始序号
 
-        double perBitLength; //单字节数据时域占比长度
+        double per_bit_length; //单字节数据时域占比长度
 
     };
 }

+ 1 - 1
ProtocolSPI/constants.h

@@ -9,7 +9,7 @@
 
 #pragma once
 #include <cstdint>
-
+#include "../BaseHelper/Constants.h"
 namespace Protocol
 {
     //

+ 0 - 20
ProtocolSPI/spi_decode_event.h

@@ -1,20 +0,0 @@
-// // ******************************************************************
-// //       /\ /|       @File         spi_decode_event.h
-// //       \ V/        @Brief
-// //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
-// //       /  |        @Creation      2024-07-16
-// //      /  \\        @Modified      2024-07-16
-// //    *(__\_\
-// // ******************************************************************
-
-#pragma once
-#include "spi_packet.h"
-#include "../decode_event.h"
-
-namespace Protocol
-{
-    struct SpiDecodeEvent : DecodeBaseEvent
-    {
-         
-    };
-}

+ 7 - 2
ProtocolSPI/spi_decode_options.h

@@ -14,7 +14,12 @@ namespace Protocol
 {
     struct SpiDecodeOptions
     {
-        Protocol::SpiEnums::DecodeChannel decode_channel;
-        Protocol::SpiEnums::Msblsb msb_lsb;
+        SpiEnums::DecodeChannel decode_channel;
+        SpiEnums::Msblsb msb_lsb;
+        Polarity clk_polarity;
+        Polarity cs_polarity;
+        Polarity mosi_polarity;
+        Polarity miso_polarity;
+        bool* is_cancel;//取消解码
     };
 }

+ 5 - 5
ProtocolSPI/spi_decode_result.h

@@ -11,15 +11,15 @@
 //#include <utility>
 
 //#include "protocol_spi_enums.h"
-
-#include "spi_decode_event.h"
+ 
+#include "spi_packet.h"
 #include "../decode_result.h"
 //#include "spi_packet.h"
 //#include "../decode_event.h"
 
 namespace Protocol
 {
-    class spiDecodeResultCell : DecodeResultCell
+    class SpiDecodeResultCell : DecodeResultCell
     {
 
 
@@ -29,8 +29,8 @@ namespace Protocol
     {
         bool decode_result_need_update = false;
         bool decode_event_need_update = false;
-        spiDecodeResultCell* decode_result_cells_ptr; //解码数据结果指针
-        SpiDecodeEvent* decode_events_ptr; //解码结果事件指针
+        SpiDecodeResultCell* decode_result_cells_ptr; //解码数据结果指针
+        SpiPacket* decode_events_ptr; //解码结果事件指针
         uint64_t decode_result_count; //结果数量
         uint64_t decode_event_count; //事件数量
         

+ 334 - 81
ProtocolSPI/spi_decoder.cc

@@ -8,123 +8,376 @@
 // // ******************************************************************
 
 #include "spi_decoder.h"
+
+#include "../BaseHelper/common_helper.h"
+#include "../BaseHelper/constants.h"
+
 namespace Protocol
 {
-    bool SpiDecoder::DecodeSpi(const SpiDecodeOptions& options, const Protocol::TwoLevelEdgePulse& edge_pulse_data_clk,
-        const Protocol::TwoLevelEdgePulse& edge_pulse_data_cs, const Protocol::TwoLevelEdgePulse& edge_pulse_data_mosi,
-        const Protocol::TwoLevelEdgePulse& edge_pulse_data_miso, Protocol::SpiDecodeResult& decode_result)
+    bool SpiDecoder::DecodeSpi(const SpiDecodeOptions& options, const EdgePulseDataTwoLevels& edge_pulse_data_clk,
+                               const EdgePulseDataTwoLevels& edge_pulse_data_cs,
+                               const EdgePulseDataTwoLevels& edge_pulse_data_mosi,
+                               const EdgePulseDataTwoLevels& edge_pulse_data_miso, SpiDecodeResult& decode_result)
     {
-    
-        if (csindex == -1 || clkindex == -1 || mosiindex == -1 || misoindex == -1) {
+        is_cancel_ptr_ = options.is_cancel;
+        decode_result = {};
+        bool checked_params = true;
+        if (edge_pulse_data_clk.waveform_data_count <= 0
+            || edge_pulse_data_cs.waveform_data_count <= 0
+            || edge_pulse_data_clk.sample_rate <= 0
+            || edge_pulse_data_cs.sample_rate <= 0)
+        {
+            checked_params = false;
+        }
+        const bool decode_mosi = options.decode_channel == SpiEnums::DecodeChannel::MOMI || options.decode_channel ==
+            SpiEnums::DecodeChannel::MOSI;
+        const bool decode_miso = options.decode_channel == SpiEnums::DecodeChannel::MOMI || options.decode_channel ==
+            SpiEnums::DecodeChannel::MISO;
+        if (decode_mosi && (edge_pulse_data_mosi.waveform_data_count <= 0 || edge_pulse_data_mosi.sample_rate <= 0))
+        {
+            checked_params = false;
+        }
+        if (decode_miso && (edge_pulse_data_miso.waveform_data_count <= 0 || edge_pulse_data_miso.sample_rate <= 0))
+        {
+            checked_params = false;
+        }
+        if (!checked_params)
+        {
             need_decode_data_ = false;
             need_update_view_info_ = true;
             packet_infos_.clear();
+            return false;
         }
-
-        bool needclear = false;
-        try {
-            if (need_decode_data_) {
+        try
+        {
+            if (need_decode_data_)
+            {
                 need_decode_data_ = false;
                 need_update_view_info_ = true;
                 packet_infos_.clear();
-                try {
-                    int packetindex = 0;
-                    uint32_t cslen = 0, clklen = 0, misolen = 0, mosilen = 0;
-                    DecodeDataHelper::Instance.TryGetPerChannelDataLength(_CS, cslen);
-                    DecodeDataHelper::Instance.TryGetPerChannelDataLength(_CLK, clklen);
-                    DecodeDataHelper::Instance.TryGetPerChannelDataLength(_MISO, misolen);
-                    DecodeDataHelper::Instance.TryGetPerChannelDataLength(_MOSI, mosilen);
-                    int csstartindex = -1;
-                    bool clkstate = clkState_ == Edge::Rise;
-
-                    while (true) {
+                try
+                {
+                    int32_t packet_index = 0;
+                    uint64_t cs_len = edge_pulse_data_cs.waveform_data_count;
+                    uint64_t clk_len = edge_pulse_data_clk.waveform_data_count;
+                    uint64_t miso_len = 0;
+                    uint64_t mosi_len = 0;
+                    uint64_t min_data_len = std::min(cs_len, clk_len);
+                    TwoLevelEdgePulse* edge_pulse_data_cs_ptr = edge_pulse_data_cs.GetDataAddrPtr();
+                    TwoLevelEdgePulse* edge_pulse_data_clk_ptr = edge_pulse_data_clk.GetDataAddrPtr();
+                    TwoLevelEdgePulse* edge_pulse_data_miso_ptr = nullptr;
+                    TwoLevelEdgePulse* edge_pulse_data_mosi_ptr = nullptr;
+                    if (decode_miso)
+                    {
+                        miso_len = edge_pulse_data_miso.waveform_data_count;
+                        edge_pulse_data_miso_ptr = edge_pulse_data_miso.GetDataAddrPtr();
+                        min_data_len = std::min(min_data_len, miso_len);
+                    }
+                    if (decode_mosi)
+                    {
+                        mosi_len = edge_pulse_data_mosi.waveform_data_count;
+                        edge_pulse_data_mosi_ptr = edge_pulse_data_mosi.GetDataAddrPtr();
+                        min_data_len = std::min(min_data_len, mosi_len);
+                    }
+                    data_len_ = static_cast<int32_t>(min_data_len);
+                    if (data_len_ == 0)
+                    {
+                        WriteLog(LogLevel::Level2, "data_len == 0");
+                        return false;
+                    }
+                    int32_t cs_start_index = -1;
+                    const bool clk_state = options.clk_polarity == Polarity::POS;
+
+                    while (true)
+                    {
                         // 检查是否取消
                         if (is_cancel_ptr_ != nullptr && *is_cancel_ptr_)
                         {
                             WriteLog(LogLevel::Level2, "AsyncFunction canceled");
                             return false;
                         }
-                        packetindex = FindStartIndex(packetindex, cslen, token, needclear, csstartindex);
-                        if (packetindex == -1 || token.load() || needclear) break;
-
-                        PacketInfo packetInfo = {};
-                        packetInfo.Datas = vector<DataPacketInfo>();
-                        packetInfo.StartIndex = csstartindex;
-                        packetInfo.StartLen = 1;
-                        packetInfo.HasStart = csstartindex >= 0;
-
-                        auto csendindex = GetCSBitNextIndex(csLevelState_ == LevelState::High, packetindex, token, needclear);
-                        if (token.load() || needclear) break;
-
-                        if (csendindex > packetindex) {
-                            packetInfo.HasEnd = true;
-                            packetInfo.EndLen = 1;
-                            packetInfo.EndIndex = csendindex;
+                        if (!FindStartNode(packet_index, cs_start_index,
+                                           edge_pulse_data_cs_ptr, edge_pulse_data_clk_ptr,
+                                           options.cs_polarity, options.clk_polarity))
+                        {
+                            WriteLog(LogLevel::Level2, "Not find start node");
+                            return false;
                         }
 
-                        vector<DataPacketInfo> tempdatapckets;
-                        while (true) {
-                            DataPacketInfo tempdatapacket = {};
-                            tempdatapacket.BitCount = frame_count_;
-                            tempdatapacket.Index = packetindex;
-                            int tempmisodata = 0, tempmosidata = 0;
-
-                            for (int bitindex = 0; bitindex < frame_count_; ++bitindex) {
-                                bool misobit = GetBit(_MISO, packetindex, _MISOThreshold, miso_polarity_ == Polarity::Negative);
-                                bool mosibit = GetBit(_MOSI, packetindex, _MOSIThreshold, mosi_polarity_ == Polarity::Negative);
-                                
-                                if (byte_order_ == MSB_LSB::MSB) {
-                                    tempmisodata <<= 1;
-                                    tempmisodata |= (misobit ? 1 : 0);
-                                    tempmosidata <<= 1;
-                                    tempmosidata |= (mosibit ? 1 : 0);
-                                } else {
-                                    tempmisodata |= (misobit ? 1 : 0) << bitindex;
-                                    tempmosidata |= (mosibit ? 1 : 0) << bitindex;
+                        if (packet_index < 0 || *is_cancel_ptr_) break;
+
+                        SpiPacket packet_info = {};
+                        packet_info.data = std::vector<DataPacketInfo>();
+                        packet_info.start_index = cs_start_index;
+                        packet_info.start_len = 1;
+                        packet_info.has_start = cs_start_index >= 0;
+
+                        if (!GetCsBitNextIndex(options.cs_polarity == Polarity::POS,
+                                               packet_index, edge_pulse_data_cs_ptr))
+                        {
+                            break;
+                        }
+                        const auto cs_end_index = edge_pulse_data_cs_ptr->start_index;
+                        if (bool need_clear = false; *is_cancel_ptr_ || need_clear) break;
+
+                        if (cs_end_index > packet_index)
+                        {
+                            packet_info.has_end = true;
+                            packet_info.end_len = 1;
+                            packet_info.end_index = cs_end_index;
+                        }
+
+                        std::vector<DataPacketInfo> temp_data_packets;
+                        //数据解码
+                        while (true)
+                        {
+                            DataPacketInfo temp_data_packet = {};
+                            temp_data_packet.bit_count = frame_count_;
+                            temp_data_packet.index = packet_index;
+                            int32_t temp_miso_data = 0, temp_mosi_data = 0;
+
+                            for (int32_t bit_index = 0; bit_index < frame_count_; ++bit_index)
+                            {
+                                bool miso_bit = false;
+                                bool mosi_bit = false;
+                                if (decode_miso)
+                                {
+                                    if (!CommonHelper::GetNodeByIndex(packet_index, edge_pulse_data_miso_ptr))
+                                    {
+                                        break;
+                                    }
+                                    miso_bit = edge_pulse_data_miso_ptr->current_level == TwoLevelEdgePulseStatusType::High;
+                                    if (options.miso_polarity == Polarity::NEG)
+                                    {
+                                        miso_bit = !miso_bit;
+                                    }
+                                }
+
+                                if (decode_mosi)
+                                {
+                                    if (!CommonHelper::GetNodeByIndex(packet_index, edge_pulse_data_mosi_ptr))
+                                    {
+                                        break;
+                                    }
+                                    mosi_bit = edge_pulse_data_mosi_ptr->current_level == TwoLevelEdgePulseStatusType::High;
+                                    if (options.mosi_polarity == Polarity::NEG)
+                                    {
+                                        mosi_bit = !mosi_bit;
+                                    }
+                                }
+
+                                if (options.msb_lsb == SpiEnums::Msblsb::MSB)
+                                {
+                                    temp_miso_data <<= 1;
+                                    temp_miso_data |= (miso_bit ? 1 : 0);
+                                    temp_mosi_data <<= 1;
+                                    temp_mosi_data |= (mosi_bit ? 1 : 0);
+                                }
+                                else
+                                {
+                                    temp_miso_data |= (miso_bit ? 1 : 0) << bit_index;
+                                    temp_mosi_data |= (mosi_bit ? 1 : 0) << bit_index;
                                 }
 
-                                tempdatapacket.MISOData.push_back(tempmisodata);
-                                tempdatapacket.MOSIData.push_back(tempmosidata);
-                                tempdatapacket.RealBitCount = bitindex + 1;
-                                packetindex = GetCLKEdge(!clkstate, packetindex, token, needclear);
+                                temp_data_packet.miso_data.push_back(static_cast<uint8_t>(temp_miso_data));
+                                temp_data_packet.mosi_data.push_back(static_cast<uint8_t>(temp_mosi_data));
+                                temp_data_packet.real_bit_count = bit_index + 1;
 
-                                if ((packetindex > csendindex && csendindex >= 0) || packetindex == -1) {
-                                    tempdatapacket.IsLast = true;
+                                if (!GetClkEdge(!clk_state, packet_index, edge_pulse_data_clk_ptr))
+                                {
+                                    break;
+                                }
+                                if ((packet_index > cs_end_index && cs_end_index >= 0) || packet_index == -1)
+                                {
+                                    temp_data_packet.is_last = true;
                                     break;
                                 }
                             }
 
-                            if (packetindex > csendindex && csendindex != -1) {
-                                packetindex = csendindex;
-                                tempdatapacket.Len = packetindex - tempdatapacket.Index;
+                            if (packet_index > cs_end_index && cs_end_index != -1)
+                            {
+                                packet_index = cs_end_index;
+                                temp_data_packet.len = packet_index - temp_data_packet.index;
                             }
-                            if (packetindex == -1) {
-                                if (csendindex != -1) {
-                                    tempdatapacket.Len = static_cast<int>(csendindex - tempdatapacket.Index);
-                                } else {
-                                    tempdatapacket.Len = static_cast<int>(misolen - tempdatapacket.Index);
+                            if (packet_index == -1)
+                            {
+                                if (cs_end_index != -1)
+                                {
+                                    temp_data_packet.len = cs_end_index - temp_data_packet.index;
+                                }
+                                else
+                                {
+                                    temp_data_packet.len = static_cast<int>(miso_len - temp_data_packet.index);
                                 }
-                            } else if (packetindex >= tempdatapacket.Index && tempdatapacket.Len == 0) {
-                                tempdatapacket.Len = packetindex - tempdatapacket.Index;
                             }
-                            if (tempdatapacket.RealBitCount > 0) tempdatapckets.push_back(tempdatapacket);
-                            if (tempdatapacket.IsLast) break;
+                            else if (packet_index >= temp_data_packet.index && temp_data_packet.len == 0)
+                            {
+                                temp_data_packet.len = packet_index - temp_data_packet.index;
+                            }
+                            if (temp_data_packet.real_bit_count > 0) temp_data_packets.push_back(temp_data_packet);
+                            if (temp_data_packet.is_last) break;
                         }
 
-                        packetInfo.Datas = tempdatapckets;
-                        packet_infos_.push_back(packetInfo);
+                        packet_info.data = temp_data_packets;
+                        packet_infos_.push_back(packet_info);
 
-                        if (packetindex >= misolen || packetindex < 0) {
+                        if (packet_index >= static_cast<int32_t>(miso_len) || packet_index < 0)
+                        {
                             break;
                         }
                     }
-                } catch (...) {}
+                }
+                catch (const std::exception& ex)
+                {
+                    std::string error_message = "DecodeSpi Error: " + std::string(ex.what());
+                    WriteLog(LogLevel::Level2, error_message.c_str());
+                }
             }
-        } catch (...) {}
+        }
+        catch (const std::exception& ex)
+        {
+            std::string error_message = "DecodeSpi Error: " + std::string(ex.what());
+            WriteLog(LogLevel::Level2, error_message.c_str());
+        }
 
-        if (need_update_view_info_) {
+        if (need_update_view_info_)
+        {
             need_update_view_info_ = false;
-            // Update view info logic here
+            if (packet_infos_.size() > 0)
+            {
+                decode_result.decode_events_ptr = packet_infos_.data();
+                decode_result.decode_event_count = packet_infos_.size();
+            }
+        }
+        return true;
+    }
+    bool SpiDecoder::GetClkEdge(const bool state, int32_t& start_index, TwoLevelEdgePulse* node_clk)
+    {
+        if (!CommonHelper::GetNodeByIndex(start_index, node_clk))
+        {
+            return false;
+        }
+        if (node_clk->current_level == TwoLevelEdgePulseStatusType::High != state)
+        {
+            if (!CommonHelper::FindNextNode(start_index, node_clk))
+            {
+                return false;
+            }
+            start_index = node_clk->start_index;
+            if (start_index < 0) return false;
+        }
+
+        if (start_index < 0) return false;
+
+        if (!CommonHelper::FindNextNode(start_index, node_clk))
+        {
+            return false;
+        }
+        start_index = node_clk->start_index;
+        if (start_index < 0) return false;
+
+        return true;
+    }
+
+    bool SpiDecoder::FindStartNode(int32_t& start_index, int32_t& cs_start_index, TwoLevelEdgePulse* node_cs,
+                                   TwoLevelEdgePulse* node_clk,
+                                   const Polarity polarity_cs, const Polarity polarity_clk) const
+    {
+        cs_start_index = -1;
+        if (start_index >= data_len_) return false;
+
+        const bool state = polarity_cs == Polarity::POS;
+        const bool clk_state = polarity_clk == Polarity::NEG;
+
+        if (!CommonHelper::GetNodeByIndex(start_index, node_cs))
+        {
+            return false;
+        }
+        if (node_cs->current_level == TwoLevelEdgePulseStatusType::High != state)
+        {
+            if (!CommonHelper::FindNextNode(start_index, node_cs))
+            {
+                return false;
+            }
+            cs_start_index = node_cs->start_index;
+            if (cs_start_index < 0) return false;
+        }
+        else
+        {
+            if (start_index > 0)
+            {
+                cs_start_index = start_index;
+            }
+        }
+
+        if (cs_start_index >= 0)
+        {
+            start_index = cs_start_index;
+        }
+
+        const auto start_time = std::chrono::steady_clock::now();
+
+        while (true)
+        {
+            if (!CommonHelper::GetNodeByIndex(start_index, node_clk))
+            {
+                return false;
+            }
+            if (node_clk->current_level == TwoLevelEdgePulseStatusType::High != clk_state)
+            {
+                if (!CommonHelper::FindNextNode(start_index, node_clk))
+                {
+                    return false;
+                }
+                start_index = node_clk->start_index;
+            }
+            if (start_index <= 0) return false;
+            if (!CommonHelper::FindNextNode(start_index, node_clk))
+            {
+                return false;
+            }
+            start_index = node_clk->start_index;
+            if (start_index <= 0) return false;
+            if (!CommonHelper::GetNodeByIndex(start_index, node_cs))
+            {
+                return false;
+            }
+            if (node_cs->current_level == TwoLevelEdgePulseStatusType::High == state) return node_cs->start_index;
+
+            if (auto end_time = std::chrono::steady_clock::now(); std::chrono::duration_cast<std::chrono::nanoseconds>(
+                    end_time - start_time).count() >
+                DECODE_OUT_TIME_BY_SEC)
+            {
+                WriteLog(LogLevel::Level2, "IIC FindStopNode TimeOut");
+                return false;
+            }
+        }
+    }
+    bool SpiDecoder::GetCsBitNextIndex(const bool state, int32_t& start_index, TwoLevelEdgePulse* node_cs)
+    {
+        if (!CommonHelper::GetNodeByIndex(start_index, node_cs))
+        {
+            return false;
+        }
+        if (node_cs->current_level == TwoLevelEdgePulseStatusType::High != state)
+        {
+            if (node_cs->current_level == TwoLevelEdgePulseStatusType::High != state)
+            {
+                if (!CommonHelper::FindNextNode(start_index, node_cs))
+                {
+                    return false;
+                }
+                start_index = node_cs->start_index;
+            }
+            if (start_index == -1) return false;
+
+            if (!CommonHelper::FindNextNode(start_index, node_cs))
+            {
+                return false;
+            }
+            start_index = node_cs->start_index;
+            return true;
         }
+        return false;
     }
-}
+}

+ 18 - 18
ProtocolSPI/spi_decoder.h

@@ -9,7 +9,7 @@
 
 #pragma once
 #include <vector>
-#include "../BaseHelper//common_helper.h"
+//#include "../BaseHelper/common_helper.h"
 
 #include "../edge_pulse_data.h"
 #include "../edge_pulse.h"
@@ -17,34 +17,34 @@
 
 #include "spi_decode_options.h"
 #include "spi_decode_result.h"
+
 namespace Protocol
 {
     class SpiDecoder
     {
     public:
         bool DecodeSpi(const SpiDecodeOptions& options,
-                       const Protocol::TwoLevelEdgePulse& edge_pulse_data_clk,
-                       const Protocol::TwoLevelEdgePulse& edge_pulse_data_cs,
-                       const Protocol::TwoLevelEdgePulse& edge_pulse_data_mosi,
-                       const Protocol::TwoLevelEdgePulse& edge_pulse_data_miso,
-                       Protocol::SpiDecodeResult& decode_result);
+                       const EdgePulseDataTwoLevels& edge_pulse_data_clk,
+                       const EdgePulseDataTwoLevels& edge_pulse_data_cs,
+                       const EdgePulseDataTwoLevels& edge_pulse_data_mosi,
+                       const EdgePulseDataTwoLevels& edge_pulse_data_miso,
+                       SpiDecodeResult& decode_result);
 
     private:
-        bool* is_cancel_ptr_;
-        std::vector<Protocol::SpiPacket> packet_infos_;
+        bool* is_cancel_ptr_ = nullptr;
+        std::vector<SpiPacket> packet_infos_;
 
         bool need_decode_data_ = false;
         bool need_update_view_info_ = false;
-        Protocol::SpiEnums::FramingMode framing_mode_ = Protocol::SpiEnums::FramingMode::MODE1;
+        //SpiEnums::FramingMode framing_mode_ = SpiEnums::FramingMode::MODE1;
 
         int frame_count_ = 0;
-
-        double idle_time_ = 0;
-
-        Protocol::SpiEnums::Msblsb byte_order_;
-        Protocol::Polarity miso_polarity_, mosi_polarity_;
-        Protocol::SpiEnums::LevelState csLevelState_;
-        Protocol::SpiEnums::Edge clk_state_;
-
+        //double idle_time_ = 0.0;
+ 
+        int32_t data_len_ = 0;
+        bool FindStartNode(int32_t& start_index, int32_t& cs_start_index, TwoLevelEdgePulse* node_cs,
+                           TwoLevelEdgePulse* node_clk, Polarity polarity_cs, Polarity polarity_clk) const;
+        static bool GetCsBitNextIndex(bool state, int32_t& start_index, TwoLevelEdgePulse* node_cs);
+        static bool GetClkEdge(bool state, int32_t& start_index, TwoLevelEdgePulse* node_clk);
     };
-}
+}

+ 3 - 2
ProtocolSPI/spi_packet.h

@@ -9,8 +9,9 @@
 
 #pragma once
 #include <cstdint>
-#include "protocol_spi_enums.h"
+#include <vector>
 
+//#include "../decode_event.h"
 namespace Protocol
 {
     //内部使用数据结构 数据帧
@@ -25,7 +26,7 @@ namespace Protocol
         int32_t real_bit_count;
     };
 
-    struct SpiPacket
+    struct SpiPacket  
     {
         int32_t start_index;
         int32_t start_len;

+ 1 - 1
ProtocolUSB/constants.h

@@ -9,7 +9,7 @@
 
 #pragma once
 #include <cstdint>
-
+#include "../BaseHelper/Constants.h"
 namespace Protocol
 {
     //差分非对称长度比例阈值

+ 11 - 11
ProtocolUSB/sync.h

@@ -16,11 +16,11 @@ namespace Protocol
     {
     public:
         TwoLevelEdgePulse* node_ptr;
-        int end_index;
-        int single_bit_timing_length;
-        int one_byte_timing_length;
+        int32_t end_index;
+        int32_t single_bit_timing_length;
+        int32_t one_byte_timing_length;
 
-        int Length() const
+        int32_t Length() const
         {
             if (node_ptr == nullptr || node_ptr->start_index < 0)
             {
@@ -29,12 +29,12 @@ namespace Protocol
             return end_index - node_ptr->start_index;
         }
 
-        int PacketEndIndex() const
+        int32_t PacketEndIndex() const
         {
             return packetEndIndex;
         }
 
-        void SetPacketEndIndex(const int value)
+        void SetPacketEndIndex(const int32_t value)
         {
             packetEndIndex = value;
         }
@@ -43,22 +43,22 @@ namespace Protocol
         {
         }
 
-        Sync(TwoLevelEdgePulse* node_ptr, const int end_index, const int single_bit_timing_length, const bool is_high_speed) : node_ptr(node_ptr),
+        Sync(TwoLevelEdgePulse* node_ptr,const int end_index, const int32_t single_bit_timing_length, const bool is_high_speed) : node_ptr(node_ptr),
                                                                                                                                end_index(end_index),
                                                                                                                                single_bit_timing_length(single_bit_timing_length),
                                                                                                                                one_byte_timing_length(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->start_index + static_cast<int32_t>(single_bit_timing_length * sync_byte_len
+            const int32_t sync_byte_len = is_high_speed ? USB_USB_SYNC_BIT_MAX_LEN : USB_BYTE_BIT_COUNT;
+            const int32_t fix_sync_end_index = node_ptr->start_index + static_cast<int32_t>(single_bit_timing_length * sync_byte_len
                 * USB_SYNC_BIT_TOL);
             if (end_index < fix_sync_end_index)
             {
-                end_index = fix_sync_end_index;
+                this->end_index = fix_sync_end_index;
             }
         }
 
     private:
-        int packetEndIndex;
+        int32_t packetEndIndex;
     };
 }

+ 1 - 1
ProtocolXXX/constants.h

@@ -9,7 +9,7 @@
 
 #pragma once
 #include <cstdint>
-
+#include "../BaseHelper/Constants.h"
 namespace Protocol
 {
     //

+ 2 - 2
edge_pulse.cc

@@ -50,13 +50,13 @@ namespace Protocol
     }
     void ReversalLevel(Edge& edge)
     {
-        if (edge == Edge::FALLING)
+        if (edge == Edge::FALL)
         {
             edge = Edge::RISE;
         }
         else if (edge == Edge::RISE)
         {
-            edge = Edge::FALLING;
+            edge = Edge::FALL;
         }
     }
     void ReversalLevel(std::vector<EdgePulse>& edge_pulses)

+ 31 - 4
export_method.cc

@@ -9,6 +9,9 @@
 
 #include "export_method.h"
 
+#include "ProtocolIIC/iic_decoder.h"
+#include "ProtocolIIC/iic_decode_options.h"
+#include "ProtocolIIC/iic_decode_result.h"
 #include "ProtocolRS232/rs232_decoder.h"
 #include "ProtocolSPI/spi_decoder.h"
 #include "ProtocolUsb/Usb_decoder.h"
@@ -22,7 +25,7 @@ namespace Protocol
         return usb_decode->DecodeUsb(option, edge_pluses_data1, edge_pluses_data2, result);
     }
 
-    void RelaseUsbHeap(const intptr_t decoder_ptr)
+    void ReleaseUsbHeap(const intptr_t decoder_ptr)
     {
         if (decoder_ptr == 0 || reinterpret_cast<void*>(decoder_ptr) == nullptr)
         {
@@ -44,7 +47,7 @@ namespace Protocol
                                          decode_result);
     }
 
-    void RelaseRs232Heap(const intptr_t decoder_ptr)
+    void ReleaseRs232Heap(const intptr_t decoder_ptr)
     {
         if (decoder_ptr == 0 || reinterpret_cast<void*>(decoder_ptr) == nullptr)
         {
@@ -53,6 +56,24 @@ namespace Protocol
         reinterpret_cast<Rs232Decoder*>(decoder_ptr)->~Rs232Decoder();
     }
 
+    bool ParseIic(const IicDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_clk,
+                  const EdgePulseDataTwoLevels& edge_pulses_data, IicDecodeResult& result)
+    {
+        const auto decoder = new IicDecoder();
+        return decoder->DecodeIic(option,
+                                  edge_pulses_clk,
+                                  edge_pulses_data,
+                                  result);
+    }
+    void ReleaseIicHeap(const intptr_t decoder_ptr)
+    {
+        if (decoder_ptr == 0 || reinterpret_cast<void*>(decoder_ptr) == nullptr)
+        {
+            return;
+        }
+        reinterpret_cast<IicDecoder*>(decoder_ptr)->~IicDecoder();
+    }
+
 
     bool ParseSpi(const SpiDecodeOptions& options,
                   const EdgePulseDataTwoLevels& edge_pulse_data_clk,
@@ -61,9 +82,15 @@ namespace Protocol
                   const EdgePulseDataTwoLevels& edge_pulse_data_miso,
                   SpiDecodeResult& decode_result)
     {
-        
+        const auto decoder = new SpiDecoder();
+        return decoder->DecodeSpi(options,
+                                  edge_pulse_data_clk,
+                                  edge_pulse_data_cs,
+                                  edge_pulse_data_mosi,
+                                  edge_pulse_data_miso,
+                                  decode_result);
     }
-    void RelaseSpiHeap(const intptr_t decoder_ptr)
+    void ReleaseSpiHeap(const intptr_t decoder_ptr)
     {
         if (decoder_ptr == 0 || reinterpret_cast<void*>(decoder_ptr) == nullptr)
         {

+ 3 - 3
export_method.h

@@ -31,7 +31,7 @@ namespace Protocol
         LIBMATH_API bool ParseUsb(const UsbDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pluses_data1,
                                   const EdgePulseDataTwoLevels& edge_pluses_data2, UsbDecodeResult& result);
 
-        LIBMATH_API void RelaseUsbHeap(intptr_t decoder_ptr);
+        LIBMATH_API void ReleaseUsbHeap(intptr_t decoder_ptr);
         // LIBMATH_API bool quantizeParamsDecodeRS232(const QuantizeParams& quantizeParams,
         //                                            const ProtocolRS232Options& options,
         //                                            rs232_decode_result& decodeResult);
@@ -40,7 +40,7 @@ namespace Protocol
         LIBMATH_API bool ParseRs232(const ProtocolRs232Options& options,
                                      const EdgePulseDataTwoLevels& edge_pulse_data,
                                      Rs232DecodeResult& decode_result);
-        LIBMATH_API void RelaseRs232Heap(intptr_t decoder_ptr);
+        LIBMATH_API void ReleaseRs232Heap(intptr_t decoder_ptr);
 
         LIBMATH_API bool ParseSpi(const SpiDecodeOptions& options,
                                      const EdgePulseDataTwoLevels& edge_pulse_data_clk,
@@ -48,7 +48,7 @@ namespace Protocol
                                      const EdgePulseDataTwoLevels& edge_pulse_data_mosi,
                                      const EdgePulseDataTwoLevels& edge_pulse_data_miso,
                                      SpiDecodeResult& decode_result);
-        LIBMATH_API void RelaseSpiHeap(intptr_t decoder_ptr);
+        LIBMATH_API void ReleaseSpiHeap(intptr_t decoder_ptr);
 
         
         inline LIBMATH_API void GetVersionExport(uint8_t* version)

+ 1 - 1
protocol_decode_base.h

@@ -21,7 +21,7 @@
 #include "BaseHelper/Loger.h"
 
 // DLL_VERSION "x.x.x"
-const std::string DLL_VERSION = "0.1.8";
+const std::string DLL_VERSION = "0.1.9";
 
 namespace Protocol
 {

BIN
x64/Debug/ProtocolDecoder.dll