USBPacket.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // // ******************************************************************
  2. // // /\ /| @File USBPacket.h
  3. // // \ V/ @Brief
  4. // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
  5. // // / | @Creation 2024-1-3
  6. // // / \\ @Modified 2024-1-15
  7. // // *(__\_\
  8. // // ******************************************************************
  9. #pragma once
  10. #include <typeinfo>
  11. #include <vector>
  12. #include "../BaseHelper//CommonHelper.h"
  13. #include "../BaseEnums/ProtocolEnums.h"
  14. #include "../EdgePulse.h"
  15. #include "SYNC.h"
  16. #include "ProtocolUSBEnums.h"
  17. namespace Protocol
  18. {
  19. class USBPacket
  20. {
  21. public:
  22. USBPacket();
  23. USBPacket(Protocol::TwoLevelEdgePulse* pidNode, int32_t& leftOverSize, SYNC sync, bool polarity);
  24. Enums::USBPacketType Type() const { return type; }
  25. uint8_t PID() const { return pid; }
  26. void SetPID(uint8_t value) { pid = value; }
  27. bool LastNRBZDataBit() const { return lastNRBZDataBit; }
  28. uint8_t RealPID() const { return static_cast<uint8_t>(pid & 0xF); }
  29. //const std::type_info& PIDType() const { return pidType; }
  30. //int PIDEndIndex() const { return pidEndIndex; }
  31. bool Polarity() const { return polarity; }
  32. const SYNC PacketSYNC() const { return packetSYNC; }
  33. const std::vector<uint8_t>& Address() const { return address; }
  34. uint8_t EndPoint() const { return endPoint; }
  35. const std::vector<uint8_t>& Datas() const { return datas; }
  36. uint8_t CRC5() const { return crc5; }
  37. bool IsValid() const { return isValid; }
  38. bool IsCRCChecked() const { return isCRCChecked; }
  39. private:
  40. Enums::USBPacketType type = Enums::USBPacketType::NoDefine;
  41. uint8_t pid;
  42. bool lastNRBZDataBit;
  43. //std::type_info& pidType;
  44. //int pidEndIndex;
  45. bool polarity;
  46. SYNC packetSYNC;
  47. std::vector<uint8_t> address;
  48. uint8_t endPoint;
  49. std::vector<uint8_t> datas;
  50. uint8_t crc5;
  51. bool isValid;
  52. bool isCRCChecked;
  53. bool CheckNibblesInverse(uint8_t value);
  54. bool GetPID(Protocol::TwoLevelEdgePulse* pidNode, int32_t& leftOverSize);
  55. bool DecodeNextByte(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, uint8_t& outData);
  56. void DecodeFields(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC& sync);
  57. void DecodeFieldsByToken(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC& sync);
  58. void DecodeFieldsByData(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, const SYNC sync);
  59. void DecodeFieldsByHandShake(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, SYNC sync);
  60. void DecodeFieldsBySpecial(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, SYNC sync);
  61. };
  62. }