edge_pulse.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // // ******************************************************************
  2. // // /\ /| @File edge_pulse.h
  3. // // \ V/ @Brief
  4. // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
  5. // // / | @Creation 2024-05-16
  6. // // / \\ @Modified 2024-06-24
  7. // // *(__\_\
  8. // // ******************************************************************
  9. #pragma once
  10. #include <cstdint>
  11. #include "BaseEnums/protocol_enums.h"
  12. #include "BaseEnums/edge_pulse_enums.h"
  13. namespace Protocol
  14. {
  15. //基结构体,仅用于继承,不会实际使用
  16. struct EdgePulse
  17. {
  18. int32_t start_index = -1; //时域起始帧号
  19. int32_t end_index = -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 current_level = TwoLevelEdgePulseStatusType::None;
  30. static uint32_t LevelCount() { return 2; }
  31. int32_t GetLength() const
  32. {
  33. return end_index > start_index && start_index >= 0 ? end_index - start_index : 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 high_level, bool low_loglevel);
  49. //uint32_t LevelCount() const override { return 3; }
  50. static uint32_t LevelCount() { return 3; }
  51. explicit ThreeLevelEdgePulse(ThreeLevelEdgePulseStatusType current);
  52. ThreeLevelEdgePulseStatusType current_level = ThreeLevelEdgePulseStatusType::None;
  53. };
  54. //初查节点有效
  55. bool CheckNodeValid(const EdgePulse* edge);
  56. //初查节点有效
  57. bool CheckNodeValid(EdgePulse edge);
  58. //电平反转
  59. void ReversalLevel(Edge& edge);
  60. //电平反转
  61. void ReversalLevel(std::vector<EdgePulse>& edge_pulses);
  62. }