123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- // // ******************************************************************
- // // /\ /| @File Usb_packet.h
- // // \ V/ @Brief
- // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
- // // / | @Creation 2024-05-17
- // // / \\ @Modified 2024-06-24
- // // *(__\_\
- // // ******************************************************************
- #pragma once
- //#include <typeinfo>
- #include <vector>
- //#include "../BaseHelper//common_helper.h"
- //#include "../BaseEnums/protocol_enums.h"
- #include "../edge_pulse.h"
- #include "protocol_Usb_enums.h"
- #include "SYNC.h"
- namespace Protocol
- {
- class UsbPacket
- {
- public:
- UsbPacket();
- UsbPacket(TwoLevelEdgePulse* pid_node, int32_t& left_over_size, const Sync& sync, bool polarity,
- int32_t max_data_length);
- UsbEnums::UsbPacketType Type() const { return packet_type_; }
- uint8_t PID() const { return pid_; }
- void SetPID(const uint8_t value) { pid_ = value; }
- bool LastNRBZDataBit() const { return last_nrbz_data_bit_; }
- uint8_t RealPID() const { return static_cast<uint8_t>(pid_ & 0xF); }
- //const std::type_info& PIDType() const { return pidType; }
- //int PIDEndIndex() const { return pidEndIndex; }
- bool Polarity() const { return polarity_; }
- const Sync PacketSYNC() const { return packet_sync_; }
- const std::vector<uint8_t>& Address() const { return address_; }
- uint8_t EndPoint() const { return end_point_; }
- const std::vector<uint8_t>& Datas() const { return datas_; }
- uint16_t CRC16() const { return crc16_; }
- // //CRC数据有效位
- uint8_t CRCSignNum() const { return crc_sign_num_; }
- bool IsValid() const { return is_valid_; }
- bool IsCRCChecked() const { return is_crc_checked_; }
- UsbEnums::EventInfoTitles PacketTitle;
- int32_t GetEndIndex() const { return to_extracted_next_data_start_index_; }
- int32_t GetStartIndex() const { return packet_sync_.node_ptr->start_index; }
- private:
- UsbEnums::UsbPacketType packet_type_ = UsbEnums::UsbPacketType::NO_DEFINE;
- uint8_t pid_;
- bool last_nrbz_data_bit_;
- bool polarity_;
- Sync packet_sync_;
- std::vector<uint8_t> address_;
- uint8_t end_point_;
- std::vector<uint8_t> datas_;
- //CRC数据有效位
- uint8_t crc_sign_num_;
- uint16_t crc16_;
- bool is_valid_;
- bool is_crc_checked_;
- //待提取下个时域位标
- int32_t to_extracted_next_data_start_index_;
- //待nrzi解码下个时域位标
- int32_t to_nrzi_decode_next_data_start_index_;
- //最大可能数据时域长度
- int32_t max_possible_data_length_;
- static bool CheckNibblesInverse(uint8_t value);
- bool GetPID(TwoLevelEdgePulse* & pid_node);
- //bool DecodeNextByte(const Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, uint8_t& outData);
- bool GetNRZIData(TwoLevelEdgePulse* & node, int32_t need_bit_count, int32_t start_index,
- std::vector<bool>& out_data);
- bool DecodeNextByteByDataField(TwoLevelEdgePulse* & node, uint8_t& out_data);
- void NRBZToNormalData(const TwoLevelEdgePulse* node, int32_t need_bit_count, std::vector<bool> nrzi_data,
- uint8_t& out_data);
- bool DecodeNextByte(TwoLevelEdgePulse* & node, int32_t start_index, uint8_t& out_data);
- bool DecodeTokenBytes(TwoLevelEdgePulse* & node, UsbEnums::TokenPackageType type);
- void DecodeFields(TwoLevelEdgePulse* & node);
- void DecodeFieldsByToken(TwoLevelEdgePulse* & node);
- void DecodeFieldsByData(TwoLevelEdgePulse* & node);
- //void DecodeFieldsByHandShake(Protocol::TwoLevelEdgePulse* node, SYNC sync);
- void DecodeFieldsBySpecial(TwoLevelEdgePulse* & node) const;
- bool IsTokenPackageType() const;
- bool IsSpecialPacketType() const;
- bool IsHandshakePackageType(UsbEnums::HandshakePackageType& type) const;
- bool IsDataPackageType();
- };
- }
|