123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- // // ******************************************************************
- // // /\ /| @File USBPacket.h
- // // \ V/ @Brief
- // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
- // // / | @Creation 2024-1-3
- // // / \\ @Modified 2024-1-15
- // // *(__\_\
- // // ******************************************************************
- #pragma once
- #include <typeinfo>
- #include <vector>
- #include "../BaseHelper//CommonHelper.h"
- #include "../BaseEnums/ProtocolEnums.h"
- #include "../EdgePulse.h"
- #include "SYNC.h"
- #include "ProtocolUSBEnums.h"
- namespace Protocol
- {
- class USBPacket
- {
- public:
- USBPacket();
- USBPacket(Protocol::TwoLevelEdgePulse* pidNode, int32_t& leftOverSize, SYNC sync, bool polarity);
- Enums::USBPacketType Type() const { return type; }
- uint8_t PID() const { return pid; }
- void SetPID(uint8_t value) { pid = value; }
- bool LastNRBZDataBit() const { return lastNRBZDataBit; }
- 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 packetSYNC; }
- const std::vector<uint8_t>& Address() const { return address; }
- uint8_t EndPoint() const { return endPoint; }
- const std::vector<uint8_t>& Datas() const { return datas; }
- uint8_t CRC5() const { return crc5; }
- bool IsValid() const { return isValid; }
- bool IsCRCChecked() const { return isCRCChecked; }
- private:
- Enums::USBPacketType type = Enums::USBPacketType::NoDefine;
- uint8_t pid;
- bool lastNRBZDataBit;
- //std::type_info& pidType;
- //int pidEndIndex;
- bool polarity;
- SYNC packetSYNC;
- std::vector<uint8_t> address;
- uint8_t endPoint;
- std::vector<uint8_t> datas;
- uint8_t crc5;
- bool isValid;
- bool isCRCChecked;
- bool CheckNibblesInverse(uint8_t value);
- bool GetPID(Protocol::TwoLevelEdgePulse* pidNode, int32_t& leftOverSize);
- bool DecodeNextByte(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, uint8_t& outData);
- void DecodeFields(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC& sync);
- void DecodeFieldsByToken(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC& sync);
- void DecodeFieldsByData(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC sync);
- void DecodeFieldsByHandShake(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, SYNC sync);
- void DecodeFieldsBySpecial(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, SYNC sync);
- };
- }
|