lijinwen 2 bulan lalu
induk
melakukan
a94a52bbe3
5 mengubah file dengan 114 tambahan dan 80 penghapusan
  1. 38 5
      ProtocolUSB/usb_decoder.cpp
  2. 75 74
      ProtocolUSB/usb_decoder.h
  3. 1 1
      protocol_decode_base.h
  4. TEMPAT SAMPAH
      x64/Debug/ProtocolDecoder.dll
  5. TEMPAT SAMPAH
      x64/Debug/ProtocolDecoder.pdb

+ 38 - 5
ProtocolUSB/usb_decoder.cpp

@@ -141,10 +141,8 @@ namespace Protocol
 		WriteLog(LogLevel::Level2, "ParseSingleData done");
 		return true;
 	}
-
 	bool USBDecoder::CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, double threshold)
 	{
-		//threshold = 0.15;
 		for (int i = 2; i < size; i++)
 		{
 			double difference = std::abs(array[i] - array[i - 1]);
@@ -161,7 +159,41 @@ namespace Protocol
 				}
 
 			}
-			if (percentage_difference > threshold)
+		
+			if (percentage_difference > threshold )
+			{
+				return false; // 如果差异大于阈值,则返回 false
+			}
+		}
+
+		return true; // 所有元素之间的差异都小于阈值
+	}
+	bool USBDecoder::CheckTimeDifferenceWithinThreshold(const double* array, int32_t size, int32_t avg_span, double threshold)
+
+	{
+		for (int i = 2; i < size; i++)
+		{
+			//double absolute_difference = array[i] / avg_span;
+
+			double difference1 = std::abs(array[i] - avg_span);
+			double percentage_difference1 = difference1 / avg_span;
+
+			double difference2 = std::abs(array[i] - array[i - 1]);
+			double percentage_difference2 = difference2 / array[i - 1];
+			if (difference2 < 50)
+			{
+				if (isAutoClk_ || usbSpeed_ == USBEnums::USBSpeed::HIGH_SPEED)
+				{
+					threshold = USB_TIME_DIFFERENCE_THRESHOLD_HIGH_SPEED;
+				}
+				else
+				{
+					threshold = USB_TIME_DIFFERENCE_THRESHOLD;
+				}
+
+			}
+		 
+			if (percentage_difference1 > threshold && percentage_difference2 > threshold)
 			{
 				return false; // 如果差异大于阈值,则返回 false
 			}
@@ -212,7 +244,7 @@ namespace Protocol
 
 
 	bool USBDecoder::CheckSyncSpansByArray(const int32_t* start_indexs, const int32_t count,
-		int32_t& avg_spans)
+		int32_t& avg_span)
 	{
 		if (count < 1)
 		{
@@ -230,7 +262,8 @@ namespace Protocol
 		{
 			total_spans += std::abs(tmp_spans[2 + (i / 2)]);
 		}
-		avg_spans = static_cast<int>(total_spans / (count - 1));
+		avg_span = static_cast<int>(total_spans / (count - 1));
+		//return CheckTimeDifferenceWithinThreshold(tmp_spans, count - 1, avg_span);
 		return CheckTimeDifferenceWithinThreshold(tmp_spans, count - 1);
 	}
 

+ 75 - 74
ProtocolUSB/usb_decoder.h

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

+ 1 - 1
protocol_decode_base.h

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

TEMPAT SAMPAH
x64/Debug/ProtocolDecoder.dll


TEMPAT SAMPAH
x64/Debug/ProtocolDecoder.pdb