sync.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // // ******************************************************************
  2. // // /\ /| @File SYNC.h
  3. // // \ V/ @Brief
  4. // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
  5. // // / | @Creation 2024-05-17
  6. // // / \\ @Modified 2024-06-24
  7. // // *(__\_\
  8. // // ******************************************************************
  9. #pragma once
  10. #include "Constants.h"
  11. namespace Protocol
  12. {
  13. class Sync
  14. {
  15. public:
  16. TwoLevelEdgePulse* node_ptr;
  17. int32_t end_index;
  18. int32_t single_bit_timing_length;
  19. int32_t one_byte_timing_length;
  20. int32_t Length() const
  21. {
  22. if (node_ptr == nullptr || node_ptr->start_index < 0)
  23. {
  24. return 0;
  25. }
  26. return end_index - node_ptr->start_index;
  27. }
  28. int32_t PacketEndIndex() const
  29. {
  30. return packetEndIndex;
  31. }
  32. void SetPacketEndIndex(const int32_t value)
  33. {
  34. packetEndIndex = value;
  35. }
  36. Sync() : node_ptr(nullptr), end_index(0), single_bit_timing_length(0), one_byte_timing_length(0), packetEndIndex(0)
  37. {
  38. }
  39. Sync(TwoLevelEdgePulse* node_ptr,const int end_index, const int32_t single_bit_timing_length, const bool is_high_speed) : node_ptr(node_ptr),
  40. end_index(end_index),
  41. single_bit_timing_length(single_bit_timing_length),
  42. one_byte_timing_length(single_bit_timing_length * USB_BYTE_BIT_COUNT),
  43. packetEndIndex(0)
  44. {
  45. const int32_t sync_byte_len = is_high_speed ? USB_USB_SYNC_BIT_MAX_LEN : USB_BYTE_BIT_COUNT;
  46. const int32_t fix_sync_end_index = node_ptr->start_index + static_cast<int32_t>(single_bit_timing_length * sync_byte_len
  47. * USB_SYNC_BIT_TOL);
  48. if (end_index < fix_sync_end_index)
  49. {
  50. this->end_index = fix_sync_end_index;
  51. }
  52. }
  53. private:
  54. int32_t packetEndIndex;
  55. };
  56. }