Browse Source

spi解码

lijinwen 1 month ago
parent
commit
2122921661

+ 1 - 1
BaseEnums/protocol_enums.h

@@ -52,7 +52,7 @@ namespace Protocol
 
 
     enum class Polarity: int32_t
     enum class Polarity: int32_t
     {
     {
-        NONE,
+        //NONE,
         POS,
         POS,
         NEG
         NEG
     };
     };

+ 120 - 120
BaseHelper/common_helper.cc

@@ -11,129 +11,129 @@
 
 
 namespace Protocol
 namespace Protocol
 {
 {
-	// 移除数组中第一个元素,如果它与其他元素的差异最大
-	std::vector<int32_t> CommonHelper::RemoveFirstIfMostDifferent(const std::vector<int32_t>& array)
-	{
-		if (array.size() < 2)
-		{
-			throw std::invalid_argument("Array must contain at least two elements.");
-		}
-		const int32_t first_value = array[0];
-		int32_t max_difference = 0;
-		int32_t most_different_index = 0;
+    // 移除数组中第一个元素,如果它与其他元素的差异最大
+    std::vector<int32_t> CommonHelper::RemoveFirstIfMostDifferent(const std::vector<int32_t>& array)
+    {
+        if (array.size() < 2)
+        {
+            throw std::invalid_argument("Array must contain at least two elements.");
+        }
+        const int32_t first_value = array[0];
+        int32_t max_difference = 0;
+        int32_t most_different_index = 0;
 
 
-		// 找到与第一个元素差异最大的元素
-		for (int32_t i = 1; i < static_cast<int32_t>(array.size()); ++i)
-		{
-			int32_t difference = std::abs(array[i] - first_value);
-			if (difference > max_difference)
-			{
-				max_difference = difference;
-				most_different_index = i;
-			}
-		}
+        // 找到与第一个元素差异最大的元素
+        for (int32_t i = 1; i < static_cast<int32_t>(array.size()); ++i)
+        {
+            int32_t difference = std::abs(array[i] - first_value);
+            if (difference > max_difference)
+            {
+                max_difference = difference;
+                most_different_index = i;
+            }
+        }
 
 
-		// 如果第一个元素与其他元素差异最大,则移除第一个元素
-		if (most_different_index == 0)
-		{
-			return std::vector<int32_t>(array.begin() + 1, array.end());
-		}
+        // 如果第一个元素与其他元素差异最大,则移除第一个元素
+        if (most_different_index == 0)
+        {
+            return std::vector<int32_t>(array.begin() + 1, array.end());
+        }
 
 
-		return array; // 如果第一个元素不是差异最大的,则返回原数组
-	}
-	bool CommonHelper::CheckTwoLevelEdgePulseValid(TwoLevelEdgePulse* node)
-	{
-		return node != nullptr && node->start_index >= 0 && node->end_index > 0
-			&& node->LevelCount() > 0 && node->current_level != TwoLevelEdgePulseStatusType::None;
-	}
+        return array; // 如果第一个元素不是差异最大的,则返回原数组
+    }
+    bool CommonHelper::CheckTwoLevelEdgePulseValid(TwoLevelEdgePulse* node)
+    {
+        return node != nullptr && node->start_index >= 0 && node->end_index > 0
+            && node->LevelCount() > 0 && node->current_level != TwoLevelEdgePulseStatusType::None;
+    }
 
 
-	uint8_t CommonHelper::SwapHighLowBits(const uint8_t value)
-	{
-		// 获取低4位
-		const uint8_t lower_nibble = value & 0x0F;
-		// 获取高4位
-		const uint8_t higher_nibble = (value >> 4) & 0x0F;
-		// 交换高低4位
-		return static_cast<uint8_t>(higher_nibble | lower_nibble << 4);
-	}
-	uint8_t CommonHelper::ReverseOrderBits(uint8_t value)
-	{
-		value = SwapHighLowBits(value); //高低互换
-		value = static_cast<uint8_t>((value & 0xCC) >> 2 | (value & 0x33) << 2); //交换每对相邻的位
-		value = static_cast<uint8_t>((value & 0xAA) >> 1 | (value & 0x55) << 1); //交换每对相邻的位
-		return value;
-	}
-	bool CommonHelper::GetNodeByIndex(const int32_t index, TwoLevelEdgePulse*& node, const int32_t time_out_by_s)
-	{
-		if (index < 0) return false;
-		if (index >= node->start_index && index <= node->end_index) return true;
+    uint8_t CommonHelper::SwapHighLowBits(const uint8_t value)
+    {
+        // 获取低4位
+        const uint8_t lower_nibble = value & 0x0F;
+        // 获取高4位
+        const uint8_t higher_nibble = (value >> 4) & 0x0F;
+        // 交换高低4位
+        return static_cast<uint8_t>(higher_nibble | lower_nibble << 4);
+    }
+    uint8_t CommonHelper::ReverseOrderBits(uint8_t value)
+    {
+        value = SwapHighLowBits(value); //高低互换
+        value = static_cast<uint8_t>((value & 0xCC) >> 2 | (value & 0x33) << 2); //交换每对相邻的位
+        value = static_cast<uint8_t>((value & 0xAA) >> 1 | (value & 0x55) << 1); //交换每对相邻的位
+        return value;
+    }
+    bool CommonHelper::GetNodeByIndex(const int32_t index, TwoLevelEdgePulse*& node, const int32_t time_out_by_s)
+    {
+        if (index < 0 || node == nullptr) return false;
+        if (index >= node->start_index && index <= node->end_index) return true;
 
 
-		TwoLevelEdgePulse* temp_node = node;
-		if (index > temp_node->end_index)
-		{
-			const auto start_time = std::chrono::steady_clock::now();
-			while (CheckTwoLevelEdgePulseValid(temp_node))
-			{
-				if (index >= temp_node->start_index && index <= temp_node->end_index)
-				{
-					node = temp_node;
-					return true;
-				}
-				temp_node++;
-				if (auto end_time = std::chrono::steady_clock::now();
-					std::chrono::duration_cast<std::chrono::seconds>(end_time - start_time).count() > time_out_by_s)
-				{
-					return false;
-				}
-			}
-		}
-		else if (index < temp_node->start_index)
-		{
-			const auto start_time = std::chrono::steady_clock::now();
-			while (CheckTwoLevelEdgePulseValid(temp_node))
-			{
-				if (index >= temp_node->start_index && index <= temp_node->end_index)
-				{
-					node = temp_node;
-					return true;
-				}
-				temp_node--;
-				if (auto end_time = std::chrono::steady_clock::now();
-					std::chrono::duration_cast<std::chrono::seconds>(end_time - start_time).count() > time_out_by_s)
-				{
-					return false;
-				}
-			}
-		}
-		return false;
-	}
-	bool CommonHelper::FindNextNode(const int32_t index, TwoLevelEdgePulse*& node, const int32_t time_out_by_s)
-	{
-		if (index < 0)
-		{
-			return false;
-		}
-		if (GetNodeByIndex(index, node))
-		{
-			node++;
-			if (CheckTwoLevelEdgePulseValid(node))
-			{
-				return true;
-			}
-		}
-		/*while (CheckTwoLevelEdgePulseValid(node) && index< node->start_index)
-		{
-			node++;
-			if (node->start_index > index)
-			{
-				break;
-			}
-		}
-		node++;
-		if (CheckTwoLevelEdgePulseValid(node) && node->start_index > index)
-		{
-			return true;
-		}*/
-		return false;
-	}
+        TwoLevelEdgePulse* temp_node = node;
+        if (index > temp_node->end_index)
+        {
+            const auto start_time = std::chrono::steady_clock::now();
+            while (CheckTwoLevelEdgePulseValid(temp_node))
+            {
+                if (index >= temp_node->start_index && index <= temp_node->end_index)
+                {
+                    node = temp_node;
+                    return true;
+                }
+                temp_node++;
+                if (auto end_time = std::chrono::steady_clock::now();
+                    std::chrono::duration_cast<std::chrono::seconds>(end_time - start_time).count() > time_out_by_s)
+                {
+                    return false;
+                }
+            }
+        }
+        else if (index < temp_node->start_index)
+        {
+            const auto start_time = std::chrono::steady_clock::now();
+            while (CheckTwoLevelEdgePulseValid(temp_node))
+            {
+                if (index >= temp_node->start_index && index <= temp_node->end_index)
+                {
+                    node = temp_node;
+                    return true;
+                }
+                temp_node--;
+                if (auto end_time = std::chrono::steady_clock::now();
+                    std::chrono::duration_cast<std::chrono::seconds>(end_time - start_time).count() > time_out_by_s)
+                {
+                    return false;
+                }
+            }
+        }
+        return false;
+    }
+    bool CommonHelper::FindNextNode(const int32_t index, TwoLevelEdgePulse*& node, const int32_t time_out_by_s)
+    {
+        if (index < 0)
+        {
+            return false;
+        }
+        if (GetNodeByIndex(index, node))
+        {
+            node++;
+            if (CheckTwoLevelEdgePulseValid(node))
+            {
+                return true;
+            }
+        }
+        /*while (CheckTwoLevelEdgePulseValid(node) && index< node->start_index)
+        {
+            node++;
+            if (node->start_index > index)
+            {
+                break;
+            }
+        }
+        node++;
+        if (CheckTwoLevelEdgePulseValid(node) && node->start_index > index)
+        {
+            return true;
+        }*/
+        return false;
+    }
 }
 }

+ 4 - 3
ProtocolSPI/constants.h

@@ -2,17 +2,18 @@
 // //       /\ /|       @File         constants.h
 // //       /\ /|       @File         constants.h
 // //       \ V/        @Brief
 // //       \ V/        @Brief
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
-// //       /  |        @Creation      2024-07-16
-// //      /  \\        @Modified      2024-07-16
+// //       /  |        @Creation      2024-07-19
+// //      /  \\        @Modified      2024-07-23
 // //    *(__\_\
 // //    *(__\_\
 // // ******************************************************************
 // // ******************************************************************
 
 
 #pragma once
 #pragma once
 #include <cstdint>
 #include <cstdint>
 #include "../BaseHelper/Constants.h"
 #include "../BaseHelper/Constants.h"
+
 namespace Protocol
 namespace Protocol
 {
 {
     //
     //
     //constexpr double xxx = 0.95;
     //constexpr double xxx = 0.95;
- 
+
 }
 }

+ 6 - 6
ProtocolSPI/protocol_spi_enums.h

@@ -2,13 +2,13 @@
 // //       /\ /|       @File         protocol_spi_enums.h
 // //       /\ /|       @File         protocol_spi_enums.h
 // //       \ V/        @Brief
 // //       \ V/        @Brief
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
-// //       /  |        @Creation      2024-07-16
-// //      /  \\        @Modified      2024-07-16
+// //       /  |        @Creation      2024-07-19
+// //      /  \\        @Modified      2024-07-23
 // //    *(__\_\
 // //    *(__\_\
 // // ******************************************************************
 // // ******************************************************************
 
 
 #pragma once
 #pragma once
- 
+
 namespace Protocol
 namespace Protocol
 {
 {
     class SpiEnums
     class SpiEnums
@@ -34,8 +34,8 @@ namespace Protocol
 
 
         enum class DecodeChannel
         enum class DecodeChannel
         {
         {
-            MOSI,
             MISO,
             MISO,
+            MOSI,
             MOMI
             MOMI
         };
         };
 
 
@@ -47,8 +47,8 @@ namespace Protocol
 
 
         enum class Msblsb
         enum class Msblsb
         {
         {
-            MSB,
-            LSB
+            LSB,
+            MSB
         };
         };
 
 
     };
     };

+ 4 - 3
ProtocolSPI/spi_decode_options.h

@@ -2,14 +2,15 @@
 // //       /\ /|       @File         spi_decode_options.h
 // //       /\ /|       @File         spi_decode_options.h
 // //       \ V/        @Brief
 // //       \ V/        @Brief
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
-// //       /  |        @Creation      2024-07-16
-// //      /  \\        @Modified      2024-07-16
+// //       /  |        @Creation      2024-07-19
+// //      /  \\        @Modified      2024-07-23
 // //    *(__\_\
 // //    *(__\_\
 // // ******************************************************************
 // // ******************************************************************
 
 
 #pragma once
 #pragma once
 
 
 #include "protocol_spi_enums.h"
 #include "protocol_spi_enums.h"
+
 namespace Protocol
 namespace Protocol
 {
 {
     struct SpiDecodeOptions
     struct SpiDecodeOptions
@@ -22,4 +23,4 @@ namespace Protocol
         Polarity miso_polarity;
         Polarity miso_polarity;
         bool* is_cancel;//取消解码
         bool* is_cancel;//取消解码
     };
     };
-}
+}

+ 36 - 28
ProtocolSPI/spi_decode_result.h

@@ -2,8 +2,8 @@
 // //       /\ /|       @File         spi_decode_result.h
 // //       /\ /|       @File         spi_decode_result.h
 // //       \ V/        @Brief
 // //       \ V/        @Brief
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
-// //       /  |        @Creation      2024-07-16
-// //      /  \\        @Modified      2024-07-16
+// //       /  |        @Creation      2024-07-19
+// //      /  \\        @Modified      2024-07-23
 // //    *(__\_\
 // //    *(__\_\
 // // ******************************************************************
 // // ******************************************************************
 
 
@@ -11,7 +11,7 @@
 //#include <utility>
 //#include <utility>
 
 
 //#include "protocol_spi_enums.h"
 //#include "protocol_spi_enums.h"
- 
+
 #include "spi_packet.h"
 #include "spi_packet.h"
 #include "../decode_result.h"
 #include "../decode_result.h"
 //#include "spi_packet.h"
 //#include "spi_packet.h"
@@ -27,64 +27,72 @@ namespace Protocol
 
 
     struct SpiDecodeResult //: DecodeResult
     struct SpiDecodeResult //: DecodeResult
     {
     {
-        bool decode_result_need_update = false;
+        //bool decode_result_need_update = false;
         bool decode_event_need_update = false;
         bool decode_event_need_update = false;
-        SpiDecodeResultCell* decode_result_cells_ptr; //解码数据结果指针
+        //SpiDecodeResultCell* decode_result_cells_ptr; //解码数据结果指针
         SpiPacket* decode_events_ptr; //解码结果事件指针
         SpiPacket* decode_events_ptr; //解码结果事件指针
-        uint64_t decode_result_count; //结果数量
+        //uint64_t decode_result_count; //结果数量
         uint64_t decode_event_count; //事件数量
         uint64_t decode_event_count; //事件数量
-        
-        SpiDecodeResult() : decode_result_cells_ptr(nullptr), decode_events_ptr(nullptr), decode_result_count(0),
-                            decode_event_count(0) 
-                          
+        intptr_t decoder_ptr;
+
+        /*  SpiDecodeResult() : decode_result_cells_ptr(nullptr), decode_events_ptr(nullptr), decode_result_count(0),
+                              decode_event_count(0) */
+        SpiDecodeResult() : decode_event_need_update(false), decode_events_ptr(nullptr), decode_event_count(0), decoder_ptr(0)
         {
         {
-            
         }
         }
-        SpiDecodeResult(const SpiDecodeResult& result)  
+        SpiDecodeResult(const SpiDecodeResult& result)
         {
         {
-            decode_result_need_update = result.decode_result_need_update;
+            //decode_result_need_update = result.decode_result_need_update;
             decode_event_need_update = result.decode_event_need_update;
             decode_event_need_update = result.decode_event_need_update;
-            decode_result_cells_ptr = result.decode_result_cells_ptr;
+            //decode_result_cells_ptr = result.decode_result_cells_ptr;
             decode_events_ptr = result.decode_events_ptr;
             decode_events_ptr = result.decode_events_ptr;
 
 
-            decode_result_count = result.decode_result_count;
+            //decode_result_count = result.decode_result_count;
             decode_event_count = result.decode_event_count;
             decode_event_count = result.decode_event_count;
+
+            decoder_ptr = result.decoder_ptr;
         }
         }
         ~SpiDecodeResult() = default;
         ~SpiDecodeResult() = default;
 
 
-        SpiDecodeResult(SpiDecodeResult&& other) noexcept
+        /*SpiDecodeResult(SpiDecodeResult&& other) noexcept
             : decode_result_need_update(other.decode_result_need_update),
             : decode_result_need_update(other.decode_result_need_update),
-              decode_event_need_update(other.decode_event_need_update),
-              decode_result_cells_ptr(other.decode_result_cells_ptr),
+            decode_event_need_update(other.decode_event_need_update),
+            decode_result_cells_ptr(other.decode_result_cells_ptr),
+            decode_events_ptr(other.decode_events_ptr),
+            decode_result_count(other.decode_result_count),
+            decode_event_count(other.decode_event_count)*/
+        SpiDecodeResult(SpiDecodeResult&& other) noexcept
+            : decode_event_need_update(other.decode_event_need_update),
               decode_events_ptr(other.decode_events_ptr),
               decode_events_ptr(other.decode_events_ptr),
-              decode_result_count(other.decode_result_count),
-              decode_event_count(other.decode_event_count) 
-
+              decode_event_count(other.decode_event_count),
+              decoder_ptr(0)
         {
         {
         }
         }
         SpiDecodeResult& operator=(const SpiDecodeResult& other)
         SpiDecodeResult& operator=(const SpiDecodeResult& other)
         {
         {
             if (this == &other) return *this;
             if (this == &other) return *this;
-            decode_result_need_update = other.decode_result_need_update;
+            //decode_result_need_update = other.decode_result_need_update;
             decode_event_need_update = other.decode_event_need_update;
             decode_event_need_update = other.decode_event_need_update;
-            decode_result_cells_ptr = other.decode_result_cells_ptr;
+            //decode_result_cells_ptr = other.decode_result_cells_ptr;
             decode_events_ptr = other.decode_events_ptr;
             decode_events_ptr = other.decode_events_ptr;
-            decode_result_count = other.decode_result_count;
+            //decode_result_count = other.decode_result_count;
             decode_event_count = other.decode_event_count;
             decode_event_count = other.decode_event_count;
+            decoder_ptr = other.decoder_ptr;
             return *this;
             return *this;
         }
         }
         SpiDecodeResult& operator=(SpiDecodeResult&& other) noexcept
         SpiDecodeResult& operator=(SpiDecodeResult&& other) noexcept
         {
         {
             if (this == &other) return *this;
             if (this == &other) return *this;
-            decode_result_need_update = other.decode_result_need_update;
+            //decode_result_need_update = other.decode_result_need_update;
             decode_event_need_update = other.decode_event_need_update;
             decode_event_need_update = other.decode_event_need_update;
-            decode_result_cells_ptr = other.decode_result_cells_ptr;
+            //decode_result_cells_ptr = other.decode_result_cells_ptr;
             decode_events_ptr = other.decode_events_ptr;
             decode_events_ptr = other.decode_events_ptr;
-            decode_result_count = other.decode_result_count;
+            //decode_result_count = other.decode_result_count;
             decode_event_count = other.decode_event_count;
             decode_event_count = other.decode_event_count;
+            decoder_ptr = other.decoder_ptr;
             return *this;
             return *this;
         }
         }
-   
+
     };
     };
 
 
 }
 }

+ 110 - 35
ProtocolSPI/spi_decoder.cc

@@ -2,8 +2,8 @@
 // //       /\ /|       @File         spi_decoder.cc
 // //       /\ /|       @File         spi_decoder.cc
 // //       \ V/        @Brief
 // //       \ V/        @Brief
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
-// //       /  |        @Creation      2024-07-16
-// //      /  \\        @Modified      2024-07-16
+// //       /  |        @Creation      2024-07-19
+// //      /  \\        @Modified      2024-07-23
 // //    *(__\_\
 // //    *(__\_\
 // // ******************************************************************
 // // ******************************************************************
 
 
@@ -21,6 +21,9 @@ namespace Protocol
     {
     {
         is_cancel_ptr_ = options.is_cancel;
         is_cancel_ptr_ = options.is_cancel;
         decode_result = {};
         decode_result = {};
+        decode_result.decoder_ptr = reinterpret_cast<intptr_t>(this);
+        need_decode_data_ = true;
+
         bool checked_params = true;
         bool checked_params = true;
         if (edge_pulse_data_clk.waveform_data_count <= 0
         if (edge_pulse_data_clk.waveform_data_count <= 0
             || edge_pulse_data_cs.waveform_data_count <= 0
             || edge_pulse_data_cs.waveform_data_count <= 0
@@ -45,6 +48,9 @@ namespace Protocol
         {
         {
             need_decode_data_ = false;
             need_decode_data_ = false;
             need_update_view_info_ = true;
             need_update_view_info_ = true;
+            /*miso_data.clear();
+            mosi_data.clear();*/
+            data_packet_info.clear();
             packet_infos_.clear();
             packet_infos_.clear();
             return false;
             return false;
         }
         }
@@ -52,12 +58,16 @@ namespace Protocol
         {
         {
             if (need_decode_data_)
             if (need_decode_data_)
             {
             {
+                /*	miso_data.clear();
+                    mosi_data.clear();*/
+                data_packet_info.clear();
+                packet_infos_.clear();
                 need_decode_data_ = false;
                 need_decode_data_ = false;
                 need_update_view_info_ = true;
                 need_update_view_info_ = true;
-                packet_infos_.clear();
+
                 try
                 try
                 {
                 {
-                    int32_t packet_index = 0;
+                    int32_t packet_index = 0, last_packet_index = 0;
                     uint64_t cs_len = edge_pulse_data_cs.waveform_data_count;
                     uint64_t cs_len = edge_pulse_data_cs.waveform_data_count;
                     uint64_t clk_len = edge_pulse_data_clk.waveform_data_count;
                     uint64_t clk_len = edge_pulse_data_clk.waveform_data_count;
                     uint64_t miso_len = 0;
                     uint64_t miso_len = 0;
@@ -101,16 +111,16 @@ namespace Protocol
                                            options.cs_polarity, options.clk_polarity))
                                            options.cs_polarity, options.clk_polarity))
                         {
                         {
                             WriteLog(LogLevel::Level2, "Not find start node");
                             WriteLog(LogLevel::Level2, "Not find start node");
-                            return false;
+                            break;
                         }
                         }
 
 
-                        if (packet_index < 0 || *is_cancel_ptr_) break;
+                        if (packet_index < 0) break;
 
 
                         SpiPacket packet_info = {};
                         SpiPacket packet_info = {};
-                        packet_info.data = std::vector<DataPacketInfo>();
+
                         packet_info.start_index = cs_start_index;
                         packet_info.start_index = cs_start_index;
                         packet_info.start_len = 1;
                         packet_info.start_len = 1;
-                        packet_info.has_start = cs_start_index >= 0;
+                        packet_info.has_start = cs_start_index >= 0 ? 1 : 0;
 
 
                         if (!GetCsBitNextIndex(options.cs_polarity == Polarity::POS,
                         if (!GetCsBitNextIndex(options.cs_polarity == Polarity::POS,
                                                packet_index, edge_pulse_data_cs_ptr))
                                                packet_index, edge_pulse_data_cs_ptr))
@@ -118,24 +128,31 @@ namespace Protocol
                             break;
                             break;
                         }
                         }
                         const auto cs_end_index = edge_pulse_data_cs_ptr->start_index;
                         const auto cs_end_index = edge_pulse_data_cs_ptr->start_index;
-                        if (bool need_clear = false; *is_cancel_ptr_ || need_clear) break;
+                        if (is_cancel_ptr_ != nullptr && *is_cancel_ptr_)
+                        {
+                            WriteLog(LogLevel::Level2, "AsyncFunction canceled");
+                            return false;
+                        }
+                        if (bool need_clear = false; need_clear) break;
 
 
                         if (cs_end_index > packet_index)
                         if (cs_end_index > packet_index)
                         {
                         {
-                            packet_info.has_end = true;
+                            packet_info.has_end = 1;
                             packet_info.end_len = 1;
                             packet_info.end_len = 1;
                             packet_info.end_index = cs_end_index;
                             packet_info.end_index = cs_end_index;
                         }
                         }
 
 
                         std::vector<DataPacketInfo> temp_data_packets;
                         std::vector<DataPacketInfo> temp_data_packets;
+
                         //数据解码
                         //数据解码
                         while (true)
                         while (true)
                         {
                         {
                             DataPacketInfo temp_data_packet = {};
                             DataPacketInfo temp_data_packet = {};
+                            //std::vector<uint8_t> temp_miso_datas = {}, temp_mosi_datas = {};
                             temp_data_packet.bit_count = frame_count_;
                             temp_data_packet.bit_count = frame_count_;
                             temp_data_packet.index = packet_index;
                             temp_data_packet.index = packet_index;
                             int32_t temp_miso_data = 0, temp_mosi_data = 0;
                             int32_t temp_miso_data = 0, temp_mosi_data = 0;
-
+                            bool get_miso_data = false, get_mosi_data = false;
                             for (int32_t bit_index = 0; bit_index < frame_count_; ++bit_index)
                             for (int32_t bit_index = 0; bit_index < frame_count_; ++bit_index)
                             {
                             {
                                 bool miso_bit = false;
                                 bool miso_bit = false;
@@ -144,6 +161,7 @@ namespace Protocol
                                 {
                                 {
                                     if (!CommonHelper::GetNodeByIndex(packet_index, edge_pulse_data_miso_ptr))
                                     if (!CommonHelper::GetNodeByIndex(packet_index, edge_pulse_data_miso_ptr))
                                     {
                                     {
+                                        get_miso_data = false;
                                         break;
                                         break;
                                     }
                                     }
                                     miso_bit = edge_pulse_data_miso_ptr->current_level == TwoLevelEdgePulseStatusType::High;
                                     miso_bit = edge_pulse_data_miso_ptr->current_level == TwoLevelEdgePulseStatusType::High;
@@ -151,12 +169,14 @@ namespace Protocol
                                     {
                                     {
                                         miso_bit = !miso_bit;
                                         miso_bit = !miso_bit;
                                     }
                                     }
+                                    get_miso_data = true;
                                 }
                                 }
 
 
                                 if (decode_mosi)
                                 if (decode_mosi)
                                 {
                                 {
                                     if (!CommonHelper::GetNodeByIndex(packet_index, edge_pulse_data_mosi_ptr))
                                     if (!CommonHelper::GetNodeByIndex(packet_index, edge_pulse_data_mosi_ptr))
                                     {
                                     {
+                                        get_miso_data = false;
                                         break;
                                         break;
                                     }
                                     }
                                     mosi_bit = edge_pulse_data_mosi_ptr->current_level == TwoLevelEdgePulseStatusType::High;
                                     mosi_bit = edge_pulse_data_mosi_ptr->current_level == TwoLevelEdgePulseStatusType::High;
@@ -164,6 +184,7 @@ namespace Protocol
                                     {
                                     {
                                         mosi_bit = !mosi_bit;
                                         mosi_bit = !mosi_bit;
                                     }
                                     }
+                                    get_mosi_data = true;
                                 }
                                 }
 
 
                                 if (options.msb_lsb == SpiEnums::Msblsb::MSB)
                                 if (options.msb_lsb == SpiEnums::Msblsb::MSB)
@@ -179,8 +200,7 @@ namespace Protocol
                                     temp_mosi_data |= (mosi_bit ? 1 : 0) << bit_index;
                                     temp_mosi_data |= (mosi_bit ? 1 : 0) << bit_index;
                                 }
                                 }
 
 
-                                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;
                                 temp_data_packet.real_bit_count = bit_index + 1;
 
 
                                 if (!GetClkEdge(!clk_state, packet_index, edge_pulse_data_clk_ptr))
                                 if (!GetClkEdge(!clk_state, packet_index, edge_pulse_data_clk_ptr))
@@ -189,7 +209,7 @@ namespace Protocol
                                 }
                                 }
                                 if ((packet_index > cs_end_index && cs_end_index >= 0) || packet_index == -1)
                                 if ((packet_index > cs_end_index && cs_end_index >= 0) || packet_index == -1)
                                 {
                                 {
-                                    temp_data_packet.is_last = true;
+                                    temp_data_packet.is_last = 1;
                                     break;
                                     break;
                                 }
                                 }
                             }
                             }
@@ -214,14 +234,71 @@ namespace Protocol
                             {
                             {
                                 temp_data_packet.len = packet_index - temp_data_packet.index;
                                 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;
+                            //if (temp_data_packet.real_bit_count > 0) temp_data_packets.push_back(temp_data_packet);
+
+                            //end
+                            if (temp_data_packet.real_bit_count > 0)
+                            {
+                                //miso
+                                if (decode_miso)
+                                {
+                                    temp_data_packet.miso_data_count = get_miso_data ? 1 : 0;
+                                    if (temp_data_packet.miso_data_count > 0)
+                                    {
+                                        /*	int32_t last_data_count = miso_data.size();
+
+                                            miso_data.push_back(temp_miso_data);
+                                            temp_data_packet.miso_data_ptr = miso_data.data() + last_data_count;  */
+                                        temp_data_packet.miso_data = static_cast<uint8_t>(temp_miso_data);
+                                    }
+                                }
+
+                                //mosi
+                                if (decode_mosi)
+                                {
+                                    temp_data_packet.mosi_data_count = get_mosi_data ? 1 : 0;
+                                    if (temp_data_packet.mosi_data_count > 0)
+                                    {
+                                        /*int32_t last_data_count = mosi_data.size();
+                                     
+                                        mosi_data.push_back(temp_mosi_data);
+                                        temp_data_packet.mosi_data_ptr = mosi_data.data() + last_data_count;*/
+                                        temp_data_packet.mosi_data = static_cast<uint8_t>(temp_mosi_data);
+                                    }
+                                }
+                                temp_data_packets.push_back(temp_data_packet);
+                            }
+                            if (temp_data_packet.is_last == 1 || packet_index >= data_len_) break;
+                            if (last_packet_index == packet_index)
+                            {
+                                break;
+                            }
+                            last_packet_index = packet_index;
                         }
                         }
 
 
-                        packet_info.data = temp_data_packets;
-                        packet_infos_.push_back(packet_info);
+                        //packet
+                        packet_info.data_count = static_cast<int32_t>(temp_data_packets.size());
+                        if (packet_info.data_count > 0)
+                        {
+                            int32_t last_data_count = static_cast<int32_t>(data_packet_info.size());
+                            // 复制到末尾
+                            data_packet_info.insert(data_packet_info.end(),
+                                                    std::make_move_iterator(temp_data_packets.begin()),
+                                                    std::make_move_iterator(temp_data_packets.end()));
+                            packet_info.data_ptr = reinterpret_cast<intptr_t>(data_packet_info.data() + last_data_count - 1);
+                            packet_info.data_info = temp_data_packets[0];
+                        }
 
 
-                        if (packet_index >= static_cast<int32_t>(miso_len) || packet_index < 0)
+                        packet_infos_.push_back(packet_info);
+                        if (decode_miso && packet_index >= static_cast<int32_t>(miso_len))
+                        {
+                            break;
+                        }
+                        if (decode_mosi && packet_index >= static_cast<int32_t>(mosi_len))
+                        {
+                            break;
+                        }
+                        if (packet_index < 0)
                         {
                         {
                             break;
                             break;
                         }
                         }
@@ -249,9 +326,10 @@ namespace Protocol
                 decode_result.decode_event_count = packet_infos_.size();
                 decode_result.decode_event_count = packet_infos_.size();
             }
             }
         }
         }
+
         return true;
         return true;
     }
     }
-    bool SpiDecoder::GetClkEdge(const bool state, int32_t& start_index, TwoLevelEdgePulse* node_clk)
+    bool SpiDecoder::GetClkEdge(const bool state, int32_t& start_index, TwoLevelEdgePulse*& node_clk)
     {
     {
         if (!CommonHelper::GetNodeByIndex(start_index, node_clk))
         if (!CommonHelper::GetNodeByIndex(start_index, node_clk))
         {
         {
@@ -279,8 +357,8 @@ namespace Protocol
         return true;
         return true;
     }
     }
 
 
-    bool SpiDecoder::FindStartNode(int32_t& start_index, int32_t& cs_start_index, TwoLevelEdgePulse* node_cs,
-                                   TwoLevelEdgePulse* node_clk,
+    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
                                    const Polarity polarity_cs, const Polarity polarity_clk) const
     {
     {
         cs_start_index = -1;
         cs_start_index = -1;
@@ -353,31 +431,28 @@ namespace Protocol
             }
             }
         }
         }
     }
     }
-    bool SpiDecoder::GetCsBitNextIndex(const bool state, int32_t& start_index, TwoLevelEdgePulse* node_cs)
+    bool SpiDecoder::GetCsBitNextIndex(const bool state, int32_t start_index, TwoLevelEdgePulse*& node_cs)
     {
     {
         if (!CommonHelper::GetNodeByIndex(start_index, node_cs))
         if (!CommonHelper::GetNodeByIndex(start_index, node_cs))
         {
         {
             return false;
             return false;
         }
         }
+
         if (node_cs->current_level == TwoLevelEdgePulseStatusType::High != state)
         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))
             if (!CommonHelper::FindNextNode(start_index, node_cs))
             {
             {
                 return false;
                 return false;
             }
             }
             start_index = node_cs->start_index;
             start_index = node_cs->start_index;
-            return true;
         }
         }
-        return false;
+        if (start_index == -1) return false;
+
+        if (!CommonHelper::FindNextNode(start_index, node_cs))
+        {
+            return false;
+        }
+        //start_index = node_cs->start_index;
+        return true;
     }
     }
 }
 }

+ 13 - 9
ProtocolSPI/spi_decoder.h

@@ -2,8 +2,8 @@
 // //       /\ /|       @File         spi_decoder.h
 // //       /\ /|       @File         spi_decoder.h
 // //       \ V/        @Brief
 // //       \ V/        @Brief
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
-// //       /  |        @Creation      2024-07-16
-// //      /  \\        @Modified      2024-07-16
+// //       /  |        @Creation      2024-07-19
+// //      /  \\        @Modified      2024-07-23
 // //    *(__\_\
 // //    *(__\_\
 // // ******************************************************************
 // // ******************************************************************
 
 
@@ -32,19 +32,23 @@ namespace Protocol
 
 
     private:
     private:
         bool* is_cancel_ptr_ = nullptr;
         bool* is_cancel_ptr_ = nullptr;
-        std::vector<SpiPacket> packet_infos_;
+        std::vector<SpiPacket> packet_infos_ = {};
 
 
         bool need_decode_data_ = false;
         bool need_decode_data_ = false;
         bool need_update_view_info_ = false;
         bool need_update_view_info_ = false;
         //SpiEnums::FramingMode framing_mode_ = SpiEnums::FramingMode::MODE1;
         //SpiEnums::FramingMode framing_mode_ = SpiEnums::FramingMode::MODE1;
 
 
-        int frame_count_ = 0;
+        int frame_count_ = 8;
         //double idle_time_ = 0.0;
         //double idle_time_ = 0.0;
- 
+
         int32_t data_len_ = 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);
+        /*std::vector<uint8_t> miso_data = {};
+        std::vector<uint8_t> mosi_data = {};*/
+        std::vector<DataPacketInfo> data_packet_info = {};
+
+        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);
     };
     };
 }
 }

+ 15 - 9
ProtocolSPI/spi_packet.h

@@ -2,8 +2,8 @@
 // //       /\ /|       @File         spi_packet.h
 // //       /\ /|       @File         spi_packet.h
 // //       \ V/        @Brief
 // //       \ V/        @Brief
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
 // //       | "")       @Author        lijinwen, ghz005@uni-trend.com.cn
-// //       /  |        @Creation      2024-07-16
-// //      /  \\        @Modified      2024-07-16
+// //       /  |        @Creation      2024-07-19
+// //      /  \\        @Modified      2024-07-23
 // //    *(__\_\
 // //    *(__\_\
 // // ******************************************************************
 // // ******************************************************************
 
 
@@ -19,21 +19,27 @@ namespace Protocol
     {
     {
         int32_t index;
         int32_t index;
         int32_t len;
         int32_t len;
-        bool is_last;
-        std::vector<uint8_t> miso_data;
-        std::vector<uint8_t> mosi_data;
+        int32_t is_last;
+        int32_t miso_data_count;
+        int32_t mosi_data_count;
+        //uint8_t* miso_data_ptr; //to std::vector<uint8_t> miso_data;
+        //uint8_t* mosi_data_ptr; //to std::vector<uint8_t> mosi_data;
+        uint8_t miso_data;
+        uint8_t mosi_data;
         int32_t bit_count;
         int32_t bit_count;
         int32_t real_bit_count;
         int32_t real_bit_count;
     };
     };
 
 
-    struct SpiPacket  
+    struct SpiPacket
     {
     {
         int32_t start_index;
         int32_t start_index;
         int32_t start_len;
         int32_t start_len;
-        bool has_start;
-        std::vector<DataPacketInfo> data;
-        bool has_end;
+        int32_t has_start;
+        intptr_t data_ptr; //to std::vector<DataPacketInfo>
+        int32_t data_count;
+        int32_t has_end;
         int32_t end_index;
         int32_t end_index;
         int32_t end_len;
         int32_t end_len;
+        DataPacketInfo data_info;
     };
     };
 }
 }

+ 1 - 1
protocol_decode_base.h

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

BIN
x64/Debug/ProtocolDecoder.dll


BIN
x64/Debug/ProtocolDecoder.pdb