// // ****************************************************************** // // /\ /| @File Usb_decoder.h // // \ V/ @Brief // // | "") @Author lijinwen, ghz005@uni-trend.com.cn // // / | @Creation 2024-05-17 // // / \\ @Modified 2024-06-24 // // *(__\_\ // // ****************************************************************** #pragma once #include #include #include #include #include #include "../edge_pulse_data.h" #include "../edge_pulse.h" #include "../protocol_decode_base.h" #include "SYNC.h" #include "protocol_Usb_enums.h" #include "Usb_decode_options.h" #include "Usb_decode_result.h" #include "Usb_packet.h" #include "../BaseHelper//common_helper.h" namespace Protocol { class UsbDecoder { public: UsbDecoder() : is_cancel_ptr_(nullptr), usb_speed_(), is_auto_clk_(false), usb_diff_signal_real_edges_count_(0), wave_max_time_index_len_(0) { difference_eop_index_ = {}; result_cells_ = {}; result_events_ = {}; usb_packets_ = {}; sign_edge_pulse_ = {}; } static std::vector EventInfoTitles(); bool DecodeUsb(const UsbDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_dp, const EdgePulseDataTwoLevels& edge_pulses_dm, UsbDecodeResult& result); ~UsbDecoder() { } private: bool* is_cancel_ptr_; UsbEnums::UsbSpeed usb_speed_; bool is_auto_clk_; std::vector result_cells_; std::vector result_events_; std::vector usb_packets_; std::vector difference_eop_index_; std::vector sign_edge_pulse_; //Usb差分信号非对齐位置 std::vector usb_diff_unaligned_frames_index_; //差分信号可用长度 int32_t usb_diff_signal_real_edges_count_; //传入波形最大时域长度 int32_t wave_max_time_index_len_; //同步帧长度 int32_t sync_bit_len_ = USB_USB_SYNC_BIT_MAX_LEN; bool ParseDiffSignalData(std::vector edge_pulses_dp, std::vector edge_pulses_dm) { //找出非对称边沿 //todo add differenceEopIndexs //temp sign_edge_pulse_ = 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); //bool GetPolarty(TwoLevelEdgePulse* node, double set_bit_time_span, int& last_valid_data_index); bool GetPolarty(TwoLevelEdgePulse* node, double set_bit_time_span); static void ClearEdgeArray(Edge* edges, int32_t size); static bool CheckSyncEdges(Edge start_edge, const Edge* edges); //检查同步域在时域间隔 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& all_sync // , double set_bit_time_span, bool force_normal_speed, bool polarity = false); bool FindAllSyncs(TwoLevelEdgePulse* node, std::vector& all_sync , double set_bit_time_span, bool polarity, int32_t& last_valid_data_index); // static bool FindAllSyncs(Protocol::TwoLevelEdgePulse* node, int32_t left_over_size, // std::vector& all_sync, bool polarity = false); bool FindPackets(int32_t& left_over_size, std::vector& all_packet, double set_bit_time_span); bool CheckOptions(UsbDecodeOptions option, const std::vector& edge_pulses_dp, const std::vector& edge_pulses_dm, double& set_bit_time_span); bool ParseSingleData(double set_bit_time_span, bool auto_clock); }; }