EdgePulse.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // // ******************************************************************
  2. // // /\ /| @File EdgePulse.h
  3. // // \ V/ @Brief
  4. // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
  5. // // / | @Creation 2024-05-16
  6. // // / \\ @Modified 2024-05-16
  7. // // *(__\_\
  8. // // ******************************************************************
  9. #pragma once
  10. #include <cstdint>
  11. #include "BaseEnums/ProtocolEnums.h"
  12. #include "BaseEnums/EdgePulseEnums.h"
  13. namespace Protocol
  14. {
  15. //基结构体,仅用于继承,不会实际使用
  16. struct EdgePulse
  17. {
  18. int32_t StartIndex = -1; //时域起始帧号
  19. int32_t EndIndex = -1; //时域结束帧号
  20. Edge Edge = Edge::None; //边沿类型 上升 or 下降
  21. // virtual uint32_t LevelCount() const { return 0; } //电平数量 2or3
  22. // virtual int32_t GetLength() const; //时域长度
  23. // virtual ~EdgePulse() = default;
  24. };
  25. //双电平边沿脉宽
  26. struct TwoLevelEdgePulse final : EdgePulse
  27. {
  28. //电平类型 Low, High, None,
  29. TwoLevelEdgePulseStatusType CurrentLevel = TwoLevelEdgePulseStatusType::None;
  30. static uint32_t LevelCount() { return 2; }
  31. int32_t GetLength() const
  32. {
  33. return EndIndex > StartIndex && StartIndex > 0 ? EndIndex - StartIndex : 0;
  34. }
  35. // uint32_t LevelCount() const override { return 2; }
  36. //
  37. // int32_t GetLength() const override
  38. // {
  39. // return EndIndex > StartIndex && StartIndex > 0 ? EndIndex - StartIndex : 0;
  40. // }
  41. //
  42. // explicit TwoLevelEdgePulse(TwoLevelEdgePulseStatusType current);
  43. };
  44. //三电平边沿脉宽
  45. struct ThreeLevelEdgePulse final : EdgePulse
  46. {
  47. //电平类型 High = 0b11,Middle = 0b01,Low = 0b00,None = 0b10,
  48. static ThreeLevelEdgePulseStatusType ConvertToStatus(bool highLevel, bool lowLoglevel);
  49. //uint32_t LevelCount() const override { return 3; }
  50. static uint32_t LevelCount() { return 3; }
  51. explicit ThreeLevelEdgePulse(ThreeLevelEdgePulseStatusType current);
  52. ThreeLevelEdgePulseStatusType CurrentLevel = ThreeLevelEdgePulseStatusType::None;
  53. };
  54. }